Make a table for cleanup

This commit is contained in:
Ukendio 2025-07-26 02:37:51 +02:00
parent 1c2dee57d3
commit 3e2d40e706

View file

@ -173,13 +173,20 @@ This is what cleanup traits are for: to specify which action needs to be execute
To configure a cleanup policy for an entity, a `(Condition, Action)` pair can be added to it. If no policy is specified, the default cleanup action (`Remove`) is performed. To configure a cleanup policy for an entity, a `(Condition, Action)` pair can be added to it. If no policy is specified, the default cleanup action (`Remove`) is performed.
There are two cleanup actions: #### Cleanup Traits Summary
| Condition | Action | Description | Use Case |
|-----------|--------|-------------|----------|
| `OnDelete` | `Remove` | Removes the component from all entities when the component is deleted | Default behavior, safe cleanup |
| `OnDelete` | `Delete` | Deletes all entities that have the component when the component is deleted | Cascading deletion, dangerous |
| `OnDeleteTarget` | `Remove` | Removes the relationship from all entities when the target is deleted | Safe relationship cleanup |
| `OnDeleteTarget` | `Delete` | Deletes all entities that have the relationship when the target is deleted | Hierarchical deletion (e.g., parent-child) |
**Cleanup Actions:**
- `Remove`: removes instances of the specified (component) id from all entities (default) - `Remove`: removes instances of the specified (component) id from all entities (default)
- `Delete`: deletes all entities with specified id - `Delete`: deletes all entities with specified id
There are two cleanup conditions: **Cleanup Conditions:**
- `OnDelete`: the component, tag or relationship is deleted - `OnDelete`: the component, tag or relationship is deleted
- `OnDeleteTarget`: a target used with the relationship is deleted - `OnDeleteTarget`: a target used with the relationship is deleted
@ -705,3 +712,10 @@ To improve the speed of evaluating queries, Jecs has indices that store all arch
While registering an archetype for a relationship index is not more expensive than registering an archetype for a regular index, an archetype with relationships has to also register itself with the appropriate wildcard indices for its relationships. For example, an archetype with relationship `pair(Likes, Apples)` registers itself with the `pair(Likes, Apples)`, `pair(Likes, jecs.Wildcard)` and `pair(jecs.Wildcard, Apples)` indices. For this reason, creating new archetypes with relationships has a higher overhead than an archetype without relationships. While registering an archetype for a relationship index is not more expensive than registering an archetype for a regular index, an archetype with relationships has to also register itself with the appropriate wildcard indices for its relationships. For example, an archetype with relationship `pair(Likes, Apples)` registers itself with the `pair(Likes, Apples)`, `pair(Likes, jecs.Wildcard)` and `pair(jecs.Wildcard, Apples)` indices. For this reason, creating new archetypes with relationships has a higher overhead than an archetype without relationships.
This page takes wording and terminology directly from Flecs, the first ECS with full support for [Entity Relationships](https://www.flecs.dev/flecs/md_docs_2Relationships.html). This page takes wording and terminology directly from Flecs, the first ECS with full support for [Entity Relationships](https://www.flecs.dev/flecs/md_docs_2Relationships.html).
## Next Steps
- [Performance Guide](./performance.md) - Learn about optimization and best practices
- [Common Patterns](./patterns.md) - ECS patterns and best practices
- [API Reference](../api/jecs.md) - Complete API documentation
- [Examples](../../examples/) - Code examples and patterns