diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-02-25 17:32:15 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-25 17:32:15 -0600 |
| commit | c1588ef66e844c067112ea880a54b4de9ec5a062 (patch) | |
| tree | 76e4f73a5f5392e1bef1f0560ed2f2c56b0d50fb /azalea-client | |
| parent | f5a8a59467a0aac3ae2f728961559217f1e1242d (diff) | |
| download | azalea-drasl-c1588ef66e844c067112ea880a54b4de9ec5a062.tar.xz | |
Fix system order ambiguities (#74)
* start fixing stuff where systems run in the wrong order
* fix ordering ambiguity
* add debugging guide
* some fixes
* fix panic for swarms
* fix some warnings
Diffstat (limited to 'azalea-client')
| -rw-r--r-- | azalea-client/Cargo.toml | 30 | ||||
| -rw-r--r-- | azalea-client/examples/echo.rs | 49 | ||||
| -rwxr-xr-x | azalea-client/src/chat.rs | 14 | ||||
| -rw-r--r-- | azalea-client/src/client.rs | 30 | ||||
| -rw-r--r-- | azalea-client/src/disconnect.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling.rs | 21 | ||||
| -rwxr-xr-x | azalea-client/src/player.rs | 6 |
7 files changed, 52 insertions, 104 deletions
diff --git a/azalea-client/Cargo.toml b/azalea-client/Cargo.toml index 9fae2fbe..6bb31069 100644 --- a/azalea-client/Cargo.toml +++ b/azalea-client/Cargo.toml @@ -11,29 +11,27 @@ version = "0.6.0" [dependencies] anyhow = "1.0.59" async-trait = "0.1.58" -azalea-auth = {path = "../azalea-auth", version = "0.6.0"} -azalea-block = {path = "../azalea-block", version = "0.6.0"} -azalea-chat = {path = "../azalea-chat", version = "0.6.0"} -azalea-core = {path = "../azalea-core", version = "0.6.0"} -azalea-crypto = {path = "../azalea-crypto", version = "0.6.0"} -azalea-ecs = {path = "../azalea-ecs", version = "0.6.0"} -azalea-physics = {path = "../azalea-physics", version = "0.6.0"} -azalea-protocol = {path = "../azalea-protocol", version = "0.6.0"} -azalea-registry = {path = "../azalea-registry", version = "0.6.0"} -azalea-world = {path = "../azalea-world", version = "0.6.0"} +azalea-auth = { path = "../azalea-auth", version = "0.6.0" } +azalea-block = { path = "../azalea-block", version = "0.6.0" } +azalea-chat = { path = "../azalea-chat", version = "0.6.0" } +azalea-core = { path = "../azalea-core", version = "0.6.0" } +azalea-crypto = { path = "../azalea-crypto", version = "0.6.0" } +azalea-ecs = { path = "../azalea-ecs", version = "0.6.0" } +azalea-physics = { path = "../azalea-physics", version = "0.6.0" } +azalea-protocol = { path = "../azalea-protocol", version = "0.6.0" } +azalea-registry = { path = "../azalea-registry", version = "0.6.0" } +azalea-world = { path = "../azalea-world", version = "0.6.0" } +bevy_log = "0.9.1" bevy_tasks = "0.9.1" bevy_time = "0.9.1" -derive_more = {version = "0.99.17", features = ["deref", "deref_mut"]} +derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] } futures = "0.3.25" log = "0.4.17" nohash-hasher = "0.2.0" once_cell = "1.16.0" -parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]} +parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] } regex = "1.7.0" thiserror = "^1.0.34" -tokio = {version = "^1.24.2", features = ["sync"]} +tokio = { version = "^1.24.2", features = ["sync"] } typemap_rev = "0.3.0" uuid = "^1.1.2" - -[dev-dependencies] -env_logger = "0.9.1" diff --git a/azalea-client/examples/echo.rs b/azalea-client/examples/echo.rs deleted file mode 100644 index f37cd904..00000000 --- a/azalea-client/examples/echo.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! A simple bot that repeats chat messages sent by other players. - -use azalea_client::{Account, Client, Event}; - -#[tokio::main] -async fn main() { - env_logger::init(); - // deadlock detection, you can safely delete this block if you're not trying to - // debug deadlocks in azalea - { - use parking_lot::deadlock; - use std::thread; - use std::time::Duration; - thread::spawn(move || loop { - thread::sleep(Duration::from_secs(10)); - let deadlocks = deadlock::check_deadlock(); - if deadlocks.is_empty() { - continue; - } - println!("{} deadlocks detected", deadlocks.len()); - for (i, threads) in deadlocks.iter().enumerate() { - println!("Deadlock #{i}"); - for t in threads { - println!("Thread Id {:#?}", t.thread_id()); - println!("{:#?}", t.backtrace()); - } - } - }); - } - - let account = Account::offline("bot"); - // or let account = Account::microsoft("email").await; - - let (client, mut rx) = Client::join(&account, "localhost").await.unwrap(); - - while let Some(event) = rx.recv().await { - match &event { - Event::Chat(m) => { - if let (Some(sender), content) = m.split_sender_and_content() { - if sender == client.profile.name { - continue; // ignore our own messages - } - client.chat(&content); - }; - } - _ => {} - } - } -} diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs index ac119f24..202cf47c 100755 --- a/azalea-client/src/chat.rs +++ b/azalea-client/src/chat.rs @@ -19,7 +19,10 @@ use std::{ }; use uuid::Uuid; -use crate::{client::Client, local_player::SendPacketEvent}; +use crate::{ + client::Client, + local_player::{handle_send_packet_event, SendPacketEvent}, +}; /// A chat packet, either a system message or a chat message. #[derive(Debug, Clone, PartialEq)] @@ -155,15 +158,12 @@ impl Plugin for ChatPlugin { app.add_event::<SendChatEvent>() .add_event::<SendChatKindEvent>() .add_event::<ChatReceivedEvent>() - .add_system( - handle_send_chat_event - .label("handle_send_chat_event") - .after("packet"), - ) + .add_system(handle_send_chat_event.label("handle_send_chat_event")) .add_system( handle_send_chat_kind_event .label("handle_send_chat_kind_event") - .after("handle_send_chat_event"), + .after(handle_send_chat_event) + .after(handle_send_packet_event), ); } } diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 69a50c33..661858db 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -20,7 +20,7 @@ use azalea_ecs::{ bundle::Bundle, component::Component, entity::Entity, - schedule::{IntoSystemDescriptor, Schedule, Stage, SystemSet}, + schedule::{IntoSystemDescriptor, ReportExecutionOrderAmbiguities, Schedule, Stage, SystemSet}, AppTickExt, }; use azalea_ecs::{ecs::Ecs, TickPlugin}; @@ -49,6 +49,7 @@ use azalea_world::{ entity::{EntityPlugin, Local, WorldName}, PartialWorld, World, WorldContainer, }; +use bevy_log::LogPlugin; use log::{debug, error}; use parking_lot::{Mutex, RwLock}; use std::{collections::HashMap, fmt::Debug, io, net::SocketAddr, sync::Arc}; @@ -497,36 +498,31 @@ impl Plugin for AzaleaPlugin { app.add_tick_system_set( SystemSet::new() - .with_system(send_position) - .with_system(update_in_loaded_chunk) + .with_system(send_position.after("ai_step")) + .with_system(update_in_loaded_chunk.before(send_position).after("travel")) .with_system( local_player_ai_step - .before("ai_step") - .after("sprint_listener"), + .before(azalea_physics::ai_step) + .label("ai_step"), ), ); // fire the Death event when the player dies. - app.add_system(death_event.after("tick").after("packet")); + app.add_system(death_event); // walk and sprint event listeners - app.add_system(walk_listener.label("walk_listener").before("travel")) + app.add_system(walk_listener.label("walk_listener")) .add_system( sprint_listener .label("sprint_listener") - .before("travel") .before("walk_listener"), ); // add GameProfileComponent when we get an AddPlayerEvent - app.add_system( - retroactively_add_game_profile_component - .after("tick") - .after("packet"), - ); + app.add_system(retroactively_add_game_profile_component.after("update_indexes")); app.add_event::<SendPacketEvent>() - .add_system(handle_send_packet_event.after("tick").after("packet")); + .add_system(handle_send_packet_event); app.init_resource::<WorldContainer>(); } @@ -547,6 +543,9 @@ pub fn init_ecs_app() -> App { // you might be able to just drop the lock or put it in its own scope to fix let mut app = App::new(); + + app.insert_resource(ReportExecutionOrderAmbiguities); + app.add_plugins(DefaultPlugins); app } @@ -609,9 +608,10 @@ pub struct DefaultPlugins; impl PluginGroup for DefaultPlugins { fn build(self) -> PluginGroupBuilder { PluginGroupBuilder::start::<Self>() + .add(LogPlugin::default()) .add(TickPlugin::default()) - .add(AzaleaPlugin) .add(PacketHandlerPlugin) + .add(AzaleaPlugin) .add(EntityPlugin) .add(PhysicsPlugin) .add(EventPlugin) diff --git a/azalea-client/src/disconnect.rs b/azalea-client/src/disconnect.rs index 83870e69..9fd57e57 100644 --- a/azalea-client/src/disconnect.rs +++ b/azalea-client/src/disconnect.rs @@ -12,7 +12,7 @@ use azalea_ecs::{ }; use derive_more::Deref; -use crate::{client::JoinedClientBundle, LocalPlayer}; +use crate::{client::JoinedClientBundle, movement::send_position, LocalPlayer}; pub struct DisconnectPlugin; impl Plugin for DisconnectPlugin { @@ -20,7 +20,9 @@ impl Plugin for DisconnectPlugin { app.add_event::<DisconnectEvent>() .add_system_to_stage(CoreStage::PostUpdate, handle_disconnect) .add_tick_system( - update_read_packets_task_running_component.before(disconnect_on_read_packets_ended), + update_read_packets_task_running_component + .before(disconnect_on_read_packets_ended) + .before(send_position), ) .add_tick_system(disconnect_on_read_packets_ended); } diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs index d5cce3a8..a4d638a4 100644 --- a/azalea-client/src/packet_handling.rs +++ b/azalea-client/src/packet_handling.rs @@ -2,13 +2,12 @@ use std::{collections::HashSet, io::Cursor, sync::Arc}; use azalea_core::{ChunkPos, ResourceLocation, Vec3}; use azalea_ecs::{ - app::{App, Plugin}, + app::{App, CoreStage, Plugin}, component::Component, ecs::Ecs, entity::Entity, event::EventWriter, query::Changed, - schedule::{IntoSystemDescriptor, SystemSet}, system::{Commands, Query, ResMut, SystemState}, }; use azalea_protocol::{ @@ -47,15 +46,13 @@ pub struct PacketHandlerPlugin; impl Plugin for PacketHandlerPlugin { fn build(&self, app: &mut App) { - app.add_system_set( - SystemSet::new().with_system(handle_packets.label("packet").before("tick")), - ) - .add_event::<AddPlayerEvent>() - .add_event::<RemovePlayerEvent>() - .add_event::<UpdatePlayerEvent>() - .add_event::<ChatReceivedEvent>() - .add_event::<DeathEvent>() - .add_event::<KeepAliveEvent>(); + app.add_system_to_stage(CoreStage::PreUpdate, handle_packets) + .add_event::<AddPlayerEvent>() + .add_event::<RemovePlayerEvent>() + .add_event::<UpdatePlayerEvent>() + .add_event::<ChatReceivedEvent>() + .add_event::<DeathEvent>() + .add_event::<KeepAliveEvent>(); } } @@ -110,7 +107,7 @@ pub struct PacketReceiver { pub run_schedule_sender: mpsc::UnboundedSender<()>, } -fn handle_packets(ecs: &mut Ecs) { +pub fn handle_packets(ecs: &mut Ecs) { let mut events_owned = Vec::new(); { diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs index 8bccedc8..3680e2d0 100755 --- a/azalea-client/src/player.rs +++ b/azalea-client/src/player.rs @@ -36,9 +36,9 @@ pub fn retroactively_add_game_profile_component( ) { for event in events.iter() { if let Some(entity) = entity_infos.get_entity_by_uuid(&event.info.uuid) { - if let Some(mut entity_commands) = commands.get_entity(entity) { - entity_commands.insert(GameProfileComponent(event.info.profile.clone())); - } + commands + .entity(entity) + .insert(GameProfileComponent(event.info.profile.clone())); } } } |
