diff --git a/src/camera/camera_replace_proxies.rs b/src/core/camera/camera_replace_proxies.rs similarity index 84% rename from src/camera/camera_replace_proxies.rs rename to src/core/camera/camera_replace_proxies.rs index 8469b69..9bd5859 100644 --- a/src/camera/camera_replace_proxies.rs +++ b/src/core/camera/camera_replace_proxies.rs @@ -3,11 +3,11 @@ use bevy::prelude::*; use bevy::core_pipeline::bloom::{BloomSettings, BloomCompositeMode}; use bevy::core_pipeline::tonemapping::{Tonemapping, DebandDither}; -use super::CameraTracking; +use super::CameraTrackingOffset; pub fn camera_replace_proxies ( mut commands: Commands, - mut added_cameras: Query<(Entity, &mut Camera), (Added, With)>, + mut added_cameras: Query<(Entity, &mut Camera), (Added, With)>, ) { for (entity, mut camera) in added_cameras.iter_mut(){ @@ -18,11 +18,11 @@ pub fn camera_replace_proxies ( DebandDither::Enabled ) .insert( - Tonemapping::None + Tonemapping::BlenderFilmic ) .insert( BloomSettings{ - intensity: 0.08, + intensity: 0.01, composite_mode:BloomCompositeMode::Additive, ..default() } diff --git a/src/camera/camera_tracking.rs b/src/core/camera/camera_tracking.rs similarity index 98% rename from src/camera/camera_tracking.rs rename to src/core/camera/camera_tracking.rs index 19d21e4..ec3a45f 100644 --- a/src/camera/camera_tracking.rs +++ b/src/core/camera/camera_tracking.rs @@ -27,7 +27,6 @@ impl Default for CameraTrackingOffset { impl CameraTrackingOffset { fn new (input: Vec3) -> Self { - println!("NEEEW"); CameraTrackingOffset(input) } } diff --git a/src/camera/mod.rs b/src/core/camera/mod.rs similarity index 100% rename from src/camera/mod.rs rename to src/core/camera/mod.rs diff --git a/src/lighting/lighting_replace_proxies.rs b/src/core/lighting/lighting_replace_proxies.rs similarity index 100% rename from src/lighting/lighting_replace_proxies.rs rename to src/core/lighting/lighting_replace_proxies.rs diff --git a/src/lighting/mod.rs b/src/core/lighting/mod.rs similarity index 100% rename from src/lighting/mod.rs rename to src/core/lighting/mod.rs diff --git a/src/core/mod.rs b/src/core/mod.rs new file mode 100644 index 0000000..b816c25 --- /dev/null +++ b/src/core/mod.rs @@ -0,0 +1,28 @@ +pub mod process_gltf; +pub use process_gltf::*; + +pub mod camera; +pub use camera::*; + +pub mod lighting; +pub use lighting::*; + +pub mod relationships; +pub use relationships::*; + +pub mod physics; +pub use physics::*; + +use bevy::prelude::*; +pub struct CorePlugin; +impl Plugin for CorePlugin { + fn build(&self, app: &mut App) { + app + .add_plugins(( + ProcessGltfPlugin, + LightingPlugin, + CameraPlugin, + PhysicsPlugin + )); + } +} diff --git a/src/physics/controls.rs b/src/core/physics/controls.rs similarity index 100% rename from src/physics/controls.rs rename to src/core/physics/controls.rs diff --git a/src/physics/mod.rs b/src/core/physics/mod.rs similarity index 97% rename from src/physics/mod.rs rename to src/core/physics/mod.rs index 8adf7cf..2e20eab 100644 --- a/src/physics/mod.rs +++ b/src/core/physics/mod.rs @@ -9,7 +9,7 @@ pub use controls::*; use bevy::prelude::*; // use crate::state::{GameState}; -use super::Collider; +use crate::Collider; pub struct PhysicsPlugin; impl Plugin for PhysicsPlugin { fn build(&self, app: &mut App) { diff --git a/src/physics/physics_replace_proxies.rs b/src/core/physics/physics_replace_proxies.rs similarity index 100% rename from src/physics/physics_replace_proxies.rs rename to src/core/physics/physics_replace_proxies.rs diff --git a/src/physics/utils.rs b/src/core/physics/utils.rs similarity index 100% rename from src/physics/utils.rs rename to src/core/physics/utils.rs diff --git a/src/physics/utils_old.rs b/src/core/physics/utils_old.rs similarity index 100% rename from src/physics/utils_old.rs rename to src/core/physics/utils_old.rs diff --git a/src/process_gltf/gltf_to_components.rs b/src/core/process_gltf/gltf_to_components.rs similarity index 100% rename from src/process_gltf/gltf_to_components.rs rename to src/core/process_gltf/gltf_to_components.rs diff --git a/src/process_gltf/mod.rs b/src/core/process_gltf/mod.rs similarity index 100% rename from src/process_gltf/mod.rs rename to src/core/process_gltf/mod.rs diff --git a/src/process_gltf/process_gltfs.rs b/src/core/process_gltf/process_gltfs.rs similarity index 100% rename from src/process_gltf/process_gltfs.rs rename to src/core/process_gltf/process_gltfs.rs diff --git a/src/process_gltf/utils.rs b/src/core/process_gltf/utils.rs similarity index 100% rename from src/process_gltf/utils.rs rename to src/core/process_gltf/utils.rs diff --git a/src/relationships/mod.rs b/src/core/relationships/mod.rs similarity index 100% rename from src/relationships/mod.rs rename to src/core/relationships/mod.rs diff --git a/src/relationships/relationships_insert_dependant_components.rs b/src/core/relationships/relationships_insert_dependant_components.rs similarity index 100% rename from src/relationships/relationships_insert_dependant_components.rs rename to src/core/relationships/relationships_insert_dependant_components.rs diff --git a/src/game.rs b/src/game.rs new file mode 100644 index 0000000..032b2c1 --- /dev/null +++ b/src/game.rs @@ -0,0 +1,103 @@ +use bevy::prelude::*; +use bevy_rapier3d::prelude::*; +use crate::insert_dependant_component; + +// this file is just for demo purposes, contains various types of components, systems etc + +#[derive(Component, Reflect, Default, Debug, )] +#[reflect(Component)] +pub enum SoundMaterial{ + Metal, + Wood, + Rock, + Cloth, + Squishy, + #[default] + None +} + + +#[derive(Component, Reflect, Default, Debug, )] +#[reflect(Component)] +/// Demo marker component +pub struct Player; + +#[derive(Component, Reflect, Default, Debug, )] +#[reflect(Component)] +/// Demo component showing auto injection of components +pub struct ShouldBeWithPlayer; + + +#[derive(Component, Reflect, Default, Debug, )] +#[reflect(Component)] +/// Demo marker component +pub struct Interactible; + + +fn player_move_demo( + keycode: Res>, + mut players: Query<&mut Transform, With>, +){ + + let speed = 0.2; + if let Ok(mut player) = players.get_single_mut() { + if keycode.pressed(KeyCode::Left) { + player.translation.x += speed; + } + if keycode.pressed(KeyCode::Right) { + player.translation.x -= speed; + } + + if keycode.pressed(KeyCode::Up) { + player.translation.z += speed; + } + if keycode.pressed(KeyCode::Down) { + player.translation.z -= speed; + } + } +} + +// collision tests/debug +pub fn test_collision_events( + mut collision_events: EventReader, + mut contact_force_events: EventReader, +) +{ + + for collision_event in collision_events.iter() { + println!("collision"); + match collision_event { + CollisionEvent::Started(entity1, entity2 ,_) => { + println!("collision started") + } + CollisionEvent::Stopped(entity1, entity2 ,_) => { + println!("collision ended") + + } + } + } + + for contact_force_event in contact_force_events.iter() { + println!("Received contact force event: {:?}", contact_force_event); + } +} + + +pub struct DemoPlugin; +impl Plugin for DemoPlugin { + fn build(&self, app: &mut App) { + app + .register_type::() + .register_type::() + .register_type::() + // little helper utility, to automatically inject components that are dependant on an other component + // ie, here an Entity with a Player component should also always have a ShouldBeWithPlayer component + // you get a warning if you use this, as I consider this to be stop-gap solution (usually you should have either a bundle, or directly define all needed components) + .add_systems(Update, ( + insert_dependant_component::, + player_move_demo, //.run_if(in_state(AppState::Running)), + test_collision_events + )) + ; + } +} diff --git a/src/main.rs b/src/main.rs index 618a395..f3a9c1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,51 +3,18 @@ use bevy::{prelude::*, asset::ChangeWatcher, gltf::Gltf}; use bevy_editor_pls::prelude::*; use bevy_rapier3d::prelude::*; -mod process_gltf; -use process_gltf::*; - -mod camera; -use camera::*; - -mod lighting; -use lighting::*; - -mod relationships; -use relationships::*; - -mod physics; -use physics::*; +mod core; +use crate::core::*; +mod game; +use crate::game::*; #[derive(Component, Reflect, Default, Debug, )] #[reflect(Component)] -/// Demo marker component -pub struct Player; - -#[derive(Component, Reflect, Default, Debug, )] -#[reflect(Component)] -/// Demo component showing auto injection of components -pub struct ShouldBeWithPlayer; - - - -#[derive(Component, Reflect, Default, Debug, )] -#[reflect(Component)] -/// Demo marker component +/// helper marker component pub struct LoadedMarker; -#[derive(Component, Reflect, Default, Debug, )] -#[reflect(Component)] -/// Demo marker component -pub struct Interactible; - -#[derive(Component, Reflect, Default, Debug, )] -#[reflect(Component)] -/// Demo marker component -pub struct MeshCollider; - - #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] enum AppState { #[default] @@ -57,22 +24,6 @@ enum AppState { -use bevy::{prelude::*}; - - -#[derive(Component, Reflect, Default, Debug, )] -#[reflect(Component)] -pub enum SoundMaterial{ - Metal, - Wood, - Rock, - Cloth, - Squishy, - #[default] - None -} - - fn main(){ App::new() .add_plugins(( @@ -91,30 +42,14 @@ fn main(){ RapierPhysicsPlugin::::default(), RapierDebugRenderPlugin::default(), // our custom plugins - ProcessGltfPlugin, - LightingPlugin, - CameraPlugin, - PhysicsPlugin + CorePlugin, // reusable plugins + DemoPlugin // specific to our game )) - .register_type::() - .register_type::() - .register_type::() - - - .register_type::() - // little helper utility, to automatically inject components that are dependant on an other component - // ie, here an Entity with a Player component should also always have a ShouldBeWithPlayer component - // you get a warning if you use this, as I consider this to be stop-gap solution (usually you should have either a bundle, or directly define all needed components) - .add_systems(Update, insert_dependant_component::) - - .add_state::() .add_systems(Startup, setup) .add_systems(Update, ( spawn_level.run_if(in_state(AppState::Loading)), - player_move_demo.run_if(in_state(AppState::Running)), - test_collision_events )) .run(); } @@ -171,53 +106,3 @@ fn spawn_level( } - - -fn player_move_demo( - keycode: Res>, - mut players: Query<&mut Transform, With>, -){ - - let speed = 0.2; - if let Ok(mut player) = players.get_single_mut() { - if keycode.pressed(KeyCode::Left) { - player.translation.x += speed; - } - if keycode.pressed(KeyCode::Right) { - player.translation.x -= speed; - } - - if keycode.pressed(KeyCode::Up) { - player.translation.z += speed; - } - if keycode.pressed(KeyCode::Down) { - player.translation.z -= speed; - } - } -} - - -// collision tests -pub fn test_collision_events( - mut collision_events: EventReader, - mut contact_force_events: EventReader, -) -{ - - for collision_event in collision_events.iter() { - println!("collision"); - match collision_event { - CollisionEvent::Started(entity1, entity2 ,_) => { - println!("collision started") - } - CollisionEvent::Stopped(entity1, entity2 ,_) => { - println!("collision ended") - - } - } - } - - for contact_force_event in contact_force_events.iter() { - println!("Received contact force event: {:?}", contact_force_event); - } -} \ No newline at end of file