Expose structs to Lua and write Lua type annotations #28

Merged
SeanOMik merged 15 commits from feat/lua-type-defs into main 2024-10-19 15:17:00 +00:00
5 changed files with 117 additions and 122 deletions
Showing only changes of commit eff6b221e0 - Show all commits

View File

@ -196,7 +196,7 @@ fn setup_scene_plugin(app: &mut App) {
fn camera_debug_plugin(app: &mut App) {
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() {
cam.debug = !cam.debug;
}

View File

@ -1,12 +1,12 @@
use lyra_engine::{
assets::{gltf::Gltf, ResourceManager}, ecs::query::View, game::App, input::{
Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource,
InputActionPlugin, KeyCode, LayoutId, MouseAxis, MouseInput,
}, math::{self, Transform, Vec3}, render::{light::directional::DirectionalLight, window::WindowOptions}, scene::{
InputActionPlugin, KeyCode, LayoutId,
}, math::{self, Transform, Vec3}, render::light::directional::DirectionalLight, scene::{
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,
}
}, winit::WindowOptions
};
#[async_std::main]
@ -82,7 +82,6 @@ async fn main() {
let mut a = App::new();
a.with_plugin(lyra_engine::DefaultPlugins)
.with_system("mouse_pos_print", mouse_pos_system, &[])
.with_plugin(setup_scene_plugin)
.with_plugin(action_handler_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);
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 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::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 {
max_tps: u32,
@ -71,9 +91,11 @@ impl Criteria for FixedTimestep {
}
}
#[allow(dead_code)]
#[derive(Clone)]
struct TpsAccumulator(f32);
#[allow(dead_code)]
#[derive(Component)]
struct CubeFlag;
@ -90,27 +112,29 @@ async fn main() {
//let diffuse_texture = resman.request::<Texture>("assets/happy-tree.png").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_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 separate_gltf = resman.request::<Gltf>("assets/pos-testing/child-node-cubes.glb").unwrap(); */
//drop(resman);
cube_gltf.wait_recurse_dependencies_load();
let cube_mesh = &cube_gltf.data_ref()
.unwrap().meshes[0];
let cube_mesh = &cube_gltf.data_ref().unwrap().meshes[0];
/* let crate_mesh = &crate_gltf.data_ref()
.unwrap().meshes[0];
let separate_scene = &separate_gltf.data_ref()
.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);
sponza_model.wait_recurse_dependencies_load();
let sponza_scene = &sponza_model.data_ref()
.unwrap().scenes[0];
let sponza_scene = &sponza_model.data_ref().unwrap().scenes[0];
world.spawn((
sponza_scene.clone(),
@ -127,8 +151,7 @@ async fn main() {
DirectionalLight {
enabled: true,
color: Vec3::ONE,
intensity: 0.35
//..Default::default()
intensity: 0.35, //..Default::default()
},
light_tran,
));
@ -139,7 +162,6 @@ async fn main() {
//Vec3::new(-5.0, 1.0, -1.28),
Vec3::new(-5.0, 1.0, -0.0),
//Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY,
Vec3::new(0.25, 0.25, 0.25),
);
@ -161,7 +183,6 @@ async fn main() {
Vec3::new(-3.0, 0.2, -1.5),
//Vec3::new(-5.0, 1.0, -0.28),
//Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY,
Vec3::new(0.15, 0.15, 0.15),
);
@ -183,7 +204,6 @@ async fn main() {
Vec3::new(0.0, 0.2, -1.5),
//Vec3::new(-5.0, 1.0, -0.28),
//Vec3::new(-10.0, 0.94, -0.28),
Quat::IDENTITY,
Vec3::new(0.15, 0.15, 0.15),
);
@ -252,33 +272,37 @@ async fn main() {
camera.transform = Transform::new(
Vec3::new(-10.0, 0.94, -0.28),
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);
world.spawn(( camera, FreeFlyCamera::default() ));
world.spawn((camera, FreeFlyCamera::default()));
Ok(())
};
let camera_debug_plugin = move |app: &mut App| {
let sys = |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> {
if handler.was_action_just_pressed("Debug") {
for mut cam in view.into_iter() {
cam.debug = !cam.debug;
let sys =
|handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> {
if let Some(true) = handler.was_action_just_pressed("Debug") {
for mut cam in view.into_iter() {
cam.debug = !cam.debug;
}
}
}
Ok(())
};
Ok(())
};
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 = ActionHandler::builder()
.add_layout(LayoutId::from(0))
.add_action(ACTLBL_MOVE_FORWARD_BACKWARD, Action::new(ActionKind::Axis))
.add_action(ACTLBL_MOVE_LEFT_RIGHT, 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_ROLL, Action::new(ActionKind::Axis))
.add_action("Debug", Action::new(ActionKind::Button))
.add_mapping(ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0))
.bind(ACTLBL_MOVE_FORWARD_BACKWARD, &[
ActionSource::Keyboard(KeyCode::KeyW).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::KeyS).into_binding_modifier(-1.0)
])
.bind(ACTLBL_MOVE_LEFT_RIGHT, &[
ActionSource::Keyboard(KeyCode::KeyA).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::KeyD).into_binding_modifier(1.0)
])
.bind(ACTLBL_MOVE_UP_DOWN, &[
ActionSource::Keyboard(KeyCode::KeyC).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::KeyZ).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),
ActionSource::Keyboard(KeyCode::ArrowRight).into_binding_modifier(1.0),
//ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickX)).into_binding(),
])
.bind(ACTLBL_LOOK_UP_DOWN, &[
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();
.add_mapping(
ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0))
.bind(
ACTLBL_MOVE_FORWARD_BACKWARD,
&[
ActionSource::Keyboard(KeyCode::KeyW).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::KeyS).into_binding_modifier(-1.0),
],
)
.bind(
ACTLBL_MOVE_LEFT_RIGHT,
&[
ActionSource::Keyboard(KeyCode::KeyA).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::KeyD).into_binding_modifier(1.0),
],
)
.bind(
ACTLBL_MOVE_UP_DOWN,
&[
ActionSource::Keyboard(KeyCode::KeyC).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::KeyZ).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),
ActionSource::Keyboard(KeyCode::ArrowRight).into_binding_modifier(1.0),
//ActionSource::Gamepad(GamepadFormat::DualAxis, GamepadInput::Axis(GamepadAxis::RThumbstickX)).into_binding(),
],
)
.bind(
ACTLBL_LOOK_UP_DOWN,
&[
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;
world.add_resource(action_handler);

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 use camera::*;