From 4a8e85ef64c3b7efba4c72ff3d30992c68ce2a32 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 25 May 2019 18:16:26 -0400 Subject: [PATCH 1/3] restore lost changes Former-commit-id: a94c52677287131e02c88748694dfbcaf90b531a --- voxygen/src/hud/mod.rs | 2 +- voxygen/src/render/pipelines/ui.rs | 2 +- voxygen/src/ui/mod.rs | 25 ++++++++++++------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 032e214275..ad6d51db3b 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -348,7 +348,7 @@ impl Hud { &mut self.ids.health_bars, &mut ui_widgets.widget_id_generator(), ); - // Healh Bar + // Health Bar Rectangle::fill_with([120.0, 8.0], Color::Rgba(0.3, 0.3, 0.3, 0.5)) .x_y(0.0, -25.0) .position_ingame(pos.0 + Vec3::new(0.0, 0.0, 3.0)) diff --git a/voxygen/src/render/pipelines/ui.rs b/voxygen/src/render/pipelines/ui.rs index 4e781c88dd..246d32f5bd 100644 --- a/voxygen/src/render/pipelines/ui.rs +++ b/voxygen/src/render/pipelines/ui.rs @@ -46,7 +46,7 @@ impl Pipeline for UiPipeline { impl From> for Locals { fn from(pos: Vec3) -> Self { Self { - pos: [pos[0], pos[1], pos[2], 1.0], + pos: [pos.x, pos.y, pos.z, 1.0], } } } diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 29934e0fb7..0eb2b519ed 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -231,7 +231,7 @@ impl Ui { enum Placement { Interface, - // Number and resolution + // Number of primitives left to render ingame and relative scaling/resolution InWorld(usize, Option), }; @@ -295,6 +295,7 @@ impl Ui { } match placement { + // No primitives left to place in the world at the current position, go back to drawing the interface Placement::InWorld(0, _) => { placement = Placement::Interface; p_scale_factor = self.scale.scale_factor_physical(); @@ -307,24 +308,22 @@ impl Ui { // Push new position command self.draw_commands.push(DrawCommand::WorldPos(None)); } - Placement::InWorld(n, res) => match kind { - // Other types don't need to be drawn in the game + // Primitives still left to draw ingame + Placement::InWorld(num_prims, res) => match kind { + // Other types don't aren't drawn & shoudn't decrement the number of primitives left to draw ingame PrimitiveKind::Other(_) => {} - _ => { - placement = Placement::InWorld(n - 1, res); - if res.is_none() { - continue; - } - } + // Decrement the number of primitives left + _ => placement = Placement::InWorld(num_prims - 1, res), }, Placement::Interface => {} } // Functions for converting for conrod scalar coords to GL vertex coords (-1.0 to 1.0). - let (ui_win_w, ui_win_h) = if let Placement::InWorld(_, Some(res)) = placement { - (res as f64, res as f64) - } else { - (self.ui.win_w, self.ui.win_h) + let (ui_win_w, ui_win_h) = match placement { + Placement::InWorld(_, Some(res)) => (res as f64, res as f64), + // Behind the camera or far away + Placement::InWorld(_, None) => continue, + Placement::Interface => (self.ui.win_w, self.ui.win_h), }; let vx = |x: f64| (x / ui_win_w * 2.0) as f32; let vy = |y: f64| (y / ui_win_h * 2.0) as f32; From 3c7f463330229403a5df8a4fed83bd1ec9f424b0 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 25 May 2019 19:02:57 -0400 Subject: [PATCH 2/3] Don't create Consts if they are not needed Former-commit-id: 3af8652100c009afda53637b292ded67587d89d4 --- voxygen/src/ui/mod.rs | 50 +++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 0eb2b519ed..271204cd39 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -60,7 +60,7 @@ enum DrawKind { enum DrawCommand { Draw { kind: DrawKind, verts: Range }, Scissor(Aabr), - WorldPos(Option>), + WorldPos(Option), } impl DrawCommand { fn image(verts: Range) -> DrawCommand { @@ -97,6 +97,8 @@ pub struct Ui { // Consts for default ui drawing position (ie the interface) interface_locals: Consts, default_globals: Consts, + // Consts to specify positions of ingame elements (e.g. Nametags) + ingame_locals: Vec>, // Window size for updating scaling window_resized: Option>, // Scaling of the ui @@ -118,6 +120,7 @@ impl Ui { model: renderer.create_dynamic_model(100)?, interface_locals: renderer.create_consts(&[UiLocals::default()])?, default_globals: renderer.create_consts(&[Globals::default()])?, + ingame_locals: Vec::new(), window_resized: None, scale, }) @@ -229,6 +232,8 @@ impl Ui { let window_scissor = default_scissor(renderer); let mut current_scissor = window_scissor; + let mut ingame_local_index = 0; + enum Placement { Interface, // Number of primitives left to render ingame and relative scaling/resolution @@ -528,16 +533,6 @@ impl Ui { .unwrap() .state .parameters; - // Finish current state - self.draw_commands.push(match current_state { - State::Plain => DrawCommand::plain(start..mesh.vertices().len()), - State::Image => DrawCommand::image(start..mesh.vertices().len()), - }); - start = mesh.vertices().len(); - // Push new position command - self.draw_commands.push(DrawCommand::WorldPos(Some( - renderer.create_consts(&[parameters.pos.into()]).unwrap(), - ))); let pos_in_view = view_mat * Vec4::from_point(parameters.pos); let scale_factor = self.ui.win_w as f64 @@ -546,7 +541,34 @@ impl Ui { * (0.5 * fov as f64).tan() * parameters.res as f64); // Don't process ingame elements behind the camera or very far away - placement = if scale_factor > 0.1 { + placement = if scale_factor > 0.2 { + // Finish current state + self.draw_commands.push(match current_state { + State::Plain => { + DrawCommand::plain(start..mesh.vertices().len()) + } + State::Image => { + DrawCommand::image(start..mesh.vertices().len()) + } + }); + start = mesh.vertices().len(); + // Push new position command + if self.ingame_locals.len() > ingame_local_index { + renderer + .update_consts( + &mut self.ingame_locals[ingame_local_index], + &[parameters.pos.into()], + ) + .unwrap(); + } else { + self.ingame_locals.push( + renderer.create_consts(&[parameters.pos.into()]).unwrap(), + ); + } + self.draw_commands + .push(DrawCommand::WorldPos(Some(ingame_local_index))); + ingame_local_index += 1; + p_scale_factor = ((scale_factor * 10.0).log2().round().powi(2) / 10.0) .min(1.6) @@ -621,8 +643,8 @@ impl Ui { DrawCommand::Scissor(new_scissor) => { scissor = *new_scissor; } - DrawCommand::WorldPos(ref pos) => { - locals = pos.as_ref().unwrap_or(&self.interface_locals); + DrawCommand::WorldPos(index) => { + locals = index.map_or(&self.interface_locals, |i| &self.ingame_locals[i]); } DrawCommand::Draw { kind, verts } => { let tex = match kind { From de4d1a0e0692c5fe110b1bddde09eedb0a0cb1a1 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 26 May 2019 10:32:15 -0400 Subject: [PATCH 3/3] Fix pet spawning leading to NaN move_dir Former-commit-id: ac68702bfdb482f32967d96e4b1da2b0ffc4e4c4 --- common/src/sys/agent.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index ea6bc8c320..8a5687ccfe 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -46,7 +46,7 @@ impl<'a> System<'a> for Sys { } // Move towards the target. - let dist = tgt_pos.distance(pos.0); + let dist: f32 = Vec2::from(tgt_pos - pos.0).magnitude(); control.move_dir = if dist > 5.0 { Vec2::from(tgt_pos - pos.0).normalized() } else if dist < 1.5 && dist > 0.0 {