diff options
author | frosch <frosch@openttd.org> | 2013-12-23 18:08:16 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2013-12-23 18:08:16 +0000 |
commit | 3eea1befa73099c6af00ea56c55087592b99039a (patch) | |
tree | 396f28548a495150af9bb5ee0dffa4aace3518f2 | |
parent | 82eb9d13df0b12ab3125b81f362f4dcd2f907c43 (diff) | |
download | openttd-3eea1befa73099c6af00ea56c55087592b99039a.tar.xz |
(svn r26172) -Codechange: Make SpriteGroup::Resolve aware of nested calls.
-rw-r--r-- | src/newgrf_spritegroup.cpp | 32 | ||||
-rw-r--r-- | src/newgrf_spritegroup.h | 14 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 2c3d19ff1..451cd59be 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -17,6 +17,25 @@ SpriteGroupPool _spritegroup_pool("SpriteGroup"); INSTANTIATE_POOL_METHODS(SpriteGroup) +TemporaryStorageArray<int32, 0x110> _temp_store; + + +/** + * ResolverObject (re)entry point. + * This cannot be made a call to a virtual function because virtual functions + * do not like NULL and checking for NULL *everywhere* is more cumbersome than + * this little helper function. + * @param group the group to resolve for + * @param object information needed to resolve the group + * @param top_level true if this is a top-level SpriteGroup, false if used nested in another SpriteGroup. + * @return the resolved group + */ +/* static */ const SpriteGroup *SpriteGroup::Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level) +{ + if (group == NULL) return NULL; + return group->Resolve(object); +} + RealSpriteGroup::~RealSpriteGroup() { free(this->loaded); @@ -34,9 +53,6 @@ RandomizedSpriteGroup::~RandomizedSpriteGroup() free(this->groups); } -TemporaryStorageArray<int32, 0x110> _temp_store; - - static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available) { /* First handle variables common with Action7/9/D */ @@ -230,7 +246,7 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) con /* Try to get the variable. We shall assume it is available, unless told otherwise. */ bool available = true; if (adjust->variable == 0x7E) { - const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust->subroutine, object); + const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust->subroutine, object, false); if (subgroup == NULL) { value = CALLBACK_FAILED; } else { @@ -247,7 +263,7 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) con if (!available) { /* Unsupported variable: skip further processing and return either * the group from the first range or the default group. */ - return SpriteGroup::Resolve(this->num_ranges > 0 ? this->ranges[0].group : this->default_group, object); + return SpriteGroup::Resolve(this->num_ranges > 0 ? this->ranges[0].group : this->default_group, object, false); } switch (this->size) { @@ -271,11 +287,11 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) con for (i = 0; i < this->num_ranges; i++) { if (this->ranges[i].low <= value && value <= this->ranges[i].high) { - return SpriteGroup::Resolve(this->ranges[i].group, object); + return SpriteGroup::Resolve(this->ranges[i].group, object, false); } } - return SpriteGroup::Resolve(this->default_group, object); + return SpriteGroup::Resolve(this->default_group, object, false); } @@ -302,7 +318,7 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const uint32 mask = (this->num_groups - 1) << this->lowest_randbit; byte index = (scope->GetRandomBits() & mask) >> this->lowest_randbit; - return SpriteGroup::Resolve(this->groups[index], object); + return SpriteGroup::Resolve(this->groups[index], object, false); } diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index da26c1a0e..e6eb4fbcb 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -81,19 +81,7 @@ public: virtual byte GetNumResults() const { return 0; } virtual uint16 GetCallbackResult() const { return CALLBACK_FAILED; } - /** - * ResolverObject (re)entry point. - * This cannot be made a call to a virtual function because virtual functions - * do not like NULL and checking for NULL *everywhere* is more cumbersome than - * this little helper function. - * @param group the group to resolve for - * @param object information needed to resolve the group - * @return the resolved group - */ - static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject &object) - { - return group == NULL ? NULL : group->Resolve(object); - } + static const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level = true); }; |