diff --git a/voxygen/shaders/figure.frag b/voxygen/shaders/figure.frag index a51a540a39..769bf224a8 100644 --- a/voxygen/shaders/figure.frag +++ b/voxygen/shaders/figure.frag @@ -17,7 +17,7 @@ uniform u_globals { vec4 focus_pos; vec4 view_distance; vec4 time_of_day; - vec4 time; + vec4 tick; }; out vec4 tgt_color; diff --git a/voxygen/shaders/figure.vert b/voxygen/shaders/figure.vert index 52d8d385df..1e8d15524c 100644 --- a/voxygen/shaders/figure.vert +++ b/voxygen/shaders/figure.vert @@ -18,7 +18,7 @@ uniform u_globals { vec4 focus_pos; vec4 view_distance; vec4 time_of_day; - vec4 time; + vec4 tick; }; struct BoneData { diff --git a/voxygen/shaders/skybox.frag b/voxygen/shaders/skybox.frag index f7387bd430..caa51fe4d9 100644 --- a/voxygen/shaders/skybox.frag +++ b/voxygen/shaders/skybox.frag @@ -15,7 +15,7 @@ uniform u_globals { vec4 focus_pos; vec4 view_distance; vec4 time_of_day; - vec4 time; + vec4 tick; }; out vec4 tgt_color; diff --git a/voxygen/shaders/skybox.vert b/voxygen/shaders/skybox.vert index 3b58fcfd18..165e747ae9 100644 --- a/voxygen/shaders/skybox.vert +++ b/voxygen/shaders/skybox.vert @@ -15,7 +15,7 @@ uniform u_globals { vec4 focus_pos; vec4 view_distance; vec4 time_of_day; - vec4 time; + vec4 tick; }; out vec3 f_pos; diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 8e055a8fd1..472ae57923 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -17,8 +17,8 @@ impl Animation for RunAnimation { skeleton: &mut Self::Skeleton, time: f64, ) { - let wave = (time as f32 * 10.0).sin(); - let wave_fast = (time as f32 * 5.0).sin(); + let wave = (time as f32 * 8.0).sin(); + let wave_fast = (time as f32 * 4.0).sin(); skeleton.head.offset = Vec3::unit_z() * 13.0; skeleton.head.ori = Quaternion::rotation_z(wave * 0.3); @@ -32,11 +32,11 @@ impl Animation for RunAnimation { skeleton.leggings.offset = Vec3::unit_z() * 4.0; skeleton.leggings.ori = Quaternion::rotation_z(wave * 0.3); - skeleton.l_hand.offset = Vec3::new(-8.0, wave * 4.0, 9.0); - skeleton.r_hand.offset = Vec3::new(8.0, -wave * 4.0, 9.0); + skeleton.l_hand.offset = Vec3::new(-8.0, wave * 5.0, 9.0); + skeleton.r_hand.offset = Vec3::new(8.0, -wave * 5.0, 9.0); - skeleton.l_foot.offset = Vec3::new(-3.5, -wave * 4.0, -(wave_fast.abs() - 0.5) * 3.0); - skeleton.r_foot.offset = Vec3::new(3.5, wave * 4.0, (wave_fast.abs() - 0.5) * 3.0); + skeleton.l_foot.offset = Vec3::new(-3.5, -wave * 4.0, -(wave_fast.abs() - 0.5).abs() * 4.0); + skeleton.r_foot.offset = Vec3::new(3.5, wave * 4.0, -(wave_fast.abs() - 0.5).abs() * 4.0); skeleton.back.offset = Vec3::new(-8.0, 5.0, 16.0); skeleton.back.ori = Quaternion::rotation_y(2.5); diff --git a/voxygen/src/anim/mod.rs b/voxygen/src/anim/mod.rs index 6351ed94df..088f56a4ca 100644 --- a/voxygen/src/anim/mod.rs +++ b/voxygen/src/anim/mod.rs @@ -8,7 +8,6 @@ use crate::render::FigureBoneData; #[derive(Copy, Clone)] pub struct Bone { - parent_idx: Option, // MUST be less than the current bone index pub offset: Vec3, pub ori: Quaternion, } @@ -16,18 +15,11 @@ pub struct Bone { impl Bone { pub fn default() -> Self { Self { - parent_idx: None, offset: Vec3::zero(), ori: Quaternion::identity(), } } - pub fn get_parent_idx(&self) -> Option { self.parent_idx } - - pub fn set_parent_idx(&mut self, parent_idx: u8) { - self.parent_idx = Some(parent_idx); - } - pub fn compute_base_matrix(&self) -> Mat4 { Mat4::::translation_3d(self.offset) * Mat4::from(self.ori) } diff --git a/voxygen/src/menu/title.rs b/voxygen/src/menu/title.rs index c38533fe7c..39c48e12a6 100644 --- a/voxygen/src/menu/title.rs +++ b/voxygen/src/menu/title.rs @@ -31,7 +31,7 @@ impl PlayState for TitleState { Event::Close => return PlayStateResult::Shutdown, // When space is pressed, start a session Event::Char(' ') => return PlayStateResult::Push( - Box::new(SessionState::from_renderer(global_state.window.renderer_mut())), + Box::new(SessionState::new(global_state.window.renderer_mut())), ), // Ignore all other events _ => {}, diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 663174b70d..cd5f408181 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -23,7 +23,7 @@ gfx_defines! { // TODO: Fix whatever alignment issue requires these uniforms to be aligned view_distance: [f32; 4] = "view_distance", time_of_day: [f32; 4] = "time_of_day", // TODO: Make this f64 - time: [f32; 4] = "time", + tick: [f32; 4] = "tick", } } @@ -37,7 +37,7 @@ impl Globals { focus_pos: [0.0; 4], view_distance: [0.0; 4], time_of_day: [0.0; 4], - time: [0.0; 4], + tick: [0.0; 4], } } @@ -49,7 +49,7 @@ impl Globals { focus_pos: Vec3, view_distance: f32, time_of_day: f64, - time: f32, + tick: f64, ) -> Self { Self { view_mat: arr_to_mat(view_mat.into_col_array()), @@ -58,7 +58,7 @@ impl Globals { focus_pos: Vec4::from(focus_pos).into_array(), view_distance: [view_distance; 4], time_of_day: [time_of_day as f32; 4], - time: [time; 4], + tick: [tick as f32; 4], } } } diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 2fb16e1ad3..c3bb5c1585 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -1,23 +1,16 @@ pub mod camera; pub mod figure; -// Standard -use std::time::Duration; - // Library use vek::*; use dot_vox; // Project -use client::{ - self, - Client, -}; use common::figure::Segment; +use client::Client; // Crate use crate::{ - Error, render::{ Consts, Globals, @@ -56,8 +49,6 @@ pub struct Scene { skybox: Skybox, test_figure: Figure, - - client: Client, } // TODO: Make a proper asset loading system @@ -105,17 +96,9 @@ impl Scene { CharacterSkeleton::new(), ) .unwrap(), - - client: Client::new(), } } - /// Tick the scene (and the client attached to it) - pub fn tick(&mut self, dt: Duration) -> Result<(), Error> { - self.client.tick(client::Input {}, dt)?; - Ok(()) - } - /// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.). pub fn handle_input_event(&mut self, event: Event) -> bool { match event { @@ -130,7 +113,7 @@ impl Scene { } /// Maintain and update GPU data such as constant buffers, models, etc. - pub fn maintain_gpu_data(&mut self, renderer: &mut Renderer) { + pub fn maintain_gpu_data(&mut self, renderer: &mut Renderer, client: &Client) { // Compute camera matrices let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(); @@ -141,15 +124,15 @@ impl Scene { cam_pos, self.camera.get_focus_pos(), 10.0, - self.client.state().get_time_of_day(), - 0.0, + client.state().get_time_of_day(), + client.state().get_tick(), )]) .expect("Failed to update global constants"); // TODO: Don't do this here RunAnimation::update_skeleton( &mut self.test_figure.skeleton, - self.client.state().get_tick(), + client.state().get_tick(), ); self.test_figure.update_locals(renderer, FigureLocals::default()).unwrap(); self.test_figure.update_skeleton(renderer).unwrap(); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index a9b97b0af3..ac8393664b 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -6,9 +6,14 @@ use vek::*; // Project use common::clock::Clock; +use client::{ + self, + Client, +}; // Crate use crate::{ + Error, PlayState, PlayStateResult, GlobalState, @@ -21,15 +26,17 @@ const FPS: u64 = 60; pub struct SessionState { scene: Scene, + client: Client, } /// Represents an active game session (i.e: one that is being played) impl SessionState { /// Create a new `SessionState` - pub fn from_renderer(renderer: &mut Renderer) -> Self { + pub fn new(renderer: &mut Renderer) -> Self { Self { // Create a scene for this session. The scene handles visible elements of the game world scene: Scene::new(renderer), + client: Client::new(), } } } @@ -38,12 +45,18 @@ impl SessionState { const BG_COLOR: Rgba = Rgba { r: 0.0, g: 0.3, b: 1.0, a: 1.0 }; impl SessionState { + /// Tick the session (and the client attached to it) + pub fn tick(&mut self, dt: Duration) -> Result<(), Error> { + self.client.tick(client::Input {}, dt)?; + Ok(()) + } + /// Render the session to the screen. /// /// This method should be called once per frame. pub fn render(&mut self, renderer: &mut Renderer) { // Maintain scene GPU data - self.scene.maintain_gpu_data(renderer); + self.scene.maintain_gpu_data(renderer, &self.client); // Clear the screen renderer.clear(BG_COLOR); @@ -79,7 +92,7 @@ impl PlayState for SessionState { } // Perform an in-game tick - self.scene.tick(clock.get_last_delta()) + self.tick(clock.get_last_delta()) .expect("Failed to tick the scene"); // Render the session