Skip to content

Commit

Permalink
simplify some code
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Nov 18, 2023
1 parent 03cc28d commit e39de79
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.*
3 changes: 3 additions & 0 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/src/packet_handling/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions azalea-client/src/packet_handling/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions azalea/examples/testbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")));
}

Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 7 additions & 2 deletions azalea/src/swarm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
}
}

Expand Down

0 comments on commit e39de79

Please sign in to comment.