Expose now via Commands
This commit is contained in:
parent
a72a72f8c1
commit
da5e137432
2 changed files with 24 additions and 6 deletions
|
@ -1,5 +1,8 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::any::{Any, TypeId};
|
use std::{
|
||||||
|
any::{Any, TypeId},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{world::ComponentChange, *};
|
use crate::{world::ComponentChange, *};
|
||||||
|
|
||||||
|
@ -11,12 +14,23 @@ enum CommandsTypes {
|
||||||
Event(TypeId, Box<dyn Any + Send + Sync>),
|
Event(TypeId, Box<dyn Any + Send + Sync>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Commands {
|
pub struct Commands {
|
||||||
commands: Vec<CommandsTypes>,
|
commands: Vec<CommandsTypes>,
|
||||||
|
now: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commands {
|
impl Commands {
|
||||||
|
pub(crate) fn new(now: Duration) -> Self {
|
||||||
|
Self {
|
||||||
|
commands: Vec::new(),
|
||||||
|
now,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn now(&self) -> Duration {
|
||||||
|
self.now
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_entity(&mut self, entity_object: EntityObject) -> Entity {
|
pub fn insert_entity(&mut self, entity_object: EntityObject) -> Entity {
|
||||||
let entity = entity_object.as_entity();
|
let entity = entity_object.as_entity();
|
||||||
|
|
||||||
|
|
|
@ -503,12 +503,14 @@ impl Archetype {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&self, world: &mut World) -> Result<()> {
|
pub fn execute(&self, world: &mut World) -> Result<()> {
|
||||||
|
let mut commands = Commands::new(world.now());
|
||||||
|
|
||||||
for (entity, callback) in self.entities.iter() {
|
for (entity, callback) in self.entities.iter() {
|
||||||
let mut commands = Commands::default();
|
|
||||||
callback(*entity, &mut commands, world)?;
|
callback(*entity, &mut commands, world)?;
|
||||||
commands.apply_deferred(world)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.apply_deferred(world)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,12 +588,14 @@ impl ArchetypePair {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn execute(&self, world: &mut World) -> Result<()> {
|
pub(crate) fn execute(&self, world: &mut World) -> Result<()> {
|
||||||
|
let mut commands = Commands::new(world.now());
|
||||||
|
|
||||||
for ((left_entity, right_entity), callback) in self.entities.iter() {
|
for ((left_entity, right_entity), callback) in self.entities.iter() {
|
||||||
let mut commands = Commands::default();
|
|
||||||
callback(*left_entity, *right_entity, &mut commands)?;
|
callback(*left_entity, *right_entity, &mut commands)?;
|
||||||
commands.apply_deferred(world)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.apply_deferred(world)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue