Struct trex::World
[−]
[src]
pub struct World { /* fields omitted */ }
Contains all entities and their components.
Methods
impl World
[src]
fn new() -> World
Create an empty World
.
fn register<C: 'static + FamilyMember>(&mut self)
Register a new component class.
fn exists(&self, entity: Entity) -> bool
Returns true
if the entity has been created and is not destroyed, otherwise false
.
Examples
let mut world = trex::World::new(); let entity = world.create(); assert!(world.exists(entity));
fn create(&mut self) -> Entity
Create a new Entity
.
fn tag(&mut self, entity: Entity, tag: &str)
Assign a tag to the Entity
so that it can be retrieved later.
Examples
let mut world = trex::World::new(); let entity = world.create(); world.tag(entity, "Example"); assert_eq!(world.lookup("Example"), Some(entity));
fn untag(&mut self, entity: Entity)
Remove the existing tag, if any, from an Entity
.
Examples
let mut world = trex::World::new(); let entity = world.create(); world.tag(entity, "Example"); world.untag(entity); assert_eq!(world.lookup("Example"), None);
fn lookup(&self, tag: &str) -> Option<Entity>
Retreive an Entity
using a tag.
fn destroy(&mut self, entity: Entity)
Destroy an existing Entity
. Also removes the tag and any attached components.
Examples
let mut world = trex::World::new(); let entity = world.create(); world.tag(entity, "Example"); world.destroy(entity); assert_eq!(world.lookup("Example"), None);
fn filter(&self, filter: &ComponentFilter) -> Vec<Entity>
Returns a list of all Entity
s with a given set of components.
fn add<C: FamilyMember>(&mut self, entity: Entity, component: C)
Attach a component to an Entity
.
fn remove<C: FamilyMember>(&mut self, entity: Entity)
Remove a component from an Entity
.
fn has<C: FamilyMember>(&self, entity: Entity) -> bool
Returns true
if the Entity
has the component, otherwise false
.
fn get<C: FamilyMember>(&self, entity: Entity) -> Option<&C>
Get a component of an Entity
.
fn get_mut<C: FamilyMember>(&mut self, entity: Entity) -> Option<&mut C>
Get a mutable component of an Entity
.