This commit is contained in:
griffi-gh 2023-01-25 03:36:24 +01:00
parent 83f06950e2
commit e68e0b39e3
3 changed files with 42 additions and 4 deletions

View file

@ -0,0 +1,18 @@
use glam::{Mat4, EulerRot, Quat};
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView};
use crate::{transform::Transform, input::Inputs};
#[derive(Component)]
pub struct FlyController;
pub fn update_controllers(
controllers: View<FlyController>,
mut transforms: ViewMut<Transform>,
inputs: UniqueView<Inputs>
) {
for (_, mut transform) in (&controllers, &mut transforms).iter() {
let (scale, mut rotation, translation) = transform.0.to_scale_rotation_translation();
rotation *= Quat::from_euler(EulerRot::XYZ, 0., 0.001, 0.);
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
}
}

View file

@ -32,6 +32,7 @@ use settings::GameSettings;
use camera::compute_cameras; use camera::compute_cameras;
use events::{clear_events, process_glutin_events}; use events::{clear_events, process_glutin_events};
use input::{init_input, process_inputs}; use input::{init_input, process_inputs};
use fly_controller::update_controllers;
#[derive(Unique)] #[derive(Unique)]
pub(crate) struct DeltaTime(Duration); pub(crate) struct DeltaTime(Duration);
@ -47,9 +48,9 @@ fn startup() -> Workload {
fn update() -> Workload { fn update() -> Workload {
( (
process_inputs, process_inputs,
update_controllers,
update_loaded_world_around_player, update_loaded_world_around_player,
compute_cameras, compute_cameras
clear_events
).into_workload() ).into_workload()
} }
fn render() -> Workload { fn render() -> Workload {
@ -58,6 +59,11 @@ fn render() -> Workload {
draw_world, draw_world,
).into_sequential_workload() ).into_sequential_workload()
} }
fn after_frame_end() -> Workload {
(
clear_events,
).into_workload()
}
fn main() { fn main() {
logging::init(); logging::init();
@ -78,6 +84,7 @@ fn main() {
world.add_workload(startup); world.add_workload(startup);
world.add_workload(update); world.add_workload(update);
world.add_workload(render); world.add_workload(render);
world.add_workload(after_frame_end);
//Run startup systems //Run startup systems
world.run_workload(startup).unwrap(); world.run_workload(startup).unwrap();
@ -123,6 +130,9 @@ fn main() {
//Finish rendering //Finish rendering
let target = world.remove_unique::<RenderTarget>().unwrap(); let target = world.remove_unique::<RenderTarget>().unwrap();
target.0.finish().unwrap(); target.0.finish().unwrap();
//FrameEnd
world.run_workload(after_frame_end).unwrap();
}, },
_ => (), _ => (),
}; };

View file

@ -2,7 +2,8 @@ use glam::Mat4;
use shipyard::{Component, EntitiesViewMut, ViewMut}; use shipyard::{Component, EntitiesViewMut, ViewMut};
use crate::{ use crate::{
transform::Transform, transform::Transform,
camera::Camera, camera::Camera,
fly_controller::FlyController,
}; };
#[derive(Component)] #[derive(Component)]
@ -11,26 +12,35 @@ pub struct LocalPlayer;
#[derive(Component)] #[derive(Component)]
pub struct Player; pub struct Player;
#[derive(Component)]
pub struct MainPlayer;
pub fn spawn_player ( pub fn spawn_player (
mut entities: EntitiesViewMut, mut entities: EntitiesViewMut,
mut vm_player: ViewMut<Player>, mut vm_player: ViewMut<Player>,
mut vm_main_player: ViewMut<MainPlayer>,
mut vm_local_player: ViewMut<LocalPlayer>, mut vm_local_player: ViewMut<LocalPlayer>,
mut vm_transform: ViewMut<Transform>, mut vm_transform: ViewMut<Transform>,
mut vm_camera: ViewMut<Camera>, mut vm_camera: ViewMut<Camera>,
mut vm_controls: ViewMut<FlyController>,
) { ) {
log::info!("spawning player"); log::info!("spawning player");
entities.add_entity( entities.add_entity(
( (
&mut vm_player, &mut vm_player,
&mut vm_main_player,
&mut vm_local_player, &mut vm_local_player,
&mut vm_transform, &mut vm_transform,
&mut vm_camera, &mut vm_camera,
&mut vm_controls
), ),
( (
Player, Player,
MainPlayer,
LocalPlayer, LocalPlayer,
Transform(Mat4::default()), Transform(Mat4::default()),
Camera::default() Camera::default(),
FlyController
) )
); );
} }