Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "builder.hpp"
9
10namespace flecs
11{
12
15 world_t *world,
16 entity_t id,
17 int32_t stage_current,
18 int32_t stage_count,
19 ecs_ftime_t delta_time,
20 void *param)
21 : stage_(world)
22 , id_(id)
23 , delta_time_(delta_time)
24 , param_(param)
25 , stage_current_(stage_current)
26 , stage_count_(stage_count) { }
27
28 system_runner_fluent& offset(int32_t offset) {
29 offset_ = offset;
30 return *this;
31 }
32
33 system_runner_fluent& limit(int32_t limit) {
34 limit_ = limit;
35 return *this;
36 }
37
38 system_runner_fluent& stage(flecs::world& stage) {
39 stage_ = stage.c_ptr();
40 return *this;
41 }
42
44 if (stage_count_) {
46 stage_, id_, stage_current_, stage_count_, delta_time_,
47 param_);
48 } else {
49 ecs_run(stage_, id_, delta_time_, param_);
50 }
51 }
52
53private:
54 world_t *stage_;
55 entity_t id_;
56 ecs_ftime_t delta_time_;
57 void *param_;
58 int32_t offset_;
59 int32_t limit_;
60 int32_t stage_current_;
61 int32_t stage_count_;
62};
63
64struct system final : entity
65{
66 using entity::entity;
67
68 explicit system() {
69 id_ = 0;
70 world_ = nullptr;
71 }
72
73 explicit system(flecs::world_t *world, ecs_system_desc_t *desc) {
74 world_ = world;
75 id_ = ecs_system_init(world, desc);
76 }
77
78 void ctx(void *ctx) {
79 ecs_system_desc_t desc = {};
80 desc.entity = id_;
81 desc.ctx = ctx;
82 ecs_system_init(world_, &desc);
83 }
84
85 void* ctx() const {
86 return ecs_system_get(world_, id_)->ctx;
87 }
88
89 flecs::query<> query() const {
90 return flecs::query<>(ecs_system_get(world_, id_)->query);
91 }
92
93 system_runner_fluent run(ecs_ftime_t delta_time = 0.0f, void *param = nullptr) const {
94 return system_runner_fluent(world_, id_, 0, 0, delta_time, param);
95 }
96
97 system_runner_fluent run_worker(
98 int32_t stage_current,
99 int32_t stage_count,
100 ecs_ftime_t delta_time = 0.0f,
101 void *param = nullptr) const
102 {
104 world_, id_, stage_current, stage_count, delta_time, param);
105 }
106
107# ifdef FLECS_TIMER
109# endif
110
111};
112
113// Mixin implementation
114inline system world::system(flecs::entity e) const {
115 return flecs::system(world_, e);
116}
117
118template <typename... Comps, typename... Args>
119inline system_builder<Comps...> world::system(Args &&... args) const {
120 return flecs::system_builder<Comps...>(world_, FLECS_FWD(args)...);
121}
122
123namespace _ {
124
125inline void system_init(flecs::world& world) {
126 world.component<TickSource>("flecs::system::TickSource");
127}
128
129} // namespace _
130} // namespace flecs
FLECS_API const ecs_system_t * ecs_system_get(const ecs_world_t *world, ecs_entity_t system)
Get system object.
FLECS_API ecs_entity_t ecs_run(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, void *param)
Run a specific system manually.
FLECS_API ecs_entity_t ecs_system_init(ecs_world_t *world, const ecs_system_desc_t *desc)
Create a system.
FLECS_API ecs_entity_t ecs_run_worker(ecs_world_t *world, ecs_entity_t system, int32_t stage_current, int32_t stage_count, ecs_ftime_t delta_time, void *param)
Same as ecs_run(), but subdivides entities across number of provided stages.
flecs::system system(flecs::entity e) const
Upcast entity to a system.
flecs::component< T > component(Args &&... args) const
Find or register component.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
System builder.
Use with ecs_system_init() to create or update a system.
Definition system.h:38
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition system.h:66
ecs_entity_t entity
Existing entity to associate with system (optional)
Definition system.h:42
void * ctx
Userdata for system.
Definition system.h:135
Entity.
Definition entity.hpp:30
System builder.
Definition builder.hpp:24
The world.
Definition world.hpp:137
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:237
Timer module system mixin.