pub struct World { /* private fields */ }Implementations§
Source§impl World
impl World
Sourcepub fn new() -> World
pub fn new() -> World
Constructs new Entity World.
Examples found in repository?
examples/spawn_system.rs (line 36)
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}More examples
examples/process_macro.rs (line 44)
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 41)
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/systems.rs (line 56)
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/render_gui_system.rs (line 82)
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}examples/process_types.rs (line 75)
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}Sourcepub fn entity_manager<'a>(&'a mut self) -> EntityManager<'a>
pub fn entity_manager<'a>(&'a mut self) -> EntityManager<'a>
Get entity manager for manupalating with entities.
§Examples
use tinyecs::*;
let mut world = World::new();
{
let mut entity_manager = world.entity_manager();
let _entity = entity_manager.create_entity();
// _entity.add_component(); or something
}Examples found in repository?
examples/spawn_system.rs (line 39)
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}More examples
examples/process_macro.rs (line 47)
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 44)
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/systems.rs (line 59)
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/render_gui_system.rs (line 88)
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}examples/process_types.rs (line 78)
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}Sourcepub fn set_system<TSys>(&mut self, system: TSys)where
TSys: 'static + System,
pub fn set_system<TSys>(&mut self, system: TSys)where
TSys: 'static + System,
Add new active system.
Examples found in repository?
examples/spawn_system.rs (line 46)
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}More examples
examples/process_macro.rs (line 54)
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 51)
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/systems.rs (line 66)
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/render_gui_system.rs (line 83)
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}examples/process_types.rs (line 94)
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}Sourcepub fn update(&mut self)
pub fn update(&mut self)
Tick all systems in world. All on_added and on_removed will passed inside this method.
Examples found in repository?
examples/spawn_system.rs (line 48)
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}More examples
examples/process_macro.rs (line 55)
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 54)
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/systems.rs (line 72)
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/render_gui_system.rs (line 103)
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}examples/process_types.rs (line 100)
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}Auto Trait Implementations§
impl Freeze for World
impl !RefUnwindSafe for World
impl !Send for World
impl !Sync for World
impl Unpin for World
impl !UnwindSafe for World
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more