From 3b77fff573d6891ffeac062b831a72008243b8d7 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 13 Mar 2023 10:25:37 +0200 Subject: [PATCH] feat!(client, server): finish transition to bevy 0.10, and in addition * change from bevy_inspector_egui to bevy_editor_pls * remove iyes_loopless, as it is now obsolete * remove bevy_console and swap logs to terminal only, in preperation for my own console logging crate --- Cargo.lock | 4 ++-- client/Cargo.toml | 13 ++++++++-- client/src/dev.rs | 35 +++++++++++++++++++++++++++ client/src/main.rs | 36 +++++++++++++++++----------- client/src/plugins/config/mod.rs | 5 ++-- client/src/plugins/menu/mod.rs | 14 +++++++---- client/src/plugins/networking/mod.rs | 17 +++++++++---- client/src/util/egui/password.rs | 4 ++-- server/src/systems/event/mod.rs | 4 ++-- 9 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 client/src/dev.rs diff --git a/Cargo.lock b/Cargo.lock index 4a0660c..86180cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1096,9 +1096,9 @@ dependencies = [ [[package]] name = "bevy_egui" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf0efb32c83ae6d2cc36bda08a029d74fdeb45870489599d3779a36649802bce" +checksum = "1ae1391dc1820f8bb3f8f489f2348cfa5f5bd0970a4c6bcb0c1a011f65ae1b4d" dependencies = [ "arboard", "bevy", diff --git a/client/Cargo.toml b/client/Cargo.toml index 8cc0b32..5ce7ec8 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,6 +11,15 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [ + "dev", +] + +dev = [ + "dep:bevy_editor_pls", +] + [dependencies] laurelin_shared = { package = "shared", path = "../shared" } @@ -24,8 +33,8 @@ toml = "0.7.1" proc-macro2 = "1.0.50" bevy = { version = "0.10.0", features = [ "wayland" ] } -bevy_editor_pls = "0.3.0" -bevy_egui = "0.20.0" +bevy_editor_pls = { version = "0.3.0", optional = true } +bevy_egui = "0.20.1" # lua scripting #bevy_mod_scripting = { version = "0.2.1", features = ["lua", "lua54", "lua_script_api"] } diff --git a/client/src/dev.rs b/client/src/dev.rs new file mode 100644 index 0000000..5afdc93 --- /dev/null +++ b/client/src/dev.rs @@ -0,0 +1,35 @@ +/* + * This file is part of laurelin/client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use bevy::{diagnostic::FrameTimeDiagnosticsPlugin, prelude::*}; +use bevy_editor_pls::{controls, EditorPlugin}; + +pub struct DevPlugin; + +impl Plugin for DevPlugin { + fn build(&self, app: &mut App) { + app.add_plugin(EditorPlugin) + .insert_resource(editor_controls()) + .add_plugin(FrameTimeDiagnosticsPlugin::default()); + } +} + +fn editor_controls() -> controls::EditorControls { + let mut editor_controls = controls::EditorControls::default_bindings(); + editor_controls.unbind(controls::Action::PlayPauseEditor); + + editor_controls.insert( + controls::Action::PlayPauseEditor, + controls::Binding { + input: controls::UserInput::Single(controls::Button::Keyboard(KeyCode::Q)), + conditions: vec![controls::BindingCondition::ListeningForText(false)], + }, + ); + + editor_controls +} diff --git a/client/src/main.rs b/client/src/main.rs index 1150a51..571855a 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -10,13 +10,14 @@ use bevy::{ app::AppExit, prelude::*, window::{ - CompositeAlphaMode, Cursor, CursorGrabMode, PresentMode, WindowLevel, WindowMode, - WindowResizeConstraints, WindowResolution, + CompositeAlphaMode, Cursor, PresentMode, WindowLevel, WindowMode, WindowResizeConstraints, + WindowResolution, }, }; -#[cfg(feature = "dev")] -use bevy_editor_pls::EditorPlugin; -use naia_bevy_client::{Client, ClientConfig as NaiaClientConfig, Plugin as NaiaClientPlugin}; +use bevy_egui::EguiPlugin; +use naia_bevy_client::{ + Client, ClientConfig as NaiaClientConfig, Plugin as NaiaClientPlugin, ReceiveEvents, +}; use laurelin_shared::server::protocol::protocol; @@ -26,6 +27,9 @@ mod plugins; mod runtime; mod util; +#[cfg(feature = "dev")] +mod dev; + // NOTE: lua things, currently not in use //use bevy_mod_scripting::prelude::*; //mod lua; @@ -40,20 +44,18 @@ pub enum GameState { Game, } +#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] struct MainLoop; +#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)] +struct AfterMainLoop; + fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - cursor: Cursor { - icon: CursorIcon::Default, - visible: true, - grab_mode: CursorGrabMode::None, - hit_test: true, - ..Default::default() - }, + cursor: Cursor::default(), present_mode: PresentMode::Fifo, mode: WindowMode::Windowed, position: WindowPosition::Centered(MonitorSelection::Primary), @@ -80,8 +82,14 @@ fn main() { ..Default::default() })); + app.configure_set(MainLoop.after(ReceiveEvents)) + .configure_set(AfterMainLoop.after(MainLoop)); + #[cfg(feature = "dev")] - app.add_plugin(EditorPlugin); + app.add_plugin(dev::DevPlugin); + if !app.is_plugin_added::() { + app.add_plugin(EguiPlugin); + } //app.add_plugin(ScriptingPlugin).add_plugin(lua::LuaPlugin); @@ -114,7 +122,7 @@ fn main() { // Graceful exit app.add_event::() - .add_system(handle_graceful_exit); + .add_system(handle_graceful_exit.in_set(AfterMainLoop)); app.run(); } diff --git a/client/src/plugins/config/mod.rs b/client/src/plugins/config/mod.rs index 5528e98..5a0a93e 100644 --- a/client/src/plugins/config/mod.rs +++ b/client/src/plugins/config/mod.rs @@ -8,7 +8,7 @@ use bevy::prelude::*; -use crate::{cfg, util}; +use crate::{cfg, util, AfterMainLoop}; /// This plugin will handle config related tasks, like saving and loading pub struct ConfigPlugin; @@ -17,8 +17,7 @@ impl Plugin for ConfigPlugin { fn build(&self, app: &mut App) { app.init_resource::>() .init_resource::>() - .add_system(handle_load_events) - .add_system(handle_save_events); + .add_systems((handle_load_events, handle_save_events).in_set(AfterMainLoop)); } } diff --git a/client/src/plugins/menu/mod.rs b/client/src/plugins/menu/mod.rs index af602df..c11ea51 100644 --- a/client/src/plugins/menu/mod.rs +++ b/client/src/plugins/menu/mod.rs @@ -8,7 +8,7 @@ use bevy::prelude::*; -use crate::GameState; +use crate::{GameState, MainLoop}; pub mod ui; @@ -22,10 +22,14 @@ impl Plugin for MenuPlugin { .add_system(menu_setup.in_schedule(OnEnter(GameState::MainMenu))) .insert_resource(ui::connect::ConnectScreenData::default()) .insert_resource(ui::play::PlayScreenData::default()) - .add_system(ui::connect::ui.run_if(in_state(MenuState::Connect))) - .add_system(ui::menu::ui.run_if(in_state(MenuState::Menu))) - .add_system(ui::settings::ui.run_if(in_state(MenuState::Settings))) - .add_system(ui::play::ui.run_if(in_state(MenuState::Play))); + .add_systems( + ( + ui::connect::ui.run_if(in_state(MenuState::Connect)), + ui::menu::ui.run_if(in_state(MenuState::Menu)), + ui::settings::ui.run_if(in_state(MenuState::Settings)), + ui::play::ui.run_if(in_state(MenuState::Play)), + ).in_set(MainLoop) + ); } } diff --git a/client/src/plugins/networking/mod.rs b/client/src/plugins/networking/mod.rs index 5d8c825..8b095cc 100644 --- a/client/src/plugins/networking/mod.rs +++ b/client/src/plugins/networking/mod.rs @@ -7,6 +7,7 @@ */ use bevy::prelude::*; +use naia_bevy_client::ReceiveEvents; mod systems; @@ -14,10 +15,16 @@ pub struct NetworkingPlugin; impl Plugin for NetworkingPlugin { fn build(&self, app: &mut App) { - app.add_system_to_stage(CoreStage::PreUpdate, systems::events::connect_events) - .add_system_to_stage(CoreStage::PreUpdate, systems::events::reject_events) - .add_system_to_stage(CoreStage::PreUpdate, systems::events::disconnect_events) - .add_system_to_stage(CoreStage::PreUpdate, systems::events::message_events) - .add_system_to_stage(CoreStage::PreUpdate, systems::events::tick_events); + app.add_systems( + ( + systems::events::connect_events, + systems::events::reject_events, + systems::events::disconnect_events, + systems::events::message_events, + systems::events::tick_events, + ) + .chain() + .in_set(ReceiveEvents), + ); } } diff --git a/client/src/util/egui/password.rs b/client/src/util/egui/password.rs index 79dbee9..5224501 100644 --- a/client/src/util/egui/password.rs +++ b/client/src/util/egui/password.rs @@ -11,7 +11,7 @@ use bevy_egui::egui; fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response { let state_id = ui.id().with("show_plaintext"); - let mut show_plaintext = ui.data(|d| d.get_temp::(state_id).unwrap_or(false)); + let mut show_plaintext = ui.data_mut(|d| d.get_temp::(state_id).unwrap_or(false)); let result = ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { // TODO: this was previously add_sized() with a max of ui.available_size() @@ -27,7 +27,7 @@ fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response { } }); - ui.data(|d| d.insert_temp(state_id, show_plaintext)); + ui.data_mut(|d| d.insert_temp(state_id, show_plaintext)); result.response } diff --git a/server/src/systems/event/mod.rs b/server/src/systems/event/mod.rs index a0bc813..5def05e 100644 --- a/server/src/systems/event/mod.rs +++ b/server/src/systems/event/mod.rs @@ -8,7 +8,7 @@ use bevy_ecs::{ event::EventReader, - system::{Commands, Res, ResMut}, + system::{Res, ResMut}, }; use bevy_log::info; use laurelin_shared::{ @@ -20,7 +20,7 @@ use laurelin_shared::{ }; use naia_bevy_server::{ events::{AuthEvents, ConnectEvent, DisconnectEvent, ErrorEvent, TickEvent}, - CommandsExt, Random, Server, + Server, }; use crate::{Config, RuntimeTemp}; -- 2.44.1