Flecs v4.0
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
36
99
101FLECS_API
103 ecs_world_t *world,
104 const ecs_system_desc_t *desc);
105
163
172FLECS_API
174 const ecs_world_t *world,
175 ecs_entity_t system);
176
177#ifndef FLECS_LEGACY
178
180#define ECS_SYSTEM_DECLARE(id) ecs_entity_t ecs_id(id)
181
190#define ECS_SYSTEM_DEFINE(world, id_, phase, ...) \
191 { \
192 ecs_system_desc_t desc = {0}; \
193 ecs_entity_desc_t edesc = {0}; \
194 ecs_id_t add_ids[3] = {\
195 ((phase) ? ecs_pair(EcsDependsOn, (phase)) : 0), \
196 (phase), \
197 0 \
198 };\
199 edesc.id = ecs_id(id_);\
200 edesc.name = #id_;\
201 edesc.add = add_ids;\
202 desc.entity = ecs_entity_init(world, &edesc);\
203 desc.query.expr = #__VA_ARGS__; \
204 desc.callback = id_; \
205 ecs_id(id_) = ecs_system_init(world, &desc); \
206 } \
207 ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, "failed to create system %s", #id_)
208
217#define ECS_SYSTEM(world, id, phase, ...) \
218 ecs_entity_t ecs_id(id) = 0; ECS_SYSTEM_DEFINE(world, id, phase, __VA_ARGS__);\
219 ecs_entity_t id = ecs_id(id);\
220 (void)ecs_id(id);\
221 (void)id
222
241#define ecs_system(world, ...)\
242 ecs_system_init(world, &(ecs_system_desc_t) __VA_ARGS__ )
243
244#endif
245
273FLECS_API
275 ecs_world_t *world,
276 ecs_entity_t system,
277 ecs_ftime_t delta_time,
278 void *param);
279
290FLECS_API
292 ecs_world_t *world,
293 ecs_entity_t system,
294 int32_t stage_current,
295 int32_t stage_count,
296 ecs_ftime_t delta_time,
297 void *param);
298
307FLECS_API
309 ecs_world_t *world);
310
311#ifdef __cplusplus
312}
313#endif
314
315#endif
316
319#endif
struct EcsTickSource EcsTickSource
Component used to provide a tick source to systems.
FLECS_API const ecs_system_t * ecs_system_get(const ecs_world_t *world, ecs_entity_t system)
Get system object.
FLECS_API void FlecsSystemImport(ecs_world_t *world)
System module import function.
struct ecs_system_desc_t ecs_system_desc_t
Use with ecs_system_init() to create or update a system.
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.
struct ecs_system_t ecs_system_t
System type, get with ecs_system_get()
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.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:339
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:383
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:515
void(* flecs_poly_dtor_t)(ecs_poly_t *poly)
Destructor function for poly objects.
Definition flecs.h:617
void(* ecs_run_action_t)(ecs_iter_t *it)
Function prototype for runnables (systems, observers).
Definition flecs.h:506
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:584
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
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
Header for ecs_poly_t objects.
Definition flecs.h:481
Used with ecs_query_init().
Definition flecs.h:1138
Queries are lists of constraints (terms) that match entities.
Definition flecs.h:760
Use with ecs_system_init() to create or update a system.
Definition system.h:38
int32_t rate
Rate at which the system should run.
Definition system.h:87
void * ctx
Context to be passed to callback (as ecs_iter_t::param)
Definition system.h:66
ecs_ctx_free_t run_ctx_free
Callback to free run ctx.
Definition system.h:81
ecs_ctx_free_t ctx_free
Callback to free ctx.
Definition system.h:69
bool multi_threaded
If true, system will be ran on multiple threads.
Definition system.h:93
bool immediate
If true, system will have access to the actual world.
Definition system.h:97
void * callback_ctx
Context associated with callback (for language bindings).
Definition system.h:72
void * run_ctx
Context associated with run (for language bindings).
Definition system.h:78
ecs_ftime_t interval
Interval in seconds at which the system should run.
Definition system.h:84
ecs_iter_action_t callback
Callback that is ran for each result returned by the system's query.
Definition system.h:50
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_ctx_free_t callback_ctx_free
Callback to free callback ctx.
Definition system.h:75
ecs_run_action_t run
Callback that is invoked when a system is ran.
Definition system.h:63
ecs_entity_t tick_source
External tick source that determines when system ticks.
Definition system.h:90
System type, get with ecs_system_get()
Definition system.h:107
ecs_iter_action_t action
See ecs_system_desc_t.
Definition system.h:114
ecs_query_t * query
System query.
Definition system.h:117
ecs_ctx_free_t ctx_free
Callback to free ctx.
Definition system.h:141
void * run_ctx
Run language binding context.
Definition system.h:138
ecs_run_action_t run
See ecs_system_desc_t.
Definition system.h:111
ecs_ftime_t time_passed
Time passed since last invocation.
Definition system.h:153
int64_t last_frame
Last frame for which the system was considered.
Definition system.h:156
ecs_ftime_t time_spent
Time spent on running system.
Definition system.h:150
ecs_ctx_free_t run_ctx_free
Callback to free run ctx.
Definition system.h:147
bool immediate
Is system ran in immediate mode.
Definition system.h:129
bool multi_threaded
Is system multithreaded.
Definition system.h:126
void * ctx
Userdata for system.
Definition system.h:132
ecs_ctx_free_t callback_ctx_free
Callback to free callback ctx.
Definition system.h:144
ecs_entity_t query_entity
Entity associated with query.
Definition system.h:120
ecs_entity_t tick_source
Tick source associated with system.
Definition system.h:123
void * callback_ctx
Callback language binding context.
Definition system.h:135