X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fentity.h;h=e6d1cf940cd8da44783976a29fd1ce407cf01770;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=7c7ee89fe85cf2c117fccd7f259540dafe3b93b6;hpb=c7d0e1aff305778f97974b329826628966380158;p=libs%2Fgame.git diff --git a/source/game/entity.h b/source/game/entity.h index 7c7ee89..e6d1cf9 100644 --- a/source/game/entity.h +++ b/source/game/entity.h @@ -2,41 +2,66 @@ #define MSP_GAME_ENTITY_H_ #include "handle.h" +#include "mspgame_api.h" +#include "owned.h" namespace Msp::Game { class Component; 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 }; + 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); + 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); 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);