Struct bones_lib::Game

source ·
pub struct Game {
    pub sessions: Sessions,
    pub systems: GameSystems,
    pub sorted_session_keys: Vec<Ustr>,
    pub shared_resources: Vec<AtomicUntypedResource>,
}
Expand description

The Game encompasses a complete bones game’s logic, independent of the renderer and IO implementations.

Games are made up of one or more Sessions, each of which contains it’s own World and SystemStages. These different sessions can be used for parts of the game with independent states, such as the main menu and the gameplay.

Fields§

§sessions: Sessions

The sessions that make up the game.

§systems: GameSystems

The collection of systems that are associated to the game itself, and not a specific session.

§sorted_session_keys: Vec<Ustr>

List of sorted session keys.

These are only guaranteed to be sorted and up-to-date immediately after calling Game::step().

§shared_resources: Vec<AtomicUntypedResource>

Collection of resources that will have a shared instance of each be inserted into each session automatically.

Implementations§

source§

impl Game

source

pub fn new() -> Self

Create an empty game with an asset server.

source

pub fn install_plugin<P: GamePlugin>(&mut self, plugin: P) -> &mut Self

Install a GamePlugin.

source

pub fn shared_resource<T: HasSchema>(&self) -> Option<Ref<'_, T>>

Get the shared resource of a given type out of this Games shared resources.

source

pub fn shared_resource_mut<T: HasSchema>(&self) -> Option<RefMut<'_, T>>

Get the shared resource of a given type out of this Games shared resources.

source

pub fn shared_resource_cell<T: HasSchema>(&self) -> Option<AtomicResource<T>>

Get the shared resource cell of a given type out of this Games shared resources.

source

pub fn init_shared_resource<T: HasSchema + Default>(&mut self) -> RefMut<'_, T>

Initialize a resource that will be shared across game sessions using it’s Default value if it is not already initialized, and borrow it for modification.

source

pub fn insert_shared_resource<T: HasSchema>(&mut self, resource: T)

Insert a resource that will be shared across all game sessions.

Note: This resource will only be visible in sessions that have not already initialized or access a resource of the same type locally.

source

pub fn step(&mut self, now: Instant)

Step the game simulation.

Trait Implementations§

source§

impl Default for Game

source§

fn default() -> Game

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

Auto Trait Implementations§

§

impl Freeze for Game

§

impl !RefUnwindSafe for Game

§

impl Send for Game

§

impl Sync for Game

§

impl Unpin for Game

§

impl !UnwindSafe for Game

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.

§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &World) -> T

Creates Self using data from the given World.
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.

§

impl<T> RawDefault for T
where T: Default,

§

unsafe fn raw_default(dst: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_default_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
§

impl<T> RawDrop for T

§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Send + Sync)>

Get a callback suitable for [SchemaData].
source§

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

§

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

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V