diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 20:52:59 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 20:52:59 -0400 |
commit | bdc0e843a4762a1abddebc53d12a351debe8d457 (patch) | |
tree | ad4c2023c5c03527b628108f2c76bf42c354724c /src | |
parent | d1dd9743d93009eef7d32d5403eeefbba29c2ee6 (diff) |
add cereal and entityx submodules; fix compile errors
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Audio.hpp | 2 | ||||
-rw-r--r-- | src/components/Component.hpp | 2 | ||||
-rw-r--r-- | src/components/EventListener.hpp | 2 | ||||
-rw-r--r-- | src/components/Light.hpp | 2 | ||||
-rw-r--r-- | src/components/Name.hpp | 2 | ||||
-rw-r--r-- | src/components/Physics.hpp | 2 | ||||
-rw-r--r-- | src/components/Player.hpp | 2 | ||||
-rw-r--r-- | src/components/Position.hpp | 2 | ||||
-rw-r--r-- | src/components/Render.hpp | 2 | ||||
-rw-r--r-- | src/components/Script.hpp | 2 | ||||
-rw-r--r-- | src/components/Velocity.hpp | 2 | ||||
-rw-r--r-- | src/gamestate.hpp | 26 |
12 files changed, 36 insertions, 12 deletions
diff --git a/src/components/Audio.hpp b/src/components/Audio.hpp index a97b235..2bb63eb 100644 --- a/src/components/Audio.hpp +++ b/src/components/Audio.hpp @@ -47,7 +47,7 @@ public: void serialize([[maybe_unused]] cereal::JSONOutputArchive& ar) final {} void serialize([[maybe_unused]] cereal::JSONInputArchive& ar) final {} - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Audio"; } }; diff --git a/src/components/Component.hpp b/src/components/Component.hpp index 2928366..576a059 100644 --- a/src/components/Component.hpp +++ b/src/components/Component.hpp @@ -33,7 +33,7 @@ public: virtual void serialize(cereal::JSONOutputArchive& ar) = 0; virtual void serialize(cereal::JSONInputArchive& ar) = 0; - void internal_serialize(bool save, void *ar) final { + virtual void internal_serialize(bool save, void *ar) final { if (save) serialize(*reinterpret_cast<cereal::JSONOutputArchive*>(ar)); else diff --git a/src/components/EventListener.hpp b/src/components/EventListener.hpp index c39b6ad..fb55d95 100644 --- a/src/components/EventListener.hpp +++ b/src/components/EventListener.hpp @@ -52,7 +52,7 @@ public: void serialize([[maybe_unused]] cereal::JSONOutputArchive& ar) final {} void serialize([[maybe_unused]] cereal::JSONInputArchive& ar) final {} - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "EventListener"; } }; diff --git a/src/components/Light.hpp b/src/components/Light.hpp index 6849d7c..c63b6cc 100644 --- a/src/components/Light.hpp +++ b/src/components/Light.hpp @@ -58,7 +58,7 @@ public: ar(CEREAL_NVP(r), CEREAL_NVP(g), CEREAL_NVP(b), CEREAL_NVP(strength)); } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Light"; } }; diff --git a/src/components/Name.hpp b/src/components/Name.hpp index a6a6d8a..6390d5e 100644 --- a/src/components/Name.hpp +++ b/src/components/Name.hpp @@ -47,7 +47,7 @@ public: ar(CEREAL_NVP(name)); } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Name"; } }; diff --git a/src/components/Physics.hpp b/src/components/Physics.hpp index 378e87f..edf5ac5 100644 --- a/src/components/Physics.hpp +++ b/src/components/Physics.hpp @@ -33,7 +33,7 @@ public: void serialize([[maybe_unused]] cereal::JSONOutputArchive& ar) final {} void serialize([[maybe_unused]] cereal::JSONInputArchive& ar) final {} - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Physics"; } }; diff --git a/src/components/Player.hpp b/src/components/Player.hpp index a550c4f..43d083e 100644 --- a/src/components/Player.hpp +++ b/src/components/Player.hpp @@ -36,7 +36,7 @@ public: void serialize([[maybe_unused]] cereal::JSONOutputArchive& ar) final {} void serialize([[maybe_unused]] cereal::JSONInputArchive& ar) final {} - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Player"; } }; diff --git a/src/components/Position.hpp b/src/components/Position.hpp index 56e8707..fcd62f8 100644 --- a/src/components/Position.hpp +++ b/src/components/Position.hpp @@ -51,7 +51,7 @@ public: ar(CEREAL_NVP(x), CEREAL_NVP(y)); } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Position"; } }; diff --git a/src/components/Render.hpp b/src/components/Render.hpp index 81ca591..93be5d8 100644 --- a/src/components/Render.hpp +++ b/src/components/Render.hpp @@ -62,7 +62,7 @@ public: ar(CEREAL_NVP(visible), CEREAL_NVP(flipX)); } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Render"; } }; diff --git a/src/components/Script.hpp b/src/components/Script.hpp index 3f96be5..d7bc147 100644 --- a/src/components/Script.hpp +++ b/src/components/Script.hpp @@ -119,7 +119,7 @@ public: } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Scripted"; } }; diff --git a/src/components/Velocity.hpp b/src/components/Velocity.hpp index 776c1dd..f48a9f3 100644 --- a/src/components/Velocity.hpp +++ b/src/components/Velocity.hpp @@ -52,7 +52,7 @@ public: ar(CEREAL_NVP(x), CEREAL_NVP(y)); } - std::string serializeName(void) const final { + virtual std::string serializeName(void) const final { return "Velocity"; } }; diff --git a/src/gamestate.hpp b/src/gamestate.hpp index 55f4e47..86a4198 100644 --- a/src/gamestate.hpp +++ b/src/gamestate.hpp @@ -27,6 +27,30 @@ #include <fstream> +struct EntitySerializer +{ + template<class Archive> + static void serialize(entityx::EntityManager& entities, entityx::Entity entity, bool save, Archive& ar) + { + // TODO try and reimplement without modifying entityx? + // Or, make a new branch... + + //const auto mask = entity.component_mask(); + + //for (size_t i = 0; i < entities.component_helpers_.size(); i++) { + // auto helper = entities.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(); + // } + //} + } +}; + + /** * @class GameState * Manages save files that contain entity data. @@ -98,7 +122,7 @@ private: for (auto entity : entities.entities_for_debugging()) { archive.setNextName((name + std::to_string(i++)).c_str()); archive.startNode(); - entities.entity_serialize(entity, save, archive); + EntitySerializer::serialize(entities, entity, save, archive); archive.finishNode(); } } |