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

View file

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