diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-01 18:18:16 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2019-09-01 18:18:16 -0400 |
commit | 100d90466f022ec7e90396225a3ccf9d5212c7ca (patch) | |
tree | 1d16abf6fbf5725024f7e71dbb973b1faafde0b8 /lib | |
parent | 5576c2d0b0130a0b3bfbef8eb09cd9297d79fd09 (diff) |
added save/load structure to entityx
Diffstat (limited to 'lib')
-rw-r--r-- | lib/entityx/entityx/Entity.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/entityx/entityx/Entity.h b/lib/entityx/entityx/Entity.h index dfa4062..11bacfa 100644 --- a/lib/entityx/entityx/Entity.h +++ b/lib/entityx/entityx/Entity.h @@ -34,6 +34,8 @@ #include "entityx/Event.h" #include "entityx/help/NonCopyable.h" +class Archive; + namespace entityx { typedef std::uint32_t uint32_t; @@ -242,6 +244,8 @@ struct BaseComponent { void operator delete([[maybe_unused]] void *p) { fail(); } void operator delete[]([[maybe_unused]] void *p) { fail(); } + virtual void save([[maybe_unused]] Archive& ar) {} + virtual void load([[maybe_unused]] Archive& ar) {} protected: static void fail() { @@ -341,6 +345,7 @@ public: virtual ~BaseComponentHelper() {} virtual void remove_component(Entity e) = 0; virtual void copy_component_to(Entity source, Entity target) = 0; + virtual BaseComponent *get_component(Entity e) = 0; }; template <typename C> @@ -352,6 +357,9 @@ public: void copy_component_to(Entity source, Entity target) override { target.assign_from_copy<C>(*(source.component<C>().get())); } + BaseComponent *get_component(Entity e) override { + return e.component<C>().get(); + } }; /** @@ -742,6 +750,20 @@ class EntityManager : entityx::help::NonCopyable { } /** + * EDIT by tcsullivan + * Iterates through all components of a given Entity. + */ + void entity_each_component(Entity entity, std::function<void(BaseComponent*)> f) + { + auto mask = entity.component_mask(); + for (size_t i = 0; i < component_helpers_.size(); i++) { + BaseComponentHelper *helper = component_helpers_[i]; + if (helper && mask.test(i)) + f(helper->get_component(entity)); + } + } + + /** * Find Entities that have all of the specified Components. * * @code |