]> git.tdb.fi Git - libs/game.git/blob - source/game/entity.cpp
8f56f670cb50de28c68876c64f12a9405c6c3278
[libs/game.git] / source / game / entity.cpp
1 #include "entity.h"
2 #include "component.h"
3 #include "root.h"
4 #include "transform.h"
5
6 using namespace std;
7
8 namespace Msp::Game {
9
10 Entity::Entity(Handle<Entity> p, TransformTag):
11         parent(p)
12 { }
13
14 Entity::Entity(Handle<Entity> p, const TransformValues &tv):
15         parent(p),
16         transform(*this)
17 {
18         transform->set_values(tv);
19 }
20
21 // Hide ~Owned<Transform> from the header
22 Entity::~Entity()
23 { }
24
25 void Entity::add_component(Handle<Component> comp)
26 {
27         if(comp->get_entity().get()!=this)
28                 throw hierarchy_error();
29
30         components.push_back(comp);
31 }
32
33 void Entity::remove_component(Handle<Component> comp)
34 {
35         erase(components, comp);
36 }
37
38 void Entity::add_child(Handle<Entity> child)
39 {
40         if(child->get_parent().get()!=this)
41                 throw hierarchy_error();
42
43         children.push_back(child);
44 }
45
46 void Entity::remove_child(Handle<Entity> child)
47 {
48         erase(children, child);
49 }
50
51 Stage &Entity::get_stage()
52 {
53         Handle<Entity> root = get_root();
54         return dynamic_cast<Root &>(*root).get_stage();
55 }
56
57 } // namespace Msp::Game