diff --git a/Cargo.lock b/Cargo.lock index 0dd5e22..535f0d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,6 +390,17 @@ dependencies = [ "glam", ] +[[package]] +name = "bevy_mod_debugdump" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5951114fabf7153eaa8050b3072f41ea2867202beadd42f1be13c94d918b3025" +dependencies = [ + "bevy", + "itertools", + "pretty-type-name", +] + [[package]] name = "bevy_pbr" version = "0.6.0" @@ -980,6 +991,7 @@ name = "cyber_rider" version = "0.1.0" dependencies = [ "bevy", + "bevy_mod_debugdump", "heron", ] @@ -1506,6 +1518,15 @@ dependencies = [ "mach", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.1" @@ -2059,6 +2080,12 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "pretty-type-name" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" + [[package]] name = "proc-macro-crate" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index f9b2470..065d5c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "cyber_rider" version = "0.1.0" edition = "2021" +[dependencies] +bevy_mod_debugdump = "0.3.0" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies.bevy] @@ -28,10 +31,10 @@ heron = { path = "../heron/" } [patch."https://github.com/bevyengine/bevy"] bevy = { path = "../bevy/" } -# Enable optimizations for dependencies (incl. Bevy), but not for our code: -[profile.dev.package."*"] -opt-level = 3 - # Maybe also enable only a small amount of optimization for our code: [profile.dev] opt-level = 1 + +# Enable optimizations for dependencies (incl. Bevy), but not for our code: +[profile.dev.package."*"] +opt-level = 3 diff --git a/src/camera.rs b/src/camera.rs index 677df1c..35b7303 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -24,8 +24,8 @@ fn follow_cyberbike( let bike_xform = bike_query.single(); let up = bike_xform.translation.normalize(); - let look_at = bike_xform.translation + (bike_xform.forward() * CAM_DIST); - let cam_pos = bike_xform.translation + (bike_xform.back() * CAM_DIST * 1.5) + (up * CAM_DIST); + let look_at = bike_xform.translation + (bike_xform.forward() * 200.0); + let cam_pos = bike_xform.translation + (bike_xform.back() * 2.7) + (up * 2.4); let mut cam_xform = cam_query.single_mut(); cam_xform.translation = cam_pos; diff --git a/src/geometry.rs b/src/geometry.rs index ceb334d..3ecf1e8 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,6 +1,8 @@ use bevy::prelude::*; use heron::prelude::{CollisionShape, RigidBody}; +use crate::Label; + pub const PLANET_RADIUS: f32 = 350.0; pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0; @@ -63,7 +65,7 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { pub struct CyberGeomPlugin; impl Plugin for CyberGeomPlugin { fn build(&self, app: &mut App) { - app.add_startup_system(spawn_giant_sphere) - .add_startup_system(spawn_cyberbike); + app.add_startup_system(spawn_giant_sphere.label(Label::Geometry)) + .add_startup_system(spawn_cyberbike.label(Label::Geometry)); } } diff --git a/src/glamor.rs b/src/glamor.rs new file mode 100644 index 0000000..a25d301 --- /dev/null +++ b/src/glamor.rs @@ -0,0 +1,30 @@ +use bevy::{ + pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin}, + prelude::*, + render::{options::WgpuOptions, render_resource::WgpuFeatures}, +}; + +use crate::geometry::CyberSphere; + +fn wireframe( + mut commands: Commands, + mut wireframe_config: ResMut, + query: Query>, +) { + let ent = query.single(); + wireframe_config.global = false; + commands.entity(ent).insert(Wireframe); +} + +// public plugin +pub struct CyberGlamorPlugin; +impl Plugin for CyberGlamorPlugin { + fn build(&self, app: &mut App) { + app.insert_resource(WgpuOptions { + features: WgpuFeatures::POLYGON_MODE_LINE, + ..Default::default() + }) + .add_startup_system_to_stage(StartupStage::PostStartup, wireframe) + .add_plugin(WireframePlugin); + } +} diff --git a/src/lib.rs b/src/lib.rs index de2f910..152a84e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,24 @@ -use bevy::prelude::{ResMut, Windows}; +use bevy::{ + ecs::schedule::StageLabel, + prelude::{ResMut, SystemLabel, Windows}, +}; +pub mod action; pub mod camera; pub mod geometry; +pub mod glamor; pub mod input; pub mod lights; -pub mod action; pub mod ui; +#[derive(Clone, Debug, Hash, PartialEq, Eq, SystemLabel, StageLabel)] +pub enum Label { + Geometry, + Glamor, + Input, + Action, +} + pub fn disable_mouse_trap(mut windows: ResMut) { let window = windows.get_primary_mut().unwrap(); window.set_cursor_lock_mode(false); diff --git a/src/main.rs b/src/main.rs index 385147f..5f0e67a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use cyber_rider::{ camera::CyberCamPlugin, disable_mouse_trap, geometry::CyberGeomPlugin, + glamor::CyberGlamorPlugin, input::CyberInputPlugin, lights::CyberSpaceLightsPlugin, ui::CyberUIPlugin, @@ -17,10 +18,11 @@ const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { }; fn main() { - App::new() - .insert_resource(Msaa { samples: 4 }) + let mut app = App::new(); + app.insert_resource(Msaa { samples: 4 }) .add_plugins(DefaultPlugins) .add_plugin(CyberGeomPlugin) + .add_plugin(CyberGlamorPlugin) .add_plugin(CyberInputPlugin) .add_plugin(CyberPhysicsPlugin) .insert_resource(MOVEMENT_SETTINGS) @@ -28,6 +30,9 @@ fn main() { .add_plugin(CyberSpaceLightsPlugin) .add_plugin(CyberUIPlugin) .add_startup_system(disable_mouse_trap) - .add_system(bevy::input::system::exit_on_esc_system) - .run(); + .add_system(bevy::input::system::exit_on_esc_system); + + //bevy_mod_debugdump::print_schedule(&mut app); + + app.run(); } diff --git a/src/ui.rs b/src/ui.rs index cb6fbd5..e0e301e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -use crate::{action::CyberBikeState, geometry::PLANET_RADIUS}; +use crate::action::CyberBikeState; #[derive(Component)] struct UpText; @@ -32,17 +32,10 @@ fn setup_ui(mut commands: Commands, asset_server: Res) { .insert(UpText); } -fn update_ui( - state_query: Query<(&CyberBikeState, &Transform)>, - mut text_query: Query<&mut Text, With>, -) { +fn update_ui(state_query: Query<&CyberBikeState>, mut text_query: Query<&mut Text, With>) { let mut text = text_query.single_mut(); let state = state_query.single(); - text.sections[0].value = format!( - "spd: {:.2}\nalt: {:.2}", - state.0.velocity.length(), - state.1.translation.length() - PLANET_RADIUS - ); + text.sections[0].value = format!("spd: {:.2}", state.velocity.length(),); } pub struct CyberUIPlugin;