8#include "Serialization.h"
17#define ADD_COMPONENT(str, type) if (type == #str ) return this->AddComponent<str>();
35 static std::string
GetType() {
return "GameComponent"; }
70 static int numberOfGameObjects;
74 std::string
name =
"new GameObject";
123 int Serialize(std::fstream* data,
int offset);
140 T* component =
nullptr;
141 if (this->components.find(T::GetType()) == this->components.end())
return component;
143 component = (T*)this->components[T::GetType()];
154 std::map<std::string, GameComponent*>::iterator temp =
components.find(T::GetType());
155 if (temp !=
components.end())
return (T*)(*&temp)->second;
156 T* ptr =
new T(
this);
157 components.insert(std::pair<std::string, GameComponent*>( T::GetType(), ptr ));
int(* DrawCallback)(void *data)
Function pointer type for draw callbacks.
Definition GameObject.h:24
Base class for game components.
Definition GameObject.h:29
virtual void * GetGameObject()
Get the GameObject associated with the game component.
Definition GameObject.h:57
static std::string GetType()
Get the type of the game component.
Definition GameObject.h:35
virtual void Start()
Start the game component.
Definition GameObject.h:45
virtual void Update()
Update the game component.
Definition GameObject.h:40
virtual ~GameComponent()
Destructor for the game component.
Definition GameObject.h:62
virtual void SetGameObject(void *go)
Set the GameObject associated with the game component.
Definition GameObject.h:51
Class representing a game object.
Definition GameObject.h:68
GameObject()
Default constructor for GameObject.
Definition GameObject.cpp:27
int Serialize(std::fstream *data, int offset)
Serialize the game object.
Definition GameObject.cpp:74
std::map< std::string, GameComponent * > components
Definition GameObject.h:73
DrawCallback _drawProc
Definition GameObject.h:76
T * GetComponent()
Get a component of the specified type.
Definition GameObject.h:139
void DeleteComponent()
Delete a component of the specified type.
Definition GameObject.h:174
T * AddComponent()
Add a component of the specified type to the game object.
Definition GameObject.h:153
int Deserialize(std::fstream *data, int offset)
Deserialize the game object.
Definition GameObject.cpp:85
int Draw()
Draw the game object.
Definition GameObject.cpp:16
void SetDrawCallback(DrawCallback callback)
Set the draw callback for the game object.
Definition GameObject.cpp:22
~GameObject()
Destructor for GameObject.
Definition GameObject.cpp:40
std::string name
Definition GameObject.h:74
void DeleteComponents()
Delete all components from the game object.
Definition GameObject.cpp:48
Base class for serialization and deserialization.
Definition Serialization.h:23