Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
System

Systems are a query + function that can be ran manually or by a pipeline. More...

Collaboration diagram for System:

Classes

struct  EcsTickSource
 Component used to provide a tick source to systems. More...
 
struct  ecs_system_desc_t
 Use with ecs_system_init() to create or update a system. More...
 
struct  ecs_system_t
 System type, get with ecs_system_get() More...
 

Macros

#define FLECS_SYSTEM_H
 
#define ECS_SYSTEM_DECLARE(id)   ecs_entity_t ecs_id(id)
 Forward declare a system.
 
#define ECS_SYSTEM_DEFINE(world, id_, phase, ...)
 Define a forward declared system.
 
#define ECS_SYSTEM(world, id, phase, ...)
 Declare & define a system.
 
#define ecs_system(world, ...)    ecs_system_init(world, &(ecs_system_desc_t) __VA_ARGS__ )
 Shorthand for creating a system with ecs_system_init().
 

Typedefs

typedef struct EcsTickSource EcsTickSource
 Component used to provide a tick source to systems.
 
typedef struct ecs_system_desc_t ecs_system_desc_t
 Use with ecs_system_init() to create or update a system.
 
typedef struct ecs_system_t ecs_system_t
 System type, get with ecs_system_get()
 

Functions

FLECS_API ecs_entity_t ecs_system_init (ecs_world_t *world, const ecs_system_desc_t *desc)
 Create a system.
 
FLECS_API const ecs_system_tecs_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_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 void FlecsSystemImport (ecs_world_t *world)
 System module import function.
 

Detailed Description

Systems are a query + function that can be ran manually or by a pipeline.

Macro Definition Documentation

◆ ECS_SYSTEM

#define ECS_SYSTEM ( world,
id,
phase,
... )
Value:
ecs_entity_t ecs_id(id) = 0; ECS_SYSTEM_DEFINE(world, id, phase, __VA_ARGS__);\
ecs_entity_t id = ecs_id(id);\
(void)ecs_id(id);\
(void)id
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component id for EcsDocDescription.
#define ECS_SYSTEM_DEFINE(world, id_, phase,...)
Define a forward declared system.
Definition system.h:193
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:346

Declare & define a system.

Example:

ECS_SYSTEM(world, Move, EcsOnUpdate, Position, Velocity);
const ecs_entity_t EcsOnUpdate
OnUpdate pipeline phase.
#define ECS_SYSTEM(world, id, phase,...)
Declare & define a system.
Definition system.h:220

Definition at line 220 of file system.h.

◆ ecs_system

#define ecs_system ( world,
... )    ecs_system_init(world, &(ecs_system_desc_t) __VA_ARGS__ )

Shorthand for creating a system with ecs_system_init().

Example:

ecs_system(world, {
.entity = ecs_entity(world, {
.name = "MyEntity",
.add = ecs_ids( ecs_dependson(EcsOnUpdate) )
}),
.query.terms = {
{ ecs_id(Position) },
{ ecs_id(Velocity) }
},
.callback = Move
});
#define ecs_system(world,...)
Shorthand for creating a system with ecs_system_init().
Definition system.h:244
#define ecs_entity(world,...)
Shorthand for creating an entity with ecs_entity_init().
Definition flecs_c.h:235
#define ecs_ids(...)
Convenience macro for creating compound literal id array.
Definition flecs_c.h:720

Definition at line 244 of file system.h.

◆ ECS_SYSTEM_DECLARE

#define ECS_SYSTEM_DECLARE ( id)    ecs_entity_t ecs_id(id)

Forward declare a system.

Definition at line 183 of file system.h.

◆ ECS_SYSTEM_DEFINE

#define ECS_SYSTEM_DEFINE ( world,
id_,
phase,
... )
Value:
{ \
ecs_system_desc_t desc = {0}; \
ecs_entity_desc_t edesc = {0}; \
ecs_id_t add_ids[3] = {\
((phase) ? ecs_pair(EcsDependsOn, (phase)) : 0), \
(phase), \
0 \
};\
edesc.id = ecs_id(id_);\
edesc.name = #id_;\
edesc.add = add_ids;\
desc.entity = ecs_entity_init(world, &edesc);\
desc.query.expr = #__VA_ARGS__; \
desc.callback = id_; \
ecs_id(id_) = ecs_system_init(world, &desc); \
} \
ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, "failed to create system %s", #id_)
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
FLECS_API ecs_entity_t ecs_system_init(ecs_world_t *world, const ecs_system_desc_t *desc)
Create a system.
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:339
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
Used with ecs_entity_init().
Definition flecs.h:976
const char * name
Name of the entity.
Definition flecs.h:983
const ecs_id_t * add
0-terminated array of ids to add to the entity.
Definition flecs.h:1009
ecs_entity_t id
Set to modify existing entity (optional)
Definition flecs.h:979
const char * expr
Query DSL expression (optional)
Definition flecs.h:1208
Use with ecs_system_init() to create or update a system.
Definition system.h:38
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

Define a forward declared system.

Example:

ECS_SYSTEM_DEFINE(world, Move, EcsOnUpdate, Position, Velocity);

Definition at line 193 of file system.h.

◆ FLECS_SYSTEM_H

#define FLECS_SYSTEM_H

Definition at line 25 of file system.h.

Function Documentation

◆ ecs_run()

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.

This operation runs a single system manually. It is an efficient way to invoke logic on a set of entities, as manual systems are only matched to tables at creation time or after creation time, when a new table is created.

Manual systems are useful to evaluate lists of pre-matched entities at application defined times. Because none of the matching logic is evaluated before the system is invoked, manual systems are much more efficient than manually obtaining a list of entities and retrieving their components.

An application may pass custom data to a system through the param parameter. This data can be accessed by the system through the param member in the ecs_iter_t value that is passed to the system callback.

Any system may interrupt execution by setting the interrupted_by member in the ecs_iter_t value. This is particularly useful for manual systems, where the value of interrupted_by is returned by this operation. This, in combination with the param argument lets applications use manual systems to lookup entities: once the entity has been found its handle is passed to interrupted_by, which is then subsequently returned.

Parameters
worldThe world.
systemThe system to run.
delta_timeThe time passed since the last system invocation.
paramA user-defined parameter to pass to the system.
Returns
handle to last evaluated entity if system was interrupted.

◆ ecs_run_worker()

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.

Parameters
worldThe world.
systemThe system to run.
stage_currentThe id of the current stage.
stage_countThe total number of stages.
delta_timeThe time passed since the last system invocation.
paramA user-defined parameter to pass to the system.
Returns
handle to last evaluated entity if system was interrupted.

◆ ecs_system_get()

FLECS_API const ecs_system_t * ecs_system_get ( const ecs_world_t * world,
ecs_entity_t system )

Get system object.

Returns the system object. Can be used to access various information about the system, like the query and context.

Parameters
worldThe world.
systemThe system.
Returns
The system object.

◆ FlecsSystemImport()

FLECS_API void FlecsSystemImport ( ecs_world_t * world)

System module import function.

Usage:

ECS_IMPORT(world, FlecsSystem)
#define ECS_IMPORT(world, id)
Wrapper around ecs_import().
Definition module.h:119
Parameters
worldThe world.