mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
fix State incorrectly being reused when calling handlers in swarm
This commit is contained in:
parent
9a687f0ffe
commit
19881c4612
2 changed files with 11 additions and 4 deletions
|
@ -168,7 +168,7 @@ impl Vec3 {
|
|||
f64::sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
|
||||
}
|
||||
|
||||
/// Get the squared distance from this position to another position.
|
||||
/// Get the distance from this position to another position.
|
||||
/// Equivalent to `(self - other).length()`.
|
||||
pub fn distance_to(&self, other: &Self) -> f64 {
|
||||
(self - other).length()
|
||||
|
|
|
@ -387,12 +387,19 @@ where
|
|||
});
|
||||
|
||||
// bot events
|
||||
while let Some((Some(event), bot)) = bots_rx.recv().await {
|
||||
while let Some((Some(first_event), first_bot)) = bots_rx.recv().await {
|
||||
if let Some(handler) = &self.handler {
|
||||
let state = bot.component::<S>();
|
||||
tokio::spawn((handler)(bot, event, state.clone()));
|
||||
let first_bot_state = first_bot.component::<S>();
|
||||
let first_bot_entity = first_bot.entity;
|
||||
tokio::spawn((handler)(first_bot, first_event, first_bot_state.clone()));
|
||||
|
||||
// this makes it not have to keep locking the ecs
|
||||
let mut states = HashMap::new();
|
||||
states.insert(first_bot_entity, first_bot_state);
|
||||
while let Ok((Some(event), bot)) = bots_rx.try_recv() {
|
||||
let state = states
|
||||
.entry(bot.entity)
|
||||
.or_insert_with(|| bot.component::<S>().clone());
|
||||
tokio::spawn((handler)(bot, event, state.clone()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue