Flecs v3.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1
10#ifdef FLECS_SYSTEM
11
20#ifndef FLECS_MODULE
21#define FLECS_MODULE
22#endif
23
24#ifndef FLECS_SYSTEM_H
25#define FLECS_SYSTEM_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
32typedef struct EcsTickSource {
33 bool tick;
36
38typedef struct ecs_system_desc_t {
39 int32_t _canary;
40
43
46
60
65
67 void *ctx;
68
71
76 ecs_ctx_free_t binding_ctx_free;
77
80
82 int32_t rate;
83
86
89
94
96FLECS_API
98 ecs_world_t *world,
99 const ecs_system_desc_t *desc);
100
101#ifndef FLECS_LEGACY
102
104#define ECS_SYSTEM_DECLARE(id) ecs_entity_t ecs_id(id)
105
111#define ECS_SYSTEM_DEFINE(world, id_, phase, ...) \
112 { \
113 ecs_system_desc_t desc = {0}; \
114 ecs_entity_desc_t edesc = {0}; \
115 edesc.id = ecs_id(id_);\
116 edesc.name = #id_;\
117 edesc.add[0] = ((phase) ? ecs_pair(EcsDependsOn, (phase)) : 0); \
118 edesc.add[1] = (phase); \
119 desc.entity = ecs_entity_init(world, &edesc);\
120 desc.query.filter.expr = #__VA_ARGS__; \
121 desc.callback = id_; \
122 ecs_id(id_) = ecs_system_init(world, &desc); \
123 } \
124 ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, NULL);
125
131#define ECS_SYSTEM(world, id, phase, ...) \
132 ecs_entity_t ecs_id(id) = 0; ECS_SYSTEM_DEFINE(world, id, phase, __VA_ARGS__);\
133 ecs_entity_t id = ecs_id(id);\
134 (void)ecs_id(id);\
135 (void)id;
136
152#define ecs_system(world, ...)\
153 ecs_system_init(world, &(ecs_system_desc_t) __VA_ARGS__ )
154
155#endif
156
184FLECS_API
186 ecs_world_t *world,
188 ecs_ftime_t delta_time,
189 void *param);
190
201FLECS_API
203 ecs_world_t *world,
205 int32_t stage_current,
206 int32_t stage_count,
207 ecs_ftime_t delta_time,
208 void *param);
209
230FLECS_API
232 ecs_world_t *world,
234 ecs_ftime_t delta_time,
235 int32_t offset,
236 int32_t limit,
237 void *param);
238
248FLECS_API
250 const ecs_world_t *world,
252
261FLECS_API
263 const ecs_world_t *world,
265
275FLECS_API
277 const ecs_world_t *world,
279
280FLECS_API
281void FlecsSystemImport(
282 ecs_world_t *world);
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif
289
292#endif
FLECS_API void * ecs_get_system_binding_ctx(const ecs_world_t *world, ecs_entity_t system)
Get system binding context.
FLECS_API void * ecs_get_system_ctx(const ecs_world_t *world, ecs_entity_t system)
Get system context.
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_query_t * ecs_system_get_query(const ecs_world_t *world, ecs_entity_t system)
Get the query object for 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_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.
ecs_id_t ecs_entity_t
An entity identifier.
Definition: flecs.h:220
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition: flecs.h:229
struct ecs_query_t ecs_query_t
A query allows for cached iteration over ECS data.
Definition: flecs.h:238
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition: flecs.h:330
void(* ecs_run_action_t)(ecs_iter_t *it)
Function prototype for runnables (systems, observers).
Definition: flecs.h:321
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition: flecs.h:416
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition: flecs.h:42
Component used to provide a tick source to systems.
Definition: system.h:32
ecs_ftime_t time_elapsed
Time elapsed since last tick.
Definition: system.h:34
bool tick
True if providing tick.
Definition: system.h:33
Used with ecs_query_init.
Definition: flecs.h:807
Use with ecs_system_init.
Definition: system.h:38
int32_t rate
Rate at which the system should run.
Definition: system.h:82
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition: system.h:67
ecs_ctx_free_t ctx_free
Functions that are invoked during system cleanup to free context data.
Definition: system.h:75
bool multi_threaded
If true, system will be ran on multiple threads.
Definition: system.h:88
bool no_readonly
If true, system will have access to actuall world.
Definition: system.h:92
ecs_ftime_t interval
Interval in seconds at which the system should run.
Definition: system.h:79
ecs_iter_action_t callback
Callback that is ran for each result returned by the system's query.
Definition: system.h:64
void * binding_ctx
Binding context, for when system is implemented in other language.
Definition: system.h:70
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
ecs_run_action_t run
Callback that is invoked when a system is ran.
Definition: system.h:59
ecs_entity_t tick_source
External tick soutce that determines when system ticks.
Definition: system.h:85
flecs::system_builder< Components... > system(Args &&... args) const
Create a new system.