Flecs
v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs_c.h
Go to the documentation of this file.
1
5
6
#ifndef FLECS_C_
7
#define FLECS_C_
8
16
23
24
/* Use for declaring entity, tag, prefab / any other entity identifier */
25
#define ECS_DECLARE(id)\
26
ecs_entity_t id, ecs_id(id)
27
29
#define ECS_ENTITY_DECLARE ECS_DECLARE
30
39
#define ECS_ENTITY_DEFINE(world, id_, ...) \
40
{ \
41
ecs_entity_desc_t desc = {0}; \
42
desc.id = id_; \
43
desc.name = #id_; \
44
desc.add_expr = #__VA_ARGS__; \
45
id_ = ecs_entity_init(world, &desc); \
46
ecs_id(id_) = id_; \
47
ecs_assert(id_ != 0, ECS_INVALID_PARAMETER, "failed to create entity %s", #id_); \
48
} \
49
(void)id_; \
50
(void)ecs_id(id_)
51
60
#define ECS_ENTITY(world, id, ...) \
61
ecs_entity_t ecs_id(id); \
62
ecs_entity_t id = 0; \
63
ECS_ENTITY_DEFINE(world, id, __VA_ARGS__)
64
66
#define ECS_TAG_DECLARE ECS_DECLARE
67
76
#define ECS_TAG_DEFINE(world, id) ECS_ENTITY_DEFINE(world, id, 0)
77
86
#define ECS_TAG(world, id) ECS_ENTITY(world, id, 0)
87
89
#define ECS_PREFAB_DECLARE ECS_DECLARE
90
99
#define ECS_PREFAB_DEFINE(world, id, ...) ECS_ENTITY_DEFINE(world, id, Prefab, __VA_ARGS__)
100
109
#define ECS_PREFAB(world, id, ...) ECS_ENTITY(world, id, Prefab, __VA_ARGS__)
110
112
#define ECS_COMPONENT_DECLARE(id) ecs_entity_t ecs_id(id)
113
122
#define ECS_COMPONENT_DEFINE(world, id_) \
123
{\
124
ecs_component_desc_t desc = {0}; \
125
ecs_entity_desc_t edesc = {0}; \
126
edesc.id = ecs_id(id_); \
127
edesc.use_low_id = true; \
128
edesc.name = #id_; \
129
edesc.symbol = #id_; \
130
desc.entity = ecs_entity_init(world, &edesc); \
131
desc.type.size = ECS_SIZEOF(id_); \
132
desc.type.alignment = ECS_ALIGNOF(id_); \
133
ecs_id(id_) = ecs_component_init(world, &desc);\
134
}\
135
ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, "failed to create component %s", #id_)
136
145
#define ECS_COMPONENT(world, id)\
146
ecs_entity_t ecs_id(id) = 0;\
147
ECS_COMPONENT_DEFINE(world, id);\
148
(void)ecs_id(id)
149
150
/* Forward declare an observer. */
151
#define ECS_OBSERVER_DECLARE(id) ecs_entity_t ecs_id(id)
152
161
#define ECS_OBSERVER_DEFINE(world, id_, kind, ...)\
162
{\
163
ecs_observer_desc_t desc = {0};\
164
ecs_entity_desc_t edesc = {0}; \
165
edesc.id = ecs_id(id_); \
166
edesc.name = #id_; \
167
desc.entity = ecs_entity_init(world, &edesc); \
168
desc.callback = id_;\
169
desc.query.expr = #__VA_ARGS__;\
170
desc.events[0] = kind;\
171
ecs_id(id_) = ecs_observer_init(world, &desc);\
172
ecs_assert(ecs_id(id_) != 0, ECS_INVALID_PARAMETER, "failed to create observer %s", #id_);\
173
}
174
183
#define ECS_OBSERVER(world, id, kind, ...)\
184
ecs_entity_t ecs_id(id) = 0; \
185
ECS_OBSERVER_DEFINE(world, id, kind, __VA_ARGS__);\
186
ecs_entity_t id = ecs_id(id);\
187
(void)ecs_id(id);\
188
(void)id
189
190
/* Forward declare a query. */
191
#define ECS_QUERY_DECLARE(name) ecs_query_t* name
192
201
#define ECS_QUERY_DEFINE(world, name_, ...)\
202
{\
203
ecs_query_desc_t desc = {0};\
204
ecs_entity_desc_t edesc = {0}; \
205
edesc.name = #name_; \
206
desc.entity = ecs_entity_init(world, &edesc); \
207
desc.expr = #__VA_ARGS__;\
208
name_ = ecs_query_init(world, &desc);\
209
ecs_assert(name_ != NULL, ECS_INVALID_PARAMETER, "failed to create query %s", #name_);\
210
}
211
220
#define ECS_QUERY(world, name, ...)\
221
ecs_query_t* name = NULL; \
222
ECS_QUERY_DEFINE(world, name, __VA_ARGS__);\
223
(void)name
224
235
#define ecs_entity(world, ...)\
236
ecs_entity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
237
249
#define ecs_component(world, ...)\
250
ecs_component_init(world, &(ecs_component_desc_t) __VA_ARGS__ )
251
260
#define ecs_component_t(world, T)\
261
ecs_component_init(world, &(ecs_component_desc_t) { \
262
.entity = ecs_entity(world, { \
263
.name = #T, \
264
.symbol = #T, \
265
.use_low_id = true \
266
}), \
267
.type.size = ECS_SIZEOF(T), \
268
.type.alignment = ECS_ALIGNOF(T) \
269
})
270
278
#define ecs_query(world, ...)\
279
ecs_query_init(world, &(ecs_query_desc_t) __VA_ARGS__ )
280
293
#define ecs_observer(world, ...)\
294
ecs_observer_init(world, &(ecs_observer_desc_t) __VA_ARGS__ )
295
297
304
309
314
315
#define ecs_new_w(world, T) ecs_new_w_id(world, ecs_id(T))
316
317
#define ecs_new_w_pair(world, first, second)\
318
ecs_new_w_id(world, ecs_pair(first, second))
319
320
#define ecs_bulk_new(world, component, count)\
321
ecs_bulk_new_w_id(world, ecs_id(component), count)
322
324
329
330
#define ecs_add(world, entity, T)\
331
ecs_add_id(world, entity, ecs_id(T))
332
333
#define ecs_add_pair(world, subject, first, second)\
334
ecs_add_id(world, subject, ecs_pair(first, second))
335
336
337
#define ecs_remove(world, entity, T)\
338
ecs_remove_id(world, entity, ecs_id(T))
339
340
#define ecs_remove_pair(world, subject, first, second)\
341
ecs_remove_id(world, subject, ecs_pair(first, second))
342
343
344
#define ecs_auto_override(world, entity, T)\
345
ecs_auto_override_id(world, entity, ecs_id(T))
346
347
#define ecs_auto_override_pair(world, subject, first, second)\
348
ecs_auto_override_id(world, subject, ecs_pair(first, second))
349
351
356
357
/* insert */
358
#define ecs_insert(world, ...)\
359
ecs_entity(world, { .set = ecs_values(__VA_ARGS__)})
360
361
/* set */
362
363
#define ecs_set_ptr(world, entity, component, ptr)\
364
ecs_set_id(world, entity, ecs_id(component), sizeof(component), ptr)
365
366
#define ecs_set(world, entity, component, ...)\
367
ecs_set_id(world, entity, ecs_id(component), sizeof(component), &(component)__VA_ARGS__)
368
369
#define ecs_set_pair(world, subject, First, second, ...)\
370
ecs_set_id(world, subject,\
371
ecs_pair(ecs_id(First), second),\
372
sizeof(First), &(First)__VA_ARGS__)
373
374
#define ecs_set_pair_second(world, subject, first, Second, ...)\
375
ecs_set_id(world, subject,\
376
ecs_pair(first, ecs_id(Second)),\
377
sizeof(Second), &(Second)__VA_ARGS__)
378
379
#define ecs_set_override(world, entity, T, ...)\
380
ecs_add_id(world, entity, ECS_AUTO_OVERRIDE | ecs_id(T));\
381
ecs_set(world, entity, T, __VA_ARGS__)
382
383
/* emplace */
384
385
#define ecs_emplace(world, entity, T, is_new)\
386
(ECS_CAST(T*, ecs_emplace_id(world, entity, ecs_id(T), is_new)))
387
388
#define ecs_emplace_pair(world, entity, First, second, is_new)\
389
(ECS_CAST(First*, ecs_emplace_id(world, entity, ecs_pair_t(First, second), is_new)))
390
391
/* get */
392
393
#define ecs_get(world, entity, T)\
394
(ECS_CAST(const T*, ecs_get_id(world, entity, ecs_id(T))))
395
396
#define ecs_get_pair(world, subject, First, second)\
397
(ECS_CAST(const First*, ecs_get_id(world, subject,\
398
ecs_pair(ecs_id(First), second))))
399
400
#define ecs_get_pair_second(world, subject, first, Second)\
401
(ECS_CAST(const Second*, ecs_get_id(world, subject,\
402
ecs_pair(first, ecs_id(Second)))))
403
404
/* get_mut */
405
406
#define ecs_get_mut(world, entity, T)\
407
(ECS_CAST(T*, ecs_get_mut_id(world, entity, ecs_id(T))))
408
409
#define ecs_get_mut_pair(world, subject, First, second)\
410
(ECS_CAST(First*, ecs_get_mut_id(world, subject,\
411
ecs_pair(ecs_id(First), second))))
412
413
#define ecs_get_mut_pair_second(world, subject, first, Second)\
414
(ECS_CAST(Second*, ecs_get_mut_id(world, subject,\
415
ecs_pair(first, ecs_id(Second)))))
416
417
#define ecs_get_mut(world, entity, T)\
418
(ECS_CAST(T*, ecs_get_mut_id(world, entity, ecs_id(T))))
419
420
/* ensure */
421
422
#define ecs_ensure(world, entity, T)\
423
(ECS_CAST(T*, ecs_ensure_id(world, entity, ecs_id(T))))
424
425
#define ecs_ensure_pair(world, subject, First, second)\
426
(ECS_CAST(First*, ecs_ensure_id(world, subject,\
427
ecs_pair(ecs_id(First), second))))
428
429
#define ecs_ensure_pair_second(world, subject, first, Second)\
430
(ECS_CAST(Second*, ecs_ensure_id(world, subject,\
431
ecs_pair(first, ecs_id(Second)))))
432
433
#define ecs_ensure(world, entity, T)\
434
(ECS_CAST(T*, ecs_ensure_id(world, entity, ecs_id(T))))
435
436
#define ecs_ensure_pair(world, subject, First, second)\
437
(ECS_CAST(First*, ecs_ensure_id(world, subject,\
438
ecs_pair(ecs_id(First), second))))
439
440
#define ecs_ensure_pair_second(world, subject, first, Second)\
441
(ECS_CAST(Second*, ecs_ensure_id(world, subject,\
442
ecs_pair(first, ecs_id(Second)))))
443
444
/* modified */
445
446
#define ecs_modified(world, entity, component)\
447
ecs_modified_id(world, entity, ecs_id(component))
448
449
#define ecs_modified_pair(world, subject, first, second)\
450
ecs_modified_id(world, subject, ecs_pair(first, second))
451
452
/* record */
453
454
#define ecs_record_get(world, record, T)\
455
(ECS_CAST(const T*, ecs_record_get_id(world, record, ecs_id(T))))
456
457
#define ecs_record_has(world, record, T)\
458
(ecs_record_has_id(world, record, ecs_id(T)))
459
460
#define ecs_record_get_pair(world, record, First, second)\
461
(ECS_CAST(const First*, ecs_record_get_id(world, record, \
462
ecs_pair(ecs_id(First), second))))
463
464
#define ecs_record_get_pair_second(world, record, first, Second)\
465
(ECS_CAST(const Second*, ecs_record_get_id(world, record,\
466
ecs_pair(first, ecs_id(Second)))))
467
468
#define ecs_record_ensure(world, record, T)\
469
(ECS_CAST(T*, ecs_record_ensure_id(world, record, ecs_id(T))))
470
471
#define ecs_record_ensure_pair(world, record, First, second)\
472
(ECS_CAST(First*, ecs_record_ensure_id(world, record, \
473
ecs_pair(ecs_id(First), second))))
474
475
#define ecs_record_ensure_pair_second(world, record, first, Second)\
476
(ECS_CAST(Second*, ecs_record_ensure_id(world, record,\
477
ecs_pair(first, ecs_id(Second)))))
478
479
#define ecs_ref_init(world, entity, T)\
480
ecs_ref_init_id(world, entity, ecs_id(T))
481
482
#define ecs_ref_get(world, ref, T)\
483
(ECS_CAST(T*, ecs_ref_get_id(world, ref, ecs_id(T))))
484
486
491
492
#define ecs_singleton_add(world, comp)\
493
ecs_add(world, ecs_id(comp), comp)
494
495
#define ecs_singleton_remove(world, comp)\
496
ecs_remove(world, ecs_id(comp), comp)
497
498
#define ecs_singleton_get(world, comp)\
499
ecs_get(world, ecs_id(comp), comp)
500
501
#define ecs_singleton_get_mut(world, comp)\
502
ecs_get_mut(world, ecs_id(comp), comp)
503
504
#define ecs_singleton_set_ptr(world, comp, ptr)\
505
ecs_set_ptr(world, ecs_id(comp), comp, ptr)
506
507
#define ecs_singleton_set(world, comp, ...)\
508
ecs_set(world, ecs_id(comp), comp, __VA_ARGS__)
509
510
#define ecs_singleton_ensure(world, comp)\
511
ecs_ensure(world, ecs_id(comp), comp)
512
513
#define ecs_singleton_emplace(world, comp, is_new)\
514
ecs_emplace(world, ecs_id(comp), comp, is_new)
515
516
#define ecs_singleton_modified(world, comp)\
517
ecs_modified(world, ecs_id(comp), comp)
518
520
525
526
#define ecs_has(world, entity, T)\
527
ecs_has_id(world, entity, ecs_id(T))
528
529
#define ecs_has_pair(world, entity, first, second)\
530
ecs_has_id(world, entity, ecs_pair(first, second))
531
532
#define ecs_owns_pair(world, entity, first, second)\
533
ecs_owns_id(world, entity, ecs_pair(first, second))
534
535
#define ecs_owns(world, entity, T)\
536
ecs_owns_id(world, entity, ecs_id(T))
537
538
#define ecs_shares_id(world, entity, id)\
539
(ecs_search_relation(world, ecs_get_table(world, entity), 0, ecs_id(id), \
540
EcsIsA, 1, 0, 0, 0, 0) != -1)
541
542
#define ecs_shares_pair(world, entity, first, second)\
543
(ecs_shares_id(world, entity, ecs_pair(first, second)))
544
545
#define ecs_shares(world, entity, T)\
546
(ecs_shares_id(world, entity, ecs_id(T)))
547
548
#define ecs_get_target_for(world, entity, rel, T)\
549
ecs_get_target_for_id(world, entity, rel, ecs_id(T))
550
552
557
558
#define ecs_enable_component(world, entity, T, enable)\
559
ecs_enable_id(world, entity, ecs_id(T), enable)
560
561
#define ecs_is_enabled(world, entity, T)\
562
ecs_is_enabled_id(world, entity, ecs_id(T))
563
564
#define ecs_enable_pair(world, entity, First, second, enable)\
565
ecs_enable_id(world, entity, ecs_pair(ecs_id(First), second), enable)
566
567
#define ecs_is_enabled_pair(world, entity, First, second)\
568
ecs_is_enabled_id(world, entity, ecs_pair(ecs_id(First), second))
569
571
576
577
#define ecs_lookup_from(world, parent, path)\
578
ecs_lookup_path_w_sep(world, parent, path, ".", NULL, true)
579
580
#define ecs_get_path_from(world, parent, child)\
581
ecs_get_path_w_sep(world, parent, child, ".", NULL)
582
583
#define ecs_get_path(world, child)\
584
ecs_get_path_w_sep(world, 0, child, ".", NULL)
585
586
#define ecs_get_path_buf(world, child, buf)\
587
ecs_get_path_w_sep_buf(world, 0, child, ".", NULL, buf, false)
588
589
#define ecs_new_from_path(world, parent, path)\
590
ecs_new_from_path_w_sep(world, parent, path, ".", NULL)
591
592
#define ecs_add_path(world, entity, parent, path)\
593
ecs_add_path_w_sep(world, entity, parent, path, ".", NULL)
594
595
#define ecs_add_fullpath(world, entity, path)\
596
ecs_add_path_w_sep(world, entity, 0, path, ".", NULL)
597
599
601
606
607
#define ecs_set_hooks(world, T, ...)\
608
ecs_set_hooks_id(world, ecs_id(T), &(ecs_type_hooks_t)__VA_ARGS__)
609
610
#define ecs_get_hooks(world, T)\
611
ecs_get_hooks_id(world, ecs_id(T));
612
620
#define ECS_CTOR(type, var, ...)\
621
ECS_XTOR_IMPL(type, ctor, var, __VA_ARGS__)
622
630
#define ECS_DTOR(type, var, ...)\
631
ECS_XTOR_IMPL(type, dtor, var, __VA_ARGS__)
632
640
#define ECS_COPY(type, dst_var, src_var, ...)\
641
ECS_COPY_IMPL(type, dst_var, src_var, __VA_ARGS__)
642
650
#define ECS_MOVE(type, dst_var, src_var, ...)\
651
ECS_MOVE_IMPL(type, dst_var, src_var, __VA_ARGS__)
652
660
#define ECS_ON_ADD(type, ptr, ...)\
661
ECS_HOOK_IMPL(type, ecs_on_add(type), ptr, __VA_ARGS__)
662
#define ECS_ON_REMOVE(type, ptr, ...)\
663
ECS_HOOK_IMPL(type, ecs_on_remove(type), ptr, __VA_ARGS__)
664
#define ECS_ON_SET(type, ptr, ...)\
665
ECS_HOOK_IMPL(type, ecs_on_set(type), ptr, __VA_ARGS__)
666
667
/* Map from typename to function name of component lifecycle action */
668
#define ecs_ctor(type) type##_ctor
669
#define ecs_dtor(type) type##_dtor
670
#define ecs_copy(type) type##_copy
671
#define ecs_move(type) type##_move
672
#define ecs_on_set(type) type##_on_set
673
#define ecs_on_add(type) type##_on_add
674
#define ecs_on_remove(type) type##_on_remove
675
677
682
683
#define ecs_count(world, type)\
684
ecs_count_id(world, ecs_id(type))
685
687
692
693
#define ecs_field(it, T, index)\
694
(ECS_CAST(T*, ecs_field_w_size(it, sizeof(T), index)))
695
696
#define ecs_field_self(it, T, index)\
697
(ECS_CAST(T*, ecs_field_self_w_size(it, sizeof(T), index)))
698
699
#define ecs_field_at(it, T, index, row)\
700
(ECS_CAST(T*, ecs_field_at_w_size(it, sizeof(T), index, row)))
701
703
708
709
#define ecs_table_get(world, table, T, offset)\
710
(ECS_CAST(T*, ecs_table_get_id(world, table, ecs_id(T), offset)))
711
712
#define ecs_table_get_pair(world, table, First, second, offset)\
713
(ECS_CAST(First*, ecs_table_get_id(world, table, ecs_pair(ecs_id(First), second), offset)))
714
715
#define ecs_table_get_pair_second(world, table, first, Second, offset)\
716
(ECS_CAST(Second*, ecs_table_get_id(world, table, ecs_pair(first, ecs_id(Second)), offset)))
717
719
724
726
#define ecs_ids(...) (ecs_id_t[]){ __VA_ARGS__, 0 }
727
729
#define ecs_values(...) (ecs_value_t[]){ __VA_ARGS__, {0, 0}}
730
732
#define ecs_value_ptr(T, ptr) ((ecs_value_t){ecs_id(T), ptr})
733
735
#define ecs_value_pair(R, t, ...) ((ecs_value_t){ecs_pair_t(R, t), &(R)__VA_ARGS__})
736
738
#define ecs_value_pair_2nd(r, T, ...) ((ecs_value_t){ecs_pair(r, ecs_id(T)), &(T)__VA_ARGS__})
739
741
#define ecs_value_new_t(world, T) ecs_value_new(world, ecs_id(T))
742
744
#define ecs_value(T, ...) ((ecs_value_t){ecs_id(T), &(T)__VA_ARGS__})
745
747
749
756
#define ecs_sort_table(id) ecs_id(id##_sort_table)
757
758
#define ecs_compare(id) ecs_id(id##_compare_fn)
759
760
/* Declare efficient table sorting operation that uses provided compare function.
761
* For best results use LTO or make the function body visible in the same compilation unit.
762
* Variadic arguments are prepended before generated functions, use it to declare static
763
* or exported functions.
764
* Parameters of the comparison function:
765
* ecs_entity_t e1, const void* ptr1,
766
* ecs_entity_t e2, const void* ptr2
767
* Parameters of the sort functions:
768
* ecs_world_t *world
769
* ecs_table_t *table
770
* ecs_entity_t *entities
771
* void *ptr
772
* int32_t elem_size
773
* int32_t lo
774
* int32_t hi
775
* ecs_order_by_action_t order_by - Pointer to the original comparison function. You are not supposed to use it.
776
* Example:
777
*
778
* @code
779
* int CompareMyType(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; }
780
* ECS_SORT_TABLE_WITH_COMPARE(MyType, MyCustomCompare, CompareMyType)
781
* @endcode
782
*/
783
#define ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn, ...) \
784
static int32_t ECS_CONCAT(op_name, _partition)( \
785
ecs_world_t *world, \
786
ecs_table_t *table, \
787
ecs_entity_t *entities, \
788
void *ptr, \
789
int32_t elem_size, \
790
int32_t lo, \
791
int32_t hi, \
792
ecs_order_by_action_t order_by) \
793
{ \
794
(void)(order_by); \
795
int32_t p = (hi + lo) / 2; \
796
void *pivot = ECS_ELEM(ptr, elem_size, p); \
797
ecs_entity_t pivot_e = entities[p]; \
798
int32_t i = lo - 1, j = hi + 1; \
799
void *el; \
800
repeat: \
801
{ \
802
do { \
803
i ++; \
804
el = ECS_ELEM(ptr, elem_size, i); \
805
} while ( compare_fn(entities[i], el, pivot_e, pivot) < 0); \
806
do { \
807
j --; \
808
el = ECS_ELEM(ptr, elem_size, j); \
809
} while ( compare_fn(entities[j], el, pivot_e, pivot) > 0); \
810
if (i >= j) { \
811
return j; \
812
} \
813
ecs_table_swap_rows(world, table, i, j); \
814
if (p == i) { \
815
pivot = ECS_ELEM(ptr, elem_size, j); \
816
pivot_e = entities[j]; \
817
} else if (p == j) { \
818
pivot = ECS_ELEM(ptr, elem_size, i); \
819
pivot_e = entities[i]; \
820
} \
821
goto repeat; \
822
} \
823
} \
824
__VA_ARGS__ void op_name( \
825
ecs_world_t *world, \
826
ecs_table_t *table, \
827
ecs_entity_t *entities, \
828
void *ptr, \
829
int32_t size, \
830
int32_t lo, \
831
int32_t hi, \
832
ecs_order_by_action_t order_by) \
833
{ \
834
if ((hi - lo) < 1) { \
835
return; \
836
} \
837
int32_t p = ECS_CONCAT(op_name, _partition)(world, table, entities, ptr, size, lo, hi, order_by); \
838
op_name(world, table, entities, ptr, size, lo, p, order_by); \
839
op_name(world, table, entities, ptr, size, p + 1, hi, order_by); \
840
}
841
842
/* Declare efficient table sorting operation that uses default component comparison operator.
843
* For best results use LTO or make the comparison operator visible in the same compilation unit.
844
* Variadic arguments are prepended before generated functions, use it to declare static
845
* or exported functions.
846
* Example:
847
*
848
* @code
849
* ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
850
* ECS_SORT_TABLE(MyType)
851
* @endcode
852
*/
853
#define ECS_SORT_TABLE(id, ...) \
854
ECS_SORT_TABLE_WITH_COMPARE(id, ecs_sort_table(id), ecs_compare(id), __VA_ARGS__)
855
856
/* Declare component comparison operations.
857
* Parameters:
858
* ecs_entity_t e1, const void* ptr1,
859
* ecs_entity_t e2, const void* ptr2
860
* Example:
861
*
862
* @code
863
* ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
864
* @endcode
865
*/
866
#define ECS_COMPARE(id, ...) \
867
int ecs_compare(id)(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { \
868
__VA_ARGS__ \
869
}
870
872
879
880
#define ecs_isa(e) ecs_pair(EcsIsA, e)
881
#define ecs_childof(e) ecs_pair(EcsChildOf, e)
882
#define ecs_dependson(e) ecs_pair(EcsDependsOn, e)
883
#define ecs_with(e) ecs_pair(EcsWith, e)
884
885
#define ecs_each(world, id) ecs_each_id(world, ecs_id(id))
886
#define ecs_each_pair(world, r, t) ecs_each_id(world, ecs_pair(r, t))
887
#define ecs_each_pair_t(world, R, t) ecs_each_id(world, ecs_pair(ecs_id(R), t))
888
890
892
893
#endif
// FLECS_C_