remove unused code, cleanup some warnings

This commit is contained in:
SeanOMik 2024-10-09 10:56:54 -04:00
parent 77ec620adb
commit eff6b221e0
Signed by: SeanOMik
GPG Key ID: FEC9E2FC15235964
5 changed files with 117 additions and 122 deletions

View File

@ -196,7 +196,7 @@ fn setup_scene_plugin(app: &mut App) {
fn camera_debug_plugin(app: &mut App) { fn camera_debug_plugin(app: &mut App) {
let sys = |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> { let sys = |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> {
if handler.was_action_just_pressed("Debug") { if let Some(true) = handler.was_action_just_pressed("Debug") {
for mut cam in view.into_iter() { for mut cam in view.into_iter() {
cam.debug = !cam.debug; cam.debug = !cam.debug;
} }

View File

@ -1,12 +1,12 @@
use lyra_engine::{ use lyra_engine::{
assets::{gltf::Gltf, ResourceManager}, ecs::query::View, game::App, input::{ assets::{gltf::Gltf, ResourceManager}, ecs::query::View, game::App, input::{
Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource, Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource,
InputActionPlugin, KeyCode, LayoutId, MouseAxis, MouseInput, InputActionPlugin, KeyCode, LayoutId,
}, math::{self, Transform, Vec3}, render::{light::directional::DirectionalLight, window::WindowOptions}, scene::{ }, math::{self, Transform, Vec3}, render::light::directional::DirectionalLight, scene::{
CameraComponent, FreeFlyCamera, FreeFlyCameraPlugin, WorldTransform, CameraComponent, FreeFlyCamera, FreeFlyCameraPlugin, WorldTransform,
ACTLBL_LOOK_LEFT_RIGHT, ACTLBL_LOOK_ROLL, ACTLBL_LOOK_UP_DOWN, ACTLBL_LOOK_LEFT_RIGHT, ACTLBL_LOOK_ROLL, ACTLBL_LOOK_UP_DOWN,
ACTLBL_MOVE_FORWARD_BACKWARD, ACTLBL_MOVE_LEFT_RIGHT, ACTLBL_MOVE_UP_DOWN, ACTLBL_MOVE_FORWARD_BACKWARD, ACTLBL_MOVE_LEFT_RIGHT, ACTLBL_MOVE_UP_DOWN,
} }, winit::WindowOptions
}; };
#[async_std::main] #[async_std::main]
@ -82,7 +82,6 @@ async fn main() {
let mut a = App::new(); let mut a = App::new();
a.with_plugin(lyra_engine::DefaultPlugins) a.with_plugin(lyra_engine::DefaultPlugins)
.with_system("mouse_pos_print", mouse_pos_system, &[])
.with_plugin(setup_scene_plugin) .with_plugin(setup_scene_plugin)
.with_plugin(action_handler_plugin) .with_plugin(action_handler_plugin)
//.with_plugin(camera_debug_plugin) //.with_plugin(camera_debug_plugin)
@ -141,11 +140,3 @@ fn setup_scene_plugin(app: &mut App) {
camera.transform.translation += math::Vec3::new(0.0, 0.0, 5.5); camera.transform.translation += math::Vec3::new(0.0, 0.0, 5.5);
world.spawn((camera, FreeFlyCamera::default())); world.spawn((camera, FreeFlyCamera::default()));
} }
fn mouse_pos_system(view: View<&WindowOptions>) -> anyhow::Result<()> {
for win in view.iter() {
//println!("Mouse pos: {:?}", win.cursor_position());
}
Ok(())
}

View File

@ -1,7 +1,27 @@
use std::ptr::NonNull; use std::ptr::NonNull;
use lyra_engine::{assets::gltf::Gltf, ecs::{query::{Res, View}, system::{Criteria, CriteriaSchedule, IntoSystem}, Component, World}, game::App, input::{Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource, InputActionPlugin, KeyCode, LayoutId, MouseAxis, MouseInput}, math::{self, Quat, Transform, Vec3}, render::{light::{directional::DirectionalLight, PointLight, SpotLight}, window::{CursorGrabMode, WindowOptions}}, scene::{self, CameraComponent, FreeFlyCamera, FreeFlyCameraPlugin, WorldTransform, ACTLBL_LOOK_LEFT_RIGHT, ACTLBL_LOOK_ROLL, ACTLBL_LOOK_UP_DOWN, ACTLBL_MOVE_FORWARD_BACKWARD, ACTLBL_MOVE_LEFT_RIGHT, ACTLBL_MOVE_UP_DOWN}, DeltaTime};
use lyra_engine::assets::ResourceManager; use lyra_engine::assets::ResourceManager;
use lyra_engine::{
assets::gltf::Gltf,
ecs::{
query::{Res, View},
system::{Criteria, CriteriaSchedule, IntoSystem},
Component, World,
},
game::App,
input::{
Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource,
InputActionPlugin, KeyCode, LayoutId, MouseAxis, MouseInput,
},
math::{self, Quat, Transform, Vec3},
render::light::{directional::DirectionalLight, PointLight, SpotLight},
scene::{
self, CameraComponent, FreeFlyCamera, FreeFlyCameraPlugin, WorldTransform,
ACTLBL_LOOK_LEFT_RIGHT, ACTLBL_LOOK_ROLL, ACTLBL_LOOK_UP_DOWN,
ACTLBL_MOVE_FORWARD_BACKWARD, ACTLBL_MOVE_LEFT_RIGHT, ACTLBL_MOVE_UP_DOWN,
},
DeltaTime,
};
struct FixedTimestep { struct FixedTimestep {
max_tps: u32, max_tps: u32,
@ -54,7 +74,7 @@ impl Criteria for FixedTimestep {
CriteriaSchedule::No CriteriaSchedule::No
} }
fn modify_world(&mut self, mut world: NonNull<World>) { fn modify_world(&mut self, mut world: NonNull<World>) {
let world = unsafe { world.as_mut() }; let world = unsafe { world.as_mut() };
self.old_dt = world.get_resource().map(|r| *r); self.old_dt = world.get_resource().map(|r| *r);
@ -71,9 +91,11 @@ impl Criteria for FixedTimestep {
} }
} }
#[allow(dead_code)]
#[derive(Clone)] #[derive(Clone)]
struct TpsAccumulator(f32); struct TpsAccumulator(f32);
#[allow(dead_code)]
#[derive(Component)] #[derive(Component)]
struct CubeFlag; struct CubeFlag;
@ -90,27 +112,29 @@ async fn main() {
//let diffuse_texture = resman.request::<Texture>("assets/happy-tree.png").unwrap(); //let diffuse_texture = resman.request::<Texture>("assets/happy-tree.png").unwrap();
//let antique_camera_model = resman.request::<Model>("assets/AntiqueCamera.glb").unwrap(); //let antique_camera_model = resman.request::<Model>("assets/AntiqueCamera.glb").unwrap();
//let cube_model = resman.request::<Model>("assets/cube-texture-bin.glb").unwrap(); //let cube_model = resman.request::<Model>("assets/cube-texture-bin.glb").unwrap();
let cube_gltf = resman.request::<Gltf>("../assets/texture-sep/texture-sep.gltf").unwrap(); let cube_gltf = resman
.request::<Gltf>("../assets/texture-sep/texture-sep.gltf")
.unwrap();
/*let crate_gltf = resman.request::<Gltf>("assets/crate/crate.gltf").unwrap(); /*let crate_gltf = resman.request::<Gltf>("assets/crate/crate.gltf").unwrap();
let separate_gltf = resman.request::<Gltf>("assets/pos-testing/child-node-cubes.glb").unwrap(); */ let separate_gltf = resman.request::<Gltf>("assets/pos-testing/child-node-cubes.glb").unwrap(); */
//drop(resman); //drop(resman);
cube_gltf.wait_recurse_dependencies_load(); cube_gltf.wait_recurse_dependencies_load();
let cube_mesh = &cube_gltf.data_ref() let cube_mesh = &cube_gltf.data_ref().unwrap().meshes[0];
.unwrap().meshes[0];
/* let crate_mesh = &crate_gltf.data_ref() /* let crate_mesh = &crate_gltf.data_ref()
.unwrap().meshes[0]; .unwrap().meshes[0];
let separate_scene = &separate_gltf.data_ref() let separate_scene = &separate_gltf.data_ref()
.unwrap().scenes[0]; */ .unwrap().scenes[0]; */
let sponza_model = resman.request::<Gltf>("../assets/sponza/Sponza.gltf").unwrap(); let sponza_model = resman
.request::<Gltf>("../assets/sponza/Sponza.gltf")
.unwrap();
drop(resman); drop(resman);
sponza_model.wait_recurse_dependencies_load(); sponza_model.wait_recurse_dependencies_load();
let sponza_scene = &sponza_model.data_ref() let sponza_scene = &sponza_model.data_ref().unwrap().scenes[0];
.unwrap().scenes[0];
world.spawn(( world.spawn((
sponza_scene.clone(), sponza_scene.clone(),
@ -127,8 +151,7 @@ async fn main() {
DirectionalLight { DirectionalLight {
enabled: true, enabled: true,
color: Vec3::ONE, color: Vec3::ONE,
intensity: 0.35 intensity: 0.35, //..Default::default()
//..Default::default()
}, },
light_tran, light_tran,
)); ));
@ -136,10 +159,9 @@ async fn main() {
{ {
let t = Transform::new( let t = Transform::new(
//Vec3::new(-5.0, 1.0, -1.28), //Vec3::new(-5.0, 1.0, -1.28),
Vec3::new(-5.0, 1.0, -0.0), Vec3::new(-5.0, 1.0, -0.0),
//Vec3::new(-10.0, 0.94, -0.28), //Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY, Quat::IDENTITY,
Vec3::new(0.25, 0.25, 0.25), Vec3::new(0.25, 0.25, 0.25),
); );
@ -160,8 +182,7 @@ async fn main() {
let t = Transform::new( let t = Transform::new(
Vec3::new(-3.0, 0.2, -1.5), Vec3::new(-3.0, 0.2, -1.5),
//Vec3::new(-5.0, 1.0, -0.28), //Vec3::new(-5.0, 1.0, -0.28),
//Vec3::new(-10.0, 0.94, -0.28), //Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY, Quat::IDENTITY,
Vec3::new(0.15, 0.15, 0.15), Vec3::new(0.15, 0.15, 0.15),
); );
@ -182,8 +203,7 @@ async fn main() {
let t = Transform::new( let t = Transform::new(
Vec3::new(0.0, 0.2, -1.5), Vec3::new(0.0, 0.2, -1.5),
//Vec3::new(-5.0, 1.0, -0.28), //Vec3::new(-5.0, 1.0, -0.28),
//Vec3::new(-10.0, 0.94, -0.28), //Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY, Quat::IDENTITY,
Vec3::new(0.15, 0.15, 0.15), Vec3::new(0.15, 0.15, 0.15),
); );
@ -215,7 +235,7 @@ async fn main() {
constant: 1.0, constant: 1.0,
linear: 0.09, linear: 0.09,
quadratic: 0.032, quadratic: 0.032,
ambient: 0.2, ambient: 0.2,
diffuse: 1.0, diffuse: 1.0,
specular: 1.3, specular: 1.3,
@ -224,7 +244,7 @@ async fn main() {
cube_mesh.clone(), cube_mesh.clone(),
)); ));
} */ } */
/* { /* {
let mut light_tran = Transform::from_xyz(-5.0, 2.5, -9.5); let mut light_tran = Transform::from_xyz(-5.0, 2.5, -9.5);
light_tran.scale = Vec3::new(0.5, 0.5, 0.5); light_tran.scale = Vec3::new(0.5, 0.5, 0.5);
@ -237,7 +257,7 @@ async fn main() {
constant: 1.0, constant: 1.0,
linear: 0.045, linear: 0.045,
quadratic: 0.0075, quadratic: 0.0075,
ambient: 0.1, ambient: 0.1,
diffuse: 1.0, diffuse: 1.0,
specular: 1.3, specular: 1.3,
@ -250,35 +270,39 @@ async fn main() {
let mut camera = CameraComponent::new_3d(); let mut camera = CameraComponent::new_3d();
// these values were taken by manually positioning the camera in the scene. // these values were taken by manually positioning the camera in the scene.
camera.transform = Transform::new( camera.transform = Transform::new(
Vec3::new(-10.0, 0.94, -0.28), Vec3::new(-10.0, 0.94, -0.28),
Quat::from_xyzw(0.03375484, -0.7116095, 0.0342693, 0.70092666), Quat::from_xyzw(0.03375484, -0.7116095, 0.0342693, 0.70092666),
Vec3::ONE Vec3::ONE,
); );
//camera.transform.translation += math::Vec3::new(0.0, 0.0, 5.5); //camera.transform.translation += math::Vec3::new(0.0, 0.0, 5.5);
world.spawn(( camera, FreeFlyCamera::default() )); world.spawn((camera, FreeFlyCamera::default()));
Ok(()) Ok(())
}; };
let camera_debug_plugin = move |app: &mut App| { let camera_debug_plugin = move |app: &mut App| {
let sys = |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> { let sys =
if handler.was_action_just_pressed("Debug") { |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> {
for mut cam in view.into_iter() { if let Some(true) = handler.was_action_just_pressed("Debug") {
cam.debug = !cam.debug; for mut cam in view.into_iter() {
cam.debug = !cam.debug;
}
} }
}
Ok(()) Ok(())
}; };
app.with_system("camera_debug_trigger", sys, &[]); app.with_system("camera_debug_trigger", sys, &[]);
app.with_system("update_world_transforms", scene::system_update_world_transforms, &[]); app.with_system(
"update_world_transforms",
scene::system_update_world_transforms,
&[],
);
}; };
let action_handler_plugin = |app: &mut App| { let action_handler_plugin = |app: &mut App| {
let action_handler = ActionHandler::builder() let action_handler = ActionHandler::builder()
.add_layout(LayoutId::from(0)) .add_layout(LayoutId::from(0))
.add_action(ACTLBL_MOVE_FORWARD_BACKWARD, Action::new(ActionKind::Axis)) .add_action(ACTLBL_MOVE_FORWARD_BACKWARD, Action::new(ActionKind::Axis))
.add_action(ACTLBL_MOVE_LEFT_RIGHT, Action::new(ActionKind::Axis)) .add_action(ACTLBL_MOVE_LEFT_RIGHT, Action::new(ActionKind::Axis))
.add_action(ACTLBL_MOVE_UP_DOWN, Action::new(ActionKind::Axis)) .add_action(ACTLBL_MOVE_UP_DOWN, Action::new(ActionKind::Axis))
@ -286,41 +310,61 @@ async fn main() {
.add_action(ACTLBL_LOOK_UP_DOWN, Action::new(ActionKind::Axis)) .add_action(ACTLBL_LOOK_UP_DOWN, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_ROLL, Action::new(ActionKind::Axis)) .add_action(ACTLBL_LOOK_ROLL, Action::new(ActionKind::Axis))
.add_action("Debug", Action::new(ActionKind::Button)) .add_action("Debug", Action::new(ActionKind::Button))
.add_mapping(
.add_mapping(ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0)) ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0))
.bind(ACTLBL_MOVE_FORWARD_BACKWARD, &[ .bind(
ActionSource::Keyboard(KeyCode::KeyW).into_binding_modifier(1.0), ACTLBL_MOVE_FORWARD_BACKWARD,
ActionSource::Keyboard(KeyCode::KeyS).into_binding_modifier(-1.0) &[
]) ActionSource::Keyboard(KeyCode::KeyW).into_binding_modifier(1.0),
.bind(ACTLBL_MOVE_LEFT_RIGHT, &[ ActionSource::Keyboard(KeyCode::KeyS).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::KeyA).into_binding_modifier(-1.0), ],
ActionSource::Keyboard(KeyCode::KeyD).into_binding_modifier(1.0) )
]) .bind(
.bind(ACTLBL_MOVE_UP_DOWN, &[ ACTLBL_MOVE_LEFT_RIGHT,
ActionSource::Keyboard(KeyCode::KeyC).into_binding_modifier(1.0), &[
ActionSource::Keyboard(KeyCode::KeyZ).into_binding_modifier(-1.0) ActionSource::Keyboard(KeyCode::KeyA).into_binding_modifier(-1.0),
]) ActionSource::Keyboard(KeyCode::KeyD).into_binding_modifier(1.0),
.bind(ACTLBL_LOOK_LEFT_RIGHT, &[ ],
ActionSource::Mouse(MouseInput::Axis(MouseAxis::X)).into_binding(), )
ActionSource::Keyboard(KeyCode::ArrowLeft).into_binding_modifier(-1.0), .bind(
ActionSource::Keyboard(KeyCode::ArrowRight).into_binding_modifier(1.0), ACTLBL_MOVE_UP_DOWN,
//ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickX)).into_binding(), &[
]) ActionSource::Keyboard(KeyCode::KeyC).into_binding_modifier(1.0),
.bind(ACTLBL_LOOK_UP_DOWN, &[ ActionSource::Keyboard(KeyCode::KeyZ).into_binding_modifier(-1.0),
ActionSource::Mouse(MouseInput::Axis(MouseAxis::Y)).into_binding(), ],
ActionSource::Keyboard(KeyCode::ArrowUp).into_binding_modifier(-1.0), )
ActionSource::Keyboard(KeyCode::ArrowDown).into_binding_modifier(1.0), .bind(
//ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickY)).into_binding(), ACTLBL_LOOK_LEFT_RIGHT,
]) &[
.bind(ACTLBL_LOOK_ROLL, &[ ActionSource::Mouse(MouseInput::Axis(MouseAxis::X)).into_binding(),
ActionSource::Keyboard(KeyCode::KeyE).into_binding_modifier(-1.0), ActionSource::Keyboard(KeyCode::ArrowLeft).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::KeyQ).into_binding_modifier(1.0), ActionSource::Keyboard(KeyCode::ArrowRight).into_binding_modifier(1.0),
]) //ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickX)).into_binding(),
.bind("Debug", &[ ],
ActionSource::Keyboard(KeyCode::KeyB).into_binding(), )
]) .bind(
.finish() ACTLBL_LOOK_UP_DOWN,
).finish(); &[
ActionSource::Mouse(MouseInput::Axis(MouseAxis::Y)).into_binding(),
ActionSource::Keyboard(KeyCode::ArrowUp).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::ArrowDown).into_binding_modifier(1.0),
//ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickY)).into_binding(),
],
)
.bind(
ACTLBL_LOOK_ROLL,
&[
ActionSource::Keyboard(KeyCode::KeyE).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::KeyQ).into_binding_modifier(1.0),
],
)
.bind(
"Debug",
&[ActionSource::Keyboard(KeyCode::KeyB).into_binding()],
)
.finish(),
)
.finish();
let world = &mut app.world; let world = &mut app.world;
world.add_resource(action_handler); world.add_resource(action_handler);
@ -341,7 +385,7 @@ async fn main() {
world.spawn((scripts,)); world.spawn((scripts,));
}; */ }; */
let mut app = App::new(); let mut app = App::new();
app.with_plugin(lyra_engine::DefaultPlugins); app.with_plugin(lyra_engine::DefaultPlugins);
app.with_startup_system(setup_sys.into_system()); app.with_startup_system(setup_sys.into_system());

View File

@ -1,37 +0,0 @@
use lyra_ecs::Component;
use lyra_reflect::Reflect;
use lyra_resource::{gltf::Mesh, ResHandle};
#[derive(Clone, Component, Reflect)]
pub struct MeshComponent {
#[reflect(skip)]
pub mesh: ResHandle<Mesh>,
}
impl From<ResHandle<Mesh>> for MeshComponent {
fn from(value: ResHandle<Mesh>) -> Self {
Self {
mesh: value
}
}
}
impl std::ops::Deref for MeshComponent {
type Target = ResHandle<Mesh>;
fn deref(&self) -> &Self::Target {
&self.mesh
}
}
impl std::ops::DerefMut for MeshComponent {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.mesh
}
}
impl MeshComponent {
pub fn new(mesh: ResHandle<Mesh>) -> Self {
Self::from(mesh)
}
}

View File

@ -1,6 +1,3 @@
pub mod mesh;
pub use mesh::*;
pub mod camera; pub mod camera;
pub use camera::*; pub use camera::*;