X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgame%2Fentity.h;h=e6d1cf940cd8da44783976a29fd1ce407cf01770;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=c28cbe5075b94567709ba562f33698097e959e29;hpb=c809f54b802727926bae40e9fe67d0e3c94fd2c0;p=libs%2Fgame.git diff --git a/source/game/entity.h b/source/game/entity.h index c28cbe5..e6d1cf9 100644 --- a/source/game/entity.h +++ b/source/game/entity.h @@ -2,6 +2,7 @@ #define MSP_GAME_ENTITY_H_ #include "handle.h" +#include "mspgame_api.h" #include "owned.h" namespace Msp::Game { @@ -11,13 +12,13 @@ class Stage; class Transform; struct TransformValues; -class hierarchy_error: public std::logic_error +class MSPGAME_API hierarchy_error: public std::logic_error { public: hierarchy_error(): std::logic_error("hierarchy error") { } }; -class Entity +class MSPGAME_API Entity { public: enum TransformTag { NO_TRANSFORM }; @@ -35,6 +36,12 @@ public: void add_component(Handle); void remove_component(Handle); + const std::vector> &get_components() const { return components; } + + template + Handle get_component(); + + Handle get_transform() const { return transform; } void add_child(Handle); void remove_child(Handle); @@ -43,10 +50,18 @@ public: Handle get_root(); const std::vector> &get_children() const { return children; } Stage &get_stage(); - Handle get_transform() const { return transform; } }; +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);