pub struct EcsApp<W, S = RandomState>{ /* private fields */ }Expand description
An ECS instance.
Clients can create the instance via Ecs::default, Ecs::create or
EcsApp::new. It’s possible to have multiple ECS instances as well if you
really need to do so, but it’s recommended to have multiple groups instead
of multiple instances to reduce memory footprint and share data with ease.
W- Worker type.S- Hasher builder type.
Implementations§
Source§impl<W, S> EcsApp<W, S>
impl<W, S> EcsApp<W, S>
Sourcepub fn new(workers: Vec<W>, groups: &[usize]) -> Self
pub fn new(workers: Vec<W>, groups: &[usize]) -> Self
Creates an ECS instance 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> = EcsApp::new(pool.into(), &[4]);
// Creates `EcsApp` with two groups consisting of 2 workers respectively.
let pool = WorkerPool::with_len(4);
let ecs: EcsApp<_, FixedState> = EcsApp::new(pool.into(), &[2, 2]);Sourcepub fn collect_poisoned_systems(&mut self) -> Vec<PoisonedSystem>
pub fn collect_poisoned_systems(&mut self) -> Vec<PoisonedSystem>
Takes out poisoned systems so far.
§Examples
use my_ecs::prelude::*;
let v = Ecs::default(WorkerPool::with_len(1), [1])
.add_once_system(|| {
panic!("panics on purpose");
})
.step()
.collect_poisoned_systems();
assert_eq!(v.len(), 1);Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of internal data structures as much as possible.
Sourcepub fn step(&mut self) -> &mut Self
pub fn step(&mut self) -> &mut Self
Executes active systems of all groups once.
Generated commands during the execution will be completely consumed at the end of system execution.
§Examples
use my_ecs::prelude::*;
use std::sync::{Arc, Mutex};
let cnt = Arc::new(Mutex::new(0));
let c_cnt = Arc::clone(&cnt);
Ecs::default(WorkerPool::new(), [])
.add_system(move || {
*c_cnt.lock().unwrap() += 1;
})
.step();
assert_eq!(*cnt.lock().unwrap(), 1);Sourcepub fn run<F, R>(&mut self, handle_error: F) -> With<&mut Self, Vec<R>>
pub fn run<F, R>(&mut self, handle_error: F) -> With<&mut Self, Vec<R>>
Executes active systems of all groups until their lifetime goes to zero.
§Examples
use my_ecs::prelude::*;
use std::sync::{Arc, Mutex};
let cnt = Arc::new(Mutex::new(0));
let c_cnt = Arc::clone(&cnt);
Ecs::default(WorkerPool::new(), [])
.add_system(
SystemDesc::new()
.with_activation(2, InsertPos::Back)
.with_system(move || {
*c_cnt.lock().unwrap() += 1;
})
)
.run(|_| {});
assert_eq!(*cnt.lock().unwrap(), 2);Sourcepub fn wait_for_idle(&mut self) -> &mut Self
pub fn wait_for_idle(&mut self) -> &mut Self
Waits for ecs to be idle.
Ecs becomes idle when all group’s workers get closed.
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Determines whether ecs has been executed completely, so that it cannot do anything.
If all conditions below are met, then ecs is considered as completed.
- No active systems
- No uncompleted commands
- No open sub workers
Trait Implementations§
Source§impl<W, S> EcsEntry for EcsApp<W, S>
impl<W, S> EcsEntry for EcsApp<W, S>
Source§fn add_system<T, Sys>(
&mut self,
desc: T,
) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<Sys>>>
fn add_system<T, Sys>( &mut self, desc: T, ) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<Sys>>>
Source§fn add_once_system<T, Req, F>(
&mut self,
sys: T,
) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<FnOnceSystem<Req, F>>>>
fn add_once_system<T, Req, F>( &mut self, sys: T, ) -> WithResult<&mut Self, SystemId, EcsError<SystemDesc<FnOnceSystem<Req, F>>>>
Source§fn unregister_system(
&mut self,
sid: SystemId,
) -> WithResult<&mut Self, (), EcsError>
fn unregister_system( &mut self, sid: SystemId, ) -> WithResult<&mut Self, (), EcsError>
Source§fn activate_system(
&mut self,
target: SystemId,
at: InsertPos,
live: Tick,
) -> WithResult<&mut Self, (), EcsError>
fn activate_system( &mut self, target: SystemId, at: InsertPos, live: Tick, ) -> WithResult<&mut Self, (), EcsError>
Source§fn inactivate_system(
&mut self,
sid: SystemId,
) -> WithResult<&mut Self, (), EcsError>
fn inactivate_system( &mut self, sid: SystemId, ) -> WithResult<&mut Self, (), EcsError>
Source§fn register_entity(
&mut self,
desc: EntityReg,
) -> WithResult<&mut Self, EntityIndex, EcsError>
fn register_entity( &mut self, desc: EntityReg, ) -> WithResult<&mut Self, EntityIndex, EcsError>
Source§fn unregister_entity<C>(
&mut self,
) -> WithResult<&mut Self, Box<dyn ContainEntity>, EcsError>where
C: Components,
fn unregister_entity<C>(
&mut self,
) -> WithResult<&mut Self, Box<dyn ContainEntity>, EcsError>where
C: Components,
Source§fn add_entity<E>(
&mut self,
ei: EntityIndex,
value: E,
) -> WithResult<&mut Self, EntityId, EcsError<E>>where
E: Entity,
fn add_entity<E>(
&mut self,
ei: EntityIndex,
value: E,
) -> WithResult<&mut Self, EntityId, EcsError<E>>where
E: Entity,
Source§fn remove_entity(
&mut self,
eid: EntityId,
) -> WithResult<&mut Self, (), EcsError>
fn remove_entity( &mut self, eid: EntityId, ) -> WithResult<&mut Self, (), EcsError>
Source§fn add_resource<T>(
&mut self,
desc: T,
) -> WithResult<&mut Self, ResourceIndex, EcsError<ResourceDesc>>where
T: Into<ResourceDesc>,
fn add_resource<T>(
&mut self,
desc: T,
) -> WithResult<&mut Self, ResourceIndex, EcsError<ResourceDesc>>where
T: Into<ResourceDesc>,
Source§fn remove_resource<R>(&mut self) -> WithResult<&mut Self, Option<R>, EcsError>where
R: Resource,
fn remove_resource<R>(&mut self) -> WithResult<&mut Self, Option<R>, EcsError>where
R: Resource,
Source§fn get_resource<R>(&self) -> Option<&R>where
R: Resource,
fn get_resource<R>(&self) -> Option<&R>where
R: Resource,
Source§fn get_resource_mut<R>(&mut self) -> Option<&mut R>where
R: Resource,
fn get_resource_mut<R>(&mut self) -> Option<&mut R>where
R: Resource,
Source§fn get_resource_index<R>(&self) -> Option<ResourceIndex>where
R: Resource,
fn get_resource_index<R>(&self) -> Option<ResourceIndex>where
R: Resource,
Source§fn execute_commands<T>(
&mut self,
cmds: T,
) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>where
T: HelpExecuteManyCommands,
fn execute_commands<T>(
&mut self,
cmds: T,
) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>where
T: HelpExecuteManyCommands,
Source§fn execute_command<F, R>(
&mut self,
f: F,
) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>
fn execute_command<F, R>( &mut self, f: F, ) -> WithResult<&mut Self, (), Box<dyn Error + Send + Sync + 'static>>
Source§fn errors(&mut self) -> Vec<Box<dyn Error + Send + Sync + 'static>>
fn errors(&mut self) -> Vec<Box<dyn Error + Send + Sync + 'static>>
Source§fn add_systems<T, Systems>(
&mut self,
descs: T,
) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManySystems<Systems>,
fn add_systems<T, Systems>(
&mut self,
descs: T,
) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManySystems<Systems>,
Source§fn add_once_systems<T, Once>(
&mut self,
descs: T,
) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManyOnce<Once>,
fn add_once_systems<T, Once>(
&mut self,
descs: T,
) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManyOnce<Once>,
Source§fn register_entity_of<T>(
&mut self,
) -> WithResult<&mut Self, EntityIndex, EcsError>where
T: AsEntityReg,
fn register_entity_of<T>(
&mut self,
) -> WithResult<&mut Self, EntityIndex, EcsError>where
T: AsEntityReg,
Source§fn add_resources<T>(&mut self, descs: T) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManyResources,
fn add_resources<T>(&mut self, descs: T) -> WithResult<&mut Self, (), EcsError>where
T: HelpAddManyResources,
Source§impl<W, S> From<EcsApp<W, S>> for LeakedEcsApp
impl<W, S> From<EcsApp<W, S>> for LeakedEcsApp
impl<W, S> Resource for EcsApp<W, S>
Auto Trait Implementations§
impl<W, S = RandomState> !Freeze for EcsApp<W, S>
impl<W, S = RandomState> !RefUnwindSafe for EcsApp<W, S>
impl<W, S = RandomState> !Send for EcsApp<W, S>
impl<W, S = RandomState> !Sync for EcsApp<W, S>
impl<W, S> Unpin for EcsApp<W, S>
impl<W, S = RandomState> !UnwindSafe for EcsApp<W, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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