diff options
author | rubidium <rubidium@openttd.org> | 2009-05-23 15:25:52 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-05-23 15:25:52 +0000 |
commit | f2317d0d9d74c3f5d14530c14b314ad32d05ef80 (patch) | |
tree | fa8a51810dfc5e6bb93d389b67c2815ce1d90967 /src/newgrf_spritegroup.h | |
parent | 8d072585aecc4ff35c922f482d99aef194e0a311 (diff) | |
download | openttd-f2317d0d9d74c3f5d14530c14b314ad32d05ef80.tar.xz |
(svn r16402) -Codechange: make Resolve a function of SpriteGroup
Diffstat (limited to 'src/newgrf_spritegroup.h')
-rw-r--r-- | src/newgrf_spritegroup.h | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 13cfb19c6..e6bbeb9d3 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -50,6 +50,8 @@ extern SpriteGroupPool _spritegroup_pool; struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> { protected: SpriteGroup(SpriteGroupType type) : type(type) {} + /** Base sprite group resolver */ + virtual const SpriteGroup *Resolve(struct ResolverObject *object) const { return this; }; public: virtual ~SpriteGroup() {} @@ -59,6 +61,20 @@ public: virtual SpriteID GetResult() const { return 0; } 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); + } }; @@ -79,6 +95,9 @@ struct RealSpriteGroup : SpriteGroup { byte num_loading; ///< Number of loading groups const SpriteGroup **loaded; ///< List of loaded groups (can be SpriteIDs or Callback results) const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results) + +protected: + const SpriteGroup *Resolve(ResolverObject *object) const; }; /* Shared by deterministic and random groups. */ @@ -159,6 +178,9 @@ struct DeterministicSpriteGroup : SpriteGroup { /* Dynamically allocated, this is the sole owner */ const SpriteGroup *default_group; + +protected: + const SpriteGroup *Resolve(ResolverObject *object) const; }; enum RandomizedSpriteGroupCompareMode { @@ -180,6 +202,9 @@ struct RandomizedSpriteGroup : SpriteGroup { byte num_groups; ///< must be power of 2 const SpriteGroup **groups; ///< Take the group with appropriate index: + +protected: + const SpriteGroup *Resolve(ResolverObject *object) const; }; @@ -316,9 +341,4 @@ struct ResolverObject { ResolverObject() : procedure_call(false) { } }; - -/* Base sprite group resolver */ -const SpriteGroup *Resolve(const SpriteGroup *group, ResolverObject *object); - - #endif /* NEWGRF_SPRITEGROUP_H */ |