Brought in nuke's idea for json serialize now to use it.
This commit is contained in:
parent
d798d154ae
commit
96efc990c1
4 changed files with 290 additions and 2 deletions
27
dinkyecs.hpp
27
dinkyecs.hpp
|
@ -7,10 +7,13 @@
|
|||
#include <any>
|
||||
#include <tuple>
|
||||
#include <queue>
|
||||
#include "tser.hpp"
|
||||
#include <functional>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include "dbc.hpp"
|
||||
|
||||
namespace DinkyECS {
|
||||
using namespace nlohmann;
|
||||
|
||||
typedef unsigned long Entity;
|
||||
|
||||
|
@ -155,4 +158,26 @@ namespace DinkyECS {
|
|||
return !queue.empty();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct NameOf;
|
||||
|
||||
using ReflFuncSignature = std::function<void(World& world, Entity ent, nlohmann::json &j)>;
|
||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||
|
||||
#define DINKY_HAS_COMPONENT(COMPONENT, ...) \
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(COMPONENT, __VA_ARGS__); \
|
||||
template <> struct DinkyECS::NameOf<COMPONENT> { \
|
||||
static constexpr const char *name = #COMPONENT; \
|
||||
};
|
||||
|
||||
template <typename COMPONENT> void Component(ComponentMap &m) {
|
||||
m[NameOf<COMPONENT>::name] = [](DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j) {
|
||||
COMPONENT c;
|
||||
from_json(j, c);
|
||||
world.set<COMPONENT>(ent, c);
|
||||
};
|
||||
}
|
||||
|
||||
void configure(World& world, const ComponentMap& component_map, Entity ent, json& data);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue