diff options
| -rwxr-xr-x | .gitignore | 9 | ||||
| -rw-r--r-- | azalea-client/src/client.rs | 3 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/configuration.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/game.rs | 11 | ||||
| -rw-r--r-- | azalea/examples/testbot.rs | 7 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 9 |
6 files changed, 26 insertions, 15 deletions
@@ -1,10 +1,13 @@ /target /doc -flamegraph.svg -perf.data -perf.data.old .vscode # created by azalea-auth/examples/auth, defined in the main .gitignore because # the example could be run from anywhere example_cache.json + +# these are created by profiling tools +flamegraph.svg +perf.data +perf.data.old +heaptrack.* diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 7f4a6170..13d180fe 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -681,6 +681,9 @@ async fn run_schedule_loop( loop { // whenever we get an event from run_schedule_receiver, run the schedule run_schedule_receiver.recv().await; + // get rid of any queued events + while let Ok(()) = run_schedule_receiver.try_recv() {} + let mut ecs = ecs.lock(); ecs.run_schedule(outer_schedule_label); ecs.clear_trackers(); diff --git a/azalea-client/src/packet_handling/configuration.rs b/azalea-client/src/packet_handling/configuration.rs index e26e3f3b..b61b2e7e 100644 --- a/azalea-client/src/packet_handling/configuration.rs +++ b/azalea-client/src/packet_handling/configuration.rs @@ -54,7 +54,7 @@ pub fn send_packet_events( }; packet_events.send(PacketEvent { entity: player_entity, - packet: packet.clone(), + packet, }); } // clear the packets right after we read them diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index a17dd13f..8f3b0e99 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -163,10 +163,13 @@ pub fn send_packet_events( continue; } }; - packet_events.send(PacketEvent { - entity: player_entity, - packet: packet.clone(), - }); + if let ClientboundGamePacket::LevelChunkWithLight(_) = packet { + } else { + packet_events.send(PacketEvent { + entity: player_entity, + packet, + }); + } } // clear the packets right after we read them packets.clear(); diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index 10bb9e4a..a7f34a77 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> { let mut accounts = Vec::new(); - for i in 0..1 { + for i in 0..200 { accounts.push(Account::offline(&format!("bot{i}"))); } @@ -98,10 +98,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< // .find(|e| e.name() == Some(sender)); // let entity = bot.entity_by::<With<Player>>(|name: &Name| name == sender); let entity = bot.entity_by::<With<Player>, (&GameProfileComponent,)>( - |(profile,): &(&GameProfileComponent,)| { - println!("entity {profile:?}"); - profile.name == sender - }, + |(profile,): &(&GameProfileComponent,)| profile.name == sender, ); println!("sender entity: {entity:?}"); match m.content().as_str() { diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 1f31db98..585e2608 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -393,7 +393,10 @@ where if let Some(handler) = &self.handler { 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())); + + let mut tasks = Vec::new(); + + tasks.push((handler)(first_bot, first_event, first_bot_state.clone())); // this makes it not have to keep locking the ecs let mut states = HashMap::new(); @@ -402,8 +405,10 @@ where let state = states .entry(bot.entity) .or_insert_with(|| bot.component::<S>().clone()); - tokio::spawn((handler)(bot, event, state.clone())); + tasks.push((handler)(bot, event, state.clone())); } + + tokio::spawn(join_all(tasks)); } } |
