Flecs v3.2
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
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
114#define ECS_SYSTEM_DEFINE(world, id_, phase, ...) \
115 { \
116 ecs_system_desc_t desc = {0}; \
117 ecs_entity_desc_t edesc = {0}; \
118 edesc.id = ecs_id(id_);\
119 edesc.name = #id_;\
120 edesc.add[0] = ((phase) ? ecs_pair(EcsDependsOn, (phase)) : 0); \
121 edesc.add[1] = (phase); \
122 desc.entity = ecs_entity_init(world, &edesc);\
123 desc.query.filter.expr = #__VA_ARGS__; \
124 desc.callback = id_; \
125 ecs_id(id_) = ecs_system_init(world, &desc); \
126 } \
127 ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, NULL)
128
137#define ECS_SYSTEM(world, id, phase, ...) \
138 ecs_entity_t ecs_id(id) = 0; ECS_SYSTEM_DEFINE(world, id, phase, __VA_ARGS__);\
139 ecs_entity_t id = ecs_id(id);\
140 (void)ecs_id(id);\
141 (void)id
142
161#define ecs_system(world, ...)\
162 ecs_system_init(world, &(ecs_system_desc_t) __VA_ARGS__ )
163
164#endif
165
193FLECS_API
195 ecs_world_t *world,
196 ecs_entity_t system,
197 ecs_ftime_t delta_time,
198 void *param);
199
210FLECS_API
212 ecs_world_t *world,
213 ecs_entity_t system,
214 int32_t stage_current,
215 int32_t stage_count,
216 ecs_ftime_t delta_time,
217 void *param);
218
239FLECS_API
241 ecs_world_t *world,
242 ecs_entity_t system,
243 ecs_ftime_t delta_time,
244 int32_t offset,
245 int32_t limit,
246 void *param);
247
257FLECS_API
259 const ecs_world_t *world,
260 ecs_entity_t system);
261
270FLECS_API
272 const ecs_world_t *world,
273 ecs_entity_t system);
274
284FLECS_API
286 const ecs_world_t *world,
287 ecs_entity_t system);
288
289FLECS_API
290void FlecsSystemImport(
291 ecs_world_t *world);
292
293#ifdef __cplusplus
294}
295#endif
296
297#endif
298
301#endif
struct EcsTickSource EcsTickSource
Component used to provide a tick source to systems.
struct ecs_system_desc_t ecs_system_desc_t
Use with ecs_system_init()
FLECS_API void * ecs_system_get_binding_ctx(const ecs_world_t *world, ecs_entity_t system)
Get system binding 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 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.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:305
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:349
struct ecs_query_t ecs_query_t
A query that caches its results.
Definition flecs.h:381
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition flecs.h:527
void(* ecs_run_action_t)(ecs_iter_t *it)
Function prototype for runnables (systems, observers).
Definition flecs.h:518
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition flecs.h:613
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:43
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:1020
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 the actual 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 source that determines when system ticks.
Definition system.h:85