6#include <unordered_map>
21 static u32 get_id(
const char* name,
u32 componentId = 0);
25 static inline std::vector<const char*>
names;
26 static inline std::unordered_map<std::string, u32>
map;
31 using CreatorFn = std::function<std::unique_ptr<Command>()>;
34 static std::unique_ptr<Command>
create(
u32 type_id);
40#define COMMAND_ID(Name) \
42 inline static u32 s_type_id; \
43 u32 get_type_id() const override { \
49#define COMMAND_ID_T(Name, T) \
51 inline static u32 s_type_id; \
52 u32 get_type_id() const override { \
58#define REGISTER_COMMAND(Name) \
60 struct Name##_CommandRegistrar { \
61 Name##_CommandRegistrar() { \
62 sd::Name::s_type_id = sd::CommandRegistry::register_(#Name); \
63 sd::CommandFactory::register_(sd::Name::s_type_id, \
64 [] { return std::make_unique<sd::Name>(); }); \
67 static Name##_CommandRegistrar s_##Name##_registrar; \
70#define REGISTER_COMPONENT_COMMANDS(T) \
72 struct AddComponentCmd##T##_Registrar { \
73 AddComponentCmd##T##_Registrar() { \
74 sd::AddComponentCmd<T>::s_type_id = \
75 sd::CommandRegistry::register_("AddComponentCmd", sd::ComponentTraits<T>::id); \
76 sd::CommandFactory::register_(sd::AddComponentCmd<T>::s_type_id, \
77 [] { return std::make_unique<sd::AddComponentCmd<T>>(); }); \
80 static AddComponentCmd##T##_Registrar s_AddComponentCmd##T##_registrar; \
83 struct RemoveComponentCmd##T##_Registrar { \
84 RemoveComponentCmd##T##_Registrar() { \
85 sd::RemoveComponentCmd<T>::s_type_id = \
86 sd::CommandRegistry::register_("RemoveComponentCmd", sd::ComponentTraits<T>::id); \
87 sd::CommandFactory::register_(sd::RemoveComponentCmd<T>::s_type_id, \
88 [] { return std::make_unique<sd::RemoveComponentCmd<T>>(); }); \
91 static RemoveComponentCmd##T##_Registrar s_RemoveComponentCmd##T##_registrar; \
135struct std::hash<
sd::EntityHandle> {
137 return std::hash<u32>{}(
h.id);
Definition Command.hpp:29
static std::vector< CreatorFn > creators
Definition Command.hpp:37
static std::unique_ptr< Command > create(u32 type_id)
Definition CommandQueue.cpp:43
std::function< std::unique_ptr< Command >()> CreatorFn
Definition Command.hpp:31
static void register_(u32 type_id, CreatorFn creator)
Definition CommandQueue.cpp:36
Definition CommandQueue.hpp:7
Definition Command.hpp:18
static std::unordered_map< std::string, u32 > map
Definition Command.hpp:26
static u32 get_id(const char *name, u32 componentId=0)
Definition CommandQueue.cpp:20
static u32 register_(const char *name, u32 component_id=0)
Definition CommandQueue.cpp:8
static const char * get_name(u32 id)
Definition CommandQueue.cpp:29
static std::vector< const char * > names
Definition Command.hpp:25
Definition Command.hpp:108
virtual void deserialize(Serializer &serializer)=0
virtual u32 get_type_id() const =0
virtual ~Command()=default
virtual void serialize(Serializer &serializer) const =0
virtual void execute(EntityManager &em, CommandQueue &queue)=0
Definition EntityManager.hpp:83
Definition serialization.hpp:36
Definition Application.hpp:28
Definition Command.hpp:97
EntityHandle()
Definition Command.hpp:99
EntityHandle(const u32 id)
Definition Command.hpp:100
bool operator==(const EntityHandle &other) const
Definition Command.hpp:104
u32 id
Definition Command.hpp:98
bool operator!=(const EntityHandle &other) const
Definition Command.hpp:105
bool is_valid() const
Definition Command.hpp:102
std::size_t operator()(sd::EntityHandle h) const noexcept
Definition Command.hpp:136
std::uint32_t u32
Definition types.hpp:15
constexpr T g_type_max
Definition types.hpp:21