From c7692d36c10e538b47b489734691a871fe3b52ac Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Thu, 16 Nov 2023 20:21:30 -0800 Subject: [PATCH] Need to figure out a better way to camera... The general idea is that we will have 2 cameras total, one for 2d and one for 3d. Start with 2d and switch to 3d. Each camera will be marked with it's state, and there will be a system which listens for some event (or resource update) to change the camera. --- .cargo/config.toml | 2 +- Cargo.toml | 3 --- TODO | 10 ++++++++++ build.rs | 1 - src/audio.rs | 1 - src/credits.rs | 1 + src/debug.rs | 16 ++++++++++++++++ src/display2d.rs | 1 + src/display3d.rs | 6 ++---- src/loading.rs | 10 ++++++++++ src/main.rs | 1 + src/menu.rs | 12 ++++++++++++ 12 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 TODO diff --git a/.cargo/config.toml b/.cargo/config.toml index d3d5e72..e1a9801 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,5 @@ [target.x86_64-unknown-linux-gnu] -rustflags = ["-Zshare-generics=y"] +rustflags = ["-Zshare-generics=y", "-Z", "threads=8"] # [target.x86_64-apple-darwin] # rustflags = [ diff --git a/Cargo.toml b/Cargo.toml index 82b2e2f..04934f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,5 @@ build = "build.rs" bevy_fmod = { version = "0.3", features = ["live-update"] } bevy = { version = "0.11", features = ["jpeg", "hdr"] } -[features] -fmod = [] - [profile.dev] opt-level = 3 diff --git a/TODO b/TODO new file mode 100644 index 0000000..8c959d5 --- /dev/null +++ b/TODO @@ -0,0 +1,10 @@ +Camera handling: +* Set all new cameras as "is_active = false" automatically. +* Set loading camera as "is_active = true" upon entering loading. +* Set menu camera as "is_active = true" upon entering menu, etc. +* Maybe this has to do with loading entry/de-entry? It goes away after entering main menu... + +OK new idea: +* Have one enum with all states (no split states) +* Assign a state to each camera. +* On state change, assign the camera with that state. diff --git a/build.rs b/build.rs index ebde081..38403d6 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,6 @@ fn main() { #[cfg(target_os = "windows")] println!("cargo:rustc-link-search=lib/windows"); - #[cfg(feature = "fmod")] { println!("cargo:rustc-link-lib=fmod"); println!("cargo:rustc-link-lib=fmodstudio"); diff --git a/src/audio.rs b/src/audio.rs index 84a2216..09bc86e 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -11,7 +11,6 @@ impl Plugin for AudioPlugin { fn build(&self, app: &mut App) { app.add_event::(); - #[cfg(feature = "fmod")] app.add_plugins(FmodPlugin { audio_banks_paths: &[ "./assets/audio/Martian Chess Audio/Build/Desktop/Master.bank", diff --git a/src/credits.rs b/src/credits.rs index 7b410d2..7573ffb 100644 --- a/src/credits.rs +++ b/src/credits.rs @@ -82,6 +82,7 @@ fn init_credits_ui(mut commands: Commands, server: Res) { ..default() }, UiCameraConfig { show_ui: true }, + Name::new("Credits Camera"), )); commands diff --git a/src/debug.rs b/src/debug.rs index 7e3fbde..e55fd83 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -31,6 +31,7 @@ impl Plugin for DebugPlugin { toggle_debug_mode.run_if(on_event::()), display_diagnostics.run_if(resource_exists::()), toggle_debug_ui.run_if(resource_changed_or_removed::()), + camera_info.run_if(resource_exists::()), ), ); } @@ -130,3 +131,18 @@ fn display_diagnostics( text.sections.sort_unstable_by(|a, b| a.value.cmp(&b.value)); }); } + +fn camera_info( + mut debug_infos: ResMut, + cameras: Query<(&Camera, &Name)>, +) { + let camera_names = cameras.iter() + .filter(|(c, _)| c.is_active) + .map(|(_, n)| n.as_str()) + .collect::>() + .iter() + .copied() + .intersperse(", ") + .collect::(); + debug_infos.set("Cameras".into(), camera_names); +} diff --git a/src/display2d.rs b/src/display2d.rs index 697dc32..7cffe85 100644 --- a/src/display2d.rs +++ b/src/display2d.rs @@ -69,6 +69,7 @@ fn initialize_camera(mut commands: Commands) { ..default() }, UiCameraConfig { show_ui: true }, + Name::new("2D Camera"), )); } diff --git a/src/display3d.rs b/src/display3d.rs index 0480f16..760f3b1 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -57,10 +57,7 @@ impl Plugin for Display3dPlugin { .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)), ) - .add_systems( - OnEnter(DisplayState::Display3d), - (activate::, set_piece_texture), - ) + .add_systems(OnEnter(DisplayState::Display3d), activate::) .add_systems(OnExit(DisplayState::Display3d), deactivate::); } } @@ -198,6 +195,7 @@ fn hydrate_camera( falloff: FogFalloff::from_visibility_colors(100.0, Color::NONE, Color::NONE), ..default() }, + Name::new("3D Camera"), )); }); } diff --git a/src/loading.rs b/src/loading.rs index 6eb13ee..83d89f9 100644 --- a/src/loading.rs +++ b/src/loading.rs @@ -5,6 +5,7 @@ pub(crate) struct LoadingPlugin; impl Plugin for LoadingPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, initialize) + .add_systems(PostUpdate, deactivate_cameras.run_if(any_component_added::)) .add_systems(OnEnter(GameState::Loading), activate::) .add_systems(OnExit(GameState::Loading), deactivate::); } @@ -24,6 +25,7 @@ fn initialize(mut commands: Commands) { ..default() }, UiCameraConfig { show_ui: true }, + Name::new("Loading Camera"), )); commands @@ -60,3 +62,11 @@ fn initialize(mut commands: Commands) { },)); }); } + +fn deactivate_cameras( + mut events: Query<&mut Camera, (Added, Without)> +) { + events.iter_mut().for_each(|mut camera| { + camera.is_active = false; + }); +} diff --git a/src/main.rs b/src/main.rs index c7d4507..31b3c4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![feature(iter_array_chunks)] // used in ray.rs +#![feature(iter_intersperse)] // used in debug.rs mod audio; mod credits; diff --git a/src/menu.rs b/src/menu.rs index 53b9b8f..8bde1c6 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -33,6 +33,18 @@ struct Menu; struct Quit; fn init_menu_ui(mut commands: Commands) { + commands.spawn(( + Menu, + Camera2dBundle { + camera: Camera { + is_active: false, + ..default() + }, + ..default() + }, + UiCameraConfig { show_ui: true }, + Name::new("Menu Camera"), + )); commands .spawn(( Menu,