[][src]Struct tecs::Ecs

pub struct Ecs { /* fields omitted */ }

Contains the entire Ecs state

Implementations

impl Ecs[src]

pub fn new() -> Ecs[src]

Create an empty Ecs.

pub fn new_entity(&mut self) -> EntityBuilder[src]

Create a new entity in the Ecs. This function will return an EntityBuilder, the entity will be stored as soon as EntityBuilder::build is called.

Examples

use tecs::*;

struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
let entity_id = ecs.new_entity()
    .with_component(Position { x: 1.0, y: 2.0 })
    .build();

assert!(ecs.component::<Position>(0).is_some())

pub fn remove_entity(&mut self, entity_id: usize)[src]

Remove an entity from the Ecs.

This will set all the entity components to None and add the entity id to the entity id free list for reuse of the id.

Examples

use tecs::*;

struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
let first_entity_id = ecs.new_entity()
    .with_component(Position { x: 1.0, y: 2.0 })
    .build();
let second_entity_id = ecs.new_entity()
    .with_component(Position { x: 3.0, y: 4.0 })
    .build();

assert!(ecs.component::<Position>(first_entity_id).is_some());
assert!(ecs.component::<Position>(second_entity_id).is_some());

ecs.remove_entity(first_entity_id);

assert!(ecs.component::<Position>(first_entity_id).is_none());
assert!(ecs.component::<Position>(second_entity_id).is_some());

let new_entity_id = ecs.new_entity()
    .with_component(Position { x: 5.0, y: 6.0 })
    .build();

assert_eq!(new_entity_id, first_entity_id);

pub fn component<T: 'static>(&self, entity_id: usize) -> Option<&T>[src]

Returns a reference to the component of an entity

Examples

use tecs::*;

#[derive(Debug, PartialEq)]
struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
let entity = ecs.new_entity()
    .with_component(Position { x: 3.0, y: 4.5 })
    .build();

assert_eq!(*ecs.component::<Position>(entity).unwrap(), Position { x: 3.0, y: 4.5 });

pub fn component_mut<T: 'static>(&mut self, entity_id: usize) -> Option<&mut T>[src]

Returns a mutable reference to the component of an entity

Examples

use tecs::*;

#[derive(Debug, PartialEq)]
struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
let entity = ecs.new_entity()
    .with_component(Position { x: 3.0, y: 4.5 })
    .build();

assert_eq!(*ecs.component::<Position>(entity).unwrap(), Position { x: 3.0, y: 4.5 });

ecs.component_mut::<Position>(entity).unwrap().x = 200.0;
assert_eq!(*ecs.component::<Position>(entity).unwrap(), Position { x: 200.0, y: 4.5 });

pub fn component_iter<T: 'static>(&mut self) -> ComponentIter<T>[src]

Returns an iterator for the given component

Examples

use tecs::*;

#[derive(Debug, PartialEq)]
struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
ecs.new_entity()
    .with_component(Position { x: 1.0, y: 2.0 })
    .build();

ecs.new_entity()
    .with_component(Position { x: 3.0, y: 4.0 })
    .build();

ecs.new_entity()
    .with_component(Position { x: 5.0, y: 6.0 })
    .build();

let component_iterator = ecs.component_iter::<Position>();
assert_eq!(component_iterator.count(), 3);

pub fn component_iter_mut<T: 'static>(&mut self) -> ComponentIterMut<T>[src]

Returns a mutable iterator for the given component

Examples

use tecs::*;

#[derive(Debug, PartialEq)]
struct Position {
    x: f32,
    y: f32
}

let mut ecs = Ecs::new();
ecs.new_entity()
    .with_component(Position { x: 1.0, y: 2.0 })
    .build();

ecs.new_entity()
    .with_component(Position { x: 3.0, y: 4.0 })
    .build();

ecs.new_entity()
    .with_component(Position { x: 5.0, y: 6.0 })
    .build();

let component_iterator = ecs.component_iter_mut::<Position>();
assert_eq!(component_iterator.count(), 3);

Auto Trait Implementations

impl !RefUnwindSafe for Ecs

impl !Send for Ecs

impl !Sync for Ecs

impl Unpin for Ecs

impl !UnwindSafe for Ecs

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.