1 #ifndef MSP_GAME_ENTITY_H_
2 #define MSP_GAME_ENTITY_H_
12 struct TransformValues;
14 class hierarchy_error: public std::logic_error
17 hierarchy_error(): std::logic_error("hierarchy error") { }
23 enum TransformTag { NO_TRANSFORM };
26 Handle<Entity> parent;
27 std::vector<Handle<Component>> components;
28 std::vector<Handle<Entity>> children;
29 Owned<Transform> transform;
32 Entity(Handle<Entity>, TransformTag);
33 Entity(Handle<Entity>, const TransformValues &);
36 void add_component(Handle<Component>);
37 void remove_component(Handle<Component>);
39 void add_child(Handle<Entity>);
40 void remove_child(Handle<Entity>);
42 Handle<Entity> get_parent() const { return parent; }
43 Handle<Entity> get_root();
44 const std::vector<Handle<Entity>> &get_children() const { return children; }
46 Handle<Transform> get_transform() const { return transform; }
50 inline Handle<Entity> Entity::get_root()
52 Handle<Entity> e = Handle<Entity>::from_object(this);
53 while(Handle<Entity> p = e->get_parent())
58 } // namespace Msp::Game