Crate despero_hecs
source ·Expand description
A handy ECS
hecs provides a high-performance, minimalist entity-component-system (ECS) world. It is a
library, not a framework. In place of an explicit “System” abstraction, a World
’s entities are
easily queried from regular code. Organize your application however you like!
In order of importance, hecs pursues:
- fast traversals
- a simple interface
- a small dependency closure
- exclusion of externally-implementable functionality
let mut world = World::new();
// Nearly any type can be used as a component with zero boilerplate
let a = world.spawn((123, true, "abc"));
let b = world.spawn((42, false));
// Systems can be simple for loops
for (id, (mut number, &flag)) in world.query_mut::<(&mut i32, &bool)>() {
if flag { *number *= 2; }
}
// Random access is simple and safe
assert_eq!(*world.get::<&i32>(a).unwrap(), 246);
assert_eq!(*world.get::<&i32>(b).unwrap(), 42);
Re-exports
pub use bundle::Bundle;
pub use bundle::DynamicBundle;
pub use bundle::DynamicBundleClone;
pub use bundle::MissingComponent;
pub use query::Access;
pub use query::Batch;
pub use query::BatchedIter;
pub use query::Or;
pub use query::PreparedQuery;
pub use query::PreparedQueryBorrow;
pub use query::PreparedQueryIter;
pub use query::PreparedView;
pub use query::Query;
pub use query::QueryBorrow;
pub use query::QueryIter;
pub use query::QueryMut;
pub use query::Satisfies;
pub use query::View;
pub use query::With;
pub use query::Without;
Modules
- Implementations of ecs bundle
- ECS-queries
- Convenience tools for serializing
World
s
Structs
- Query that retrieves added state of type
T
component. - A collection of entities having the same component types
- Shared reference to a single column of component data in an
Archetype
- Unique reference to a single column of component data in an
Archetype
- Determines freshness of information derived from
World::archetypes
- Error indicating that a
ColumnBatchBuilder
was missing components - Handle for appending components
- A collection of components that implement
Clone
- Query that retrieves changed state of type
T
component. Changed component is one that have either been mutated or added. - A collection of component data for entities with the same component types
- An incomplete collection of component data for entities with the same component types
- A collection of component types
- Records operations for future application to a
World
- Lightweight unique ID, or handle, of an entity
- Helper for incrementally constructing a bundle of components with dynamic component types
- Variant of
EntityBuilder
that clones components on use - Handle to an entity with any component types
- Iterator over all of a world’s entities
- Query that retrieves mutation state of type
T
component. Added components do not count as mutated. - Error indicating that no entity with a particular ID exists
- A borrow of a
World
sufficient to execute the queryQ
on a single entity - Shared borrow of an entity’s component
- Unique borrow of an entity’s component
- Entity IDs created by
World::spawn_batch
- Iterator over
Entity
s spawned byWorld::spawn_column_batch()
- An entity removed from a
World
- An unordered collection of entities, each having any number of distinctly typed components
Enums
- Errors that arise when accessing components
- Errors that arise when querying a single entity
Traits
- Types that can be components, implemented automatically for all
Send + Sync + 'static
types &T
or&mut T
whereT
is some component type&T
whereT
is some component type
Derive Macros
- Implement
Bundle
for a struct - Implement
DynamicBundleClone
for a struct. - Implement
Query
for a struct