diff options
| author | mat <git@matdoes.dev> | 2023-10-11 00:02:12 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-10-11 00:02:12 -0500 |
| commit | 19881c4612fe8372d8ddffa72c33b4339704f3b6 (patch) | |
| tree | fdb8fd1bd66f44759f72e966df93abd8d9be8726 /azalea/src | |
| parent | 9a687f0ffebad80441e036aabe14e7cf80c774d3 (diff) | |
| download | azalea-drasl-19881c4612fe8372d8ddffa72c33b4339704f3b6.tar.xz | |
fix State incorrectly being reused when calling handlers in swarm
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/swarm/mod.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 18c92438..af381c0b 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -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())); } } |
