Flecs v3.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs.h
Go to the documentation of this file.
1
8#ifndef FLECS_H
9#define FLECS_H
10
34#ifndef ecs_float_t
35#define ecs_float_t float
36#endif
37
41#ifndef ecs_ftime_t
42#define ecs_ftime_t ecs_float_t
43#endif
44
48// #define FLECS_LEGACY
49
53#define FLECS_NO_DEPRECATED_WARNINGS
54
60// #define FLECS_ACCURATE_COUNTERS
61
62/* Make sure provided configuration is valid */
63#if defined(FLECS_DEBUG) && defined(FLECS_NDEBUG)
64#error "invalid configuration: cannot both define FLECS_DEBUG and FLECS_NDEBUG"
65#endif
66#if defined(FLECS_DEBUG) && defined(NDEBUG)
67#error "invalid configuration: cannot both define FLECS_DEBUG and NDEBUG"
68#endif
69
74#if !defined(FLECS_DEBUG) && !defined(FLECS_NDEBUG)
75#if defined(NDEBUG)
76#define FLECS_NDEBUG
77#else
78#define FLECS_DEBUG
79#endif
80#endif
81
86#ifdef FLECS_SANITIZE
87#define FLECS_DEBUG /* If sanitized mode is enabled, so is debug mode */
88#endif
89
90/* Tip: if you see weird behavior that you think might be a bug, make sure to
91 * test with the FLECS_DEBUG or FLECS_SANITIZE flags enabled. There's a good
92 * chance that this gives you more information about the issue! */
93
107// #define FLECS_SOFT_ASSERT
108
114// #define FLECS_KEEP_ASSERT
115
139// #define FLECS_CUSTOM_BUILD
140
141#ifndef FLECS_CUSTOM_BUILD
142// #define FLECS_C /**< C API convenience macros, always enabled */
143#define FLECS_CPP
144#define FLECS_MODULE
145#define FLECS_PARSER
146#define FLECS_PLECS
147#define FLECS_RULES
148#define FLECS_SNAPSHOT
149#define FLECS_STATS
150#define FLECS_MONITOR
151#define FLECS_SYSTEM
152#define FLECS_PIPELINE
153#define FLECS_TIMER
154#define FLECS_META
155#define FLECS_META_C
156#define FLECS_UNITS
157#define FLECS_EXPR
158#define FLECS_JSON
159#define FLECS_DOC
160#define FLECS_COREDOC
161#define FLECS_LOG
162#define FLECS_APP
163#define FLECS_OS_API_IMPL
164#define FLECS_HTTP
165#define FLECS_REST
166// #define FLECS_JOURNAL /**< Journaling addon (disabled by default) */
167#endif // ifndef FLECS_CUSTOM_BUILD
168
171#ifndef ECS_ID_CACHE_SIZE
172#define ECS_ID_CACHE_SIZE (32)
173#endif
174
177#define ECS_TERM_DESC_CACHE_SIZE (16)
178
181#define ECS_OBSERVER_DESC_EVENT_COUNT_MAX (8)
182
185#define ECS_VARIABLE_COUNT_MAX (64)
186
189#include "flecs/private/api_defines.h"
190#include "flecs/private/vec.h" /* Vector datatype */
191#include "flecs/private/sparse.h" /* Sparse set */
192#include "flecs/private/block_allocator.h" /* Block allocator */
193#include "flecs/private/map.h" /* Map */
194#include "flecs/private/allocator.h" /* Allocator */
195#include "flecs/private/strbuf.h" /* String builder */
196#include "flecs/os_api.h" /* Abstraction for operating system functions */
197
198#ifdef __cplusplus
199extern "C" {
200#endif
201
216typedef uint64_t ecs_id_t;
217
220
222typedef struct {
223 ecs_id_t *array;
224 int32_t count;
225} ecs_type_t;
226
229
232
234typedef struct ecs_term_t ecs_term_t;
235
238
241
243typedef struct ecs_rule_t ecs_rule_t;
244
247
250
251/* An iterator lets an application iterate entities across tables. */
252typedef struct ecs_iter_t ecs_iter_t;
253
255typedef struct ecs_ref_t ecs_ref_t;
256
259
262
263/* Internal index that stores tables tables for a (component) id */
264typedef struct ecs_id_record_t ecs_id_record_t;
265
266/* Internal table storage record */
267typedef struct ecs_table_record_t ecs_table_record_t;
268
291typedef void ecs_poly_t;
292
295
297typedef struct ecs_header_t {
298 int32_t magic; /* Magic number verifying it's a flecs object */
299 int32_t type; /* Magic number indicating which type of flecs object */
300 ecs_mixins_t *mixins; /* Table with offsets to (optional) mixins */
302
320typedef void (*ecs_run_action_t)(
321 ecs_iter_t *it);
322
329typedef void (*ecs_iter_action_t)(
330 ecs_iter_t *it);
331
344 const ecs_world_t *world,
345 const ecs_poly_t *iterable,
346 ecs_iter_t *it,
347 ecs_term_t *filter);
348
357 ecs_iter_t *it);
358
365 ecs_iter_t *it);
366
369 ecs_entity_t e1,
370 const void *ptr1,
371 ecs_entity_t e2,
372 const void *ptr2);
373
376 ecs_world_t* world,
377 ecs_table_t* table,
378 ecs_entity_t* entities,
379 void* ptr,
380 int32_t size,
381 int32_t lo,
382 int32_t hi,
383 ecs_order_by_action_t order_by);
384
386typedef uint64_t (*ecs_group_by_action_t)(
387 ecs_world_t *world,
388 ecs_table_t *table,
389 ecs_id_t group_id,
390 void *ctx);
391
392/* Callback invoked when a query creates a new group. */
393typedef void* (*ecs_group_create_action_t)(
394 ecs_world_t *world,
395 uint64_t group_id,
396 void *group_by_ctx); /* from ecs_query_desc_t */
397
398/* Callback invoked when a query deletes an existing group. */
399typedef void (*ecs_group_delete_action_t)(
400 ecs_world_t *world,
401 uint64_t group_id,
402 void *group_ctx, /* return value from ecs_group_create_action_t */
403 void *group_by_ctx); /* from ecs_query_desc_t */
404
406typedef void (*ecs_module_action_t)(
407 ecs_world_t *world);
408
410typedef void (*ecs_fini_action_t)(
411 ecs_world_t *world,
412 void *ctx);
413
415typedef void (*ecs_ctx_free_t)(
416 void *ctx);
417
419typedef int (*ecs_compare_action_t)(
420 const void *ptr1,
421 const void *ptr2);
422
424typedef uint64_t (*ecs_hash_value_action_t)(
425 const void *ptr);
426
428typedef void (*ecs_xtor_t)(
429 void *ptr,
430 int32_t count,
431 const ecs_type_info_t *type_info);
432
434typedef void (*ecs_copy_t)(
435 void *dst_ptr,
436 const void *src_ptr,
437 int32_t count,
438 const ecs_type_info_t *type_info);
439
441typedef void (*ecs_move_t)(
442 void *dst_ptr,
443 void *src_ptr,
444 int32_t count,
445 const ecs_type_info_t *type_info);
446
447/* Destructor function for poly objects */
448typedef void (*ecs_poly_dtor_t)(
449 ecs_poly_t *poly);
450
461typedef struct ecs_iterable_t {
464
474typedef enum ecs_inout_kind_t {
481
483typedef enum ecs_oper_kind_t {
492
493/* Term id flags */
494#define EcsSelf (1u << 1)
495#define EcsUp (1u << 2)
496#define EcsDown (1u << 3)
497#define EcsTraverseAll (1u << 4)
498#define EcsCascade (1u << 5)
499#define EcsParent (1u << 6)
500#define EcsIsVariable (1u << 7)
501#define EcsIsEntity (1u << 8)
502#define EcsIsName (1u << 9)
503#define EcsFilter (1u << 10)
504#define EcsTraverseFlags (EcsUp|EcsDown|EcsTraverseAll|EcsSelf|EcsCascade|EcsParent)
505
506/* Term flags discovered & set during filter creation. */
507#define EcsTermMatchAny (1 << 0)
508#define EcsTermMatchAnySrc (1 << 1)
509#define EcsTermSrcFirstEq (1 << 2)
510#define EcsTermSrcSecondEq (1 << 3)
511#define EcsTermTransitive (1 << 4)
512#define EcsTermReflexive (1 << 5)
513#define EcsTermIdInherited (1 << 6)
514
516typedef struct ecs_term_id_t {
523 char *name;
534 ecs_flags32_t flags;
536
552 char *name;
554 int32_t field_index;
555 ecs_id_record_t *idr;
557 ecs_flags16_t flags;
559 bool move;
560};
561
563FLECS_API extern ecs_filter_t ECS_FILTER_INIT;
564
567 ecs_header_t hdr;
568
570 int32_t term_count;
571 int32_t field_count;
573 bool owned;
576 ecs_flags32_t flags;
578 char *variable_names[1];
580 /* Mixins */
582 ecs_world_t *world;
584 ecs_poly_dtor_t dtor;
585};
586
587/* An observer reacts to events matching a filter */
589 ecs_header_t hdr;
590
593 /* Observer events */
595 int32_t event_count;
596
600 void *ctx;
608 int32_t *last_event_id;
609 int32_t last_event_id_storage;
610
612 int32_t term_index;
618 bool is_multi;
620 /* Mixins */
621 ecs_poly_dtor_t dtor;
622};
623
638
641
647
653
657
662
667
668 void *ctx;
673};
674
680 ecs_size_t size;
681 ecs_size_t alignment;
684 const char *name;
685};
686
687#include "flecs/private/api_types.h" /* Supporting API types */
688#include "flecs/private/api_support.h" /* Supporting API functions */
689#include "flecs/private/vec.h" /* Vector */
690#include "flecs/private/hashmap.h" /* Hashmap */
691
696typedef struct ecs_entity_desc_t {
697 int32_t _canary;
698
701 const char *name;
706 const char *sep;
710 const char *root_sep;
712 const char *symbol;
728
730 const char *add_expr;
732
737typedef struct ecs_bulk_desc_t {
738 int32_t _canary;
739
745 int32_t count;
749 void **data;
762
767typedef struct ecs_component_desc_t {
768 int32_t _canary;
769
772
776
781typedef struct ecs_filter_desc_t {
782 int32_t _canary;
783
787
790
793
796
803
805 ecs_flags32_t flags;
806
808 const char *expr;
809
813
818typedef struct ecs_query_desc_t {
819 int32_t _canary;
820
823
826
831
835
840
847
850 ecs_group_create_action_t on_group_create;
851
854 ecs_group_delete_action_t on_group_delete;
855
858
861
870
875typedef struct ecs_observer_desc_t {
876 int32_t _canary;
877
880
883
886
891
894
902
904 void *ctx;
905
908
911
914
917
921
923 int32_t term_index;
925
932/* Utility to hold a value of a dynamic type */
933typedef struct ecs_value_t {
934 ecs_entity_t type;
935 void *ptr;
937
939typedef struct ecs_world_info_t {
969 int32_t id_count;
970 int32_t tag_id_count;
975 int32_t table_count;
982 /* -- Command counts -- */
983 struct {
984 int64_t add_count;
985 int64_t remove_count;
986 int64_t delete_count;
987 int64_t clear_count;
988 int64_t set_count;
991 int64_t other_count;
995 } cmd;
996
997 const char *name_prefix;
1002
1005 int32_t match_count;
1006 int32_t table_count;
1007 void *ctx;
1009
1019typedef struct EcsIdentifier {
1020 char *value;
1021 ecs_size_t length;
1022 uint64_t hash;
1023 uint64_t index_hash;
1024 ecs_hashmap_t *index;
1026
1028typedef struct EcsComponent {
1029 ecs_size_t size;
1030 ecs_size_t alignment;
1032
1034typedef struct EcsPoly {
1037
1039typedef struct EcsTarget {
1040 int32_t count;
1041 ecs_record_t *target;
1043
1046
1050/* Only include deprecated definitions if deprecated addon is required */
1051#ifdef FLECS_DEPRECATED
1053#endif
1054
1068#define ECS_ID_FLAG_BIT (1ull << 63)
1069
1071FLECS_API extern const ecs_id_t ECS_PAIR;
1072
1074FLECS_API extern const ecs_id_t ECS_OVERRIDE;
1075
1077FLECS_API extern const ecs_id_t ECS_TOGGLE;
1078
1080FLECS_API extern const ecs_id_t ECS_AND;
1081
1089/* Builtin component ids */
1090FLECS_API extern const ecs_entity_t ecs_id(EcsComponent);
1091FLECS_API extern const ecs_entity_t ecs_id(EcsIdentifier);
1092FLECS_API extern const ecs_entity_t ecs_id(EcsIterable);
1093FLECS_API extern const ecs_entity_t ecs_id(EcsPoly);
1094
1095FLECS_API extern const ecs_entity_t EcsQuery;
1096FLECS_API extern const ecs_entity_t EcsObserver;
1097
1098/* System module component ids */
1099FLECS_API extern const ecs_entity_t EcsSystem;
1100FLECS_API extern const ecs_entity_t ecs_id(EcsTickSource);
1101
1102/* Pipeline module component ids */
1103FLECS_API extern const ecs_entity_t ecs_id(EcsPipelineQuery);
1104
1105/* Timer module component ids */
1106FLECS_API extern const ecs_entity_t ecs_id(EcsTimer);
1107FLECS_API extern const ecs_entity_t ecs_id(EcsRateFilter);
1108
1110FLECS_API extern const ecs_entity_t EcsFlecs;
1111
1113FLECS_API extern const ecs_entity_t EcsFlecsCore;
1114
1116FLECS_API extern const ecs_entity_t EcsWorld;
1117
1119FLECS_API extern const ecs_entity_t EcsWildcard;
1120
1122FLECS_API extern const ecs_entity_t EcsAny;
1123
1125FLECS_API extern const ecs_entity_t EcsThis;
1126
1128FLECS_API extern const ecs_entity_t EcsVariable;
1129
1134FLECS_API extern const ecs_entity_t EcsTransitive;
1135
1140FLECS_API extern const ecs_entity_t EcsReflexive;
1141
1149FLECS_API extern const ecs_entity_t EcsFinal;
1150
1156FLECS_API extern const ecs_entity_t EcsDontInherit;
1157
1163FLECS_API extern const ecs_entity_t EcsAlwaysOverride;
1164
1169FLECS_API extern const ecs_entity_t EcsSymmetric;
1170
1177FLECS_API extern const ecs_entity_t EcsExclusive;
1178
1180FLECS_API extern const ecs_entity_t EcsAcyclic;
1181
1184FLECS_API extern const ecs_entity_t EcsTraversable;
1185
1192FLECS_API extern const ecs_entity_t EcsWith;
1193
1200FLECS_API extern const ecs_entity_t EcsOneOf;
1201
1204FLECS_API extern const ecs_entity_t EcsTag;
1205
1209FLECS_API extern const ecs_entity_t EcsUnion;
1210
1212FLECS_API extern const ecs_entity_t EcsName;
1213
1215FLECS_API extern const ecs_entity_t EcsSymbol;
1216
1218FLECS_API extern const ecs_entity_t EcsAlias;
1219
1221FLECS_API extern const ecs_entity_t EcsChildOf;
1222
1224FLECS_API extern const ecs_entity_t EcsIsA;
1225
1227FLECS_API extern const ecs_entity_t EcsDependsOn;
1228
1230FLECS_API extern const ecs_entity_t EcsSlotOf;
1231
1233FLECS_API extern const ecs_entity_t EcsModule;
1234
1236FLECS_API extern const ecs_entity_t EcsPrivate;
1237
1240FLECS_API extern const ecs_entity_t EcsPrefab;
1241
1243FLECS_API extern const ecs_entity_t EcsDisabled;
1244
1246FLECS_API extern const ecs_entity_t EcsOnAdd;
1247
1249FLECS_API extern const ecs_entity_t EcsOnRemove;
1250
1252FLECS_API extern const ecs_entity_t EcsOnSet;
1253
1255FLECS_API extern const ecs_entity_t EcsUnSet;
1256
1258FLECS_API extern const ecs_entity_t EcsMonitor;
1259
1264FLECS_API extern const ecs_entity_t EcsOnDelete;
1265
1267FLECS_API extern const ecs_entity_t EcsOnTableCreate;
1268
1270FLECS_API extern const ecs_entity_t EcsOnTableDelete;
1271
1273FLECS_API extern const ecs_entity_t EcsOnTableEmpty;
1274
1276FLECS_API extern const ecs_entity_t EcsOnTableFill;
1277
1282FLECS_API extern const ecs_entity_t EcsOnDeleteTarget;
1283
1286FLECS_API extern const ecs_entity_t EcsRemove;
1287
1290FLECS_API extern const ecs_entity_t EcsDelete;
1291
1294FLECS_API extern const ecs_entity_t EcsPanic;
1295
1296FLECS_API extern const ecs_entity_t ecs_id(EcsTarget);
1297FLECS_API extern const ecs_entity_t EcsFlatten;
1298
1304FLECS_API extern const ecs_entity_t EcsDefaultChildComponent;
1305
1306/* Builtin predicates for comparing entity ids in queries. Only supported by rules */
1307FLECS_API extern const ecs_entity_t EcsPredEq;
1308FLECS_API extern const ecs_entity_t EcsPredMatch;
1309FLECS_API extern const ecs_entity_t EcsPredLookup;
1310
1312FLECS_API extern const ecs_entity_t EcsEmpty;
1313
1314/* Pipeline module tags */
1315FLECS_API extern const ecs_entity_t ecs_id(EcsPipeline);
1316FLECS_API extern const ecs_entity_t EcsOnStart;
1317FLECS_API extern const ecs_entity_t EcsPreFrame;
1318FLECS_API extern const ecs_entity_t EcsOnLoad;
1319FLECS_API extern const ecs_entity_t EcsPostLoad;
1320FLECS_API extern const ecs_entity_t EcsPreUpdate;
1321FLECS_API extern const ecs_entity_t EcsOnUpdate;
1322FLECS_API extern const ecs_entity_t EcsOnValidate;
1323FLECS_API extern const ecs_entity_t EcsPostUpdate;
1324FLECS_API extern const ecs_entity_t EcsPreStore;
1325FLECS_API extern const ecs_entity_t EcsOnStore;
1326FLECS_API extern const ecs_entity_t EcsPostFrame;
1327FLECS_API extern const ecs_entity_t EcsPhase;
1328
1331#define EcsLastInternalComponentId (ecs_id(EcsPoly))
1332
1335#define EcsFirstUserComponentId (8)
1336
1339#define EcsFirstUserEntityId (ECS_HI_COMPONENT_ID + 128)
1340
1364FLECS_API
1366
1371FLECS_API
1373
1381FLECS_API
1383 int argc,
1384 char *argv[]);
1385
1392FLECS_API
1394 ecs_world_t *world);
1395
1401FLECS_API
1403 const ecs_world_t *world);
1404
1412FLECS_API
1414 ecs_world_t *world,
1415 ecs_fini_action_t action,
1416 void *ctx);
1417
1443FLECS_API
1445 ecs_world_t *world,
1446 ecs_ftime_t delta_time);
1447
1454FLECS_API
1456 ecs_world_t *world);
1457
1465FLECS_API
1467 ecs_world_t *world,
1468 ecs_fini_action_t action,
1469 void *ctx);
1470
1477FLECS_API
1479 ecs_world_t *world);
1480
1485FLECS_API
1487 const ecs_world_t *world);
1488
1501 ecs_world_t *world,
1502 bool enable);
1503
1515 ecs_world_t *world,
1516 bool enable);
1517
1533FLECS_API
1535 ecs_world_t *world,
1536 ecs_ftime_t fps);
1537
1574FLECS_API
1576 ecs_world_t *world);
1577
1585FLECS_API
1587 ecs_world_t *world);
1588
1599FLECS_API
1601 ecs_world_t *world);
1602
1612FLECS_API
1614 ecs_world_t *world);
1615
1621FLECS_API
1623 const ecs_world_t *world);
1624
1633FLECS_API
1635 ecs_world_t *world);
1636
1646FLECS_API
1648 ecs_world_t *world);
1649
1655FLECS_API
1657 ecs_world_t *world);
1658
1675FLECS_API
1677 ecs_world_t *world,
1678 bool automerge);
1679
1693FLECS_API
1695 ecs_world_t *world,
1696 int32_t stages);
1697
1704FLECS_API
1706 const ecs_world_t *world);
1707
1715FLECS_API
1717 const ecs_world_t *world);
1718
1734FLECS_API
1736 const ecs_world_t *world,
1737 int32_t stage_id);
1738
1746FLECS_API
1748 const ecs_world_t *world);
1749
1768FLECS_API
1770 ecs_world_t *world);
1771
1778FLECS_API
1780 ecs_world_t *stage);
1781
1788FLECS_API
1790 ecs_world_t *stage);
1791
1806FLECS_API
1808 ecs_world_t *world,
1809 void *ctx);
1810
1818FLECS_API
1820 const ecs_world_t *world);
1821
1828FLECS_API
1830 const ecs_world_t *world);
1831
1840FLECS_API
1842 ecs_world_t *world,
1843 int32_t entity_count);
1844
1860FLECS_API
1862 ecs_world_t *world,
1863 ecs_entity_t id_start,
1864 ecs_entity_t id_end);
1865
1876FLECS_API
1878 ecs_world_t *world,
1879 bool enable);
1880
1894FLECS_API
1896 ecs_world_t *world,
1897 ecs_flags32_t flags);
1898
1932FLECS_API
1934 ecs_world_t *world,
1935 ecs_id_t id,
1936 uint16_t clear_generation,
1937 uint16_t delete_generation,
1938 int32_t min_id_count,
1939 double time_budget_seconds);
1940
1946FLECS_API
1948 const ecs_poly_t *poly);
1949
1955FLECS_API
1957 const ecs_poly_t *poly);
1958
1969FLECS_API
1971 const ecs_poly_t *object,
1972 int32_t type);
1973
1974#define ecs_poly_is(object, type)\
1975 _ecs_poly_is(object, type##_magic)
1976
1984FLECS_API
1986 ecs_entity_t first,
1987 ecs_entity_t second);
1988
2013FLECS_API
2015 ecs_world_t *world);
2016
2034FLECS_API
2036 ecs_world_t *world);
2037
2046FLECS_API
2048 ecs_world_t *world,
2049 ecs_id_t id);
2050
2058FLECS_API
2060 ecs_world_t *world,
2061 ecs_table_t *table);
2062
2081FLECS_API
2083 ecs_world_t *world,
2084 const ecs_entity_desc_t *desc);
2085
2112FLECS_API
2114 ecs_world_t *world,
2115 const ecs_bulk_desc_t *desc);
2116
2126FLECS_API
2128 ecs_world_t *world,
2129 ecs_id_t id,
2130 int32_t count);
2131
2143FLECS_API
2145 ecs_world_t *world,
2146 ecs_entity_t dst,
2147 ecs_entity_t src,
2148 bool copy_value);
2149
2159FLECS_API
2161 ecs_world_t *world,
2162 ecs_entity_t entity);
2163
2171FLECS_API
2173 ecs_world_t *world,
2174 ecs_id_t id);
2175
2192FLECS_API
2194 ecs_world_t *world,
2195 ecs_entity_t entity,
2196 ecs_id_t id);
2197
2206FLECS_API
2208 ecs_world_t *world,
2209 ecs_entity_t entity,
2210 ecs_id_t id);
2211
2234FLECS_API
2236 ecs_world_t *world,
2237 ecs_entity_t entity,
2238 ecs_id_t id);
2239
2248FLECS_API
2250 ecs_world_t *world,
2251 ecs_entity_t entity);
2252
2253
2261FLECS_API
2263 ecs_world_t *world,
2264 ecs_id_t id);
2265
2273FLECS_API
2275 ecs_world_t *world,
2276 ecs_id_t id);
2277
2284FLECS_API
2286 const ecs_world_t *world);
2287
2305FLECS_API
2307 ecs_world_t *world,
2308 ecs_entity_t entity,
2309 bool enabled);
2310
2324FLECS_API
2326 ecs_world_t *world,
2327 ecs_entity_t entity,
2328 ecs_id_t id,
2329 bool enable);
2330
2341FLECS_API
2343 const ecs_world_t *world,
2344 ecs_entity_t entity,
2345 ecs_id_t id);
2346
2364FLECS_API
2365const void* ecs_get_id(
2366 const ecs_world_t *world,
2367 ecs_entity_t entity,
2368 ecs_id_t id);
2369
2380FLECS_API
2382 const ecs_world_t *world,
2383 ecs_entity_t entity,
2384 ecs_id_t id);
2385
2394FLECS_API
2396 const ecs_world_t *world,
2397 ecs_ref_t *ref,
2398 ecs_id_t id);
2399
2407FLECS_API
2409 const ecs_world_t *world,
2410 ecs_ref_t *ref);
2411
2426FLECS_API
2428 ecs_world_t *world,
2429 ecs_entity_t entity,
2430 ecs_id_t id);
2431
2450FLECS_API
2451ecs_record_t* ecs_write_begin(
2452 ecs_world_t *world,
2453 ecs_entity_t entity);
2454
2461FLECS_API
2463 ecs_record_t *record);
2464
2484FLECS_API
2485const ecs_record_t* ecs_read_begin(
2486 ecs_world_t *world,
2487 ecs_entity_t entity);
2488
2494FLECS_API
2496 const ecs_record_t *record);
2497
2503FLECS_API
2505 const ecs_record_t *record);
2506
2520FLECS_API
2522 ecs_world_t *world,
2523 const ecs_record_t *record,
2524 ecs_id_t id);
2525
2534FLECS_API
2536 ecs_world_t *world,
2537 ecs_record_t *record,
2538 ecs_id_t id);
2539
2546FLECS_API
2548 ecs_world_t *world,
2549 const ecs_record_t *record,
2550 ecs_id_t id);
2551
2565FLECS_API
2567 ecs_world_t *world,
2568 ecs_entity_t entity,
2569 ecs_id_t id);
2570
2581FLECS_API
2583 ecs_world_t *world,
2584 ecs_entity_t entity,
2585 ecs_id_t id);
2586
2600FLECS_API
2602 ecs_world_t *world,
2603 ecs_entity_t entity,
2604 ecs_id_t id,
2605 size_t size,
2606 const void *ptr);
2607
2634FLECS_API
2636 const ecs_world_t *world,
2637 ecs_entity_t e);
2638
2647FLECS_API
2649 const ecs_world_t *world,
2650 ecs_entity_t e);
2651
2657FLECS_API
2659 ecs_entity_t e);
2660
2672FLECS_API
2674 ecs_world_t *world,
2675 ecs_entity_t entity);
2676
2693FLECS_API
2695 const ecs_world_t *world,
2696 ecs_entity_t e);
2697
2718FLECS_API
2720 ecs_world_t *world,
2721 ecs_entity_t entity);
2722
2741FLECS_API
2743 ecs_world_t *world,
2744 ecs_id_t id);
2745
2753FLECS_API
2755 const ecs_world_t *world,
2756 ecs_entity_t entity);
2757
2772FLECS_API
2774 const ecs_world_t *world,
2775 ecs_entity_t entity);
2776
2783FLECS_API
2785 const ecs_world_t *world,
2786 ecs_entity_t entity);
2787
2795FLECS_API
2797 const ecs_world_t *world,
2798 const ecs_type_t* type);
2799
2808FLECS_API
2810 const ecs_world_t *world,
2811 const ecs_table_t *table);
2812
2824FLECS_API
2826 const ecs_world_t *world,
2827 ecs_entity_t entity);
2828
2838FLECS_API
2840 const ecs_world_t *world,
2841 ecs_entity_t entity,
2842 ecs_id_t id);
2843
2858FLECS_API
2860 const ecs_world_t *world,
2861 ecs_entity_t entity,
2862 ecs_entity_t rel,
2863 int32_t index);
2864
2873FLECS_API
2875 const ecs_world_t *world,
2876 ecs_entity_t entity);
2877
2896FLECS_API
2898 const ecs_world_t *world,
2899 ecs_entity_t entity,
2900 ecs_entity_t rel,
2901 ecs_id_t id);
2902
2913FLECS_API
2915 const ecs_world_t *world,
2916 ecs_entity_t entity,
2917 ecs_entity_t rel);
2918
2919typedef struct ecs_flatten_desc_t {
2920 /* When true, the flatten operation will not remove names from entities in
2921 * the flattened tree. This may fail if entities from different subtrees
2922 * have the same name. */
2923 bool keep_names;
2924
2925 /* When true, the flattened tree won't contain information about the
2926 * original depth of the entities. This can reduce fragmentation, but may
2927 * cause existing code, such as cascade queries, to no longer work. */
2928 bool lose_depth;
2930
2955FLECS_API
2957 ecs_world_t *world,
2958 ecs_id_t pair,
2959 const ecs_flatten_desc_t *desc);
2960
2968FLECS_API
2970 const ecs_world_t *world,
2971 ecs_id_t entity);
2972
2989FLECS_API
2990const char* ecs_get_name(
2991 const ecs_world_t *world,
2992 ecs_entity_t entity);
2993
3001FLECS_API
3002const char* ecs_get_symbol(
3003 const ecs_world_t *world,
3004 ecs_entity_t entity);
3005
3017FLECS_API
3019 ecs_world_t *world,
3020 ecs_entity_t entity,
3021 const char *name);
3022
3034FLECS_API
3036 ecs_world_t *world,
3037 ecs_entity_t entity,
3038 const char *symbol);
3039
3051FLECS_API
3053 ecs_world_t *world,
3054 ecs_entity_t entity,
3055 const char *alias);
3056
3065FLECS_API
3067 const ecs_world_t *world,
3068 const char *name);
3069
3079FLECS_API
3081 const ecs_world_t *world,
3082 ecs_entity_t parent,
3083 const char *name);
3084
3103FLECS_API
3105 const ecs_world_t *world,
3106 ecs_entity_t parent,
3107 const char *path,
3108 const char *sep,
3109 const char *prefix,
3110 bool recursive);
3111
3119FLECS_API
3121 const ecs_world_t *world,
3122 const char *symbol,
3123 bool lookup_as_path);
3124
3144FLECS_API
3146 const ecs_world_t *world,
3147 ecs_entity_t parent,
3148 ecs_entity_t child,
3149 const char *sep,
3150 const char *prefix);
3151
3163 const ecs_world_t *world,
3164 ecs_entity_t parent,
3165 ecs_entity_t child,
3166 const char *sep,
3167 const char *prefix,
3168 ecs_strbuf_t *buf);
3169
3185FLECS_API
3187 ecs_world_t *world,
3188 ecs_entity_t parent,
3189 const char *path,
3190 const char *sep,
3191 const char *prefix);
3192
3207FLECS_API
3209 ecs_world_t *world,
3210 ecs_entity_t entity,
3211 ecs_entity_t parent,
3212 const char *path,
3213 const char *sep,
3214 const char *prefix);
3215
3227FLECS_API
3229 ecs_world_t *world,
3230 ecs_entity_t scope);
3231
3239FLECS_API
3241 const ecs_world_t *world);
3242
3252FLECS_API
3254 ecs_world_t *world,
3255 const char *prefix);
3256
3281FLECS_API
3283 ecs_world_t *world,
3284 const ecs_entity_t *lookup_path);
3285
3292FLECS_API
3294 const ecs_world_t *world);
3295
3319FLECS_API
3321 ecs_world_t *world,
3322 const ecs_component_desc_t *desc);
3323
3335FLECS_API
3337 ecs_world_t *world,
3338 ecs_entity_t id,
3339 const ecs_type_hooks_t *hooks);
3340
3347FLECS_API
3349 ecs_world_t *world,
3350 ecs_entity_t id);
3351
3374FLECS_API
3376 const ecs_world_t *world,
3377 ecs_id_t id);
3378
3391FLECS_API
3393 const ecs_world_t *world,
3394 ecs_id_t id);
3395
3404FLECS_API
3406 const ecs_world_t *world,
3407 ecs_id_t id);
3408
3418FLECS_API
3420 const ecs_world_t *world,
3421 ecs_id_t id);
3422
3442FLECS_API
3444 const ecs_world_t *world,
3445 ecs_id_t id);
3446
3454FLECS_API
3456 ecs_id_t id,
3457 ecs_id_t pattern);
3458
3464FLECS_API
3466 ecs_id_t id);
3467
3473FLECS_API
3475 ecs_id_t id);
3476
3490FLECS_API
3492 const ecs_world_t *world,
3493 ecs_id_t id);
3494
3503FLECS_API
3504ecs_flags32_t ecs_id_get_flags(
3505 const ecs_world_t *world,
3506 ecs_id_t id);
3507
3514FLECS_API
3516 ecs_id_t id_flags);
3517
3525FLECS_API
3527 const ecs_world_t *world,
3528 ecs_id_t id);
3529
3537FLECS_API
3539 const ecs_world_t *world,
3540 ecs_id_t id,
3541 ecs_strbuf_t *buf);
3542
3560FLECS_API
3561ecs_iter_t ecs_term_iter(
3562 const ecs_world_t *world,
3563 ecs_term_t *term);
3564
3573FLECS_API
3575 const ecs_iter_t *it,
3576 ecs_term_t *term);
3577
3587FLECS_API
3589 ecs_iter_t *it);
3590
3599FLECS_API
3600ecs_iter_t ecs_children(
3601 const ecs_world_t *world,
3602 ecs_entity_t parent);
3603
3610FLECS_API
3612 ecs_iter_t *it);
3613
3619FLECS_API
3621 const ecs_term_id_t *id);
3622
3634FLECS_API
3636 const ecs_term_t *term);
3637
3638FLECS_API
3639bool ecs_term_match_this(
3640 const ecs_term_t *term);
3641
3642FLECS_API
3643bool ecs_term_match_0(
3644 const ecs_term_t *term);
3645
3664FLECS_API
3666 const ecs_world_t *world,
3667 ecs_term_t *term);
3668
3677FLECS_API
3679 const ecs_term_t *src);
3680
3691FLECS_API
3693 ecs_term_t *src);
3694
3701FLECS_API
3703 ecs_term_t *term);
3704
3728FLECS_API
3730 ecs_world_t *world,
3731 const ecs_filter_desc_t *desc);
3732
3738FLECS_API
3740 ecs_filter_t *filter);
3741
3755FLECS_API
3757 const ecs_world_t *world,
3758 ecs_filter_t *filter);
3759
3771FLECS_API
3773 const ecs_filter_t *filter);
3774
3779FLECS_API
3781 const ecs_world_t *world,
3782 const ecs_term_t *term);
3783
3788FLECS_API
3790 const ecs_world_t *world,
3791 const ecs_filter_t *filter);
3792
3802FLECS_API
3804 const ecs_world_t *world,
3805 const ecs_filter_t *filter);
3806
3815FLECS_API
3817 const ecs_iter_t *it,
3818 const ecs_filter_t *filter);
3819
3839FLECS_API
3841 const ecs_world_t *world,
3842 const ecs_filter_t *filter);
3843
3853FLECS_API
3855 ecs_iter_t *it);
3856
3860FLECS_API
3862 ecs_iter_t *it);
3863
3865FLECS_API
3867 ecs_filter_t *dst,
3868 ecs_filter_t *src);
3869
3871FLECS_API
3873 ecs_filter_t *dst,
3874 const ecs_filter_t *src);
3875
3918FLECS_API
3920 ecs_world_t *world,
3921 const ecs_query_desc_t *desc);
3922
3930FLECS_API
3933
3940FLECS_API
3942 const ecs_query_t *query);
3943
3971FLECS_API
3973 const ecs_world_t *world,
3975
3985FLECS_API
3987 ecs_iter_t *iter);
3988
3992FLECS_API
3994 ecs_iter_t *iter);
3995
4006FLECS_API
4008 ecs_iter_t *iter);
4009
4027FLECS_API
4029 ecs_iter_t *iter);
4030
4060FLECS_API
4063 const ecs_iter_t *it);
4064
4075FLECS_API
4077 ecs_iter_t *it);
4078
4101FLECS_API
4103 ecs_iter_t *it,
4104 uint64_t group_id);
4105
4114FLECS_API
4116 const ecs_query_t *query,
4117 uint64_t group_id);
4118
4127FLECS_API
4129 const ecs_query_t *query,
4130 uint64_t group_id);
4131
4140FLECS_API
4142 const ecs_query_t *query);
4143
4149FLECS_API
4151 const ecs_query_t *query);
4152
4158FLECS_API
4160 const ecs_query_t *query);
4161
4167FLECS_API
4169 const ecs_query_t *query);
4170
4178FLECS_API
4180 const ecs_query_t *query);
4181
4190typedef struct ecs_event_desc_t {
4193
4198
4201
4205
4207 int32_t offset;
4208
4212 int32_t count;
4213
4216
4218 const void *param;
4219
4222
4224 ecs_flags32_t flags;
4226
4256FLECS_API
4258 ecs_world_t *world,
4259 ecs_event_desc_t *desc);
4260
4270FLECS_API
4272 ecs_world_t *world,
4273 const ecs_observer_desc_t *desc);
4274
4284FLECS_API
4286 ecs_iter_t *it);
4287
4288FLECS_API
4289void* ecs_get_observer_ctx(
4290 const ecs_world_t *world,
4292
4293FLECS_API
4294void* ecs_get_observer_binding_ctx(
4295 const ecs_world_t *world,
4297
4327FLECS_API
4329 const ecs_world_t *world,
4330 const ecs_poly_t *poly,
4331 ecs_iter_t *iter,
4332 ecs_term_t *filter);
4333
4347FLECS_API
4349 ecs_iter_t *it);
4350
4360FLECS_API
4362 ecs_iter_t *it);
4363
4375FLECS_API
4377 ecs_iter_t *it);
4378
4391FLECS_API
4393 ecs_iter_t *it);
4394
4402FLECS_API
4404 ecs_iter_t *it);
4405
4439FLECS_API
4441 ecs_iter_t *it,
4442 int32_t var_id,
4443 ecs_entity_t entity);
4444
4452FLECS_API
4454 ecs_iter_t *it,
4455 int32_t var_id,
4456 const ecs_table_t *table);
4457
4465FLECS_API
4467 ecs_iter_t *it,
4468 int32_t var_id,
4469 const ecs_table_range_t *range);
4470
4482FLECS_API
4484 ecs_iter_t *it,
4485 int32_t var_id);
4486
4499FLECS_API
4501 ecs_iter_t *it,
4502 int32_t var_id);
4503
4516FLECS_API
4518 ecs_iter_t *it,
4519 int32_t var_id);
4520
4521
4533FLECS_API
4535 ecs_iter_t *it,
4536 int32_t var_id);
4537
4553FLECS_API
4554ecs_iter_t ecs_page_iter(
4555 const ecs_iter_t *it,
4556 int32_t offset,
4557 int32_t limit);
4558
4565FLECS_API
4567 ecs_iter_t *it);
4568
4589FLECS_API
4591 const ecs_iter_t *it,
4592 int32_t index,
4593 int32_t count);
4594
4601FLECS_API
4603 ecs_iter_t *it);
4604
4628FLECS_API
4630 const ecs_iter_t *it,
4631 size_t size,
4632 int32_t index);
4633
4642FLECS_API
4644 const ecs_iter_t *it,
4645 int32_t index);
4646
4657FLECS_API
4659 const ecs_iter_t *it,
4660 int32_t index);
4661
4668FLECS_API
4670 const ecs_iter_t *it,
4671 int32_t index);
4672
4679FLECS_API
4681 const ecs_iter_t *it,
4682 int32_t index);
4683
4691FLECS_API
4693 const ecs_iter_t *it,
4694 int32_t index);
4695
4704FLECS_API
4706 const ecs_iter_t *it,
4707 int32_t index);
4708
4722FLECS_API
4724 const ecs_iter_t *it,
4725 int32_t index);
4726
4738FLECS_API
4740 const ecs_iter_t *it);
4741
4742
4756FLECS_API
4758 const ecs_table_t *table);
4759
4768FLECS_API
4770 const ecs_table_t *table,
4771 int32_t index,
4772 int32_t offset);
4773
4782FLECS_API
4784 const ecs_world_t *world,
4785 const ecs_table_t *table,
4786 ecs_id_t id);
4787
4796FLECS_API
4798 const ecs_world_t *world,
4799 const ecs_table_t *table,
4800 ecs_id_t id,
4801 int32_t offset);
4802
4813FLECS_API
4815 const ecs_world_t *world,
4816 const ecs_table_t *table,
4817 ecs_entity_t rel);
4818
4824FLECS_API
4826 const ecs_table_t *table);
4827
4829FLECS_API
4831 const ecs_table_t *table,
4832 int32_t index);
4833
4835FLECS_API
4837 const ecs_table_t *table,
4838 int32_t index);
4839
4848FLECS_API
4850 const ecs_table_t *table);
4851
4861FLECS_API
4863 ecs_world_t *world,
4864 ecs_table_t *table,
4865 ecs_id_t id);
4866
4877FLECS_API
4879 ecs_world_t *world,
4880 const ecs_id_t *ids,
4881 int32_t id_count);
4882
4892FLECS_API
4894 ecs_world_t *world,
4895 ecs_table_t *table,
4896 ecs_id_t id);
4897
4913FLECS_API
4915 ecs_world_t *world,
4916 ecs_table_t *table);
4917
4924FLECS_API
4926 ecs_world_t *world,
4927 ecs_table_t *table);
4928
4936FLECS_API
4938 ecs_table_t *table);
4939
4947FLECS_API
4949 ecs_world_t* world,
4950 ecs_table_t* table,
4951 int32_t row_1,
4952 int32_t row_2);
4953
4976FLECS_API
4978 ecs_world_t *world,
4979 ecs_entity_t entity,
4980 ecs_record_t *record,
4981 ecs_table_t *table,
4982 const ecs_type_t *added,
4983 const ecs_type_t *removed);
4984
4986FLECS_API
4987ecs_record_t* ecs_record_find(
4988 const ecs_world_t *world,
4989 ecs_entity_t entity);
4990
4992FLECS_API
4994 const ecs_record_t *r,
4995 int32_t column,
4996 size_t c_size);
4997
5013FLECS_API
5015 const ecs_world_t *world,
5016 const ecs_table_t *table,
5017 ecs_id_t id,
5018 ecs_id_t *id_out);
5019
5050FLECS_API
5052 const ecs_world_t *world,
5053 const ecs_table_t *table,
5054 int32_t offset,
5055 ecs_id_t id,
5056 ecs_id_t *id_out);
5057
5094FLECS_API
5096 const ecs_world_t *world,
5097 const ecs_table_t *table,
5098 int32_t offset,
5099 ecs_id_t id,
5100 ecs_entity_t rel,
5101 ecs_flags32_t flags, /* EcsSelf and/or EcsUp */
5102 ecs_entity_t *subject_out,
5103 ecs_id_t *id_out,
5104 struct ecs_table_record_t **tr_out);
5105
5121FLECS_API
5123 const ecs_world_t *world,
5124 ecs_entity_t type,
5125 void *ptr);
5126
5134FLECS_API
5136 const ecs_world_t *world,
5137 const ecs_type_info_t *ti,
5138 void *ptr);
5139
5146FLECS_API
5148 ecs_world_t *world,
5149 ecs_entity_t type);
5150
5158 ecs_world_t *world,
5159 const ecs_type_info_t *ti);
5160
5169 const ecs_world_t *world,
5170 const ecs_type_info_t *ti,
5171 void *ptr);
5172
5180FLECS_API
5182 const ecs_world_t *world,
5183 ecs_entity_t type,
5184 void* ptr);
5185
5192FLECS_API
5194 ecs_world_t *world,
5195 ecs_entity_t type,
5196 void* ptr);
5197
5206FLECS_API
5208 const ecs_world_t *world,
5209 const ecs_type_info_t *ti,
5210 void* dst,
5211 const void *src);
5212
5221FLECS_API
5223 const ecs_world_t *world,
5224 ecs_entity_t type,
5225 void* dst,
5226 const void *src);
5227
5237 const ecs_world_t *world,
5238 const ecs_type_info_t *ti,
5239 void* dst,
5240 void *src);
5241
5251 const ecs_world_t *world,
5252 ecs_entity_t type,
5253 void* dst,
5254 void *src);
5255
5265 const ecs_world_t *world,
5266 const ecs_type_info_t *ti,
5267 void* dst,
5268 void *src);
5269
5279 const ecs_world_t *world,
5280 ecs_entity_t type,
5281 void* dst,
5282 void *src);
5283
5298#include "flecs/addons/flecs_c.h"
5299
5300#ifdef __cplusplus
5301}
5302#endif
5303
5304#include "flecs/private/addons.h"
5305
5306#endif
The deprecated addon contains deprecated operations.
Extends the core API with convenience macros for C applications.
ecs_entity_t ecs_set_with(ecs_world_t *world, ecs_id_t id)
Set current with id.
void ecs_override_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add override for (component) id.
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Add a (component) id to an entity.
void ecs_remove_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Remove a (component) id from an entity.
void ecs_clear(ecs_world_t *world, ecs_entity_t entity)
Clear all components.
ecs_id_t ecs_get_with(const ecs_world_t *world)
Get current with id.
void ecs_remove_all(ecs_world_t *world, ecs_id_t id)
Remove all instances of the specified id.
ecs_iterable_t EcsIterable
Component for iterable entities.
Definition: flecs.h:1045
const ecs_entity_t EcsOnRemove
Event.
const ecs_entity_t EcsThis
This entity.
const ecs_entity_t EcsWildcard
Wildcard entity ("*").
const ecs_entity_t EcsName
Tag to indicate name identifier.
const ecs_entity_t EcsAcyclic
Marks a relationship as acyclic.
const ecs_entity_t EcsSymmetric
Marks relationship as commutative.
const ecs_entity_t EcsAlias
Tag to indicate alias identifier.
const ecs_entity_t EcsOnSet
Event.
const ecs_entity_t EcsReflexive
Marks a relatoinship as reflexive.
const ecs_entity_t EcsEmpty
Tag used to indicate query is empty.
const ecs_entity_t EcsOneOf
Ensure that relationship target is child of specified entity.
const ecs_entity_t EcsOnTableDelete
Event.
const ecs_entity_t EcsOnTableCreate
Event.
const ecs_entity_t EcsTraversable
Marks a relationship as traversable.
const ecs_entity_t EcsUnSet
Event.
const ecs_entity_t EcsIsA
Used to express inheritance relationships.
const ecs_entity_t EcsExclusive
Can be added to relationship to indicate that the relationship can only occur once on an entity.
const ecs_entity_t EcsSymbol
Tag to indicate symbol identifier.
const ecs_entity_t EcsDependsOn
Used to express dependency relationships.
const ecs_entity_t EcsAlwaysOverride
Ensures a component is always overridden.
const ecs_entity_t EcsTransitive
Marks a relationship as transitive.
const ecs_entity_t EcsDelete
Delete cleanup policy.
const ecs_entity_t EcsOnTableFill
Event.
const ecs_entity_t EcsChildOf
Used to express parent-child relationships.
const ecs_entity_t EcsFlecsCore
Core module scope.
const ecs_entity_t EcsMonitor
Event.
const ecs_entity_t EcsOnTableEmpty
Event.
const ecs_entity_t EcsWorld
Entity associated with world (used for "attaching" components to world)
const ecs_entity_t EcsPrivate
Tag to indicate an entity/component/system is private to a module.
const ecs_entity_t EcsRemove
Remove cleanup policy.
const ecs_entity_t EcsSlotOf
Used to express a slot (used with prefab inheritance)
const ecs_entity_t EcsModule
Tag added to module entities.
const ecs_entity_t EcsOnAdd
Event.
const ecs_entity_t EcsPrefab
Tag added to prefab entities.
const ecs_entity_t EcsUnion
Tag to indicate that relationship is stored as union.
const ecs_entity_t EcsAny
Any entity ("_").
const ecs_entity_t EcsWith
Ensure that a component always is added together with another component.
const ecs_entity_t EcsTag
Can be added to relationship to indicate that it should never hold data, even when it or the relation...
const ecs_entity_t EcsOnDelete
Event.
const ecs_entity_t EcsOnDeleteTarget
Relationship used to define what should happen when a target entity (second element of a pair) is del...
const ecs_entity_t EcsFlecs
Root scope for builtin flecs entities.
const ecs_entity_t EcsDisabled
When this tag is added to an entity it is skipped by all queries/filters.
const ecs_entity_t EcsDontInherit
Ensures that component is never inherited from an IsA target.
const ecs_entity_t EcsPanic
Panic cleanup policy.
const ecs_entity_t EcsDefaultChildComponent
Used like (EcsDefaultChildComponent, Component).
const ecs_entity_t EcsFinal
Ensures that entity/component cannot be used as target in IsA relationship.
const ecs_entity_t EcsVariable
Variable entity ("$").
bool ecs_defer_end(ecs_world_t *world)
End block of operations to defer.
void ecs_defer_resume(ecs_world_t *world)
Resume deferring.
bool ecs_defer_begin(ecs_world_t *world)
Defer operations until end of frame.
void ecs_defer_suspend(ecs_world_t *world)
Suspend deferring but do not flush queue.
bool ecs_is_deferred(const ecs_world_t *world)
Test if deferring is enabled for current stage.
bool ecs_stage_is_async(ecs_world_t *stage)
Test whether provided stage is asynchronous.
void ecs_merge(ecs_world_t *world)
Merge world or stage.
void ecs_async_stage_free(ecs_world_t *stage)
Free asynchronous stage.
void ecs_set_automerge(ecs_world_t *world, bool automerge)
Enable/disable automerging for world or stage.
ecs_world_t * ecs_async_stage_new(ecs_world_t *world)
Create asynchronous stage.
bool ecs_stage_is_readonly(const ecs_world_t *world)
Test whether the current world is readonly.
int32_t ecs_get_stage_count(const ecs_world_t *world)
Get number of configured stages.
bool ecs_readonly_begin(ecs_world_t *world)
Begin readonly mode.
ecs_world_t * ecs_get_stage(const ecs_world_t *world, int32_t stage_id)
Get stage-specific world pointer.
void ecs_set_stage_count(ecs_world_t *world, int32_t stages)
Configure world to have N stages.
void ecs_readonly_end(ecs_world_t *world)
End readonly mode.
int32_t ecs_get_stage_id(const ecs_world_t *world)
Get current stage id.
const ecs_type_hooks_t * ecs_get_hooks_id(ecs_world_t *world, ecs_entity_t id)
Get hooks for component.
ecs_entity_t ecs_component_init(ecs_world_t *world, const ecs_component_desc_t *desc)
Find or create a component.
void ecs_set_hooks_id(ecs_world_t *world, ecs_entity_t id, const ecs_type_hooks_t *hooks)
Register hooks for component.
struct ecs_ref_t ecs_ref_t
Refs cache data that lets them access components faster than ecs_get.
Definition: flecs.h:255
ecs_id_t ecs_entity_t
An entity identifier.
Definition: flecs.h:219
struct ecs_rule_t ecs_rule_t
A rule implements a non-trivial filter.
Definition: flecs.h:243
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition: flecs.h:228
struct ecs_mixins_t ecs_mixins_t
Type that stores poly mixins.
Definition: flecs.h:294
uint64_t ecs_id_t
An id.
Definition: flecs.h:216
struct ecs_query_t ecs_query_t
A query allows for cached iteration over ECS data.
Definition: flecs.h:237
struct ecs_observable_t ecs_observable_t
An observable contains lists of triggers for specific events/components.
Definition: flecs.h:249
struct ecs_table_t ecs_table_t
A table is where entities and components are stored.
Definition: flecs.h:231
void ecs_poly_t
A poly object.
Definition: flecs.h:291
ecs_entity_t ecs_new_low_id(ecs_world_t *world)
Create new low id.
ecs_entity_t ecs_new_w_id(ecs_world_t *world, ecs_id_t id)
Create new entity with (component) id.
ecs_entity_t ecs_new_id(ecs_world_t *world)
Create new entity id.
const ecs_entity_t * ecs_bulk_init(ecs_world_t *world, const ecs_bulk_desc_t *desc)
Bulk create/populate new entities.
ecs_entity_t ecs_clone(ecs_world_t *world, ecs_entity_t dst, ecs_entity_t src, bool copy_value)
Clone an entity This operation clones the components of one entity into another entity.
const ecs_entity_t * ecs_bulk_new_w_id(ecs_world_t *world, ecs_id_t id, int32_t count)
Create N new entities.
ecs_entity_t ecs_entity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Find or create an entity.
void ecs_delete_with(ecs_world_t *world, ecs_id_t id)
Delete all entities with the specified id.
void ecs_delete(ecs_world_t *world, ecs_entity_t entity)
Delete an entity.
ecs_entity_t ecs_new_w_table(ecs_world_t *world, ecs_table_t *table)
Create new entity in table.
bool ecs_is_enabled_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Test if component is enabled.
void ecs_enable_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, bool enable)
Enable or disable component.
void ecs_enable(ecs_world_t *world, ecs_entity_t entity, bool enabled)
Enable or disable entity.
char * ecs_entity_str(const ecs_world_t *world, ecs_entity_t entity)
Convert entity to string.
ecs_entity_t ecs_get_target(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, int32_t index)
Get the target of a relationship.
ecs_entity_t ecs_get_parent(const ecs_world_t *world, ecs_entity_t entity)
Get parent (target of ChildOf relationship) for entity.
const ecs_type_t * ecs_get_type(const ecs_world_t *world, ecs_entity_t entity)
Get the type of an entity.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Test if an entity has an entity.
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert type to string.
char * ecs_table_str(const ecs_world_t *world, const ecs_table_t *table)
Convert table to string.
int32_t ecs_count_id(const ecs_world_t *world, ecs_id_t entity)
Count entities that have the specified id.
void ecs_flatten(ecs_world_t *world, ecs_id_t pair, const ecs_flatten_desc_t *desc)
Recursively flatten relationship for target entity (experimental).
int32_t ecs_get_depth(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel)
Return depth for entity in tree for relationship rel.
ecs_entity_t ecs_get_target_for_id(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, ecs_id_t id)
Get the target of a relationship for a given id.
ecs_table_t * ecs_get_table(const ecs_world_t *world, ecs_entity_t entity)
Get the table of an entity.
bool ecs_children_next(ecs_iter_t *it)
Progress a children iterator.
ecs_term_t ecs_term_copy(const ecs_term_t *src)
Copy resources of a term to another term.
ecs_iter_t ecs_term_chain_iter(const ecs_iter_t *it, ecs_term_t *term)
Return a chained term iterator.
void ecs_term_fini(ecs_term_t *term)
Free resources of term.
ecs_filter_t * ecs_filter_init(ecs_world_t *world, const ecs_filter_desc_t *desc)
Initialize filter A filter is a lightweight object that can be used to query for entities in a world.
bool ecs_filter_next(ecs_iter_t *it)
Iterate tables matched by filter.
ecs_iter_t ecs_filter_iter(const ecs_world_t *world, const ecs_filter_t *filter)
Return a filter iterator.
char * ecs_term_str(const ecs_world_t *world, const ecs_term_t *term)
Convert ter, to string expression.
int ecs_filter_finalize(const ecs_world_t *world, ecs_filter_t *filter)
Finalize filter.
char * ecs_filter_str(const ecs_world_t *world, const ecs_filter_t *filter)
Convert filter to string expression.
void ecs_filter_fini(ecs_filter_t *filter)
Deinitialize filter.
bool ecs_filter_next_instanced(ecs_iter_t *it)
Same as ecs_filter_next, but always instanced.
bool ecs_term_next(ecs_iter_t *it)
Progress a term iterator.
int32_t ecs_filter_pivot_term(const ecs_world_t *world, const ecs_filter_t *filter)
Get pivot term for filter.
ecs_iter_t ecs_children(const ecs_world_t *world, ecs_entity_t parent)
Iterator for a parent's children.
int32_t ecs_filter_find_this_var(const ecs_filter_t *filter)
Find index for This variable.
int ecs_term_finalize(const ecs_world_t *world, ecs_term_t *term)
Finalize term.
bool ecs_term_id_is_set(const ecs_term_id_t *id)
Test whether term id is set.
void ecs_filter_move(ecs_filter_t *dst, ecs_filter_t *src)
Move resources of one filter to another.
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_term_t ecs_term_move(ecs_term_t *src)
Move resources of a term to another term.
void ecs_filter_copy(ecs_filter_t *dst, const ecs_filter_t *src)
Copy resources of one filter to another.
ecs_iter_t ecs_filter_chain_iter(const ecs_iter_t *it, const ecs_filter_t *filter)
Return a chained filter iterator.
ecs_iter_t ecs_term_iter(const ecs_world_t *world, ecs_term_t *term)
Iterator for a single (component) id.
void(* ecs_module_action_t)(ecs_world_t *world)
Initialization action for modules.
Definition: flecs.h:406
uint64_t(* ecs_group_by_action_t)(ecs_world_t *world, ecs_table_t *table, ecs_id_t group_id, void *ctx)
Callback used for grouping tables in a query.
Definition: flecs.h:386
uint64_t(* ecs_hash_value_action_t)(const void *ptr)
Callback used for hashing values.
Definition: flecs.h:424
void(* ecs_iter_fini_action_t)(ecs_iter_t *it)
Function prototype for freeing an iterator.
Definition: flecs.h:364
void(* ecs_sort_table_action_t)(ecs_world_t *world, ecs_table_t *table, ecs_entity_t *entities, void *ptr, int32_t size, int32_t lo, int32_t hi, ecs_order_by_action_t order_by)
Callback used for sorting the entire table of components.
Definition: flecs.h:375
bool(* ecs_iter_next_action_t)(ecs_iter_t *it)
Function prototype for iterating an iterator.
Definition: flecs.h:356
void(* ecs_iter_action_t)(ecs_iter_t *it)
Function prototype for iterables.
Definition: flecs.h:329
void(* ecs_copy_t)(void *dst_ptr, const void *src_ptr, int32_t count, const ecs_type_info_t *type_info)
Copy is invoked when a component is copied into another component.
Definition: flecs.h:434
int(* ecs_compare_action_t)(const void *ptr1, const void *ptr2)
Callback used for sorting values.
Definition: flecs.h:419
void(* ecs_fini_action_t)(ecs_world_t *world, void *ctx)
Action callback on world exit.
Definition: flecs.h:410
void(* ecs_move_t)(void *dst_ptr, void *src_ptr, int32_t count, const ecs_type_info_t *type_info)
Move is invoked when a component is moved to another component.
Definition: flecs.h:441
void(* ecs_run_action_t)(ecs_iter_t *it)
Function prototype for runnables (systems, observers).
Definition: flecs.h:320
void(* ecs_ctx_free_t)(void *ctx)
Function to cleanup context data.
Definition: flecs.h:415
int(* ecs_order_by_action_t)(ecs_entity_t e1, const void *ptr1, ecs_entity_t e2, const void *ptr2)
Callback used for comparing components.
Definition: flecs.h:368
void(* ecs_iter_init_action_t)(const ecs_world_t *world, const ecs_poly_t *iterable, ecs_iter_t *it, ecs_term_t *filter)
Function prototype for creating an iterator from a poly.
Definition: flecs.h:343
void(* ecs_xtor_t)(void *ptr, int32_t count, const ecs_type_info_t *type_info)
Constructor/destructor callback.
Definition: flecs.h:428
void * ecs_emplace_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Emplace a component.
ecs_ref_t ecs_ref_init_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Create a component ref.
void * ecs_record_get_mut_id(ecs_world_t *world, ecs_record_t *record, ecs_id_t id)
Same as ecs_record_get_id, but returns a mutable pointer.
ecs_entity_t ecs_record_get_entity(const ecs_record_t *record)
Get entity corresponding with record.
void ecs_ref_update(const ecs_world_t *world, ecs_ref_t *ref)
Update ref.
void ecs_read_end(const ecs_record_t *record)
End read access to entity.
void ecs_write_end(ecs_record_t *record)
End exclusive write access to entity.
void * ecs_ref_get_id(const ecs_world_t *world, ecs_ref_t *ref, ecs_id_t id)
Get component from ref.
bool ecs_record_has_id(ecs_world_t *world, const ecs_record_t *record, ecs_id_t id)
Test if entity for record has component.
const void * ecs_record_get_id(ecs_world_t *world, const ecs_record_t *record, ecs_id_t id)
Get component from entity record.
ecs_entity_t ecs_set_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, size_t size, const void *ptr)
Set the value of a component.
const void * ecs_get_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get an immutable pointer to a component.
ecs_record_t * ecs_write_begin(ecs_world_t *world, ecs_entity_t entity)
Begin exclusive write access to entity.
void ecs_modified_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Signal that a component has been modified.
const ecs_record_t * ecs_read_begin(ecs_world_t *world, ecs_entity_t entity)
Begin read access to entity.
void * ecs_get_mut_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get a mutable pointer to a component.
const ecs_id_t ECS_PAIR
Indicates that the id is a pair.
const ecs_id_t ECS_OVERRIDE
Automatically override component when it is inherited.
const ecs_id_t ECS_AND
Include all components from entity to which AND is applied.
const ecs_id_t ECS_TOGGLE
Adds bitset to storage which allows component to be enabled/disabled.
bool ecs_id_is_union(const ecs_world_t *world, ecs_id_t id)
Return whether represents a union.
bool ecs_id_is_valid(const ecs_world_t *world, ecs_id_t id)
Utility to check if id is valid.
bool ecs_id_is_pair(ecs_id_t id)
Utility to check if id is a pair.
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
bool ecs_id_match(ecs_id_t id, ecs_id_t pattern)
Utility to match an id with a pattern.
const char * ecs_id_flag_str(ecs_id_t id_flags)
Convert id flag to string.
bool ecs_id_in_use(const ecs_world_t *world, ecs_id_t id)
Returns whether specified id is in use.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
bool ecs_id_is_tag(const ecs_world_t *world, ecs_id_t id)
Returns whether specified id a tag.
void ecs_id_str_buf(const ecs_world_t *world, ecs_id_t id, ecs_strbuf_t *buf)
Write id string to buffer.
char * ecs_id_str(const ecs_world_t *world, ecs_id_t id)
Convert id to string.
bool ecs_id_is_wildcard(ecs_id_t id)
Utility to check if id is a wildcard.
ecs_flags32_t ecs_id_get_flags(const ecs_world_t *world, ecs_id_t id)
Get flags associated with id.
bool ecs_field_is_set(const ecs_iter_t *it, int32_t index)
Test whether field is set.
bool ecs_field_is_writeonly(const ecs_iter_t *it, int32_t index)
Test whether the field is writeonly.
bool ecs_field_is_self(const ecs_iter_t *it, int32_t index)
Test whether the field is matched on self.
void * ecs_field_w_size(const ecs_iter_t *it, size_t size, int32_t index)
Obtain data for a query field.
ecs_iter_t ecs_worker_iter(const ecs_iter_t *it, int32_t index, int32_t count)
Create a worker iterator.
size_t ecs_field_size(const ecs_iter_t *it, int32_t index)
Return field type size.
bool ecs_iter_is_true(ecs_iter_t *it)
Test if iterator is true.
void ecs_iter_fini(ecs_iter_t *it)
Cleanup iterator resources.
char * ecs_iter_str(const ecs_iter_t *it)
Convert iterator to string.
bool ecs_iter_var_is_constrained(ecs_iter_t *it, int32_t var_id)
Returns whether variable is constrained.
ecs_iter_t ecs_page_iter(const ecs_iter_t *it, int32_t offset, int32_t limit)
Create a paged iterator.
void ecs_iter_poly(const ecs_world_t *world, const ecs_poly_t *poly, ecs_iter_t *iter, ecs_term_t *filter)
Create iterator from poly object.
ecs_id_t ecs_field_id(const ecs_iter_t *it, int32_t index)
Return id matched for field.
bool ecs_field_is_readonly(const ecs_iter_t *it, int32_t index)
Test whether the field is readonly.
void ecs_iter_set_var(ecs_iter_t *it, int32_t var_id, ecs_entity_t entity)
Set value for iterator variable.
bool ecs_iter_next(ecs_iter_t *it)
Progress any iterator.
ecs_entity_t ecs_iter_get_var(ecs_iter_t *it, int32_t var_id)
Get value of iterator variable as entity.
bool ecs_worker_next(ecs_iter_t *it)
Progress a worker iterator.
ecs_entity_t ecs_iter_first(ecs_iter_t *it)
Get first matching entity from iterator.
void ecs_iter_set_var_as_table(ecs_iter_t *it, int32_t var_id, const ecs_table_t *table)
Same as ecs_iter_set_var, but for a table.
ecs_table_t * ecs_iter_get_var_as_table(ecs_iter_t *it, int32_t var_id)
Get value of iterator variable as table.
ecs_entity_t ecs_field_src(const ecs_iter_t *it, int32_t index)
Return field source.
int32_t ecs_iter_count(ecs_iter_t *it)
Count number of matched entities in query.
bool ecs_page_next(ecs_iter_t *it)
Progress a paged iterator.
void ecs_iter_set_var_as_range(ecs_iter_t *it, int32_t var_id, const ecs_table_range_t *range)
Same as ecs_iter_set_var, but for a range of entities This constrains the variable to a range of enti...
ecs_table_range_t ecs_iter_get_var_as_range(ecs_iter_t *it, int32_t var_id)
Get value of iterator variable as table range.
ecs_id_t ecs_strip_generation(ecs_entity_t e)
Remove generation from entity id.
void ecs_ensure(ecs_world_t *world, ecs_entity_t entity)
Ensure id is alive.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
void ecs_set_entity_generation(ecs_world_t *world, ecs_entity_t entity)
Override the generation of an entity.
ecs_entity_t ecs_get_alive(const ecs_world_t *world, ecs_entity_t e)
Get alive identifier.
bool ecs_exists(const ecs_world_t *world, ecs_entity_t entity)
Test whether an entity exists.
void ecs_ensure_id(ecs_world_t *world, ecs_id_t id)
Same as ecs_ensure, but for (component) ids.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
void ecs_emit(ecs_world_t *world, ecs_event_desc_t *desc)
Send event.
ecs_entity_t ecs_observer_init(ecs_world_t *world, const ecs_observer_desc_t *desc)
Create observer.
bool ecs_observer_default_run_action(ecs_iter_t *it)
Default run action for observer.
#define ECS_TERM_DESC_CACHE_SIZE
Maximum number of terms in desc (larger, as these are temp objects)
Definition: flecs.h:177
#define ECS_ID_CACHE_SIZE
Maximum number of components to add/remove in a single operation.
Definition: flecs.h:172
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition: flecs.h:42
#define ECS_OBSERVER_DESC_EVENT_COUNT_MAX
Maximum number of events to set in static array of observer descriptor.
Definition: flecs.h:181
char * ecs_get_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, ecs_entity_t child, const char *sep, const char *prefix)
Get a path identifier for an entity.
ecs_entity_t ecs_new_from_path_w_sep(ecs_world_t *world, ecs_entity_t parent, const char *path, const char *sep, const char *prefix)
Find or create entity from path.
ecs_entity_t ecs_lookup(const ecs_world_t *world, const char *name)
Lookup an entity by name.
void ecs_set_alias(ecs_world_t *world, ecs_entity_t entity, const char *alias)
Set alias for entity.
void ecs_get_path_w_sep_buf(const ecs_world_t *world, ecs_entity_t parent, ecs_entity_t child, const char *sep, const char *prefix, ecs_strbuf_t *buf)
Write path identifier to buffer.
ecs_entity_t ecs_get_scope(const ecs_world_t *world)
Get the current scope.
ecs_entity_t * ecs_set_lookup_path(ecs_world_t *world, const ecs_entity_t *lookup_path)
Set search path for lookup operations.
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
ecs_entity_t ecs_lookup_symbol(const ecs_world_t *world, const char *symbol, bool lookup_as_path)
Lookup an entity by its symbol name.
const char * ecs_get_symbol(const ecs_world_t *world, ecs_entity_t entity)
Get the symbol of an entity.
ecs_entity_t ecs_lookup_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, const char *path, const char *sep, const char *prefix, bool recursive)
Lookup an entity from a path.
ecs_entity_t ecs_set_symbol(ecs_world_t *world, ecs_entity_t entity, const char *symbol)
Set the symbol of an entity.
ecs_entity_t ecs_lookup_child(const ecs_world_t *world, ecs_entity_t parent, const char *name)
Lookup a child entity by name.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
ecs_entity_t ecs_add_path_w_sep(ecs_world_t *world, ecs_entity_t entity, ecs_entity_t parent, const char *path, const char *sep, const char *prefix)
Add specified path to entity.
ecs_entity_t * ecs_get_lookup_path(const ecs_world_t *world)
Get current lookup path.
ecs_entity_t ecs_set_scope(ecs_world_t *world, ecs_entity_t scope)
Set the current scope.
const char * ecs_set_name_prefix(ecs_world_t *world, const char *prefix)
Set a name prefix for newly created entities.
const ecs_query_group_info_t * ecs_query_get_group_info(const ecs_query_t *query, uint64_t group_id)
Get information about query group.
bool ecs_query_next_instanced(ecs_iter_t *iter)
Same as ecs_query_next, but always instanced.
void ecs_query_fini(ecs_query_t *query)
Destroy a query.
void ecs_query_skip(ecs_iter_t *it)
Skip a table while iterating.
int32_t ecs_query_table_count(const ecs_query_t *query)
Returns number of tables query matched with.
bool ecs_query_next_table(ecs_iter_t *iter)
Fast alternative to ecs_query_next that only returns matched tables.
int32_t ecs_query_entity_count(const ecs_query_t *query)
Returns number of entities query matched with.
char * ecs_query_str(const ecs_query_t *query)
Convert query to string.
ecs_query_t * ecs_query_init(ecs_world_t *world, const ecs_query_desc_t *desc)
Create a query.
int ecs_query_populate(ecs_iter_t *iter)
Populate iterator fields.
void ecs_query_set_group(ecs_iter_t *it, uint64_t group_id)
Set group to iterate for query iterator.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, ecs_query_t *query)
Return a query iterator.
bool ecs_query_next(ecs_iter_t *iter)
Progress the query iterator.
void * ecs_query_get_group_ctx(const ecs_query_t *query, uint64_t group_id)
Get context of query group.
bool ecs_query_orphaned(const ecs_query_t *query)
Returns whether query is orphaned.
const ecs_filter_t * ecs_query_get_filter(const ecs_query_t *query)
Get filter from a query.
int32_t ecs_query_empty_table_count(const ecs_query_t *query)
Returns number of empty tables query matched with.
bool ecs_query_changed(ecs_query_t *query, const ecs_iter_t *it)
Returns whether the query data changed since the last iteration.
ecs_inout_kind_t
Specify read/write access for term.
Definition: flecs.h:474
ecs_oper_kind_t
Specify operator for term.
Definition: flecs.h:483
ecs_filter_t ECS_FILTER_INIT
Use this variable to initialize user-allocated filter object.
@ EcsOut
Term is only written.
Definition: flecs.h:479
@ EcsInOut
Term is both read and written.
Definition: flecs.h:477
@ EcsInOutDefault
InOut for regular terms, In for shared terms.
Definition: flecs.h:475
@ EcsInOutNone
Term is neither read nor written.
Definition: flecs.h:476
@ EcsIn
Term is only read.
Definition: flecs.h:478
@ EcsNot
The term must not match.
Definition: flecs.h:486
@ EcsOptional
The term may match.
Definition: flecs.h:487
@ EcsOr
One of the terms in an or chain must match.
Definition: flecs.h:485
@ EcsOrFrom
Term must match at least one component from term id.
Definition: flecs.h:489
@ EcsAnd
The term must match.
Definition: flecs.h:484
@ EcsNotFrom
Term must match none of the components from term id.
Definition: flecs.h:490
@ EcsAndFrom
Term must match all components from term id.
Definition: flecs.h:488
int32_t ecs_table_get_index(const ecs_world_t *world, const ecs_table_t *table, ecs_id_t id)
Get column index for id.
ecs_table_t * ecs_table_add_id(ecs_world_t *world, ecs_table_t *table, ecs_id_t id)
Get table that has all components of current table plus the specified id.
int32_t ecs_search(const ecs_world_t *world, const ecs_table_t *table, ecs_id_t id, ecs_id_t *id_out)
Search for component id in table type.
const ecs_type_t * ecs_table_get_type(const ecs_table_t *table)
Get type for table.
int32_t ecs_search_offset(const ecs_world_t *world, const ecs_table_t *table, int32_t offset, ecs_id_t id, ecs_id_t *id_out)
Search for component id in table type starting from an offset.
int32_t ecs_table_storage_to_type_index(const ecs_table_t *table, int32_t index)
Convert index in table storage type to index in table type.
int32_t ecs_search_relation(const ecs_world_t *world, const ecs_table_t *table, int32_t offset, ecs_id_t id, ecs_entity_t rel, ecs_flags32_t flags, ecs_entity_t *subject_out, ecs_id_t *id_out, struct ecs_table_record_t **tr_out)
Search for component/relationship id in table type starting from an offset.
bool ecs_commit(ecs_world_t *world, ecs_entity_t entity, ecs_record_t *record, ecs_table_t *table, const ecs_type_t *added, const ecs_type_t *removed)
Commit (move) entity to a table.
ecs_table_t * ecs_table_get_storage_table(const ecs_table_t *table)
Get storage type for table.
void * ecs_table_get_column(const ecs_table_t *table, int32_t index, int32_t offset)
Get column from table.
ecs_table_t * ecs_table_remove_id(ecs_world_t *world, ecs_table_t *table, ecs_id_t id)
Get table that has all components of current table minus the specified id.
int32_t ecs_table_type_to_storage_index(const ecs_table_t *table, int32_t index)
Convert index in table type to index in table storage type.
int32_t ecs_table_count(const ecs_table_t *table)
Returns the number of records in the table.
void ecs_table_unlock(ecs_world_t *world, ecs_table_t *table)
Unlock a table.
bool ecs_table_has_module(ecs_table_t *table)
Returns whether table is a module or contains module contents Returns true for tables that have modul...
int32_t ecs_table_get_depth(const ecs_world_t *world, const ecs_table_t *table, ecs_entity_t rel)
Return depth for table in tree for relationship rel.
void * ecs_table_get_id(const ecs_world_t *world, const ecs_table_t *table, ecs_id_t id, int32_t offset)
Get column from table by component id.
void ecs_table_swap_rows(ecs_world_t *world, ecs_table_t *table, int32_t row_1, int32_t row_2)
Swaps two elements inside the table.
void ecs_table_lock(ecs_world_t *world, ecs_table_t *table)
Lock or unlock table.
void * ecs_record_get_column(const ecs_record_t *r, int32_t column, size_t c_size)
Get component pointer from column/record.
ecs_table_t * ecs_table_find(ecs_world_t *world, const ecs_id_t *ids, int32_t id_count)
Find table from id array.
ecs_record_t * ecs_record_find(const ecs_world_t *world, ecs_entity_t entity)
Find record for entity.
int ecs_value_fini_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *ptr)
Destruct a value.
int ecs_value_fini(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Destruct a value.
int ecs_value_copy(const ecs_world_t *world, ecs_entity_t type, void *dst, const void *src)
Copy value.
int ecs_value_move(const ecs_world_t *world, ecs_entity_t type, void *dst, void *src)
Move value.
int ecs_value_move_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, void *src)
Move value.
void * ecs_value_new_w_type_info(ecs_world_t *world, const ecs_type_info_t *ti)
Construct a value in new storage.
int ecs_value_move_ctor_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, void *src)
Move construct value.
int ecs_value_copy_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, const void *src)
Copy value.
int ecs_value_init_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *ptr)
Construct a value in existing storage.
void * ecs_value_new(ecs_world_t *world, ecs_entity_t type)
Construct a value in new storage.
int ecs_value_free(ecs_world_t *world, ecs_entity_t type, void *ptr)
Destruct a value, free storage.
int ecs_value_move_ctor(const ecs_world_t *world, ecs_entity_t type, void *dst, void *src)
Move construct value.
int ecs_value_init(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Construct a value in existing storage.
void ecs_atfini(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed when world is destroyed.
bool ecs_is_fini(const ecs_world_t *world)
Returns whether the world is being deleted.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_mini(void)
Same as ecs_init, but with minimal set of modules loaded.
ecs_world_t * ecs_init(void)
Create a new world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
void ecs_set_target_fps(ecs_world_t *world, float fps)
Set target frames per second (FPS) for application.
void ecs_measure_system_time(ecs_world_t *world, bool enable)
Measure system time.
float ecs_frame_begin(ecs_world_t *world, float delta_time)
Begin frame.
void ecs_run_post_frame(ecs_world_t *world, ecs_fini_action_t action, void *ctx)
Register action to be executed once after frame.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been signaled.
void ecs_quit(ecs_world_t *world)
Signal exit This operation signals that the application should quit.
void ecs_measure_frame_time(ecs_world_t *world, bool enable)
Measure frame time.
void ecs_frame_end(ecs_world_t *world)
End frame.
ecs_entity_t ecs_get_entity(const ecs_poly_t *poly)
Get entity from poly.
ecs_id_t ecs_make_pair(ecs_entity_t first, ecs_entity_t second)
Make a pair id.
void ecs_set_context(ecs_world_t *world, void *ctx)
Set a world context.
void ecs_run_aperiodic(ecs_world_t *world, ecs_flags32_t flags)
Force aperiodic actions.
void ecs_dim(ecs_world_t *world, int32_t entity_count)
Dimension the world for a specified number of entities.
void ecs_set_entity_range(ecs_world_t *world, ecs_entity_t id_start, ecs_entity_t id_end)
Set a range for issueing new entity ids.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get world from poly.
bool _ecs_poly_is(const ecs_poly_t *object, int32_t type)
Test if pointer is of specified type.
void * ecs_get_context(const ecs_world_t *world)
Get the world context.
int32_t ecs_delete_empty_tables(ecs_world_t *world, ecs_id_t id, uint16_t clear_generation, uint16_t delete_generation, int32_t min_id_count, double time_budget_seconds)
Cleanup empty tables.
bool ecs_enable_range_check(ecs_world_t *world, bool enable)
Enable/disable range limits.
flecs::observer_builder< Components... > observer(Args &&... args) const
Create a new observer.
Operating system abstraction API.
flecs::query< Comps... > query(flecs::query_base &parent, Args &&... args) const
Create a subquery.
Component information.
Definition: flecs.h:1028
ecs_size_t size
Component size.
Definition: flecs.h:1029
ecs_size_t alignment
Component alignment.
Definition: flecs.h:1030
A (string) identifier.
Definition: flecs.h:1019
ecs_size_t length
Length of identifier.
Definition: flecs.h:1021
char * value
Identifier string.
Definition: flecs.h:1020
ecs_hashmap_t * index
Current index.
Definition: flecs.h:1024
uint64_t hash
Hash of current value.
Definition: flecs.h:1022
uint64_t index_hash
Hash of existing record in current index.
Definition: flecs.h:1023
Component for storing a poly object.
Definition: flecs.h:1034
ecs_poly_t * poly
Pointer to poly object.
Definition: flecs.h:1035
Apply a rate filter to a tick source.
Definition: timer.h:45
Target data for flattened relationships.
Definition: flecs.h:1039
Component used to provide a tick source to systems.
Definition: system.h:32
Component used for one shot/interval timer functionality.
Definition: timer.h:35
Used with ecs_bulk_init.
Definition: flecs.h:737
void ** data
Array with component data to insert.
Definition: flecs.h:749
ecs_id_t ids[(32)]
Ids to create the entities with.
Definition: flecs.h:747
int32_t count
Number of entities to create/populate.
Definition: flecs.h:745
ecs_entity_t * entities
Entities to bulk insert.
Definition: flecs.h:740
ecs_table_t * table
Table to insert the entities into.
Definition: flecs.h:756
Used with ecs_component_init.
Definition: flecs.h:767
ecs_type_info_t type
Parameters for type (size, hooks, ...)
Definition: flecs.h:774
ecs_entity_t entity
Existing entity to associate with observer (optional)
Definition: flecs.h:771
Used with ecs_entity_init.
Definition: flecs.h:696
const char * sep
Optional custom separator for hierarchical names.
Definition: flecs.h:706
const char * root_sep
Optional, used for identifiers relative to root.
Definition: flecs.h:710
const char * name
Name of the entity.
Definition: flecs.h:701
bool use_low_id
When set to true, a low id (typically reserved for components) will be used to create the entity,...
Definition: flecs.h:722
ecs_id_t add[(32)]
Array of ids to add to the new or existing entity.
Definition: flecs.h:727
const char * symbol
Optional entity symbol.
Definition: flecs.h:712
const char * add_expr
String expression with components to add.
Definition: flecs.h:730
ecs_entity_t id
Set to modify existing entity (optional)
Definition: flecs.h:699
ecs_entity_t entity
Single-entity alternative to setting table / offset / count.
Definition: flecs.h:4215
ecs_table_t * table
The table for which to notify.
Definition: flecs.h:4200
int32_t count
Limit number of notified entities to count.
Definition: flecs.h:4212
ecs_table_t * other_table
Optional 2nd table to notify.
Definition: flecs.h:4204
const void * param
Optional context.
Definition: flecs.h:4218
int32_t offset
Limit notified entities to ones starting from offset (row) in table.
Definition: flecs.h:4207
const ecs_type_t * ids
Component ids.
Definition: flecs.h:4197
ecs_poly_t * observable
Observable (usually the world)
Definition: flecs.h:4221
ecs_entity_t event
The event id.
Definition: flecs.h:4192
ecs_flags32_t flags
Event flags.
Definition: flecs.h:4224
Used with ecs_filter_init.
Definition: flecs.h:781
ecs_term_t * terms_buffer
For filters with lots of terms an outside array can be provided.
Definition: flecs.h:789
bool instanced
When true, terms returned by an iterator may either contain 1 or N elements, where terms with N eleme...
Definition: flecs.h:802
ecs_term_t terms[(16)]
Terms of the filter.
Definition: flecs.h:786
int32_t terms_buffer_count
Number of terms in array provided in terms_buffer.
Definition: flecs.h:792
ecs_entity_t entity
Entity associated with query (optional)
Definition: flecs.h:811
ecs_flags32_t flags
Flags for advanced usage.
Definition: flecs.h:805
ecs_filter_t * storage
External storage to prevent allocation of the filter object.
Definition: flecs.h:795
const char * expr
Filter expression.
Definition: flecs.h:808
Filters alllow for ad-hoc quick filtering of entity tables.
Definition: flecs.h:566
ecs_term_t * terms
Array containing terms for filter.
Definition: flecs.h:569
bool owned
Is filter object owned by filter.
Definition: flecs.h:573
int32_t field_count
Number of fields in iterator for filter.
Definition: flecs.h:571
int32_t term_count
Number of elements in terms array.
Definition: flecs.h:570
ecs_flags32_t flags
Filter flags.
Definition: flecs.h:576
bool terms_owned
Is terms array owned by filter.
Definition: flecs.h:574
char * variable_names[1]
Placeholder variable names array.
Definition: flecs.h:578
ecs_poly_dtor_t dtor
Dtor mixin.
Definition: flecs.h:584
ecs_entity_t entity
Entity associated with filter (optional)
Definition: flecs.h:581
ecs_iterable_t iterable
Iterable mixin.
Definition: flecs.h:583
Header for ecs_poly_t objects.
Definition: flecs.h:297
Iterable mixin.
Definition: flecs.h:461
ecs_iter_init_action_t init
Callback that creates iterator.
Definition: flecs.h:462
Used with ecs_observer_init.
Definition: flecs.h:875
void * binding_ctx
Context to be used for language bindings.
Definition: flecs.h:907
ecs_ctx_free_t ctx_free
Callback to free ctx.
Definition: flecs.h:910
ecs_entity_t entity
Existing entity to associate with observer (optional)
Definition: flecs.h:879
ecs_filter_desc_t filter
Filter for observer.
Definition: flecs.h:882
int32_t term_index
Used for internal purposes.
Definition: flecs.h:923
ecs_entity_t events[(8)]
Events to observe (OnAdd, OnRemove, OnSet, UnSet)
Definition: flecs.h:885
int32_t * last_event_id
Optional shared last event id for multiple observers.
Definition: flecs.h:920
ecs_ctx_free_t binding_ctx_free
Callback to free binding_ctx.
Definition: flecs.h:913
void * ctx
User context to pass to callback.
Definition: flecs.h:904
ecs_poly_t * observable
Observable with which to register the observer.
Definition: flecs.h:916
ecs_iter_action_t callback
Callback to invoke on an event, invoked when the observer matches.
Definition: flecs.h:893
bool yield_existing
When observer is created, generate events from existing data.
Definition: flecs.h:890
ecs_run_action_t run
Callback invoked on an event.
Definition: flecs.h:901
ecs_iter_action_t callback
See ecs_observer_desc_t::callback.
Definition: flecs.h:597
int32_t term_index
Index of the term in parent observer (single term observers only)
Definition: flecs.h:612
ecs_observable_t * observable
Observable for observer.
Definition: flecs.h:606
ecs_run_action_t run
See ecs_observer_desc_t::run.
Definition: flecs.h:598
int32_t * last_event_id
Last handled event id.
Definition: flecs.h:608
ecs_ctx_free_t ctx_free
Callback to free ctx.
Definition: flecs.h:603
ecs_filter_t filter
Query for observer.
Definition: flecs.h:591
void * ctx
Callback context.
Definition: flecs.h:600
ecs_id_t register_id
Id observer is registered with (single term observers only)
Definition: flecs.h:611
void * binding_ctx
Binding context (for language bindings)
Definition: flecs.h:601
bool is_monitor
If true, the observer only triggers when the filter did not match with the entity before the event ha...
Definition: flecs.h:614
ecs_ctx_free_t binding_ctx_free
Callback to free binding_ctx.
Definition: flecs.h:604
bool is_multi
If true, the observer triggers on more than one term.
Definition: flecs.h:618
Used with ecs_query_init.
Definition: flecs.h:818
ecs_order_by_action_t order_by
Callback used for ordering query results.
Definition: flecs.h:830
ecs_id_t group_by_id
Id to be used by group_by.
Definition: flecs.h:839
ecs_group_by_action_t group_by
Callback used for grouping results.
Definition: flecs.h:846
ecs_ctx_free_t group_by_ctx_free
Function to free group_by_ctx.
Definition: flecs.h:860
void * group_by_ctx
Context to pass to group_by.
Definition: flecs.h:857
ecs_group_create_action_t on_group_create
Callback that is invoked when a new group is created.
Definition: flecs.h:850
ecs_query_t * parent
If set, the query will be created as a subquery.
Definition: flecs.h:868
ecs_entity_t order_by_component
Component to be used by order_by.
Definition: flecs.h:825
ecs_filter_desc_t filter
Filter for the query.
Definition: flecs.h:822
ecs_group_delete_action_t on_group_delete
Callback that is invoked when an existing group is deleted.
Definition: flecs.h:854
ecs_sort_table_action_t sort_table
Callback used for ordering query results.
Definition: flecs.h:834
Type that contains information about a query group.
Definition: flecs.h:1004
int32_t table_count
Number of tables in group.
Definition: flecs.h:1006
void * ctx
Group context, returned by on_group_create.
Definition: flecs.h:1007
int32_t match_count
How often tables have been matched/unmatched.
Definition: flecs.h:1005
Type that describes a single identifier in a term.
Definition: flecs.h:516
ecs_flags32_t flags
Term flags.
Definition: flecs.h:534
ecs_entity_t trav
Relationship to traverse when looking for the component.
Definition: flecs.h:530
char * name
Name.
Definition: flecs.h:523
ecs_entity_t id
Entity id.
Definition: flecs.h:517
Type that describes a term (single element in a query)
Definition: flecs.h:538
ecs_term_id_t second
Second element of pair.
Definition: flecs.h:546
ecs_id_t id
Component id to be matched by term.
Definition: flecs.h:539
char * name
Name of term.
Definition: flecs.h:552
ecs_term_id_t src
Source of term.
Definition: flecs.h:544
ecs_id_record_t * idr
Cached pointer to internal index.
Definition: flecs.h:555
ecs_term_id_t first
Component or first element of pair.
Definition: flecs.h:545
int32_t field_index
Index of field for term in iterator.
Definition: flecs.h:554
ecs_id_t id_flags
Id flags of term id.
Definition: flecs.h:551
bool move
Used by internals.
Definition: flecs.h:559
ecs_flags16_t flags
Flags that help eval, set by ecs_filter_init.
Definition: flecs.h:557
ecs_inout_kind_t inout
Access to contents matched by term.
Definition: flecs.h:548
ecs_oper_kind_t oper
Operator of term.
Definition: flecs.h:549
Type that contains component lifecycle callbacks.
Definition: flecs.h:630
ecs_copy_t copy_ctor
Ctor + copy.
Definition: flecs.h:637
void * ctx
User defined context.
Definition: flecs.h:668
ecs_iter_action_t on_remove
Callback that is invoked when an instance of the component is removed.
Definition: flecs.h:666
void * binding_ctx
Language binding context.
Definition: flecs.h:669
ecs_move_t move_dtor
Move + dtor.
Definition: flecs.h:652
ecs_copy_t copy
copy assignment
Definition: flecs.h:633
ecs_iter_action_t on_set
Callback that is invoked when an instance of the component is set.
Definition: flecs.h:661
ecs_move_t move
move assignment
Definition: flecs.h:634
ecs_xtor_t ctor
ctor
Definition: flecs.h:631
ecs_ctx_free_t ctx_free
Callback to free ctx.
Definition: flecs.h:671
ecs_iter_action_t on_add
Callback that is invoked when an instance of a component is added.
Definition: flecs.h:656
ecs_ctx_free_t binding_ctx_free
Callback to free binding_ctx.
Definition: flecs.h:672
ecs_move_t move_ctor
Ctor + move.
Definition: flecs.h:640
ecs_move_t ctor_move_dtor
Ctor + move + dtor (or move_ctor + dtor).
Definition: flecs.h:646
ecs_xtor_t dtor
dtor
Definition: flecs.h:632
Type that contains component information (passed to ctors/dtors/...)
Definition: flecs.h:679
ecs_size_t alignment
Alignment of type.
Definition: flecs.h:681
ecs_size_t size
Size of type.
Definition: flecs.h:680
const char * name
Type name.
Definition: flecs.h:684
ecs_entity_t component
Handle to component (do not set)
Definition: flecs.h:683
ecs_type_hooks_t hooks
Type hooks.
Definition: flecs.h:682
An array with (component) ids.
Definition: flecs.h:222
Type that contains information about the world.
Definition: flecs.h:939
int64_t get_mut_count
get_mut/emplace commands processed
Definition: flecs.h:989
float delta_time
Time passed to or computed by ecs_progress.
Definition: flecs.h:946
int32_t id_count
Number of ids in the world (excluding wildcards)
Definition: flecs.h:969
ecs_entity_t min_id
First allowed entity id.
Definition: flecs.h:942
int32_t trivial_table_count
Number of tables with trivial components (no lifecycle callbacks)
Definition: flecs.h:977
int64_t set_count
set commands processed
Definition: flecs.h:988
float world_time_total
Time elapsed in simulation.
Definition: flecs.h:953
int32_t tag_id_count
Number of tag (no data) ids in the world.
Definition: flecs.h:970
int32_t tag_table_count
Number of tag-only tables.
Definition: flecs.h:976
int32_t component_id_count
Number of component (data) ids in the world.
Definition: flecs.h:971
int32_t table_record_count
Total number of table records (entries in table caches)
Definition: flecs.h:979
int64_t pipeline_build_count_total
Total number of pipeline builds.
Definition: flecs.h:965
int32_t table_count
Number of tables.
Definition: flecs.h:975
float delta_time_raw
Raw delta time (no time scaling)
Definition: flecs.h:945
float frame_time_total
Total time spent processing a frame.
Definition: flecs.h:949
ecs_entity_t last_id
Last issued entity id.
Definition: flecs.h:941
float world_time_total_raw
Time elapsed in simulation (no scaling)
Definition: flecs.h:954
int64_t table_create_total
Total number of times a table was created.
Definition: flecs.h:963
int64_t observers_ran_frame
Total number of times observer was invoked.
Definition: flecs.h:967
float system_time_total
Total time spent in systems.
Definition: flecs.h:950
int64_t id_delete_total
Total number of times an id was deleted.
Definition: flecs.h:962
int64_t systems_ran_frame
Total number of systems ran in last frame.
Definition: flecs.h:966
float merge_time_total
Total time spent in merges.
Definition: flecs.h:952
int64_t discard_count
commands discarded, happens when entity is no longer alive when running the command
Definition: flecs.h:992
int64_t clear_count
clear commands processed
Definition: flecs.h:987
ecs_entity_t last_component_id
Last issued component entity id.
Definition: flecs.h:940
int32_t empty_table_count
Number of tables without entities.
Definition: flecs.h:978
int64_t frame_count_total
Total number of frames.
Definition: flecs.h:957
ecs_entity_t max_id
Last allowed entity id.
Definition: flecs.h:943
int64_t merge_count_total
Total number of merges.
Definition: flecs.h:958
int64_t other_count
other commands processed
Definition: flecs.h:991
int64_t batched_command_count
commands batched
Definition: flecs.h:994
int64_t table_delete_total
Total number of times a table was deleted.
Definition: flecs.h:964
int64_t delete_count
delete commands processed
Definition: flecs.h:986
int64_t rematch_count_total
Total number of rematches.
Definition: flecs.h:959
int64_t id_create_total
Total number of times a new id was created.
Definition: flecs.h:961
int64_t batched_entity_count
entities for which commands were batched
Definition: flecs.h:993
float time_scale
Time scale applied to delta_time.
Definition: flecs.h:947
int32_t pair_id_count
Number of pair ids in the world.
Definition: flecs.h:972
float rematch_time_total
Time spent on query rematching.
Definition: flecs.h:955
float target_fps
Target fps.
Definition: flecs.h:948
int32_t wildcard_id_count
Number of wildcard ids.
Definition: flecs.h:973
int32_t table_storage_count
Total number of table storages.
Definition: flecs.h:980
float emit_time_total
Total time spent notifying observers.
Definition: flecs.h:951
int64_t modified_count
modified commands processed
Definition: flecs.h:990
const char * name_prefix
Value set by ecs_set_name_prefix.
Definition: flecs.h:997
int64_t add_count
add commands processed
Definition: flecs.h:984
int64_t remove_count
remove commands processed
Definition: flecs.h:985
flecs::term term() const
Create a term for a (component) type.