aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/packet/mod.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-02-22 11:35:41 +0700
committermat <git@matdoes.dev>2026-02-22 11:35:41 +0700
commit2756eb419af2210eed3d0574e20a620918e4e577 (patch)
tree0d209e70f65db16b7b982c3e941355589b7d5181 /azalea-client/src/plugins/packet/mod.rs
parentca2fbe329b0879496cf12de4e85d81ca3aa3c351 (diff)
downloadazalea-drasl-2756eb419af2210eed3d0574e20a620918e4e577.tar.xz
optimizations at high entity counts
Diffstat (limited to 'azalea-client/src/plugins/packet/mod.rs')
-rw-r--r--azalea-client/src/plugins/packet/mod.rs50
1 files changed, 32 insertions, 18 deletions
diff --git a/azalea-client/src/plugins/packet/mod.rs b/azalea-client/src/plugins/packet/mod.rs
index 63a94ee0..4309850e 100644
--- a/azalea-client/src/plugins/packet/mod.rs
+++ b/azalea-client/src/plugins/packet/mod.rs
@@ -11,6 +11,7 @@ use crate::chat::ChatReceivedEvent;
pub mod config;
pub mod game;
pub mod login;
+pub mod relative_updates;
pub struct PacketPlugin;
@@ -30,23 +31,27 @@ pub fn death_event_on_0_health(
impl Plugin for PacketPlugin {
fn build(&self, app: &mut App) {
- app.add_observer(game::handle_outgoing_packets_observer)
- .add_observer(config::handle_outgoing_packets_observer)
- .add_observer(login::handle_outgoing_packets_observer)
- .add_systems(Update, death_event_on_0_health)
- .add_message::<game::ReceiveGamePacketEvent>()
- .add_message::<config::ReceiveConfigPacketEvent>()
- .add_message::<login::ReceiveLoginPacketEvent>()
- //
- .add_message::<game::AddPlayerEvent>()
- .add_message::<game::RemovePlayerEvent>()
- .add_message::<game::UpdatePlayerEvent>()
- .add_message::<ChatReceivedEvent>()
- .add_message::<game::DeathEvent>()
- .add_message::<game::KeepAliveEvent>()
- .add_message::<game::ResourcePackEvent>()
- .add_message::<game::WorldLoadedEvent>()
- .add_message::<login::ReceiveCustomQueryEvent>();
+ app.add_systems(
+ Update,
+ relative_updates::debug_detect_updates_received_on_local_entities,
+ )
+ .add_observer(game::handle_outgoing_packets_observer)
+ .add_observer(config::handle_outgoing_packets_observer)
+ .add_observer(login::handle_outgoing_packets_observer)
+ .add_systems(Update, death_event_on_0_health)
+ .add_message::<game::ReceiveGamePacketEvent>()
+ .add_message::<config::ReceiveConfigPacketEvent>()
+ .add_message::<login::ReceiveLoginPacketEvent>()
+ //
+ .add_message::<game::AddPlayerEvent>()
+ .add_message::<game::RemovePlayerEvent>()
+ .add_message::<game::UpdatePlayerEvent>()
+ .add_message::<ChatReceivedEvent>()
+ .add_message::<game::DeathEvent>()
+ .add_message::<game::KeepAliveEvent>()
+ .add_message::<game::ResourcePackEvent>()
+ .add_message::<game::WorldLoadedEvent>()
+ .add_message::<login::ReceiveCustomQueryEvent>();
}
}
@@ -70,12 +75,21 @@ macro_rules! __declare_packet_handlers {
pub(crate) use __declare_packet_handlers as declare_packet_handlers;
+#[derive(Resource)]
+struct CachedSystemState<T: SystemParam + 'static>(SystemState<T>);
+
pub(crate) fn as_system<T>(ecs: &mut World, f: impl FnOnce(T::Item<'_, '_>))
where
T: SystemParam + 'static,
{
- let mut system_state = SystemState::<T>::new(ecs);
+ // creating a new SystemState is expensive, so we save them as a Resource in the
+ // ecs
+ let mut system_state = match ecs.remove_resource::<CachedSystemState<T>>() {
+ Some(s) => s.0,
+ None => SystemState::<T>::new(ecs),
+ };
let values = system_state.get_mut(ecs);
f(values);
system_state.apply(ecs);
+ ecs.insert_resource(CachedSystemState(system_state));
}