diff --git a/.gitignore b/.gitignore index e97aa75a5..c5b441e73 100755 --- a/.gitignore +++ b/.gitignore @@ -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 7f4a6170e..13d180fe3 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 e26e3f3b0..b61b2e7e2 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 a17dd13f5..8f3b0e997 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 10bb9e4a0..a7f34a776 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::>(|name: &Name| name == sender); let entity = bot.entity_by::, (&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 1f31db98c..585e26084 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::(); 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::().clone()); - tokio::spawn((handler)(bot, event, state.clone())); + tasks.push((handler)(bot, event, state.clone())); } + + tokio::spawn(join_all(tasks)); } }