-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.h
63 lines (54 loc) · 1.61 KB
/
Entity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Wrapper class for collections of components and behaviors that constitute anything.
*
* Author: Skylar Payne
* Date: 6/8/2013
* File: Entity.h
**/
#pragma once
#include <list>
#include "IComponent.h"
#include "IBehavior.h"
class Entity
{
friend class EntityManager;
friend class BehaviorSystem;
private:
unsigned int _ID;
std::string _Tag;
std::list<IComponent*> _Components;
std::list<IBehavior*> _Behaviors;
private:
bool FindComponent(const char* type, std::list<IComponent*>::iterator& loc);
bool FindBehavior(const char* type, std::list<IBehavior*>::iterator& loc);
public:
Entity(const char* tag = "") : _Tag(tag) { }
~Entity();
unsigned int GetID() const { return _ID; }
const char* GetTag() const { return _Tag.c_str(); }
void SetTag(const char* tag) { _Tag = tag; }
bool AttachComponent(IComponent* comp);
void RemoveComponent(const char* type);
bool HasComponent(const char* type);
template<class T>
T* GetComponent(const char* type);
bool AttachBehavior(IBehavior* beh);
void RemoveBehavior(const char* type);
bool HasBehavior(const char* type);
IBehavior* GetBehavior(const char* type);
};
/**
* @brief Entity::GetComponent templated method to get a Component
* @param type the type of component to get
* @return the component, if found, nullptr otherwise.
*/
template<class T>
T* Entity::GetComponent(const char* type)
{
std::list<IComponent*>::iterator it;
if(this->FindComponent(type, it))
{
return static_cast<T*>(*it);
}
return nullptr;
}