Added codegen to register components, and started reworking lua
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
#include "ecs-serial.h"
|
||||
|
||||
#include "/home/tim/Projects/cpp/iohelper/iohelper/include/iohelper/read.h"
|
||||
#include "/home/tim/Projects/cpp/iohelper/iohelper/include/iohelper/write.h"
|
||||
#include "ecs.h"
|
||||
#include <ostream>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
// @todo We need to make sure that the id list stays the same between versions
|
||||
// Maybe store that in the stream as well?
|
||||
namespace ecs::serial {
|
||||
std::unordered_map<size_t, std::tuple<std::function<void(std::ostream&, ecs::Component*)>, std::function<void(std::istream&, ecs::Component*)>, std::function<ecs::Component*()>>> internal::functions;
|
||||
|
||||
@@ -11,8 +19,12 @@ namespace ecs::serial {
|
||||
auto components = entity->get_components();
|
||||
iohelper::write_length(os, components.size());
|
||||
for (auto [id, component] : components) {
|
||||
auto functions = internal::functions.find(id);
|
||||
if (functions == internal::functions.end()) {
|
||||
throw std::runtime_error("Unknown id");
|
||||
}
|
||||
|
||||
iohelper::write_length(os, id);
|
||||
// @todo What if the function does not exist?
|
||||
std::get<0>(internal::functions[id])(os, component);
|
||||
}
|
||||
}
|
||||
@@ -60,4 +72,14 @@ namespace ecs::serial {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void serialize_ids(std::ostream& os) {
|
||||
auto& ids = ComponentID::_ids();
|
||||
|
||||
iohelper::write_length(os, ids.size());
|
||||
for (auto& [name, id] : ids) {
|
||||
iohelper::write<std::string>(os, name);
|
||||
iohelper::write_length(os, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user