Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
8#pragma once
9
10namespace flecs {
11namespace _ {
12
13// Macros for template types so we don't go cross-eyed
14#define FLECS_TBUILDER template<typename ... Components> class
15#define FLECS_IBUILDER template<typename IBase, typename ... Components> class
16
17template<FLECS_TBUILDER T, typename TDesc, typename Base, FLECS_IBUILDER IBuilder, typename ... Components>
18struct builder : IBuilder<Base, Components ...>
19{
20 using IBase = IBuilder<Base, Components ...>;
21
22public:
23 builder(flecs::world_t *world)
24 : IBase(&desc_)
25 , desc_{}
26 , world_(world) { }
27
28 builder(const builder& f)
29 : IBase(&desc_, f.term_index_)
30 {
31 world_ = f.world_;
32 desc_ = f.desc_;
33 }
34
35 builder(builder&& f) noexcept
36 : builder<T, TDesc, Base, IBuilder, Components...>(f) { }
37
38 operator TDesc*() {
39 return &desc_;
40 }
41
42 T<Components ...> build() {
43 return T<Components...>(world_, *static_cast<Base*>(this));
44 }
45
46protected:
47 flecs::world_t* world_v() override { return world_; }
48 TDesc desc_;
49 flecs::world_t *world_;
50};
51
52#undef FLECS_TBUILDER
53#undef FLECS_IBUILDER
54
55} // namespace _
56} // namespace flecs
The world.
Definition world.hpp:137