diff options
author | clyne <clyne@bitgloo.com> | 2019-09-03 18:17:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 18:17:51 -0400 |
commit | ec1d57aeadbd0f34616eeec8f1a922ca61b90085 (patch) | |
tree | 9d2233f2437b8e85d151f9610b1a147310b9c13e /lib/entityx | |
parent | 0b3d24c4295bb89eb4ce3f91163cabd64d0ca6e2 (diff) | |
parent | 95cc88ad5f6c2abb4890d00a57ae4ad0db030e9b (diff) |
Merge pull request #1 from tcsullivan/save-load
Save load looks good
Diffstat (limited to 'lib/entityx')
-rw-r--r-- | lib/entityx/entityx/Entity.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/entityx/entityx/Entity.h b/lib/entityx/entityx/Entity.h index dfa4062..27a8820 100644 --- a/lib/entityx/entityx/Entity.h +++ b/lib/entityx/entityx/Entity.h @@ -242,6 +242,8 @@ struct BaseComponent { void operator delete([[maybe_unused]] void *p) { fail(); } void operator delete[]([[maybe_unused]] void *p) { fail(); } + virtual void internal_serialize(bool save, void *ar) = 0; + virtual std::string serializeName(void) const = 0; protected: static void fail() { @@ -341,6 +343,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 +355,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 +748,26 @@ class EntityManager : entityx::help::NonCopyable { } /** + * EDIT by tcsullivan + * Iterates through all components of a given Entity. + */ + template<class Archive> + void entity_serialize(Entity entity, bool save, Archive& ar) + { + auto mask = component_mask(entity.id()); + for (size_t i = 0; i < component_helpers_.size(); i++) { + BaseComponentHelper *helper = component_helpers_[i]; + if (helper && mask.test(i)) { + auto* c = helper->get_component(entity); + ar.setNextName(c->serializeName().c_str()); + ar.startNode(); + c->internal_serialize(save, static_cast<void*>(&ar)); + ar.finishNode(); + } + } + } + + /** * Find Entities that have all of the specified Components. * * @code |