Flecs v3.2
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 : m_stage(world)
22 , m_id(id)
23 , m_delta_time(delta_time)
24 , m_param(param)
25 , m_offset(0)
26 , m_limit(0)
27 , m_stage_current(stage_current)
28 , m_stage_count(stage_count) { }
29
30 system_runner_fluent& offset(int32_t offset) {
31 m_offset = offset;
32 return *this;
33 }
34
35 system_runner_fluent& limit(int32_t limit) {
36 m_limit = limit;
37 return *this;
38 }
39
40 system_runner_fluent& stage(flecs::world& stage) {
41 m_stage = stage.c_ptr();
42 return *this;
43 }
44
46 if (m_stage_count) {
48 m_stage, m_id, m_stage_current, m_stage_count, m_delta_time,
49 m_param);
50 } else {
52 m_stage, m_id, m_delta_time, m_offset, m_limit, m_param);
53 }
54 }
55
56private:
57 world_t *m_stage;
58 entity_t m_id;
59 ecs_ftime_t m_delta_time;
60 void *m_param;
61 int32_t m_offset;
62 int32_t m_limit;
63 int32_t m_stage_current;
64 int32_t m_stage_count;
65};
66
67struct system final : entity
68{
69 using entity::entity;
70
71 explicit system() {
72 m_id = 0;
73 m_world = nullptr;
74 }
75
76 explicit system(flecs::world_t *world, ecs_system_desc_t *desc, bool instanced)
77 {
78 if (!desc->query.filter.instanced) {
79 desc->query.filter.instanced = instanced;
80 }
81
82 m_world = world;
83 m_id = ecs_system_init(world, desc);
84
85 if (desc->query.filter.terms_buffer) {
86 ecs_os_free(desc->query.filter.terms_buffer);
87 }
88 }
89
90 void ctx(void *ctx) {
91 ecs_system_desc_t desc = {};
92 desc.entity = m_id;
93 desc.ctx = ctx;
94 ecs_system_init(m_world, &desc);
95 }
96
97 void* ctx() const {
98 return ecs_system_get_ctx(m_world, m_id);
99 }
100
101 flecs::query<> query() const {
102 return flecs::query<>(m_world, ecs_system_get_query(m_world, m_id));
103 }
104
105 system_runner_fluent run(ecs_ftime_t delta_time = 0.0f, void *param = nullptr) const {
106 return system_runner_fluent(m_world, m_id, 0, 0, delta_time, param);
107 }
108
109 system_runner_fluent run_worker(
110 int32_t stage_current,
111 int32_t stage_count,
112 ecs_ftime_t delta_time = 0.0f,
113 void *param = nullptr) const
114 {
116 m_world, m_id, stage_current, stage_count, delta_time, param);
117 }
118
119# ifdef FLECS_TIMER
121# endif
122
123};
124
125// Mixin implementation
126inline system world::system(flecs::entity e) const {
127 return flecs::system(m_world, e);
128}
129
130template <typename... Comps, typename... Args>
131inline system_builder<Comps...> world::system(Args &&... args) const {
132 return flecs::system_builder<Comps...>(m_world, FLECS_FWD(args)...);
133}
134
135namespace _ {
136
137inline void system_init(flecs::world& world) {
138 world.component<TickSource>("flecs::system::TickSource");
139}
140
141} // namespace _
142} // namespace flecs
FLECS_API ecs_entity_t ecs_system_init(ecs_world_t *world, const ecs_system_desc_t *desc)
Create a system.
FLECS_API ecs_query_t * ecs_system_get_query(const ecs_world_t *world, ecs_entity_t system)
Get the query object for a system.
FLECS_API void * ecs_system_get_ctx(const ecs_world_t *world, ecs_entity_t system)
Get system context.
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_API ecs_entity_t ecs_run_w_filter(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, int32_t offset, int32_t limit, void *param)
Run system with offset/limit and type filter.
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:57
System builder.
ecs_term_t * terms_buffer
For filters with lots of terms an outside array can be provided.
Definition flecs.h:1006
bool instanced
When true, terms returned by an iterator may either contain 1 or N elements, where terms with N eleme...
Definition flecs.h:1019
ecs_filter_desc_t filter
Filter for the query.
Definition flecs.h:1039
Use with ecs_system_init()
Definition system.h:38
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition system.h:67
ecs_entity_t entity
Existing entity to associate with system (optional)
Definition system.h:42
ecs_query_desc_t query
System query parameters.
Definition system.h:45
Entity.
Definition entity.hpp:30
System builder.
Definition builder.hpp:24
The world.
Definition world.hpp:132
world_t * c_ptr() const
Obtain pointer to C world object.
Definition world.hpp:200
Timer module system mixin.