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.
bevy0.12
Elijah Voigt 2 years ago
parent 1d17937b4a
commit c7692d36c1

@ -1,5 +1,5 @@
[target.x86_64-unknown-linux-gnu] [target.x86_64-unknown-linux-gnu]
rustflags = ["-Zshare-generics=y"] rustflags = ["-Zshare-generics=y", "-Z", "threads=8"]
# [target.x86_64-apple-darwin] # [target.x86_64-apple-darwin]
# rustflags = [ # rustflags = [

@ -8,8 +8,5 @@ build = "build.rs"
bevy_fmod = { version = "0.3", features = ["live-update"] } bevy_fmod = { version = "0.3", features = ["live-update"] }
bevy = { version = "0.11", features = ["jpeg", "hdr"] } bevy = { version = "0.11", features = ["jpeg", "hdr"] }
[features]
fmod = []
[profile.dev] [profile.dev]
opt-level = 3 opt-level = 3

10
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.

@ -5,7 +5,6 @@ fn main() {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
println!("cargo:rustc-link-search=lib/windows"); println!("cargo:rustc-link-search=lib/windows");
#[cfg(feature = "fmod")]
{ {
println!("cargo:rustc-link-lib=fmod"); println!("cargo:rustc-link-lib=fmod");
println!("cargo:rustc-link-lib=fmodstudio"); println!("cargo:rustc-link-lib=fmodstudio");

@ -11,7 +11,6 @@ impl Plugin for AudioPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<AudioEvent>(); app.add_event::<AudioEvent>();
#[cfg(feature = "fmod")]
app.add_plugins(FmodPlugin { app.add_plugins(FmodPlugin {
audio_banks_paths: &[ audio_banks_paths: &[
"./assets/audio/Martian Chess Audio/Build/Desktop/Master.bank", "./assets/audio/Martian Chess Audio/Build/Desktop/Master.bank",

@ -82,6 +82,7 @@ fn init_credits_ui(mut commands: Commands, server: Res<AssetServer>) {
..default() ..default()
}, },
UiCameraConfig { show_ui: true }, UiCameraConfig { show_ui: true },
Name::new("Credits Camera"),
)); ));
commands commands

@ -31,6 +31,7 @@ impl Plugin for DebugPlugin {
toggle_debug_mode.run_if(on_event::<KeyboardInput>()), toggle_debug_mode.run_if(on_event::<KeyboardInput>()),
display_diagnostics.run_if(resource_exists::<DebugEnabled>()), display_diagnostics.run_if(resource_exists::<DebugEnabled>()),
toggle_debug_ui.run_if(resource_changed_or_removed::<DebugEnabled>()), toggle_debug_ui.run_if(resource_changed_or_removed::<DebugEnabled>()),
camera_info.run_if(resource_exists::<DebugEnabled>()),
), ),
); );
} }
@ -130,3 +131,18 @@ fn display_diagnostics(
text.sections.sort_unstable_by(|a, b| a.value.cmp(&b.value)); text.sections.sort_unstable_by(|a, b| a.value.cmp(&b.value));
}); });
} }
fn camera_info(
mut debug_infos: ResMut<DebugInfo>,
cameras: Query<(&Camera, &Name)>,
) {
let camera_names = cameras.iter()
.filter(|(c, _)| c.is_active)
.map(|(_, n)| n.as_str())
.collect::<Vec<&str>>()
.iter()
.copied()
.intersperse(", ")
.collect::<String>();
debug_infos.set("Cameras".into(), camera_names);
}

@ -69,6 +69,7 @@ fn initialize_camera(mut commands: Commands) {
..default() ..default()
}, },
UiCameraConfig { show_ui: true }, UiCameraConfig { show_ui: true },
Name::new("2D Camera"),
)); ));
} }

@ -57,10 +57,7 @@ impl Plugin for Display3dPlugin {
.run_if(in_state(GameState::Play)) .run_if(in_state(GameState::Play))
.run_if(in_state(DisplayState::Display3d)), .run_if(in_state(DisplayState::Display3d)),
) )
.add_systems( .add_systems(OnEnter(DisplayState::Display3d), activate::<Display3d>)
OnEnter(DisplayState::Display3d),
(activate::<Display3d>, set_piece_texture),
)
.add_systems(OnExit(DisplayState::Display3d), deactivate::<Display3d>); .add_systems(OnExit(DisplayState::Display3d), deactivate::<Display3d>);
} }
} }
@ -198,6 +195,7 @@ fn hydrate_camera(
falloff: FogFalloff::from_visibility_colors(100.0, Color::NONE, Color::NONE), falloff: FogFalloff::from_visibility_colors(100.0, Color::NONE, Color::NONE),
..default() ..default()
}, },
Name::new("3D Camera"),
)); ));
}); });
} }

@ -5,6 +5,7 @@ pub(crate) struct LoadingPlugin;
impl Plugin for LoadingPlugin { impl Plugin for LoadingPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, initialize) app.add_systems(Startup, initialize)
.add_systems(PostUpdate, deactivate_cameras.run_if(any_component_added::<Camera>))
.add_systems(OnEnter(GameState::Loading), activate::<Loading>) .add_systems(OnEnter(GameState::Loading), activate::<Loading>)
.add_systems(OnExit(GameState::Loading), deactivate::<Loading>); .add_systems(OnExit(GameState::Loading), deactivate::<Loading>);
} }
@ -24,6 +25,7 @@ fn initialize(mut commands: Commands) {
..default() ..default()
}, },
UiCameraConfig { show_ui: true }, UiCameraConfig { show_ui: true },
Name::new("Loading Camera"),
)); ));
commands commands
@ -60,3 +62,11 @@ fn initialize(mut commands: Commands) {
},)); },));
}); });
} }
fn deactivate_cameras(
mut events: Query<&mut Camera, (Added<Camera>, Without<Loading>)>
) {
events.iter_mut().for_each(|mut camera| {
camera.is_active = false;
});
}

@ -1,4 +1,5 @@
#![feature(iter_array_chunks)] // used in ray.rs #![feature(iter_array_chunks)] // used in ray.rs
#![feature(iter_intersperse)] // used in debug.rs
mod audio; mod audio;
mod credits; mod credits;

@ -33,6 +33,18 @@ struct Menu;
struct Quit; struct Quit;
fn init_menu_ui(mut commands: Commands) { 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 commands
.spawn(( .spawn((
Menu, Menu,

Loading…
Cancel
Save