bbecs_tutorial

Struct World

Source
pub struct World { /* private fields */ }

Implementations§

Source§

impl World

Source

pub fn new() -> Self

Source

pub fn add_resource(&mut self, resource_data: impl Any)

Add a resource to the world so that anyone with access to the world can query for it immutably or mutably. Generally resources are pieces of data that are not associated with individual entities. An example of a resource could be the average fps.

Resources are stored based on their type id, so we could store one u32 resource. If we want to store more u32’s then we can wrap the data in a tuple struct. See the integration tests for an example.

use bbecs_tutorial::World;
let mut world = World::new();
world.add_resource(10_u32);
Source

pub fn get_resource<T: Any>(&self) -> Option<&T>

Query for a resource and get a reference to it. The type of the resource must be added in so that we can find it.

use bbecs_tutorial::World;
let mut world = World::new();
world.add_resource(10_u32);
let resource = world.get_resource::<u32>().unwrap();
assert_eq!(*resource, 10);
Source

pub fn get_resource_mut<T: Any>(&mut self) -> Option<&mut T>

Query for a resource and get a mutable reference to it. The type of the resource must be added in so that we can find it.

use bbecs_tutorial::World;
let mut world = World::new();
world.add_resource(10_u32);
{
  let resource = world.get_resource_mut::<u32>().unwrap();
  *resource += 1;
}
let resource = world.get_resource::<u32>().unwrap();
assert_eq!(*resource, 11);
Source

pub fn delete_resource<T: Any>(&mut self)

This will remove the resource from the world, and it doesn’t care if the resource exists at this point in time.

Source

pub fn register_component<T: Any + 'static>(&mut self)

Source

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

Source

pub fn query(&self) -> Query<'_>

Source

pub fn delete_component_by_entity_id<T: Any>( &mut self, index: usize, ) -> Result<()>

Source

pub fn add_component_to_entity_by_id( &mut self, data: impl Any, index: usize, ) -> Result<()>

Source

pub fn delete_entity_by_id(&mut self, index: usize) -> Result<()>

Trait Implementations§

Source§

impl Debug for World

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for World

Source§

fn default() -> World

Returns the “default value” for a type. Read more

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> 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.