mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
simplify some code
This commit is contained in:
parent
03cc28d8e7
commit
e39de79a6b
6 changed files with 26 additions and 15 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -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.*
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue