EntityManager

Struct EntityManager 

Source
pub struct EntityManager<'a> { /* private fields */ }
Expand description

part of the world, manipulating entities

Implementations§

Source§

impl<'a> EntityManager<'a>

Source

pub fn create_entity(&mut self) -> &mut Entity

Examples found in repository?
examples/render_gui_system.rs (line 56)
55    fn on_created(&mut self, entity_manager : &mut EntityManager) {
56        let data_entity = entity_manager.create_entity();
57        data_entity.add_component(RenderData {facade : self.facade.clone()});
58    }
59    fn process_one(&mut self, _ : &mut Entity) {
60        self.facade.borrow_mut().draw_something("triangles triangles");
61    }
62}
63
64pub struct GuiSystem;
65
66impl System for GuiSystem {
67    fn aspect(&self) -> Aspect {
68        aspect_all!(GuiWindow)
69    }
70    fn data_aspects(&self) -> Vec<Aspect> {
71        vec![aspect_all!(RenderData, HeavyGuiData)]
72    }
73
74    fn process_d(&mut self, _ : &mut Entity, data : &mut DataList) {
75        let render_data = data.unwrap_entity().get_component::<RenderData>();
76        let _gui_data   = data.unwrap_entity().get_component::<HeavyGuiData>();
77        render_data.facade.borrow_mut().draw_something("gui gui gui");
78    }
79}
80
81fn main() {
82    let mut world = World::new();
83    world.set_system(RenderSystem::new());
84    world.set_system(GuiSystem);
85    world.set_system(Glutin2HeavySystem);
86
87    {
88        let mut entity_manager = world.entity_manager();
89
90        {
91            let mesh = entity_manager.create_entity();
92
93            mesh.add_component(Renderable);
94            mesh.refresh();
95        }
96        {
97            let window = entity_manager.create_entity();
98
99            window.add_component(GuiWindow);
100            window.refresh();
101        }
102    }
103    world.update();
104    world.update();
105    world.update();
106}
More examples
Hide additional examples
examples/process_macro.rs (line 48)
43fn main() {
44    let mut world = World::new();
45
46    {
47        let mut entity_manager = world.entity_manager();
48        let entity = entity_manager.create_entity();
49
50        entity.add_component(Position {x : 0});
51        entity.add_component(Velocity {x : 1});
52        entity.refresh();
53    }
54    world.set_system(MoveSystem);
55    world.update();
56
57    world.update();
58    world.update();
59}
examples/multiple_fields.rs (line 45)
40fn main() {
41    let mut world = World::new();
42
43    {
44        let mut manager = world.entity_manager();
45        let entity = manager.create_entity();
46        entity.add_component(Health {hp : 100});
47        entity.add_component(Position {x : 5});
48        entity.add_component(Alive);
49        entity.refresh();
50    }
51    world.set_system(BleedZoneSystem);
52
53    for _ in 0..100 {
54        world.update();
55    }
56}
examples/spawn_system.rs (line 26)
22    fn process_w(&mut self, entity : &mut Entity, world : &mut WorldHandle) {
23        let mut spawn_point = entity.get_component::<SpawnPoint>();
24
25        if spawn_point.count > 0 {
26            let spawned = world.entity_manager.create_entity();
27            spawned.add_component(SomeComponent { _some_data : spawn_point.data.to_string() });
28            spawned.refresh();
29
30            spawn_point.count -= 1;
31        }
32    }
33}
34
35fn main() {
36    let mut world = World::new();
37
38    {
39        let mut w = world.entity_manager();
40        let entity = w.create_entity();
41
42        entity.add_component(SpawnPoint {data : "player", count : 5});
43        entity.refresh();
44    }
45
46    world.set_system(SpawnSystem);
47
48    world.update();
49    world.update();
50}
examples/systems.rs (line 60)
55fn main() {
56    let mut world = World::new();
57
58    {
59        let mut entity_manager = world.entity_manager();
60        let entity = entity_manager.create_entity();
61        entity.add_component(Position {pos : [0.0, 0.0, 0.0]});
62        entity.refresh();
63    }
64
65    // if you have position, you will be drawn
66    world.set_system(DrawerSystem);
67    // except you are dead
68    world.set_system(MoverSystem);
69    // but only if you are dead your corpse will be draw, too
70    world.set_system(DeadDrawerSystem);
71
72    world.update();
73    world.update();
74}
examples/process_types.rs (line 79)
74fn main() {
75    let mut world = World::new();
76
77    {
78        let mut entity_manager = world.entity_manager();
79        let entity = entity_manager.create_entity();
80
81        entity.add_component(Position {pos : [0.0, 0.0, 0.0]});
82        entity.add_component(Mesh {mesh : "player".to_string()});
83        entity.refresh();
84    }
85
86    {
87        let mut entity_manager = world.entity_manager();
88        let entity = entity_manager.create_entity();
89        entity.add_component(Camera {pos : [0.0, 0.0, 0.0]});
90        entity.refresh();
91    }
92    // will process all entities with Position and Mesh,
93    // and in this process all entities with Camera will be accessable
94    world.set_system(RenderSystem);
95
96
97    // same system, but we will use another implementetion inside it, for processing all entities at once
98    world.set_system(DeferRenderSystem);
99
100    world.update();
101    world.update();
102}
Source

pub fn try_get_entity(&mut self, id: i32) -> Option<&mut Entity>

Source

pub fn get_entities_by_ids<'b>( &mut self, ids: &HashSet<i32>, ) -> Vec<&'b mut Entity>

Auto Trait Implementations§

§

impl<'a> Freeze for EntityManager<'a>

§

impl<'a> !RefUnwindSafe for EntityManager<'a>

§

impl<'a> !Send for EntityManager<'a>

§

impl<'a> !Sync for EntityManager<'a>

§

impl<'a> Unpin for EntityManager<'a>

§

impl<'a> !UnwindSafe for EntityManager<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.