Streamlined library and reworked the way runtime components work

This commit is contained in:
2020-05-12 02:06:10 +02:00
parent c794e4a5d2
commit de5af0a5aa
11 changed files with 424 additions and 359 deletions

View File

@@ -41,32 +41,25 @@ namespace ecs::serial {
template <typename T, typename... Args>
void register_component(Args... args) {
// Serialize component
auto func1 = [args...] (std::ostream& os, ecs::Component* component) {
auto serialize = [args...] (std::ostream& os, ecs::Component* component) {
T* t = (T*)component;
serialize_member(os, t, args...);
};
// Deserialize component
auto func2 = [args...] (std::istream& is, ecs::Component* component) {
auto deserialize = [args...] (std::istream& is, ecs::Component* component) {
T* t = (T*)component;
deserialize_member(is, t, args...);
};
auto func3 = [] () -> Component* {
auto create = [] () -> Component* {
return new T();
};
internal::functions.insert({ComponentID::id<T>, {func1, func2, func3}});
internal::functions.insert({ComponentID::id<T>, {serialize, deserialize, create}});
}
template <typename T>
void register_component_custom(std::function<void(std::ostream&, ecs::Component*)> func1, std::function<void(std::istream&, Component*)> func2) {
auto func3 = [] () -> Component* {
return new T();
};
internal::functions.insert({ComponentID::id<T>, {func1, func2, func3}});
}
void register_component_custom(size_t id, std::function<void(std::ostream&, ecs::Component*)> serialize, std::function<void(std::istream&, Component*)> deserialize, std::function<ecs::Component*()> create);
void serialize(std::ostream& os, Entity* entity);
void deserialize(std::istream& is, Manager& manager);