X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fentity.h;h=c4cf83c119b26bce36fce09ac1238be2bebcd1d2;hb=33aed7ee82844023346f8cb9c3108cb0d6c80369;hp=7c7ee89fe85cf2c117fccd7f259540dafe3b93b6;hpb=c7d0e1aff305778f97974b329826628966380158;p=libs%2Fgame.git diff --git a/source/game/entity.h b/source/game/entity.h index 7c7ee89..c4cf83c 100644 --- a/source/game/entity.h +++ b/source/game/entity.h @@ -2,11 +2,14 @@ #define MSP_GAME_ENTITY_H_ #include "handle.h" +#include "owned.h" namespace Msp::Game { class Component; class Stage; +class Transform; +struct TransformValues; class hierarchy_error: public std::logic_error { @@ -16,27 +19,47 @@ public: class Entity { +public: + enum TransformTag { NO_TRANSFORM }; + private: Handle parent; std::vector> components; std::vector> children; + Owned transform; public: - Entity(Handle); + Entity(Handle, TransformTag); + Entity(Handle, const TransformValues &); virtual ~Entity(); void add_component(Handle); void remove_component(Handle); + template + Handle get_component(); + + Handle get_transform() const { return transform; } + void add_child(Handle); void remove_child(Handle); Handle get_parent() const { return parent; } Handle get_root(); + const std::vector> &get_children() const { return children; } Stage &get_stage(); }; +template +inline Handle Entity::get_component() +{ + for(Handle c: components) + if(Handle tc = dynamic_handle_cast(c)) + return tc; + return nullptr; +} + inline Handle Entity::get_root() { Handle e = Handle::from_object(this);