[−][src]Crate kudo
A simple and predictable Entity Component System.
An entity-component-system (ECS) is a data structure and organizational pattern often used by game-like code.
An ECS is made up of three parts:
- Entities: IDs associated with various components
- Components: Individual units of data associated with an entity.
- Systems: Code that iterates over components
// First we create the world. let mut world = World::new(); // Let's create a new entity with a name and a health component. // Components are just plain structs. // This will be our health component struct Health(i32); // Spawn the entity with a String component we'll use for the name and a Health component. // Within the call to spawn we pass in a tuple that can have multiple components. world.spawn(("Medusa".to_string(), Health(-2))); // Query the world for entities that have a String component and a Health component. // The '&' before each component requests read-only access to the component. // Using '&mut' would request write/read access for that component. let mut query = world.query::<(&String, &Health)>().unwrap(); // Iterate over all the components we found and check if their health is less than 0. for (name, health) in query.iter() { if health.0 < 0 { println!("{} has perished!", name); } }
Structs
ComponentAlreadyBorrowed | |
Entity | A handle to an entity within the world. |
EntityMissingComponent | |
NoSuchEntity | This entity has been despawned so operations can no longer be performed on it. |
Query | Query for entities with specific components. |
Single | Used to get a single immutable instance of a component from the world. If there are multiple of the component in the world an arbitrary instance is returned. |
SingleMut | Used to get a single mutable instance of a component from the world. If there are multiple of the component in the world an arbitrary instance is returned. |
World | The world holds all components and associated entities. |
Zip3 | |
Zip4 | |
Zip5 | |
Zip6 | |
Zip7 | |
Zip8 |
Enums
ComponentError |
Traits
ComponentBundle | A bundle of components Used to spawn new |
GetIter | |
QueryParam | A member of a |
QueryParams | The parameters passed into a query. Like: |
System | A function that can be run as system by pulling in queries from the world. |
TopLevelQuery | An empty trait used to indicate which queries can be constructed at the top level of a query. |