File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ impl Vec3 {
168
168
f64:: sqrt ( self . x * self . x + self . y * self . y + self . z * self . z )
169
169
}
170
170
171
- /// Get the squared distance from this position to another position.
171
+ /// Get the distance from this position to another position.
172
172
/// Equivalent to `(self - other).length()`.
173
173
pub fn distance_to ( & self , other : & Self ) -> f64 {
174
174
( self - other) . length ( )
Original file line number Diff line number Diff line change @@ -387,12 +387,19 @@ where
387
387
} ) ;
388
388
389
389
// bot events
390
- while let Some ( ( Some ( event ) , bot ) ) = bots_rx. recv ( ) . await {
390
+ while let Some ( ( Some ( first_event ) , first_bot ) ) = bots_rx. recv ( ) . await {
391
391
if let Some ( handler) = & self . handler {
392
- let state = bot. component :: < S > ( ) ;
393
- tokio:: spawn ( ( handler) ( bot, event, state. clone ( ) ) ) ;
392
+ let first_bot_state = first_bot. component :: < S > ( ) ;
393
+ let first_bot_entity = first_bot. entity ;
394
+ tokio:: spawn ( ( handler) ( first_bot, first_event, first_bot_state. clone ( ) ) ) ;
395
+
394
396
// this makes it not have to keep locking the ecs
397
+ let mut states = HashMap :: new ( ) ;
398
+ states. insert ( first_bot_entity, first_bot_state) ;
395
399
while let Ok ( ( Some ( event) , bot) ) = bots_rx. try_recv ( ) {
400
+ let state = states
401
+ . entry ( bot. entity )
402
+ . or_insert_with ( || bot. component :: < S > ( ) . clone ( ) ) ;
396
403
tokio:: spawn ( ( handler) ( bot, event, state. clone ( ) ) ) ;
397
404
}
398
405
}
You can’t perform that action at this time.
0 commit comments