From ea719de76706140ce87f16fd9bde61c0e665d089 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 20 Aug 2022 11:15:45 -0400 Subject: fix serialization support --- .gitmodules | 2 +- Makefile | 8 +++++--- lib/entityx | 2 +- lib/soil/Makefile | 4 ++++ src/components/Script.hpp | 2 +- src/gamestate.hpp | 32 +++++++------------------------- 6 files changed, 19 insertions(+), 31 deletions(-) create mode 100644 lib/soil/Makefile diff --git a/.gitmodules b/.gitmodules index 911085e..812302f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,7 @@ [submodule "lib/entityx"] path = lib/entityx url = https://github.com/tcsullivan/entityx - branch = remove-std-iterator + branch = serialize [submodule "lib/cereal"] path = lib/cereal url = https://github.com/USCiLab/cereal diff --git a/Makefile b/Makefile index db7c130..cc46888 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,8 @@ directories: clean: @echo " CLEAN" @$(RM) -rf $(OUTDIR) + +cleanall: clean @$(RM) -f lib/libentityx.a lib/libluajit.a lib/libsoil.a cleaner: clean @@ -96,8 +98,8 @@ lib/libluajit.a: @cp lib/luajit/src/libluajit.a lib/libluajit.a lib/libsoil.a: - @gcc -c lib/soil/soil/*.c - @ar rcs lib/libsoil.a lib/soil/soil/*.o + @make -Clib/soil -j4 + @cp lib/soil/libsoil.a lib/libsoil.a -.PHONY: all remake clean cleaner resources +.PHONY: all remake clean cleaner cleanall resources diff --git a/lib/entityx b/lib/entityx index 39e0709..e04b856 160000 --- a/lib/entityx +++ b/lib/entityx @@ -1 +1 @@ -Subproject commit 39e07099da7227d7d7baec072411ddc0abfd8be4 +Subproject commit e04b856006cfe6b7e8ba5d6c1434331351cc791a diff --git a/lib/soil/Makefile b/lib/soil/Makefile new file mode 100644 index 0000000..0b67b7c --- /dev/null +++ b/lib/soil/Makefile @@ -0,0 +1,4 @@ +all: + @gcc -c soil/*.c + @ar rcs libsoil.a *.o + diff --git a/src/components/Script.hpp b/src/components/Script.hpp index d7bc147..93997a9 100644 --- a/src/components/Script.hpp +++ b/src/components/Script.hpp @@ -74,7 +74,7 @@ public: else if (value.get_type() == sol::type::number) table_components.push_back(std::make_tuple( key.as(), - std::string("return " + value.as()) + std::string("return ") + std::to_string(value.as()) )); else if (value.get_type() == sol::type::boolean) { table_components.push_back(std::make_tuple( diff --git a/src/gamestate.hpp b/src/gamestate.hpp index 86a4198..3ef641f 100644 --- a/src/gamestate.hpp +++ b/src/gamestate.hpp @@ -27,30 +27,6 @@ #include -struct EntitySerializer -{ - template - 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(&ar)); - // ar.finishNode(); - // } - //} - } -}; - - /** * @class GameState * Manages save files that contain entity data. @@ -122,7 +98,13 @@ private: for (auto entity : entities.entities_for_debugging()) { archive.setNextName((name + std::to_string(i++)).c_str()); archive.startNode(); - EntitySerializer::serialize(entities, entity, save, archive); + entities.serialize(entity, + [&archive, &save](auto c) { + archive.setNextName(c->serializeName().c_str()); + archive.startNode(); + c->internal_serialize(save, static_cast(&archive)); + archive.finishNode(); + }); archive.finishNode(); } } -- cgit v1.2.3