Skip to content
Flecs v4.1
constraint_traits.h
Go to the documentation of this file.
1/**
2 * @file addons/constraint_traits.h
3 * @brief Constraint traits addon.
4 */
5
6#ifdef FLECS_CONSTRAINT_TRAITS
7
8#ifndef FLECS_CONSTRAINT_TRAITS_H
9#define FLECS_CONSTRAINT_TRAITS_H
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15/**
16 * @defgroup c_addons_constraint_traits Constraint Traits
17 * @ingroup c_addons
18 * Traits that enforce constraints on entities, components and relationships.
19 *
20 * @{
21 */
22
23/** Ensure that an entity or component cannot be used as a target in an `IsA` relationship.
24 * Final can improve the performance of queries as they will not attempt to
25 * substitute a final component with its subsets.
26 *
27 * Behavior:
28 *
29 * @code
30 * if IsA(X, Y) and Final(Y) throw error
31 * @endcode
32 */
33FLECS_API extern const ecs_entity_t EcsFinal;
34
35/** Mark relationship as commutative.
36 * Behavior:
37 *
38 * @code
39 * if R(X, Y) then R(Y, X)
40 * @endcode
41 */
42FLECS_API extern const ecs_entity_t EcsSymmetric;
43
44/** Mark a relationship as acyclic. Acyclic relationships may not form cycles. */
45FLECS_API extern const ecs_entity_t EcsAcyclic;
46
47/** Ensure that a relationship target is a child of the specified entity.
48 *
49 * Behavior:
50 *
51 * @code
52 * If OneOf(R, O) and R(X, Y), Y must be a child of O
53 * If OneOf(R) and R(X, Y), Y must be a child of R
54 * @endcode
55 */
56FLECS_API extern const ecs_entity_t EcsOneOf;
57
58/** Can be added to components to indicate it is a trait. Traits are components
59 * and/or tags that are added to other components to modify their behavior.
60 */
61FLECS_API extern const ecs_entity_t EcsTrait;
62
63/** Ensure that an entity is always used in a pair as a relationship.
64 *
65 * Behavior:
66 *
67 * @code
68 * e.add(R) panics
69 * e.add(X, R) panics, unless X has the "Trait" trait
70 * @endcode
71 */
72FLECS_API extern const ecs_entity_t EcsRelationship;
73
74/** Ensure that an entity is always used in a pair as a target.
75 *
76 * Behavior:
77 *
78 * @code
79 * e.add(T) panics
80 * e.add(T, X) panics
81 * @endcode
82 */
83FLECS_API extern const ecs_entity_t EcsTarget;
84
85/** Mark component as singleton. Singleton components may only be added to
86 * themselves. */
87FLECS_API extern const ecs_entity_t EcsSingleton;
88
89/** @} */
90
91#ifdef __cplusplus
92}
93#endif
94
95#endif
96
97#endif // FLECS_CONSTRAINT_TRAITS
FLECS_API const ecs_entity_t EcsTrait
Can be added to components to indicate it is a trait.
FLECS_API const ecs_entity_t EcsOneOf
Ensure that a relationship target is a child of the specified entity.
FLECS_API const ecs_entity_t EcsSingleton
Mark component as singleton.
FLECS_API const ecs_entity_t EcsSymmetric
Mark relationship as commutative.
FLECS_API const ecs_entity_t EcsFinal
Ensure that an entity or component cannot be used as a target in an IsA relationship.
FLECS_API const ecs_entity_t EcsTarget
Ensure that an entity is always used in a pair as a target.
FLECS_API const ecs_entity_t EcsRelationship
Ensure that an entity is always used in a pair as a relationship.
FLECS_API const ecs_entity_t EcsAcyclic
Mark a relationship as acyclic.
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:395