Struct Ecs

Source
pub struct Ecs<'ecs> { /* private fields */ }
Expand description

A handle to EcsApp, which is real ecs instance.

This type is just for easy use in some cases such as writing a command. By removing verbose generic parameters, clients can declare parameters as Ecs instead of EcsApp<W, S> in their command functions for example.

Implementations§

Source§

impl<'ecs> Ecs<'ecs>

Source

pub fn default<Wp, W, G>(pool: Wp, groups: G) -> EcsApp<W, RandomState>
where Wp: Into<Vec<W>>, W: Work + 'static, G: AsRef<[usize]>,

Creates EcsApp with the given worker pool and group information.

The returned instance uses RandomState as hasher builder for its internal data structures. If you want another, call Ecs::create instead.

§Examples
use my_ecs::prelude::*;

// Creates `EcsApp` with one group consisting of 4 workers.
let pool = WorkerPool::with_len(4);
let ecs = Ecs::default(pool, [4]);

// Creates `EcsApp` with two groups consisting of 2 workers respectively.
let pool = WorkerPool::with_len(4);
let ecs = Ecs::default(pool, [2, 2]);
Source

pub fn create<Wp, W, G, S>(pool: Wp, groups: G) -> EcsApp<W, S>
where Wp: Into<Vec<W>>, W: Work + 'static, G: AsRef<[usize]>, S: BuildHasher + Default + 'static,

Creates EcsApp with the given workers, group information, and hasher builder type.

§Examples
use my_ecs::prelude::*;
use std::hash::{BuildHasher, DefaultHasher};

// Something like `std::hash::RandomState`.
#[derive(Default)] struct FixedState;
impl BuildHasher for FixedState {
    type Hasher = DefaultHasher;
    fn build_hasher(&self) -> Self::Hasher {
        DefaultHasher::new()
    }
}

// Creates `EcsApp` with one group consisting of 4 workers.
let pool = WorkerPool::with_len(4);
let ecs: EcsApp<_, FixedState> = Ecs::create(pool, [4]);

// Creates `EcsApp` with two groups consisting of 2 workers respectively.
let pool = WorkerPool::with_len(4);
let ecs: EcsApp<_, FixedState> = Ecs::create(pool, [2, 2]);

Trait Implementations§

Source§

impl<'ecs> Debug for Ecs<'ecs>

Source§

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

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

impl EcsEntry for Ecs<'_>

Source§

fn add_system<T, Sys>( &mut self, desc: T, ) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<Sys>>>
where T: Into<SystemDesc<Sys>>, Sys: System,

Adds the given system. Read more
Source§

fn add_once_system<T, Req, F>( &mut self, sys: T, ) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<FnOnceSystem<Req, F>>>>
where T: Into<FnOnceSystem<Req, F>>, FnOnceSystem<Req, F>: System,

Adds the given FnOnce system. Read more
Source§

fn unregister_system( &mut self, sid: SystemId, ) -> WithResult<&mut Self, (), EcsError>

Unregisters an inactive system for the given system id. Read more
Source§

fn activate_system( &mut self, target: SystemId, at: InsertPos, live: Tick, ) -> WithResult<&mut Self, (), EcsError>

Activates a system for the given system id if it’s not active. Read more
Source§

fn inactivate_system( &mut self, sid: SystemId, ) -> WithResult<&mut Self, (), EcsError>

Inactivates a system for the given system id. Read more
Source§

fn register_entity( &mut self, desc: EntityReg, ) -> WithResult<&mut Self, EntityIndex, EcsError>

Registers an entity type from the given descriptor. Read more
Source§

fn unregister_entity<C>( &mut self, ) -> WithResult<&mut Self, Box<dyn ContainEntity>, EcsError>
where C: Components,

Unregisters an entity type. Read more
Source§

fn add_entity<E>( &mut self, ei: EntityIndex, value: E, ) -> WithResult<&mut Self, EntityId, EcsError<E>>
where E: Entity,

Adds an entity. Read more
Source§

fn remove_entity( &mut self, eid: EntityId, ) -> WithResult<&mut Self, (), EcsError>

Removes an entity. Read more
Source§

fn add_resource<T>( &mut self, desc: T, ) -> WithResult<&mut Self, ResourceIndex, EcsError<ResourceDesc>>
where T: Into<ResourceDesc>,

Adds the given resource. Read more
Source§

fn remove_resource<R>(&mut self) -> WithResult<&mut Self, Option<R>, EcsError>
where R: Resource,

Removes a resource from the given resource type. Read more
Source§

fn get_resource<R>(&self) -> Option<&R>
where R: Resource,

Retrieves shared reference to a resource for the given resource type. Read more
Source§

fn get_resource_mut<R>(&mut self) -> Option<&mut R>
where R: Resource,

Retrieves mutable reference to a resource for the given resource type. Read more
Source§

fn get_resource_index<R>(&self) -> Option<ResourceIndex>
where R: Resource,

Returns resource index for the given resource type. Read more
Source§

fn execute_commands<T>( &mut self, cmds: T, ) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>

Executes the given commands in order. Read more
Source§

fn execute_command<F, R>( &mut self, f: F, ) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>
where F: FnOnce(Commander<'_>) -> R, R: Command,

Execute the given command. Read more
Source§

fn errors(&mut self) -> Vec<Box<dyn Error + Send + Sync + 'static>>

Returns errors generated from commands or futures. Read more
Source§

fn add_systems<T, Systems>( &mut self, descs: T, ) -> WithResult<&mut Self, (), EcsError>
where T: HelpAddManySystems<Systems>,

Adds the given systems. Read more
Source§

fn add_once_systems<T, Once>( &mut self, descs: T, ) -> WithResult<&mut Self, (), EcsError>
where T: HelpAddManyOnce<Once>,

Adds the given FnOnce systems. Read more
Source§

fn register_entity_of<T>( &mut self, ) -> WithResult<&mut Self, EntityIndex, EcsError>
where T: AsEntityReg,

Registers an entity type. Read more
Source§

fn add_resources<T>(&mut self, descs: T) -> WithResult<&mut Self, (), EcsError>
where T: HelpAddManyResources,

Adds the given resources. Read more

Auto Trait Implementations§

§

impl<'ecs> Freeze for Ecs<'ecs>

§

impl<'ecs> RefUnwindSafe for Ecs<'ecs>

§

impl<'ecs> !Send for Ecs<'ecs>

§

impl<'ecs> !Sync for Ecs<'ecs>

§

impl<'ecs> Unpin for Ecs<'ecs>

§

impl<'ecs> !UnwindSafe for Ecs<'ecs>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.