From c9d9152e4533c6a7ac9480836e191712f6746faa Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 2 Apr 2013 13:48:16 -0400 Subject: [PATCH] convert all instances of copy+pasted type-system code to use the new macros --- src/effects/dimeffect.h | 8 +-- src/effects/effect.h | 39 +----------- src/effects/fadeeffect.h | 8 +-- src/effects/flasheffect.h | 8 +-- src/entities/component.h | 39 +----------- .../components/entitypresetcomponent.h | 8 +-- src/entities/components/inactivecomponent.h | 8 +-- src/entities/componentsystem.h | 39 +----------- src/entities/entitypreset.h | 39 +----------- src/entities/entitypresetargs.h | 37 +---------- src/entities/globalcomponent.h | 39 +----------- src/events/event.h | 38 +---------- src/framework/assets/animation/keyframemesh.h | 8 +-- src/framework/assets/animation/skeletalmesh.h | 8 +-- src/framework/assets/static/staticmesh.h | 8 +-- src/framework/content/content.h | 63 +------------------ src/framework/graphics/image.h | 8 +-- src/framework/graphics/spritefont.h | 8 +-- src/framework/graphics/texture.h | 8 +-- src/game/debuginfoprocess.h | 8 +-- src/game/testingstate.h | 8 +-- src/processes/gameprocess.h | 39 +----------- src/processes/gwengameprocess.h | 8 +-- src/states/gamestate.h | 39 +----------- src/states/gwengamestate.h | 8 +-- 25 files changed, 59 insertions(+), 472 deletions(-) diff --git a/src/effects/dimeffect.h b/src/effects/dimeffect.h index 2dabf4b..f790734 100644 --- a/src/effects/dimeffect.h +++ b/src/effects/dimeffect.h @@ -2,6 +2,7 @@ #define __EFFECTS_DIMEFFECT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "effect.h" #include "../framework/graphics/color.h" @@ -10,12 +11,7 @@ class RenderContext; class DimEffect : public Effect { public: - static EFFECT_TYPE GetType() - { - static EFFECT_TYPE typeName = "DimEffect"; - return typeName; - } - EFFECT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(EFFECT_TYPE, "DimEffect"); DimEffect(); virtual ~DimEffect(); diff --git a/src/effects/effect.h b/src/effects/effect.h index ae148b4..0d0aa9b 100644 --- a/src/effects/effect.h +++ b/src/effects/effect.h @@ -2,6 +2,7 @@ #define __EFFECTS_EFFECT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" class RenderContext; @@ -10,6 +11,8 @@ typedef const char* EFFECT_TYPE; class Effect { public: + TYPE_BASE(EFFECT_TYPE); + Effect(); virtual ~Effect(); @@ -28,13 +31,6 @@ public: BOOL IsActive() const { return m_isActive; } void MarkInactive(); - virtual EFFECT_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(EFFECT_TYPE type) const; - template T* As(); - template const T* As() const; - private: BOOL m_isActive; }; @@ -53,34 +49,5 @@ inline void Effect::MarkInactive() m_isActive = FALSE; } -template -inline BOOL Effect::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL Effect::Is(EFFECT_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* Effect::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* Effect::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/effects/fadeeffect.h b/src/effects/fadeeffect.h index 23b16c0..9632582 100644 --- a/src/effects/fadeeffect.h +++ b/src/effects/fadeeffect.h @@ -2,6 +2,7 @@ #define __EFFECTS_FADEEFFECT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "effect.h" #include "../framework/graphics/color.h" @@ -10,12 +11,7 @@ class RenderContext; class FadeEffect : public Effect { public: - static EFFECT_TYPE GetType() - { - static EFFECT_TYPE typeName = "FadeEffect"; - return typeName; - } - EFFECT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(EFFECT_TYPE, "FadeEffect"); FadeEffect(); virtual ~FadeEffect(); diff --git a/src/effects/flasheffect.h b/src/effects/flasheffect.h index 21d1dc8..b4ceb2d 100644 --- a/src/effects/flasheffect.h +++ b/src/effects/flasheffect.h @@ -2,6 +2,7 @@ #define __EFFECTS_FLASHEFFECT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "effect.h" #include "../framework/graphics/color.h" @@ -10,12 +11,7 @@ class RenderContext; class FlashEffect : public Effect { public: - static EFFECT_TYPE GetType() - { - static EFFECT_TYPE typeName = "FlashEffect"; - return typeName; - } - EFFECT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(EFFECT_TYPE, "FlashEffect"); FlashEffect(); virtual ~FlashEffect(); diff --git a/src/entities/component.h b/src/entities/component.h index 2dbcd74..f51ffc1 100644 --- a/src/entities/component.h +++ b/src/entities/component.h @@ -2,21 +2,17 @@ #define __ENTITIES_COMPONENT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" typedef const char* COMPONENT_TYPE; class Component { public: + TYPE_BASE(COMPONENT_TYPE); + virtual ~Component(); virtual void Reset(); - - virtual COMPONENT_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(COMPONENT_TYPE type) const; - template T* As(); - template const T* As() const; }; inline Component::~Component() @@ -27,34 +23,5 @@ inline void Component::Reset() { } -template -inline BOOL Component::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL Component::Is(COMPONENT_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* Component::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* Component::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/entities/components/entitypresetcomponent.h b/src/entities/components/entitypresetcomponent.h index 2d57af4..7ff4a12 100644 --- a/src/entities/components/entitypresetcomponent.h +++ b/src/entities/components/entitypresetcomponent.h @@ -3,16 +3,12 @@ #include "../component.h" #include "../entitypreset.h" +#include "../../framework/util/typesystem.h" class EntityPresetComponent : public Component { public: - static COMPONENT_TYPE GetType() - { - static COMPONENT_TYPE typeName = "EntityPresetComponent"; - return typeName; - } - COMPONENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(COMPONENT_TYPE, "EntityPresetComponent"); EntityPresetComponent(); void Reset(); diff --git a/src/entities/components/inactivecomponent.h b/src/entities/components/inactivecomponent.h index a39fc2b..da6f9fa 100644 --- a/src/entities/components/inactivecomponent.h +++ b/src/entities/components/inactivecomponent.h @@ -2,16 +2,12 @@ #define __ENTITIES_COMPONENTS_INACTIVECOMPONENT_H_INCLUDED__ #include "../component.h" +#include "../../framework/util/typesystem.h" class InactiveComponent : public Component { public: - static COMPONENT_TYPE GetType() - { - static COMPONENT_TYPE typeName = "InactiveComponent"; - return typeName; - } - COMPONENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(COMPONENT_TYPE, "InactiveComponent"); }; #endif diff --git a/src/entities/componentsystem.h b/src/entities/componentsystem.h index adc5b53..5192dc2 100644 --- a/src/entities/componentsystem.h +++ b/src/entities/componentsystem.h @@ -2,6 +2,7 @@ #define __ENTITIES_COMPONENTSYSTEM_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "../events/eventlistenerex.h" class EntityManager; @@ -14,6 +15,8 @@ typedef const char* COMPONENTSYSTEM_TYPE; class ComponentSystem : public EventListenerEx { public: + TYPE_BASE(COMPONENTSYSTEM_TYPE); + virtual ~ComponentSystem(); virtual void OnLostContext() {} @@ -24,13 +27,6 @@ public: virtual BOOL Handle(const Event *event); - virtual COMPONENTSYSTEM_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(COMPONENTSYSTEM_TYPE type) const; - template T* As(); - template const T* As() const; - protected: ComponentSystem(EntityManager *entityManager, EventManager *eventManager); @@ -55,34 +51,5 @@ inline BOOL ComponentSystem::Handle(const Event *event) return FALSE; } -template -inline BOOL ComponentSystem::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL ComponentSystem::Is(COMPONENTSYSTEM_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* ComponentSystem::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* ComponentSystem::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/entities/entitypreset.h b/src/entities/entitypreset.h index 2c7b261..e7b9185 100644 --- a/src/entities/entitypreset.h +++ b/src/entities/entitypreset.h @@ -2,6 +2,7 @@ #define __ENTITIES_ENTITYPRESET_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "entitypresetargs.h" typedef const char* ENTITYPRESET_TYPE; @@ -12,16 +13,11 @@ class EntityManager; class EntityPreset { public: + TYPE_BASE(ENTITYPRESET_TYPE); + EntityPreset(EntityManager *entityManager); virtual ~EntityPreset(); - virtual ENTITYPRESET_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(ENTITYPRESET_TYPE type) const; - template T* As(); - template const T* As() const; - virtual Entity* Create(EntityPresetArgs *args = NULL) = 0; protected: @@ -40,33 +36,4 @@ inline EntityPreset::~EntityPreset() { } -template -inline BOOL EntityPreset::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL EntityPreset::Is(ENTITYPRESET_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* EntityPreset::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* EntityPreset::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/entities/entitypresetargs.h b/src/entities/entitypresetargs.h index 8382536..8498363 100644 --- a/src/entities/entitypresetargs.h +++ b/src/entities/entitypresetargs.h @@ -2,46 +2,13 @@ #define __ENTITIES_ENTITYPRESETARGS_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" typedef const char* ENTITYPRESETARGS_TYPE; struct EntityPresetArgs { - virtual ENTITYPRESETARGS_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(ENTITYPRESETARGS_TYPE type) const; - template T* As(); - template const T* As() const; + TYPE_BASE(ENTITYPRESETARGS_TYPE); }; -template -inline BOOL EntityPresetArgs::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL EntityPresetArgs::Is(ENTITYPRESETARGS_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* EntityPresetArgs::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* EntityPresetArgs::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/entities/globalcomponent.h b/src/entities/globalcomponent.h index 7875407..e272a52 100644 --- a/src/entities/globalcomponent.h +++ b/src/entities/globalcomponent.h @@ -2,21 +2,17 @@ #define __ENTITIES_GLOBALCOMPONENT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" typedef const char* GLOBAL_COMPONENT_TYPE; class GlobalComponent { public: + TYPE_BASE(GLOBAL_COMPONENT_TYPE); + virtual ~GlobalComponent(); virtual void Reset(); - - virtual GLOBAL_COMPONENT_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(GLOBAL_COMPONENT_TYPE type) const; - template T* As(); - template const T* As() const; }; inline GlobalComponent::~GlobalComponent() @@ -27,34 +23,5 @@ inline void GlobalComponent::Reset() { } -template -inline BOOL GlobalComponent::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL GlobalComponent::Is(GLOBAL_COMPONENT_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* GlobalComponent::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* GlobalComponent::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/events/event.h b/src/events/event.h index 0f8cb88..705993c 100644 --- a/src/events/event.h +++ b/src/events/event.h @@ -2,6 +2,7 @@ #define __EVENTS_EVENT_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" typedef const char* EVENT_TYPE; @@ -9,46 +10,13 @@ const EVENT_TYPE EVENT_TYPE_WILDCARD = "EventWildcard"; struct Event { + TYPE_BASE(EVENT_TYPE); + virtual ~Event(); - virtual EVENT_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(EVENT_TYPE type) const; - template T* As(); - template const T* As() const; }; inline Event::~Event() { } -template -inline BOOL Event::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL Event::Is(EVENT_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* Event::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* Event::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/framework/assets/animation/keyframemesh.h b/src/framework/assets/animation/keyframemesh.h index 3e29e50..181e3c2 100644 --- a/src/framework/assets/animation/keyframemesh.h +++ b/src/framework/assets/animation/keyframemesh.h @@ -5,6 +5,7 @@ #include #include "../../support/animationsequence.h" #include "../../content/content.h" +#include "../../util/typesystem.h" class Keyframe; class KeyframeMeshFile; @@ -19,12 +20,7 @@ class VertexBuffer; class KeyframeMesh : public Content { public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "KeyframeMesh"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "KeyframeMesh"); /** * Creates a keyframe mesh object. diff --git a/src/framework/assets/animation/skeletalmesh.h b/src/framework/assets/animation/skeletalmesh.h index e822f3d..94002a9 100644 --- a/src/framework/assets/animation/skeletalmesh.h +++ b/src/framework/assets/animation/skeletalmesh.h @@ -4,6 +4,7 @@ #include "../../common.h" #include "../../support/animationsequence.h" #include "../../content/content.h" +#include "../../util/typesystem.h" #include class SkeletalMeshFile; @@ -18,12 +19,7 @@ class SkeletalMesh : public Content friend class SkeletalMeshFile; public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "SkeletalMesh"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "SkeletalMesh"); virtual ~SkeletalMesh(); diff --git a/src/framework/assets/static/staticmesh.h b/src/framework/assets/static/staticmesh.h index fcedf64..b06843c 100644 --- a/src/framework/assets/static/staticmesh.h +++ b/src/framework/assets/static/staticmesh.h @@ -3,6 +3,7 @@ #include "../../common.h" #include "../../content/content.h" +#include "../../util/typesystem.h" class ContentManager; class StaticMeshFile; @@ -14,12 +15,7 @@ class StaticMeshSubset; class StaticMesh : public Content { public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "StaticMesh"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "StaticMesh"); /** * Creates a static mesh object. diff --git a/src/framework/content/content.h b/src/framework/content/content.h index ef98af4..4ce113b 100644 --- a/src/framework/content/content.h +++ b/src/framework/content/content.h @@ -2,6 +2,7 @@ #define __FRAMEWORK_CONTENT_CONTENT_H_INCLUDED__ #include "../common.h" +#include "../util/typesystem.h" class ContentLoaderBase; @@ -16,6 +17,8 @@ class Content friend class ContentLoaderBase; public: + TYPE_BASE(CONTENT_TYPE); + Content(); virtual ~Content(); @@ -38,37 +41,6 @@ public: * @return the number of references currently being held for this content */ uint32_t GetNumReferences() const { return m_referenceCount; } - - /** - * @return the type of content being held in this object - */ - virtual CONTENT_TYPE GetTypeOf() const = 0; - - /** - * @param the type of content to check - * @return TRUE if this content object is of type T - */ - template BOOL Is() const; - - /** - * @param type the content type to check - * @return TRUE if this content object is the same as the type specified - */ - BOOL Is(CONTENT_TYPE type) const; - - /** - * @param the type of content to attempt to cast to - * @return this content object casted to type T if this content object - * is of type T, or NULL if the types don't match - */ - template T* As(); - - /** - * @param the type of content to attempt to cast to - * @return this content object casted to type T if this content object - * is of type T, or NULL if the types don't match - */ - template const T* As() const; private: /** @@ -86,34 +58,5 @@ private: uint32_t m_referenceCount; }; -template -inline BOOL Content::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL Content::Is(CONTENT_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* Content::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* Content::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/framework/graphics/image.h b/src/framework/graphics/image.h index cb7e9cc..0332db2 100644 --- a/src/framework/graphics/image.h +++ b/src/framework/graphics/image.h @@ -3,6 +3,7 @@ #include "../common.h" #include "../content/content.h" +#include "../util/typesystem.h" #include "color.h" #include "imageformats.h" @@ -15,12 +16,7 @@ class File; class Image : public Content { public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "Image"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "Image"); Image(); virtual ~Image() { Release(); } diff --git a/src/framework/graphics/spritefont.h b/src/framework/graphics/spritefont.h index 88c13bd..98575a3 100644 --- a/src/framework/graphics/spritefont.h +++ b/src/framework/graphics/spritefont.h @@ -3,6 +3,7 @@ #include "../common.h" #include "../content/content.h" +#include "../util/typesystem.h" class Texture; class TextureAtlas; @@ -18,12 +19,7 @@ const uint8_t HIGH_GLYPH = 127; class SpriteFont : public Content { public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "SpriteFont"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "SpriteFont"); /** * Creates an uninitialized sprite font object. diff --git a/src/framework/graphics/texture.h b/src/framework/graphics/texture.h index f46968e..430143a 100644 --- a/src/framework/graphics/texture.h +++ b/src/framework/graphics/texture.h @@ -3,6 +3,7 @@ #include "../common.h" #include "../content/content.h" +#include "../util/typesystem.h" #include "textureformats.h" class GraphicsDevice; @@ -14,12 +15,7 @@ class Image; class Texture : public Content { public: - static CONTENT_TYPE GetType() - { - static CONTENT_TYPE typeName = "Texture"; - return typeName; - } - CONTENT_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(CONTENT_TYPE, "Texture"); Texture(); virtual ~Texture(); diff --git a/src/game/debuginfoprocess.h b/src/game/debuginfoprocess.h index fe47844..d5bfa19 100644 --- a/src/game/debuginfoprocess.h +++ b/src/game/debuginfoprocess.h @@ -2,6 +2,7 @@ #define __GAME_DEBUGINFOPROCESS_H_INCLUDED__ #include "../processes/gameprocess.h" +#include "../framework/util/typesystem.h" class GameState; class ProcessManager; @@ -10,12 +11,7 @@ class RenderContext; class DebugInfoProcess : public GameProcess { public: - static GAMEPROCESS_TYPE GetType() - { - static GAMEPROCESS_TYPE typeName = "DebugInfoProcess"; - return typeName; - } - GAMEPROCESS_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(GAMEPROCESS_TYPE, "DebugInfoProcess"); DebugInfoProcess(GameState *gameState, ProcessManager *processManager); virtual ~DebugInfoProcess(); diff --git a/src/game/testingstate.h b/src/game/testingstate.h index 243c6e5..89b1b3b 100644 --- a/src/game/testingstate.h +++ b/src/game/testingstate.h @@ -2,6 +2,7 @@ #define __GAME_TESTINGSTATE_H_INCLUDED__ #include "../states/gamestate.h" +#include "../framework/util/typesystem.h" class FreeCamera; class GameApp; @@ -12,12 +13,7 @@ class StateManager; class TestingState : public GameState { public: - static GAMESTATE_TYPE GetType() - { - static GAMESTATE_TYPE typeName = "TestingState"; - return typeName; - } - GAMESTATE_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(GAMESTATE_TYPE, "TestingState"); TestingState(GameApp *gameApp, StateManager *stateManager); virtual ~TestingState(); diff --git a/src/processes/gameprocess.h b/src/processes/gameprocess.h index d48287a..1c608cd 100644 --- a/src/processes/gameprocess.h +++ b/src/processes/gameprocess.h @@ -2,6 +2,7 @@ #define __PROCESSES_GAMEPROCESS_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "../states/gamestate.h" #include "../events/eventlistenerex.h" @@ -16,6 +17,8 @@ struct Event; class GameProcess : public EventListenerEx { public: + TYPE_BASE(GAMEPROCESS_TYPE); + GameProcess(GameState *gameState, ProcessManager *processManager); virtual ~GameProcess(); @@ -36,13 +39,6 @@ public: virtual BOOL Handle(const Event *event); - virtual GAMEPROCESS_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(GAMEPROCESS_TYPE type) const; - template T* As(); - template const T* As() const; - GameApp* GetGameApp() const { return m_gameState->GetGameApp(); } BOOL IsFinished() const { return m_finished; } @@ -60,34 +56,5 @@ private: BOOL m_finished; }; -template -inline BOOL GameProcess::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL GameProcess::Is(GAMEPROCESS_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* GameProcess::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* GameProcess::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/processes/gwengameprocess.h b/src/processes/gwengameprocess.h index 20b2e67..b08e08a 100644 --- a/src/processes/gwengameprocess.h +++ b/src/processes/gwengameprocess.h @@ -3,6 +3,7 @@ #include "../framework/common.h" #include "../framework/debug.h" +#include "../framework/util/typesystem.h" #include "gameprocess.h" class GwenGameProcessUIController; @@ -14,12 +15,7 @@ struct Event; class GwenGameProcess : public GameProcess { public: - static GAMEPROCESS_TYPE GetType() - { - static GAMEPROCESS_TYPE typeName = "GwenGameProcess"; - return typeName; - } - GAMEPROCESS_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(GAMEPROCESS_TYPE, "GwenGameProcess"); GwenGameProcess(GameState *gameState, ProcessManager *processManager); virtual ~GwenGameProcess(); diff --git a/src/states/gamestate.h b/src/states/gamestate.h index be25b61..df696bc 100644 --- a/src/states/gamestate.h +++ b/src/states/gamestate.h @@ -2,6 +2,7 @@ #define __STATES_GAMESTATE_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "../events/eventlistenerex.h" typedef const char* GAMESTATE_TYPE; @@ -16,6 +17,8 @@ struct Event; class GameState : public EventListenerEx { public: + TYPE_BASE(GAMESTATE_TYPE); + GameState(GameApp *gameApp, StateManager *stateManager); virtual ~GameState(); @@ -36,13 +39,6 @@ public: virtual BOOL Handle(const Event *event); - virtual GAMESTATE_TYPE GetTypeOf() const = 0; - - template BOOL Is() const; - BOOL Is(GAMESTATE_TYPE type) const; - template T* As(); - template const T* As() const; - GameApp* GetGameApp() const { return m_gameApp; } ProcessManager* GetProcessManager() const { return m_processManager; } EffectManager* GetEffectManager() const { return m_effectManager; } @@ -69,34 +65,5 @@ private: BOOL m_hasReturnValue; }; -template -inline BOOL GameState::Is() const -{ - return (GetTypeOf() == T::GetType()); -} - -inline BOOL GameState::Is(GAMESTATE_TYPE type) const -{ - return (GetTypeOf() == type); -} - -template -inline T* GameState::As() -{ - if (Is()) - return (T*)this; - else - return NULL; -} - -template -inline const T* GameState::As() const -{ - if (Is()) - return (const T*)this; - else - return NULL; -} - #endif diff --git a/src/states/gwengamestate.h b/src/states/gwengamestate.h index 5568f8f..4a211ca 100644 --- a/src/states/gwengamestate.h +++ b/src/states/gwengamestate.h @@ -2,6 +2,7 @@ #define __STATES_GWENGAMESTATE_H_INCLUDED__ #include "../framework/common.h" +#include "../framework/util/typesystem.h" #include "../framework/debug.h" #include "gamestate.h" @@ -14,12 +15,7 @@ struct Event; class GwenGameState : public GameState { public: - static GAMESTATE_TYPE GetType() - { - static GAMESTATE_TYPE typeName = "GwenGameState"; - return typeName; - } - GAMESTATE_TYPE GetTypeOf() const { return GetType(); } + TYPE_DEFINE(GAMESTATE_TYPE, "GwenGameState"); GwenGameState(GameApp *gameApp, StateManager *stateManager); virtual ~GwenGameState();