aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-08-20 11:15:45 -0400
committerClyne Sullivan <clyne@bitgloo.com>2022-08-20 11:15:45 -0400
commitea719de76706140ce87f16fd9bde61c0e665d089 (patch)
tree7c196eb8fbaca94bdcf3da588cb0f9d7e79df93d
parent0dc221b200b9d3df550e2d760cb396e4cb5f7176 (diff)
fix serialization support
-rw-r--r--.gitmodules2
-rw-r--r--Makefile8
m---------lib/entityx0
-rw-r--r--lib/soil/Makefile4
-rw-r--r--src/components/Script.hpp2
-rw-r--r--src/gamestate.hpp32
6 files changed, 18 insertions, 30 deletions
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
-Subproject 39e07099da7227d7d7baec072411ddc0abfd8be
+Subproject e04b856006cfe6b7e8ba5d6c1434331351cc791
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>(),
- 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(
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 <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();
}
}