ixa/entity/
mod.rs

1/*!
2
3A "person" is represented by a `PersonId` and has multiple `PersonProperty` values
4associated with it. Entities generalize this: An `Entity` is analogous to a table in
5a relationship database, and the properties of an entity are analogous to the columns
6that exist on the table. A row in the table is addressable with an `EntityId<Entity>`
7(implemented as a newtype of a `usize`). In this new paradigm, `Person` is a particular
8entity, possibly one of several, and `PersonId` is a type alias for `EntityId<Person>`.
9
10Entity property getters and setters exists on `Context` like this:
11
12```rust,ignore
13// The `my_entity_id` value is of type `MyEntityId`, which is a type alias for `EntityId<MyEntity>`.
14// (The `MyProperty` type knows which entity it belongs to.)
15let my_property_value = context.get_property::<MyProperty>(my_entity_id);
16// Turbofish-less version of the same call:
17let my_property_value: MyProperty = context.get_property(my_entity_id);
18
19// For setters, the property is inferred from the type of the value we are passing in.
20context.set_property(my_entity_id, some_property_value);
21// ...but if you want to be super-explicit, you could use a turbofish version:
22context.set_property::<MyProperty>(my_entity_id, some_property_value);
23```
24
25This implementation of entities relies heavily on the "registry pattern" for efficient
26lookup of entities and properties. The idea is that concrete types implementing `Entity` (and
27separately, `Property<Entity>`) have a `ctor` that initializes a global (per concrete type)
28static variable `index`. Each concrete `Entity` type is thus assigned a unique index ranging from
29`0` to `ENTITY_COUNT - 1`. Then instances of container types like `EntityStore` (respectively
30`PropertyStore`) use this index to look up the corresponding instances in a vector it owns.
31
32*/
33
34pub mod context_extension;
35mod entity;
36pub mod entity_set;
37pub mod entity_store;
38pub mod events;
39pub(crate) mod index;
40pub mod multi_property;
41pub mod property;
42pub mod property_list;
43pub mod property_store;
44pub(crate) mod property_value_store;
45pub(crate) mod property_value_store_core;
46pub mod query;
47
48// Flatten the module hierarchy.
49pub use context_extension::ContextEntitiesExt;
50pub use entity::*;
51pub use entity_set::EntitySetIterator;
52pub use index::PropertyIndexType;
53pub use query::EntityPropertyTuple;
54pub(crate) use query::Query;
55
56/// The type used in the indexing infrastructure. This type alias is
57/// public, because it is used by any implementor of `Property<E: Entity>`.
58pub type HashValueType = u128;