# HG changeset patch # User frosch # Date 2013-12-23 18:08:16 # Node ID 1f99ef8ae88f7641b2eb0215e7ed9b67541960f8 # Parent 647d6358127c2b931ede6ee604258a450762c29e (svn r26172) -Codechange: Make SpriteGroup::Resolve aware of nested calls. diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -17,6 +17,25 @@ SpriteGroupPool _spritegroup_pool("SpriteGroup"); INSTANTIATE_POOL_METHODS(SpriteGroup) +TemporaryStorageArray _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::~RandomizedSprite free(this->groups); } -TemporaryStorageArray _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 *DeterministicSpriteGr /* 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 *DeterministicSpriteGr 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 *DeterministicSpriteGr 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 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 --- 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); };