]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
fix serialization support
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 20 Aug 2022 15:15:45 +0000 (11:15 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 20 Aug 2022 15:15:45 +0000 (11:15 -0400)
.gitmodules
Makefile
lib/entityx
lib/soil/Makefile [new file with mode: 0644]
src/components/Script.hpp
src/gamestate.hpp

index 911085ed5454b7ab1fa4b274f68d2b208c9ab978..812302f3e9e387873d62f161c132ecb61c31b113 100644 (file)
@@ -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
index db7c1306c1883c741a44b3bbe38a06b6dcfe3060..cc468888175a108d3974f29418905979e237c9a4 100644 (file)
--- 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
 
index 39e07099da7227d7d7baec072411ddc0abfd8be4..e04b856006cfe6b7e8ba5d6c1434331351cc791a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 39e07099da7227d7d7baec072411ddc0abfd8be4
+Subproject commit e04b856006cfe6b7e8ba5d6c1434331351cc791a
diff --git a/lib/soil/Makefile b/lib/soil/Makefile
new file mode 100644 (file)
index 0000000..0b67b7c
--- /dev/null
@@ -0,0 +1,4 @@
+all:
+       @gcc -c soil/*.c
+       @ar rcs libsoil.a *.o
+
index d7bc1470bff8dd69e7a71d6c8df85807a3c41d22..93997a9a7f425fd1e1e2ec5d6d8b4d2c0333e01c 100644 (file)
@@ -74,7 +74,7 @@ public:
             else if (value.get_type() == sol::type::number)
                 table_components.push_back(std::make_tuple(
                     key.as<std::string>(),
-                    std::string("return " + value.as<std::string>())
+                    std::string("return ") + std::to_string(value.as<double>())
                 ));
             else if (value.get_type() == sol::type::boolean) {
                 table_components.push_back(std::make_tuple(
index 86a419800e28f5e8796a9da6b9c701e39ec3ff07..3ef641fe6e7b7449451a725c574239aa517ed503 100644 (file)
 
 #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.
@@ -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<void*>(&archive));
+                    archive.finishNode();
+                });
             archive.finishNode();
         }
     }