SDEngine
Game Engine
Loading...
Searching...
No Matches
ComponentFactory.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <vector>
6
7#include "SD/core/types.hpp"
8#include "SD/export.hpp"
9#include "SparseEntitySet.hpp"
10
11namespace sd {
12
14public:
15 using PoolCreatorFn = std::function<std::unique_ptr<SparseEntitySetBase>()>;
16
17 static void register_component(u32 component_id, PoolCreatorFn creator);
18 static std::unique_ptr<SparseEntitySetBase> create(u32 component_id);
19 static bool is_registered(u32 component_id);
20
21private:
22 static inline std::vector<PoolCreatorFn> m_creators;
23};
24
25#define REGISTER_SERIALIZABLE_COMPONENT(T) \
26 namespace { \
27 struct T##PoolRegistrar { \
28 T##PoolRegistrar() { \
29 ComponentFactory::register_component(ComponentTraits<T>::id, \
30 [] { return std::make_unique<SparseEntitySet<T>>(); }); \
31 } \
32 }; \
33 static T##PoolRegistrar T##s_pool_registrar; \
34 }
35
36} // namespace sd
Definition ComponentFactory.hpp:13
static std::vector< PoolCreatorFn > m_creators
Definition ComponentFactory.hpp:22
std::function< std::unique_ptr< SparseEntitySetBase >()> PoolCreatorFn
Definition ComponentFactory.hpp:15
Definition Application.hpp:28
std::uint32_t u32
Definition types.hpp:15
constexpr T g_type_max
Definition types.hpp:21