00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _BASECOMPONENT_
00019 #define _BASECOMPONENT_
00020
00021 #include <iostream>
00022
00023 #include "game/AbstractComponent.h"
00024 #include "game/ComponentFactory.h"
00025
00026
00027 #define GET_ENTITY m_pGameEntity
00028 #define GET_GAME GET_ENTITY->GetGame()
00029 #define GET_ENGINE GET_GAME->GetEngine()
00030 #define GET_PHYSICS GET_GAME->GetPhysics()
00031 #define GET_RENDERER GET_ENGINE->GetRenderer()
00032 #define GET_PLATFORM GET_ENGINE->GetPlatform()
00033 #define GET_RESOURCE_CACHE GET_ENGINE->GetResourceCache()
00034
00035
00036 #define DEFAULT_COMPONENT_CONSTRUCTOR(base_class_name, class_name, initialization_list, initialization_list_2, initialization_list_3) \
00037 class_name##(const std::string& componentName, const std::string& familyName) \
00038 :##base_class_name##(componentName, familyName) initialization_list initialization_list_2 initialization_list_3\
00039 {\
00040 }
00041
00042 class GameEntity;
00043
00048 class BaseComponent : public AbstractComponent
00049 {
00050 protected:
00051
00052 GameEntity* m_pGameEntity;
00053
00054 std::string m_componentName;
00055
00056 std::string m_familyName;
00057
00058 public:
00065 BaseComponent(const std::string & componentName, const std::string familyName)
00066 :m_componentName(componentName), m_familyName(familyName)
00067 {
00068 }
00069
00074 virtual void Attach(GameEntity* pGameEntity)
00075 {
00076 m_pGameEntity = pGameEntity;
00077 }
00078
00082 virtual void Detach() { }
00083
00087 virtual void ToStream(std::ostream& stream) const { }
00088
00092 virtual void FromStream(std::istream& stream) { }
00093
00097 virtual const std::string & GetComponentName() const
00098 {
00099 return m_componentName;
00100 }
00101
00105 virtual const std::string & GetFamilyName() const
00106 {
00107 return m_familyName;
00108 }
00109
00113 GameEntity* GetGameEntity() const
00114 {
00115 return m_pGameEntity;
00116 }
00117 };
00118
00119 #endif