aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-12-04 23:42:49 -0600
committerGitHub <noreply@github.com>2023-12-04 23:42:49 -0600
commit421d8ce2c837e3140d8f866e63032c277b31a413 (patch)
treed5f06fbcd02c24c6b40edd22cbdfda4d6ed6a39f /azalea-client/src
parentda4afa8ae3afec4cd59b9a19ae1e04818f1763a7 (diff)
downloadazalea-drasl-421d8ce2c837e3140d8f866e63032c277b31a413.tar.xz
Replace Bevy's FixedUpdate with Azalea's GameTick (#119)
* replace bevy FixedUpdate with azalea GameTick * Update to Bevy 0.12.1
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/attack.rs6
-rw-r--r--azalea-client/src/client.rs58
-rw-r--r--azalea-client/src/events.rs5
-rw-r--r--azalea-client/src/mining.rs6
-rw-r--r--azalea-client/src/movement.rs5
5 files changed, 49 insertions, 31 deletions
diff --git a/azalea-client/src/attack.rs b/azalea-client/src/attack.rs
index c22de727..a28f800d 100644
--- a/azalea-client/src/attack.rs
+++ b/azalea-client/src/attack.rs
@@ -1,4 +1,4 @@
-use azalea_core::game_type::GameMode;
+use azalea_core::{game_type::GameMode, tick::GameTick};
use azalea_entity::{
metadata::{ShiftKeyDown, Sprinting},
update_bounding_box, Attributes, Physics,
@@ -8,7 +8,7 @@ use azalea_protocol::packets::game::serverbound_interact_packet::{
self, ServerboundInteractPacket,
};
use azalea_world::MinecraftEntityId;
-use bevy_app::{App, FixedUpdate, Plugin, Update};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
@@ -29,7 +29,7 @@ impl Plugin for AttackPlugin {
.after(perform_respawn),
)
.add_systems(
- FixedUpdate,
+ GameTick,
(
increment_ticks_since_last_attack,
update_attack_strength_scale.after(PhysicsSet),
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 02800c3d..8a98df31 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -27,7 +27,7 @@ use crate::{
use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerError};
use azalea_buf::McBufWritable;
use azalea_chat::FormattedText;
-use azalea_core::{position::Vec3, resource_location::ResourceLocation};
+use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick};
use azalea_entity::{
indexing::{EntityIdIndex, EntityUuidIndex},
metadata::Health,
@@ -58,7 +58,7 @@ use azalea_protocol::{
resolver, ServerAddress,
};
use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance};
-use bevy_app::{App, FixedUpdate, Plugin, PluginGroup, PluginGroupBuilder, Update};
+use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder, Update};
use bevy_ecs::{
bundle::Bundle,
component::Component,
@@ -67,11 +67,17 @@ use bevy_ecs::{
system::{ResMut, Resource},
world::World,
};
-use bevy_time::{Fixed, Time, TimePlugin};
+use bevy_time::TimePlugin;
use derive_more::Deref;
use parking_lot::{Mutex, RwLock};
use std::{
- collections::HashMap, fmt::Debug, io, net::SocketAddr, ops::Deref, sync::Arc, time::Duration,
+ collections::HashMap,
+ fmt::Debug,
+ io,
+ net::SocketAddr,
+ ops::Deref,
+ sync::Arc,
+ time::{Duration, Instant},
};
use thiserror::Error;
use tokio::{
@@ -665,21 +671,19 @@ pub struct InConfigurationState;
pub struct AzaleaPlugin;
impl Plugin for AzaleaPlugin {
fn build(&self, app: &mut App) {
- // Minecraft ticks happen every 50ms
- app.insert_resource(Time::<Fixed>::from_duration(Duration::from_millis(50)))
- .add_systems(
- Update,
- (
- // fire the Death event when the player dies.
- death_event,
- // add GameProfileComponent when we get an AddPlayerEvent
- retroactively_add_game_profile_component.after(EntityUpdateSet::Index),
- handle_send_packet_event,
- ),
- )
- .add_event::<SendPacketEvent>()
- .init_resource::<InstanceContainer>()
- .init_resource::<TabList>();
+ app.add_systems(
+ Update,
+ (
+ // fire the Death event when the player dies.
+ death_event,
+ // add GameProfileComponent when we get an AddPlayerEvent
+ retroactively_add_game_profile_component.after(EntityUpdateSet::Index),
+ handle_send_packet_event,
+ ),
+ )
+ .add_event::<SendPacketEvent>()
+ .init_resource::<InstanceContainer>()
+ .init_resource::<TabList>();
}
}
@@ -712,6 +716,7 @@ async fn run_schedule_loop(
outer_schedule_label: InternedScheduleLabel,
mut run_schedule_receiver: mpsc::UnboundedReceiver<()>,
) {
+ let mut last_tick: Option<Instant> = None;
loop {
// get rid of any queued events
while let Ok(()) = run_schedule_receiver.try_recv() {}
@@ -720,7 +725,18 @@ async fn run_schedule_loop(
run_schedule_receiver.recv().await;
let mut ecs = ecs.lock();
+
+ // if last tick is None or more than 50ms ago, run the GameTick schedule
+ if last_tick
+ .map(|last_tick| last_tick.elapsed() > Duration::from_millis(50))
+ .unwrap_or(true)
+ {
+ last_tick = Some(Instant::now());
+ ecs.run_schedule(GameTick);
+ }
+
ecs.run_schedule(outer_schedule_label);
+
ecs.clear_trackers();
}
}
@@ -771,7 +787,7 @@ pub struct TickBroadcastPlugin;
impl Plugin for TickBroadcastPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(TickBroadcast(broadcast::channel(1).0))
- .add_systems(FixedUpdate, send_tick_broadcast);
+ .add_systems(GameTick, send_tick_broadcast);
}
}
@@ -784,7 +800,7 @@ impl Plugin for AmbiguityLoggerPlugin {
..Default::default()
});
});
- app.edit_schedule(FixedUpdate, |schedule| {
+ app.edit_schedule(GameTick, |schedule| {
schedule.set_build_settings(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Warn,
..Default::default()
diff --git a/azalea-client/src/events.rs b/azalea-client/src/events.rs
index 9f2632a8..9a51992c 100644
--- a/azalea-client/src/events.rs
+++ b/azalea-client/src/events.rs
@@ -4,11 +4,12 @@
use std::sync::Arc;
use azalea_chat::FormattedText;
+use azalea_core::tick::GameTick;
use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
};
use azalea_world::{InstanceName, MinecraftEntityId};
-use bevy_app::{App, FixedUpdate, Plugin, PreUpdate, Update};
+use bevy_app::{App, Plugin, PreUpdate, Update};
use bevy_ecs::{
component::Component,
event::EventReader,
@@ -128,7 +129,7 @@ impl Plugin for EventPlugin {
PreUpdate,
init_listener.before(crate::packet_handling::game::process_packet_events),
)
- .add_systems(FixedUpdate, tick_listener);
+ .add_systems(GameTick, tick_listener);
}
}
diff --git a/azalea-client/src/mining.rs b/azalea-client/src/mining.rs
index 4c160a9b..d1bc169e 100644
--- a/azalea-client/src/mining.rs
+++ b/azalea-client/src/mining.rs
@@ -1,5 +1,5 @@
use azalea_block::{Block, BlockState, FluidState};
-use azalea_core::{direction::Direction, game_type::GameMode, position::BlockPos};
+use azalea_core::{direction::Direction, game_type::GameMode, position::BlockPos, tick::GameTick};
use azalea_entity::{mining::get_mine_progress, FluidOnEyes, Physics};
use azalea_inventory::ItemSlot;
use azalea_physics::PhysicsSet;
@@ -7,7 +7,7 @@ use azalea_protocol::packets::game::serverbound_player_action_packet::{
self, ServerboundPlayerActionPacket,
};
use azalea_world::{InstanceContainer, InstanceName};
-use bevy_app::{App, FixedUpdate, Plugin, Update};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
@@ -33,7 +33,7 @@ impl Plugin for MinePlugin {
.add_event::<StopMiningBlockEvent>()
.add_event::<MineBlockProgressEvent>()
.add_event::<AttackBlockEvent>()
- .add_systems(FixedUpdate, continue_mining_block.before(PhysicsSet))
+ .add_systems(GameTick, continue_mining_block.before(PhysicsSet))
.add_systems(
Update,
(
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index 58fe1ff8..eb742a3c 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -1,6 +1,7 @@
use crate::client::Client;
use crate::packet_handling::game::SendPacketEvent;
use azalea_core::position::Vec3;
+use azalea_core::tick::GameTick;
use azalea_entity::{metadata::Sprinting, Attributes, Jumping};
use azalea_entity::{InLoadedChunk, LastSentPosition, LookDirection, Physics, Position};
use azalea_physics::{ai_step, PhysicsSet};
@@ -12,7 +13,7 @@ use azalea_protocol::packets::game::{
serverbound_move_player_status_only_packet::ServerboundMovePlayerStatusOnlyPacket,
};
use azalea_world::{MinecraftEntityId, MoveEntityError};
-use bevy_app::{App, FixedUpdate, Plugin, Update};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::{Event, EventWriter};
use bevy_ecs::schedule::SystemSet;
use bevy_ecs::{
@@ -54,7 +55,7 @@ impl Plugin for PlayerMovePlugin {
.in_set(MoveEventsSet),
)
.add_systems(
- FixedUpdate,
+ GameTick,
(
(tick_controls, local_player_ai_step)
.chain()