Struct topaz::Universe
[−]
[src]
pub struct Universe<T, S> { pub entities: Vec<Rc<T>>, pub systems: Vec<Rc<System<T, S>>>, pub special: S, pub events: Vec<Vec<usize>>, pub time_delta: f64, pub frames: usize, // some fields omitted }
The Universe contains all the meta-data neccessary for the game engine.
T
: The type of entities.S
: A singleton used to contain things that don't fit comfortably elsewhere.
Fields
entities: Vec<Rc<T>>
Entities in the universe.
systems: Vec<Rc<System<T, S>>>
Systems in the universe.
special: S
An instance of the Special
type, meant to store data that
doesn't fit comfortably elsewhere.
events: Vec<Vec<usize>>
List of possible events, and their subscribers.
time_delta: f64
Amount of time in seconds since the last frame.
frames: usize
Number of frames the universe has run so far.
Methods
impl<T: HasComponents, S> Universe<T, S>
[src]
fn new(special: S) -> Self
[src]
Create a new Universe
. Takes one instance of the Special
type. (See the field documentation.)
fn run(&mut self)
[src]
Run the universe. Returns when EVENT_QUIT
is triggered.
fn stop(&mut self)
[src]
Stop the universe. Using EVENT_QUIT
is favored, since it allows
subscribed systems to save and shutdown safely.
fn new_event(&mut self) -> usize
[src]
Allocate a new event.
fn new_system(&mut self, system: Rc<System<T, S>>) -> usize
[src]
Install a system.
fn subscribe(&mut self, system: usize, event: usize)
[src]
Subscribe an installed system to an event.
fn add_and_subscribe(&mut self, system: Rc<System<T, S>>, events: Vec<usize>)
[src]
Install a system and subscribe it to as many events as needed.
fn do_event(&mut self, event: usize)
[src]
Queue an event. The event will be triggered after all the systems subscribed to the currently running event have been run.
fn alloc(&mut self) -> usize
[src]
Allocate space for a new entity.
Componentless entities are considered un-allocated and consequently can be overwritten.
Keep this in mind when implementing HasComponents
.
fn queue_destroy(&self, index: usize)
[src]
Queue an entity for destruction. The entity will be destroyed after the system is finished running.
fn destroy(&mut self, index: usize)
[src]
Immediately destroy an entity.
fn set(&mut self, index: usize, entity: T)
[src]
Set an index to an entity.
fn add_entity(&mut self, entity: T) -> usize
[src]
Combines alloc
and set
. Allocates space for a new entity and installs it.