Struct specs::World
[−]
[src]
pub struct World { pub res: Resources, // some fields omitted }
The World
struct contains the component storages and
other resources.
Many methods take &self
which works because everything
is stored with interior mutability. In case you violate
the borrowing rules of Rust (multiple reads xor one write),
you will get a panic.
Component / Resources ids
Components and resources may, in addition to their type, be identified
by an id of type usize
. The convenience methods dealing
with components assume that it's 0
.
If a system attempts to access a component/resource that has not been
registered/added, it will panic when run. Add all components with
World::register
before running any systems. Also add all resources
with World::add_resource
.
Examples
use specs::World; let mut world = World::new(); world.register::<Pos>(); world.register::<Vel>(); world.add_resource(DeltaTime(0.02)); world.create_entity() .with(Pos { x: 1.0, y: 2.0 }) .with(Vel { x: -1.0, y: 0.0 }) .build(); world.create_entity() .with(Pos { x: 3.0, y: 5.0 }) .with(Vel { x: 1.0, y: 0.0 }) .build(); world.create_entity() .with(Pos { x: 0.0, y: 1.0 }) .with(Vel { x: 0.0, y: 1.0 }) .build();
Fields
res: Resources
The resources used for this world.
Methods
impl World
[src]
fn new() -> World
[src]
Creates a new empty World
.
fn register<T: Component>(&mut self)
[src]
Registers a new component.
Calls register_with_id
with id 0
, which
is the default for component ids.
Does nothing if the component was already registered.
fn register_with_id<T: Component>(&mut self, id: usize)
[src]
Registers a new component with a given id.
Does nothing if the component was already registered.
fn add_resource<T: Resource>(&mut self, res: T)
[src]
Adds a resource with the default ID (0
).
If the resource already exists it will be overwritten.
fn add_resource_with_id<T: Resource>(&mut self, res: T, id: usize)
[src]
Adds a resource with a given ID.
If the resource already exists it will be overwritten.
fn read<T: Component>(&self) -> ReadStorage<T>
[src]
Fetches a component's storage with the default id for reading.
Convenience method for read_with_id
, using the default component
id (0
).
Panics
Panics if it is already borrowed mutably. Panics if the component has not been registered.
fn write<T: Component>(&self) -> WriteStorage<T>
[src]
Fetches a component's storage with the default id for writing.
Convenience method for write_with_id
, using the default component
id (0
).
Panics
Panics if it is already borrowed. Panics if the component has not been registered.
fn read_with_id<T: Component>(&self, id: usize) -> ReadStorage<T>
[src]
Fetches a component's storage with a specified id for reading.
Panics
Panics if it is already borrowed mutably.
Also panics if the component is not registered with World::register
.
fn write_with_id<T: Component>(&self, id: usize) -> WriteStorage<T>
[src]
Fetches a component's storage with a specified id for writing.
Panics
Panics if it is already borrowed.
Also panics if the component is not registered with World::register
.
fn read_resource_with_id<T: Resource>(&self, id: usize) -> Fetch<T>
[src]
Fetches a resource with a specified id for reading.
Panics
Panics if it is already borrowed mutably. Panics if the resource has not been added.
fn write_resource_with_id<T: Resource>(&self, id: usize) -> FetchMut<T>
[src]
Fetches a resource with a specified id for writing.
Panics
Panics if it is already borrowed. Panics if the resource has not been added.
fn read_resource<T: Resource>(&self) -> Fetch<T>
[src]
Fetches a resource with the default id for reading.
Convenience method for read_resource_with_id
, using the default component
id (0
).
Panics
Panics if it is already borrowed mutably. Panics if the resource has not been added.
fn write_resource<T: Resource>(&self) -> FetchMut<T>
[src]
Fetches a resource with the default id for writing.
Convenience method for write_resource_with_id
, using the default component
id (0
).
Panics
Panics if it is already borrowed. Panics if the resource has not been added.
fn entities(&self) -> Fetch<EntitiesRes>
[src]
Convenience method for fetching entities.
Creation and deletion of entities with the Entities
struct
are atomically, so the actual changes will be applied
with the next call to maintain()
.
fn create_entity(&mut self) -> EntityBuilder
[src]
Allows building an entity with its components.
fn create_iter(&mut self) -> CreateIter
[src]
Returns an iterator for entity creation. This makes it easy to create a whole collection of them.
Examples
use specs::World; let mut world = World::new(); let five_entities: Vec<_> = world.create_iter().take(5).collect();
fn delete_entity(&mut self, entity: Entity) -> Result<(), WrongGeneration>
[src]
Deletes an entity and its components.
fn delete_entities(&mut self, delete: &[Entity]) -> Result<(), WrongGeneration>
[src]
Deletes the specified entities and their components.
fn delete_all(&mut self)
[src]
Deletes all entities and their components.
fn is_alive(&self, e: Entity) -> bool
[src]
Checks if an entity is alive.
Please note that atomically created or deleted entities
(the ones created / deleted with the Entities
struct)
are not handled by this method. Therefore, you
should have called maintain()
before using this
method.
If you want to get this functionality before a maintain()
,
you are most likely in a system; from there, just access the
Entities
resource and call the is_alive
method.
Panics
Panics if generation is dead.
fn maintain(&mut self)
[src]
Merges in the appendix, recording all the dynamically created and deleted entities into the persistent generations vector. Also removes all the abandoned components.
Additionally, LazyUpdate
will be merged.
Trait Implementations
impl Send for World
[src]
impl Sync for World
[src]
impl Borrow<Resources> for World
[src]
impl Component for World
[src]
type Storage = DenseVecStorage<Self>
Associated storage type for this component.