From 67ea2449639701f2c4d332b48d5b6332d12c8c70 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Fri, 12 Aug 2022 19:18:07 -0400 Subject: [PATCH 01/13] Fix Clippy warnings introduced by Rust 1.63.0 --- client/src/graphics/window.rs | 2 +- client/src/lahar_deprecated/transfer.rs | 1 + common/src/node.rs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/graphics/window.rs b/client/src/graphics/window.rs index 2544a778..568b47ea 100644 --- a/client/src/graphics/window.rs +++ b/client/src/graphics/window.rs @@ -314,7 +314,7 @@ impl SwapchainMgr { /// Construct a swapchain manager for a certain window fn new(window: &Window, gfx: Arc, fallback_size: PhysicalSize) -> Self { let device = &*gfx.device; - let swapchain_fn = khr::Swapchain::new(&gfx.core.instance, &*device); + let swapchain_fn = khr::Swapchain::new(&gfx.core.instance, device); let surface_formats = unsafe { window .surface_fn diff --git a/client/src/lahar_deprecated/transfer.rs b/client/src/lahar_deprecated/transfer.rs index 445f3ccb..99d1e687 100644 --- a/client/src/lahar_deprecated/transfer.rs +++ b/client/src/lahar_deprecated/transfer.rs @@ -52,6 +52,7 @@ impl fmt::Display for ShutDown { impl std::error::Error for ShutDown {} +#[allow(clippy::type_complexity)] struct Message { sender: oneshot::Sender<()>, op: Box, diff --git a/common/src/node.rs b/common/src/node.rs index 50cbe4ca..a65316c9 100644 --- a/common/src/node.rs +++ b/common/src/node.rs @@ -30,7 +30,6 @@ impl Default for Chunk { } } -#[derive(PartialEq)] pub enum VoxelData { Solid(Material), Dense(Box<[Material]>), From 631f84b0822a240c1a23873380acb799138fb19d Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sat, 27 Aug 2022 10:45:06 -0400 Subject: [PATCH 02/13] Add normals and dual coordinates to dodeca.rs --- common/src/dodeca.rs | 57 +++++++++++++++++++++++++++++++++++--------- common/src/plane.rs | 7 +++--- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/common/src/dodeca.rs b/common/src/dodeca.rs index c0609f39..accf6a1f 100644 --- a/common/src/dodeca.rs +++ b/common/src/dodeca.rs @@ -43,6 +43,12 @@ impl Side { ADJACENT[self as usize][other as usize] } + /// Outward normal vector of this side + #[inline] + pub fn normal(self) -> &'static na::Vector4 { + &SIDE_NORMALS[self as usize] + } + /// Reflection across this side #[inline] pub fn reflection(self) -> &'static na::Matrix4 { @@ -137,6 +143,16 @@ impl Vertex { ]) * na::Matrix4::new_scaling(0.5) } + /// Transform from cube-centric coordinates to dodeca-centric coordinates + pub fn dual_to_node(self) -> &'static na::Matrix4 { + &DUAL_TO_NODE[self as usize] + } + + /// Transform from dodeca-centric coordinates to cube-centric coordinates + pub fn node_to_dual(self) -> &'static na::Matrix4 { + &NODE_TO_DUAL[self as usize] + } + /// Convenience method for `self.chunk_to_node().determinant() < 0`. pub fn parity(self) -> bool { CHUNK_TO_NODE_PARITY[self as usize] @@ -163,13 +179,12 @@ lazy_static! { result }; - /// Transform that moves from a neighbor to a reference node, for each side - static ref REFLECTIONS: [na::Matrix4; SIDE_COUNT] = { + /// Vector corresponding to the outer normal of each side + static ref SIDE_NORMALS: [na::Vector4; SIDE_COUNT] = { let phi = 1.25f64.sqrt() + 0.5; // golden ratio - let root_phi = phi.sqrt(); - let f = math::lorentz_normalize(&na::Vector4::new(root_phi, phi * root_phi, 0.0, phi + 2.0)); + let f = math::lorentz_normalize(&na::Vector4::new(1.0, phi, 0.0, phi.sqrt())); - let mut result = [na::zero(); SIDE_COUNT]; + let mut result: [na::Vector4; SIDE_COUNT] = [na::zero(); SIDE_COUNT]; let mut i = 0; for (x, y, z, w) in [ (f.x, f.y, f.z, f.w), @@ -177,19 +192,20 @@ lazy_static! { (f.x, -f.y, -f.z, f.w), (-f.x, -f.y, f.z, f.w), ] - .iter() - .cloned() { - for (x, y, z, w) in [(x, y, z, w), (y, z, x, w), (z, x, y, w)].iter().cloned() { - result[i] = math::translate(&math::origin(), &na::Vector4::new(x, y, z, w)) - * math::euclidean_reflect(&na::Vector4::new(x, y, z, 0.0)) - * math::translate(&math::origin(), &na::Vector4::new(-x, -y, -z, w)); + for (x, y, z, w) in [(x, y, z, w), (y, z, x, w), (z, x, y, w)] { + result[i] = na::Vector4::new(x, y, z, w); i += 1; } } result }; + /// Transform that moves from a neighbor to a reference node, for each side + static ref REFLECTIONS: [na::Matrix4; SIDE_COUNT] = { + SIDE_NORMALS.map(|r| math::reflect(&r)) + }; + /// Sides incident to a vertex, in canonical order static ref VERTEX_SIDES: [[Side; 3]; VERTEX_COUNT] = { let mut result = [[Side::A; 3]; VERTEX_COUNT]; @@ -210,6 +226,25 @@ lazy_static! { result }; + /// Transform that converts from cube-centric coordinates to dodeca-centric coordinates + static ref DUAL_TO_NODE: [na::Matrix4; VERTEX_COUNT] = { + let mip_origin_normal = math::mip(&math::origin(), &SIDE_NORMALS[0]); // This value is the same for every side + let mut result = [na::zero(); VERTEX_COUNT]; + for i in 0..VERTEX_COUNT { + let [a, b, c] = VERTEX_SIDES[i]; + let vertex_position = math::lorentz_normalize( + &(math::origin() - (a.normal() + b.normal() + c.normal()) * mip_origin_normal), + ); + result[i] = na::Matrix4::from_columns(&[-a.normal(), -b.normal(), -c.normal(), vertex_position]); + } + result + }; + + /// Transform that converts from dodeca-centric coordinates to cube-centric coordinates + static ref NODE_TO_DUAL: [na::Matrix4; VERTEX_COUNT] = { + DUAL_TO_NODE.map(|m| m.try_inverse().unwrap()) + }; + /// Vertex shared by 3 sides static ref SIDES_TO_VERTEX: [[[Option; SIDE_COUNT]; SIDE_COUNT]; SIDE_COUNT] = { let mut result = [[[None; SIDE_COUNT]; SIDE_COUNT]; SIDE_COUNT]; diff --git a/common/src/plane.rs b/common/src/plane.rs index 96faa9ca..b7106043 100644 --- a/common/src/plane.rs +++ b/common/src/plane.rs @@ -2,7 +2,7 @@ use std::ops::{Mul, Neg}; use crate::{ dodeca::{Side, Vertex}, - math::{lorentz_normalize, mip, origin}, + math::{lorentz_normalize, mip}, }; /// A hyperbolic plane @@ -14,9 +14,8 @@ pub struct Plane { impl From for Plane { /// A surface overlapping with a particular dodecahedron side fn from(side: Side) -> Self { - let n = side.reflection().column(3) - origin(); Self { - normal: lorentz_normalize(&n), + normal: *side.normal(), } } } @@ -81,7 +80,7 @@ impl Plane { #[cfg(test)] mod tests { use super::*; - use crate::math::translate_along; + use crate::math::{origin, translate_along}; use approx::*; #[test] From f4629c0375ea84570321f6fa6289eac0fa78a18a Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sat, 27 Aug 2022 11:13:13 -0400 Subject: [PATCH 03/13] Flip 0 and 1 for chunk coordinates for easier math Instead of (0,0,0) being at a dodecahedron's center and (1,1,1) being at the vertex, this change makes it so that (0,0,0) is at the vertex and (1,1,1) is at the corner. This puts the origin where the distortion from a Euclidean cube is at its weakest. --- common/src/dodeca.rs | 45 +++++++++++++++++++++++++++++++++--------- common/src/plane.rs | 22 ++++++++++----------- common/src/worldgen.rs | 13 ++++++------ 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/common/src/dodeca.rs b/common/src/dodeca.rs index accf6a1f..8b67c3bc 100644 --- a/common/src/dodeca.rs +++ b/common/src/dodeca.rs @@ -133,14 +133,12 @@ impl Vertex { /// Transform from euclidean chunk coordinates to hyperbolic node space pub fn chunk_to_node(self) -> na::Matrix4 { - let origin = na::Vector4::new(0.0, 0.0, 0.0, 1.0); - let [a, b, c] = self.canonical_sides(); - na::Matrix4::from_columns(&[ - a.reflection().column(3) - origin, - b.reflection().column(3) - origin, - c.reflection().column(3) - origin, - origin, - ]) * na::Matrix4::new_scaling(0.5) + self.dual_to_node() * na::Matrix4::new_scaling(1.0 / Self::dual_to_chunk_factor()) + } + + /// Transform from hyperbolic node space to euclidean chunk coordinates + pub fn node_to_chunk(self) -> na::Matrix4 { + na::Matrix4::new_scaling(Self::dual_to_chunk_factor()) * self.node_to_dual() } /// Transform from cube-centric coordinates to dodeca-centric coordinates @@ -153,6 +151,13 @@ impl Vertex { &NODE_TO_DUAL[self as usize] } + /// Scale factor used in conversion from cube-centric coordinates to euclidean chunk coordinates. + /// Scaling the x, y, and z components of a vector in cube-centric coordinates by this value + /// and dividing them by the w coordinate will yield euclidean chunk coordinates. + pub fn dual_to_chunk_factor() -> f64 { + (2.0 + 5.0f64.sqrt()).sqrt() + } + /// Convenience method for `self.chunk_to_node().determinant() < 0`. pub fn parity(self) -> bool { CHUNK_TO_NODE_PARITY[self as usize] @@ -328,7 +333,7 @@ mod tests { #[test] fn radius() { - let corner = Vertex::A.chunk_to_node() * na::Vector4::repeat(1.0); + let corner = Vertex::A.chunk_to_node() * math::origin(); assert_abs_diff_eq!( BOUNDING_SPHERE_RADIUS, math::distance(&corner, &math::origin()), @@ -341,4 +346,26 @@ mod tests { epsilon = 1e-10 ); } + + #[test] + fn chunk_to_node() { + // Chunk coordinates of (1, 1, 1) should be at the center of a dodecahedron. + let mut chunk_corner_in_node_coordinates = + Vertex::A.chunk_to_node() * na::Vector4::new(1.0, 1.0, 1.0, 1.0); + chunk_corner_in_node_coordinates /= chunk_corner_in_node_coordinates.w; + assert_abs_diff_eq!( + chunk_corner_in_node_coordinates, + na::Vector4::new(0.0, 0.0, 0.0, 1.0), + epsilon = 1e-10 + ); + } + + #[test] + fn node_to_chunk() { + assert_abs_diff_eq!( + Vertex::A.chunk_to_node().try_inverse().unwrap(), + Vertex::A.node_to_chunk(), + epsilon = 1e-10 + ); + } } diff --git a/common/src/plane.rs b/common/src/plane.rs index b7106043..49375394 100644 --- a/common/src/plane.rs +++ b/common/src/plane.rs @@ -104,8 +104,8 @@ mod tests { fn check_surface_flipped() { let root = Plane::from(Side::A); assert_abs_diff_eq!( - root.distance_to_chunk(Vertex::A, &(na::Vector3::x() * 2.0)), - root.distance_to_chunk(Vertex::J, &(na::Vector3::x() * 2.0)) * -1.0, + root.distance_to_chunk(Vertex::A, &na::Vector3::new(-1.0, 1.0, 1.0)), + root.distance_to_chunk(Vertex::J, &na::Vector3::new(-1.0, 1.0, 1.0)) * -1.0, epsilon = 1e-5 ); } @@ -115,7 +115,7 @@ mod tests { assert_abs_diff_eq!( Plane::from(Side::A).distance_to_chunk( Vertex::from_sides(Side::A, Side::B, Side::C).unwrap(), - &na::Vector3::new(1.0, 0.3, 0.9), // The first 1.0 is important, the plane is the midplane of the cube in Side::A direction + &na::Vector3::new(0.0, 0.7, 0.1), // The first 0.0 is important, the plane is the midplane of the cube in Side::A direction ), 0.0, epsilon = 1e-8, @@ -128,33 +128,33 @@ mod tests { // A cube corner should have the same elevation seen from different cubes assert_abs_diff_eq!( - Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(0.0, 0.0, 0.0)), + Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(1.0, 1.0, 1.0)), Plane::from(Side::A).distance_to_chunk( Vertex::from_sides(Side::F, Side::H, Side::J).unwrap(), - &na::Vector3::new(0.0, 0.0, 0.0), + &na::Vector3::new(1.0, 1.0, 1.0), ), epsilon = 1e-8, ); // The same corner should have the same distance_to_chunk when represented from the same cube at different corners assert_abs_diff_eq!( - Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(1.0, 0.0, 0.0)), + Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(0.0, 1.0, 1.0)), (Side::A * Plane::from(Side::A)) - .distance_to_chunk(abc, &na::Vector3::new(1.0, 0.0, 0.0),), + .distance_to_chunk(abc, &na::Vector3::new(0.0, 1.0, 1.0),), epsilon = 1e-8, ); // Corners of midplane cubes separated by the midplane should have the same distance_to_chunk with a different sign assert_abs_diff_eq!( - Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(0.0, 0.0, 0.0)), - -Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(2.0, 0.0, 0.0)), + Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(1.0, 1.0, 1.0)), + -Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(-1.0, 1.0, 1.0)), epsilon = 1e-8, ); // Corners of midplane cubes not separated by the midplane should have the same distance_to_chunk assert_abs_diff_eq!( - Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(0.0, 0.0, 0.0)), - Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(0.0, 0.0, 2.0)), + Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(1.0, 1.0, 1.0)), + Plane::from(Side::A).distance_to_chunk(abc, &na::Vector3::new(1.0, 1.0, -1.0)), epsilon = 1e-8, ); } diff --git a/common/src/worldgen.rs b/common/src/worldgen.rs index 1b785f7f..4c8a4696 100644 --- a/common/src/worldgen.rs +++ b/common/src/worldgen.rs @@ -263,15 +263,16 @@ impl ChunkParams { for (x, y, z) in VoxelCoords::new(self.dimension) { let coords = na::Vector3::new(x, y, z); let center = voxel_center(self.dimension, coords); - let cube_coords = center * 0.5; + let trilerp_coords = center.map(|x| (1.0 - x) * 0.5); - let rain = trilerp(&self.env.rainfalls, cube_coords) + rng.sample(&normal.unwrap()); - let temp = trilerp(&self.env.temperatures, cube_coords) + rng.sample(&normal.unwrap()); + let rain = trilerp(&self.env.rainfalls, trilerp_coords) + rng.sample(&normal.unwrap()); + let temp = + trilerp(&self.env.temperatures, trilerp_coords) + rng.sample(&normal.unwrap()); // elev is calculated in multiple steps. The initial value elev_pre_terracing // is used to calculate elev_pre_noise which is used to calculate elev. - let elev_pre_terracing = trilerp(&self.env.max_elevations, cube_coords); - let block = trilerp(&self.env.blockinesses, cube_coords); + let elev_pre_terracing = trilerp(&self.env.max_elevations, trilerp_coords); + let block = trilerp(&self.env.blockinesses, trilerp_coords); let voxel_elevation = self.surface.distance_to_chunk(self.chunk, ¢er); let strength = 0.4 / (1.0 + voxel_elevation.powi(2)); let terracing_small = terracing_diff(elev_pre_terracing, block, 5.0, strength, 2.0); @@ -371,7 +372,7 @@ impl ChunkParams { let x = coords[0]; let y = coords[1]; let z = coords[2]; - let offset = 2 * self.dimension / 3; + let offset = self.dimension / 3; // straight lines. criteria_met += u32::from(x == offset); From 1b9c598bacdd566ac704ba7550cae693f562fe8c Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sat, 27 Aug 2022 11:16:52 -0400 Subject: [PATCH 04/13] Rename faces to is_facing Avoid confusion with faces as a plural nooun, which would normally correspond to polyhedral faces --- common/src/dodeca.rs | 8 ++++---- common/src/graph.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/dodeca.rs b/common/src/dodeca.rs index 8b67c3bc..c51d6a86 100644 --- a/common/src/dodeca.rs +++ b/common/src/dodeca.rs @@ -57,7 +57,7 @@ impl Side { /// Whether `p` is opposite the dodecahedron across the plane containing `self` #[inline] - pub fn faces(self, p: &na::Vector4) -> bool { + pub fn is_facing(self, p: &na::Vector4) -> bool { let r = na::convert::<_, na::RowVector4>(self.reflection().row(3).clone_owned()); (r * p).x < p.w } @@ -324,10 +324,10 @@ mod tests { } #[test] - fn side_faces() { + fn side_is_facing() { for side in Side::iter() { - assert!(!side.faces::(&math::origin())); - assert!(side.faces(&(side.reflection() * math::origin()))); + assert!(!side.is_facing::(&math::origin())); + assert!(side.is_facing(&(side.reflection() * math::origin()))); } } diff --git a/common/src/graph.rs b/common/src/graph.rs index ee7cbc2b..a2936318 100644 --- a/common/src/graph.rs +++ b/common/src/graph.rs @@ -120,7 +120,7 @@ impl Graph { let mut location = original * math::origin(); 'outer: loop { for side in Side::iter() { - if !side.faces(&location) { + if !side.is_facing(&location) { continue; } reference = match self.neighbor(reference, side) { From feace43ed948c93f0febe993fb9e69d8aacc422f Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 7 Aug 2022 15:32:00 -0400 Subject: [PATCH 05/13] Upgrade tracing-subscriber --- common/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/Cargo.toml b/common/Cargo.toml index 7aca1658..9fe7cfff 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -18,7 +18,7 @@ lazy_static = "1.4.0" fxhash = "0.2.1" tracing = "0.1.10" hecs = "0.7.6" -tracing-subscriber = { version = "0.2.5", default-features = false, features = ["env-filter", "smallvec", "fmt", "ansi", "chrono", "parking_lot"] } +tracing-subscriber = { version = "0.3.15", default-features = false, features = ["env-filter", "smallvec", "fmt", "ansi", "time", "parking_lot"] } rand = "0.7.3" rand_pcg = "0.2.1" rand_distr = "0.3.0" From d5c2f604e6294be56e8ced90df8430bf7d1ff0f0 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 7 Aug 2022 15:50:56 -0400 Subject: [PATCH 06/13] Upgrade hecs from 0.7.6 to 0.9.0 --- client/Cargo.toml | 2 +- client/src/graphics/draw.rs | 4 ++-- client/src/sim.rs | 8 ++++---- common/Cargo.toml | 2 +- server/Cargo.toml | 2 +- server/src/sim.rs | 10 +++++----- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index bd0fb882..73e359e5 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -31,7 +31,7 @@ quinn = "0.8.3" futures-util = "0.3.1" rustls = { version = "0.20.6", features = ["dangerous_configuration"] } webpki = "0.21.0" -hecs = "0.7.6" +hecs = "0.9.0" rcgen = { version = "0.9.2", default-features = false } memoffset = "0.6" gltf = { version = "1.0.0", default-features = false, features = ["utils"] } diff --git a/client/src/graphics/draw.rs b/client/src/graphics/draw.rs index abb4fe45..b09c59ad 100644 --- a/client/src/graphics/draw.rs +++ b/client/src/graphics/draw.rs @@ -447,10 +447,10 @@ impl Draw { } let pos = sim .world - .get::(entity) + .get::<&Position>(entity) .expect("positionless entity in graph"); if let Some(character_model) = self.loader.get(self.character_model) { - if let Ok(ch) = sim.world.get::(entity) { + if let Ok(ch) = sim.world.get::<&Character>(entity) { let transform = transform * pos.local * na::Matrix4::new_scaling(params.meters_to_absolute) diff --git a/client/src/sim.rs b/client/src/sim.rs index ec36301c..6941eed5 100644 --- a/client/src/sim.rs +++ b/client/src/sim.rs @@ -152,7 +152,7 @@ impl Sim { for &(id, orientation) in &msg.character_orientations { match self.entity_ids.get(&id) { None => debug!(%id, "character orientation update for unknown entity"), - Some(&entity) => match self.world.get_mut::(entity) { + Some(&entity) => match self.world.get::<&mut Character>(entity) { Ok(mut ch) => { ch.orientation = orientation; } @@ -172,7 +172,7 @@ impl Sim { } match self.entity_ids.get(&id) { None => debug!(%id, "position update for unknown entity"), - Some(&entity) => match self.world.get_mut::(entity) { + Some(&entity) => match self.world.get::<&mut Position>(entity) { Ok(mut pos) => { if pos.node != new_pos.node { self.graph_entities.remove(pos.node, entity); @@ -277,7 +277,7 @@ impl Sim { fn destroy(&mut self, entity: Entity) { let id = *self .world - .get::(entity) + .get::<&EntityId>(entity) .expect("destroyed nonexistent entity"); self.entity_ids.remove(&id); self.destroy_idless(entity); @@ -285,7 +285,7 @@ impl Sim { /// Destroy an entity without an EntityId mapped fn destroy_idless(&mut self, entity: Entity) { - if let Ok(position) = self.world.get::(entity) { + if let Ok(position) = self.world.get::<&Position>(entity) { self.graph_entities.remove(position.node, entity); } self.world diff --git a/common/Cargo.toml b/common/Cargo.toml index 9fe7cfff..c2051de1 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -17,7 +17,7 @@ quinn = "0.8.3" lazy_static = "1.4.0" fxhash = "0.2.1" tracing = "0.1.10" -hecs = "0.7.6" +hecs = "0.9.0" tracing-subscriber = { version = "0.3.15", default-features = false, features = ["env-filter", "smallvec", "fmt", "ansi", "time", "parking_lot"] } rand = "0.7.3" rand_pcg = "0.2.1" diff --git a/server/Cargo.toml b/server/Cargo.toml index 3814eec2..66cbef02 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -20,7 +20,7 @@ anyhow = "1.0.26" rcgen = { version = "0.9.2", default-features = false } hostname = "0.3.0" futures = "0.3.1" -hecs = "0.7.6" +hecs = "0.9.0" rand = { version = "0.7.2", features = [ "small_rng" ] } fxhash = "0.2.1" na = { package = "nalgebra", version = "0.19" } diff --git a/server/src/sim.rs b/server/src/sim.rs index 565a9e0e..23c8dc38 100644 --- a/server/src/sim.rs +++ b/server/src/sim.rs @@ -71,7 +71,7 @@ impl Sim { entity: Entity, command: Command, ) -> Result<(), hecs::ComponentError> { - let mut ch = self.world.get_mut::(entity)?; + let mut ch = self.world.get::<&mut Character>(entity)?; let (direction, speed) = sanitize_motion_input(command.velocity); ch.direction = direction; ch.speed = speed * self.cfg.movement_speed; @@ -80,7 +80,7 @@ impl Sim { } pub fn destroy(&mut self, entity: Entity) { - let id = *self.world.get::(entity).unwrap(); + let id = *self.world.get::<&EntityId>(entity).unwrap(); self.entity_ids.remove(&id); self.world.despawn(entity).unwrap(); self.despawns.push(id); @@ -124,7 +124,7 @@ impl Sim { // Capture state changes for broadcast to clients let mut spawns = Vec::with_capacity(self.spawns.len()); for entity in self.spawns.drain(..) { - let id = *self.world.get::(entity).unwrap(); + let id = *self.world.get::<&EntityId>(entity).unwrap(); spawns.push((id, dump_entity(&self.world, entity))); } if !self.graph.fresh().is_empty() { @@ -185,10 +185,10 @@ enum Empty {} fn dump_entity(world: &hecs::World, entity: Entity) -> Vec { let mut components = Vec::new(); - if let Ok(x) = world.get::(entity) { + if let Ok(x) = world.get::<&Position>(entity) { components.push(Component::Position(*x)); } - if let Ok(x) = world.get::(entity) { + if let Ok(x) = world.get::<&Character>(entity) { components.push(Component::Character(proto::Character { name: x.name.clone(), orientation: x.orientation, From a69714c31fe159c09120eca9fe803bf29d947088 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 7 Aug 2022 16:09:19 -0400 Subject: [PATCH 07/13] Upgrade math libraries --- client/Cargo.toml | 2 +- common/Cargo.toml | 10 +++++----- common/src/dodeca.rs | 2 +- common/src/graph.rs | 2 +- common/src/math.rs | 34 ++++++++++++++++------------------ common/src/plane.rs | 8 ++++---- common/src/worldgen.rs | 8 ++++---- server/Cargo.toml | 4 ++-- 8 files changed, 34 insertions(+), 36 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 73e359e5..bdbd7a6d 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -18,7 +18,7 @@ winit = "0.26.1" ash-window = "0.10.0" directories = "4.0.1" vk-shader-macros = "0.2.5" -na = { package = "nalgebra", version = "0.19" } +na = { package = "nalgebra", version = "0.31.2" } tokio = { version = "1.18.2", features = ["rt-multi-thread", "sync", "macros"] } png = "0.17.5" anyhow = "1.0.26" diff --git a/common/Cargo.toml b/common/Cargo.toml index c2051de1..2eb76972 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -10,7 +10,7 @@ license = "Apache-2.0 OR Zlib" [dependencies] serde = { version = "1.0.104", features = ["derive"] } -na = { package = "nalgebra", version = "0.19", features = ["serde-serialize"] } +na = { package = "nalgebra", version = "0.31.2", features = ["rand", "serde-serialize"] } bincode = "1.2.1" anyhow = "1.0.26" quinn = "0.8.3" @@ -19,9 +19,9 @@ fxhash = "0.2.1" tracing = "0.1.10" hecs = "0.9.0" tracing-subscriber = { version = "0.3.15", default-features = false, features = ["env-filter", "smallvec", "fmt", "ansi", "time", "parking_lot"] } -rand = "0.7.3" -rand_pcg = "0.2.1" -rand_distr = "0.3.0" +rand = "0.8.5" +rand_pcg = "0.3.1" +rand_distr = "0.4.3" [dev-dependencies] -approx = "0.3.2" +approx = "0.5.1" diff --git a/common/src/dodeca.rs b/common/src/dodeca.rs index c51d6a86..732c6851 100644 --- a/common/src/dodeca.rs +++ b/common/src/dodeca.rs @@ -57,7 +57,7 @@ impl Side { /// Whether `p` is opposite the dodecahedron across the plane containing `self` #[inline] - pub fn is_facing(self, p: &na::Vector4) -> bool { + pub fn is_facing(self, p: &na::Vector4) -> bool { let r = na::convert::<_, na::RowVector4>(self.reflection().row(3).clone_owned()); (r * p).x < p.w } diff --git a/common/src/graph.rs b/common/src/graph.rs index a2936318..5a027c8e 100644 --- a/common/src/graph.rs +++ b/common/src/graph.rs @@ -111,7 +111,7 @@ impl Graph { /// Given a `transform` relative to a `reference` node, computes the node /// that it's closest to and the transform that moves it there - pub fn normalize_transform( + pub fn normalize_transform( &self, mut reference: NodeId, original: &na::Matrix4, diff --git a/common/src/math.rs b/common/src/math.rs index 5434e410..2749fc82 100644 --- a/common/src/math.rs +++ b/common/src/math.rs @@ -22,7 +22,7 @@ impl HPoint { } } -impl HPoint { +impl HPoint { pub fn origin() -> Self { Self::new(na::zero(), na::zero(), na::zero()) } @@ -37,18 +37,18 @@ impl HPoint { } /// Point reflection around `p` -pub fn reflect(p: &na::Vector4) -> na::Matrix4 { +pub fn reflect(p: &na::Vector4) -> na::Matrix4 { na::Matrix4::::identity() - (*p * p.transpose() * i31::()) * na::convert::<_, N>(2.0) / mip(p, p) } /// Transform that translates `a` to `b` -pub fn translate(a: &na::Vector4, b: &na::Vector4) -> na::Matrix4 { +pub fn translate(a: &na::Vector4, b: &na::Vector4) -> na::Matrix4 { reflect(&midpoint(a, b)) * reflect(a) } #[rustfmt::skip] -pub fn translate_along(v: &na::Unit>, distance: N) -> na::Matrix4 { +pub fn translate_along(v: &na::Unit>, distance: N) -> na::Matrix4 { if distance == na::zero() { return na::Matrix4::identity(); } @@ -66,23 +66,23 @@ pub fn translate_along(v: &na::Unit>, distance: N) } /// 4D reflection around a normal vector; length is not significant (so long as it's nonzero) -pub fn euclidean_reflect(v: &na::Vector4) -> na::Matrix4 { +pub fn euclidean_reflect(v: &na::Vector4) -> na::Matrix4 { na::Matrix4::identity() - v * v.transpose() * (na::convert::<_, N>(2.0) / v.norm_squared()) } -pub fn midpoint(a: &na::Vector4, b: &na::Vector4) -> na::Vector4 { +pub fn midpoint(a: &na::Vector4, b: &na::Vector4) -> na::Vector4 { a * (mip(b, b) * mip(a, b)).sqrt() + b * (mip(a, a) * mip(a, b)).sqrt() } -pub fn distance(a: &na::Vector4, b: &na::Vector4) -> N { +pub fn distance(a: &na::Vector4, b: &na::Vector4) -> N { (mip(a, b).powi(2) / (mip(a, a) * mip(b, b))).sqrt().acosh() } -pub fn origin() -> na::Vector4 { +pub fn origin() -> na::Vector4 { na::Vector4::new(na::zero(), na::zero(), na::zero(), na::one()) } -pub fn lorentz_normalize(v: &na::Vector4) -> na::Vector4 { +pub fn lorentz_normalize(v: &na::Vector4) -> na::Vector4 { let sf2 = mip(v, v); if sf2 == na::zero() { return origin(); @@ -91,22 +91,20 @@ pub fn lorentz_normalize(v: &na::Vector4) -> na::Vector4 { v / sf } -pub fn renormalize_isometry(m: &na::Matrix4) -> na::Matrix4 { +pub fn renormalize_isometry(m: &na::Matrix4) -> na::Matrix4 { let dest = m.index((.., 3)); let norm = dest.xyz().norm(); let boost_length = (dest.w + norm).ln(); let direction = na::Unit::new_unchecked(dest.xyz() / norm); let inverse_boost = translate_along(&direction, -boost_length); let rotation = renormalize_rotation_reflection( - &(inverse_boost * m) - .fixed_slice::(0, 0) - .clone_owned(), + &(inverse_boost * m).fixed_slice::<3, 3>(0, 0).clone_owned(), ); translate_along(&direction, boost_length) * rotation.to_homogeneous() } #[rustfmt::skip] -fn renormalize_rotation_reflection(m: &na::Matrix3) -> na::Matrix3 { +fn renormalize_rotation_reflection(m: &na::Matrix3) -> na::Matrix3 { let zv = m.index((.., 2)).normalize(); let yv = m.index((.., 1)); let dot = zv.dot(&yv); @@ -120,17 +118,17 @@ fn renormalize_rotation_reflection(m: &na::Matrix3) -> na::Matr } /// Whether an isometry reverses winding with respect to the norm -pub fn parity(m: &na::Matrix4) -> bool { - m.fixed_slice::(0, 0).determinant() < na::zero::() +pub fn parity(m: &na::Matrix4) -> bool { + m.fixed_slice::<3, 3>(0, 0).determinant() < na::zero::() } /// Minkowski inner product, aka _h -pub fn mip(a: &na::Vector4, b: &na::Vector4) -> N { +pub fn mip(a: &na::Vector4, b: &na::Vector4) -> N { a.x * b.x + a.y * b.y + a.z * b.z - a.w * b.w } #[rustfmt::skip] -fn i31() -> na::Matrix4 { +fn i31() -> na::Matrix4 { na::convert::<_, na::Matrix4>(na::Matrix4::::new( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, diff --git a/common/src/plane.rs b/common/src/plane.rs index 49375394..18e2ee2b 100644 --- a/common/src/plane.rs +++ b/common/src/plane.rs @@ -20,7 +20,7 @@ impl From for Plane { } } -impl From>> for Plane { +impl From>> for Plane { /// A plane passing through the origin fn from(x: na::Unit>) -> Self { Self { @@ -29,7 +29,7 @@ impl From>> for Plane { } } -impl Neg for Plane { +impl Neg for Plane { type Output = Self; fn neg(self) -> Self { Self { @@ -46,7 +46,7 @@ impl Mul> for Side { } } -impl<'a, N: na::RealField> Mul> for &'a na::Matrix4 { +impl<'a, N: na::RealField + Copy> Mul> for &'a na::Matrix4 { type Output = Plane; fn mul(self, rhs: Plane) -> Plane { Plane { @@ -55,7 +55,7 @@ impl<'a, N: na::RealField> Mul> for &'a na::Matrix4 { } } -impl Plane { +impl Plane { /// Hyperbolic normal vector identifying the plane pub fn normal(&self) -> &na::Vector4 { &self.normal diff --git a/common/src/worldgen.rs b/common/src/worldgen.rs index 4c8a4696..4ea8d08d 100644 --- a/common/src/worldgen.rs +++ b/common/src/worldgen.rs @@ -552,14 +552,14 @@ fn chunk_incident_enviro_factors( } /// Linearly interpolate at interior and boundary of a cube given values at the eight corners. -fn trilerp( +fn trilerp( &[v000, v001, v010, v011, v100, v101, v110, v111]: &[N; 8], t: na::Vector3, ) -> N { - fn lerp(v0: N, v1: N, t: N) -> N { + fn lerp(v0: N, v1: N, t: N) -> N { v0 * (N::one() - t) + v1 * t } - fn bilerp(v00: N, v01: N, v10: N, v11: N, t: na::Vector2) -> N { + fn bilerp(v00: N, v01: N, v10: N, v11: N, t: na::Vector2) -> N { lerp(lerp(v00, v01, t.x), lerp(v10, v11, t.x), t.y) } @@ -574,7 +574,7 @@ fn trilerp( /// v0 for [0, threshold], v1 for [1-threshold, 1], and linear interpolation in between /// such that the overall shape is an S-shaped piecewise function. /// threshold should be between 0 and 0.5. -fn serp(v0: N, v1: N, t: N, threshold: N) -> N { +fn serp(v0: N, v1: N, t: N, threshold: N) -> N { if t < threshold { v0 } else if t < (N::one() - threshold) { diff --git a/server/Cargo.toml b/server/Cargo.toml index 66cbef02..ac94900c 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -21,9 +21,9 @@ rcgen = { version = "0.9.2", default-features = false } hostname = "0.3.0" futures = "0.3.1" hecs = "0.9.0" -rand = { version = "0.7.2", features = [ "small_rng" ] } +rand = { version = "0.8.5", features = [ "small_rng" ] } fxhash = "0.2.1" -na = { package = "nalgebra", version = "0.19" } +na = { package = "nalgebra", version = "0.31.2" } slotmap = "1.0.6" rustls = "0.20.6" rustls-pemfile = "1.0.0" From 2c92455191e6360c1cbd89f4665c0fb39a528d62 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 7 Aug 2022 17:43:34 -0400 Subject: [PATCH 08/13] Reintroduce debug assertions --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 12def8d9..1f94d986 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = ["client", "server", "common"] [profile.dev] opt-level = 1 +debug-assertions = true [profile.dev.package."*"] opt-level = 2 From 7062086847491fa18357d030b9194f0a444786df Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 7 Aug 2022 18:33:17 -0400 Subject: [PATCH 09/13] Upgrade client side packages other than winit and metrics --- client/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index bdbd7a6d..3939cb08 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -15,7 +15,7 @@ tracing = "0.1.10" ash = { version = "0.37.0", features = ["loaded"] } lahar = { git = "https://github.com/Ralith/lahar", rev = "88abd75e41d04c3a4199d95f581cb135f5962844" } winit = "0.26.1" -ash-window = "0.10.0" +ash-window = "0.11.0" directories = "4.0.1" vk-shader-macros = "0.2.5" na = { package = "nalgebra", version = "0.31.2" } @@ -30,7 +30,7 @@ downcast-rs = "1.1.1" quinn = "0.8.3" futures-util = "0.3.1" rustls = { version = "0.20.6", features = ["dangerous_configuration"] } -webpki = "0.21.0" +webpki = "0.22.0" hecs = "0.9.0" rcgen = { version = "0.9.2", default-features = false } memoffset = "0.6" @@ -44,7 +44,7 @@ default = ["use-repo-assets"] use-repo-assets = [] [dev-dependencies] -approx = "0.3.2" +approx = "0.5.1" bencher = "0.1.5" renderdoc = "0.10.1" From 3d127d16473a65bafee92d041841b4ab8b8d288c Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Fri, 12 Aug 2022 22:27:28 -0400 Subject: [PATCH 10/13] Upgrade metrics crate --- client/Cargo.toml | 3 +- client/src/graphics/draw.rs | 14 ++++--- client/src/graphics/voxels/mod.rs | 8 ++-- client/src/metrics.rs | 66 +++++++++++++++++++++++++------ 4 files changed, 67 insertions(+), 24 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 3939cb08..17a5475d 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -35,8 +35,7 @@ hecs = "0.9.0" rcgen = { version = "0.9.2", default-features = false } memoffset = "0.6" gltf = { version = "1.0.0", default-features = false, features = ["utils"] } -metrics = { version = "0.12.1", features = ["std"] } -metrics-core = "0.5.2" +metrics = { version = "0.20.1" } hdrhistogram = { version = "7", default-features = false } [features] diff --git a/client/src/graphics/draw.rs b/client/src/graphics/draw.rs index b09c59ad..00ccde7a 100644 --- a/client/src/graphics/draw.rs +++ b/client/src/graphics/draw.rs @@ -4,7 +4,7 @@ use std::time::Instant; use ash::vk; use fxhash::FxHashSet; use lahar::Staged; -use metrics::timing; +use metrics::histogram; use super::{fog, voxels, Base, Fog, Frustum, GltfScene, Meshes, Voxels}; use crate::{sim, Asset, Config, Loader, Sim}; @@ -312,10 +312,12 @@ impl Draw { vk::QueryResultFlags::TYPE_64 | vk::QueryResultFlags::WAIT, ) .unwrap(); - let draw_nanos = self.gfx.limits.timestamp_period * (queries[1] - queries[0]) as f32; - let after_nanos = self.gfx.limits.timestamp_period * (queries[2] - queries[1]) as f32; - timing!("frame.gpu.draw", draw_nanos as u64); - timing!("frame.gpu.after_draw", after_nanos as u64); + let draw_seconds = + self.gfx.limits.timestamp_period as f64 * 1e-9 * (queries[1] - queries[0]) as f64; + let after_seconds = + self.gfx.limits.timestamp_period as f64 * 1e-9 * (queries[2] - queries[1]) as f64; + histogram!("frame.gpu.draw", draw_seconds); + histogram!("frame.gpu.after_draw", after_seconds); } device @@ -516,7 +518,7 @@ impl Draw { .unwrap(); state.used = true; state.in_flight = true; - timing!("frame.cpu", draw_started.elapsed()); + histogram!("frame.cpu", draw_started.elapsed()); } /// Wait for all drawing to complete diff --git a/client/src/graphics/voxels/mod.rs b/client/src/graphics/voxels/mod.rs index 417f2d00..b93d8ef3 100644 --- a/client/src/graphics/voxels/mod.rs +++ b/client/src/graphics/voxels/mod.rs @@ -7,7 +7,7 @@ mod tests; use std::{sync::Arc, time::Instant}; use ash::{vk, Device}; -use metrics::timing; +use metrics::histogram; use tracing::warn; use super::draw::nearby_nodes; @@ -120,7 +120,7 @@ impl Voxels { &view, f64::from(self.config.local_simulation.view_distance), ); - timing!( + histogram!( "frame.cpu.voxels.graph_traversal", graph_traversal_started.elapsed() ); @@ -240,7 +240,7 @@ impl Voxels { cmd, &extractions, ); - timing!("frame.cpu.voxels.node_scan", node_scan_started.elapsed()); + histogram!("frame.cpu.voxels.node_scan", node_scan_started.elapsed()); } pub unsafe fn draw( @@ -265,7 +265,7 @@ impl Voxels { for chunk in &frame.drawn { self.draw.draw(device, cmd, &self.surfaces, chunk.0); } - timing!("frame.cpu.voxels.draw", started.elapsed()); + histogram!("frame.cpu.voxels.draw", started.elapsed()); } pub unsafe fn destroy(&mut self, device: &Device) { diff --git a/client/src/metrics.rs b/client/src/metrics.rs index 24631803..a54bd795 100644 --- a/client/src/metrics.rs +++ b/client/src/metrics.rs @@ -5,7 +5,6 @@ use std::{ }; use hdrhistogram::Histogram; -use metrics_core::Key; use tracing::info; pub fn init() -> Arc { @@ -17,11 +16,13 @@ pub fn init() -> Arc { } pub struct Recorder { - histograms: RwLock>>>, + histograms: RwLock>>>, } impl Recorder { pub fn report(&self) { + // metrics crate documentation assures us that Key's interior mutability does not affect the hash code. + #[allow(clippy::mutable_key_type)] let histograms = &*self.histograms.read().unwrap(); for (key, histogram) in histograms { let histogram = histogram.lock().unwrap(); @@ -40,29 +41,70 @@ impl Recorder { struct ArcRecorder(Arc); impl metrics::Recorder for ArcRecorder { - fn increment_counter(&self, _key: Key, _value: u64) { + fn describe_counter( + &self, + _key: metrics::KeyName, + _unit: Option, + _description: metrics::SharedString, + ) { todo!() } - fn update_gauge(&self, _key: Key, _value: i64) { + fn describe_gauge( + &self, + _key: metrics::KeyName, + _unit: Option, + _description: metrics::SharedString, + ) { todo!() } - fn record_histogram(&self, key: Key, value: u64) { - let mut histograms = self.0.histograms.read().unwrap(); - let mut histogram = match histograms.get(&key) { + fn describe_histogram( + &self, + _key: metrics::KeyName, + _unit: Option, + _description: metrics::SharedString, + ) { + todo!() + } + + fn register_counter(&self, _key: &metrics::Key) -> metrics::Counter { + todo!() + } + + fn register_gauge(&self, _key: &metrics::Key) -> metrics::Gauge { + todo!() + } + + fn register_histogram(&self, key: &metrics::Key) -> metrics::Histogram { + metrics::Histogram::from_arc(Arc::new(Handle { + recorder: self.0.clone(), + key: key.clone(), + })) + } +} + +struct Handle { + recorder: Arc, + key: metrics::Key, +} + +impl metrics::HistogramFn for Handle { + fn record(&self, value: f64) { + let mut histograms = self.recorder.histograms.read().unwrap(); + let mut histogram = match histograms.get(&self.key) { Some(x) => x.lock().unwrap(), None => { drop(histograms); - self.0 + self.recorder .histograms .write() .unwrap() - .insert(key.clone(), Mutex::new(Histogram::new(3).unwrap())); - histograms = self.0.histograms.read().unwrap(); - histograms.get(&key).unwrap().lock().unwrap() + .insert(self.key.clone(), Mutex::new(Histogram::new(3).unwrap())); + histograms = self.recorder.histograms.read().unwrap(); + histograms.get(&self.key).unwrap().lock().unwrap() } }; - histogram.record(value).unwrap(); + histogram.record((value * 1e9) as u64).unwrap(); } } From c0aef4b091d29412260841b475caf7b3ed324726 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Mon, 15 Aug 2022 19:02:10 -0400 Subject: [PATCH 11/13] Upgrade winit --- client/Cargo.toml | 2 +- client/src/graphics/window.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 17a5475d..472dc346 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -14,7 +14,7 @@ server = { path = "../server" } tracing = "0.1.10" ash = { version = "0.37.0", features = ["loaded"] } lahar = { git = "https://github.com/Ralith/lahar", rev = "88abd75e41d04c3a4199d95f581cb135f5962844" } -winit = "0.26.1" +winit = "0.27.2" ash-window = "0.11.0" directories = "4.0.1" vk-shader-macros = "0.2.5" diff --git a/client/src/graphics/window.rs b/client/src/graphics/window.rs index 568b47ea..4227b8d8 100644 --- a/client/src/graphics/window.rs +++ b/client/src/graphics/window.rs @@ -11,7 +11,7 @@ use winit::{ DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent, }, event_loop::{ControlFlow, EventLoop}, - window::{Window as WinitWindow, WindowBuilder}, + window::{CursorGrabMode, Window as WinitWindow, WindowBuilder}, }; use super::{Base, Core, Draw, Frustum}; @@ -180,7 +180,10 @@ impl Window { state: ElementState::Pressed, .. } => { - let _ = self.window.set_cursor_grab(true); + let _ = self + .window + .set_cursor_grab(CursorGrabMode::Confined) + .or_else(|_e| self.window.set_cursor_grab(CursorGrabMode::Locked)); self.window.set_cursor_visible(false); mouse_captured = true; } @@ -218,7 +221,7 @@ impl Window { down = state == ElementState::Pressed; } VirtualKeyCode::Escape => { - let _ = self.window.set_cursor_grab(false); + let _ = self.window.set_cursor_grab(CursorGrabMode::None); self.window.set_cursor_visible(true); mouse_captured = false; } @@ -226,7 +229,7 @@ impl Window { }, WindowEvent::Focused(focused) => { if !focused { - let _ = self.window.set_cursor_grab(false); + let _ = self.window.set_cursor_grab(CursorGrabMode::None); self.window.set_cursor_visible(true); mouse_captured = false; } From 3f4a639f1531bf5b6515fe0670d21fc583d79ed9 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sat, 20 Aug 2022 01:54:54 -0400 Subject: [PATCH 12/13] Allow both nalgebra:: and na:: to be used nalgebra's proc macros are unhygenic and hardcode the package name as nalgebra when looking up functions, so using the matrix! and vector! macros require the ability to reference nalgebra with its full name. --- client/Cargo.toml | 2 +- client/src/lib.rs | 1 + common/Cargo.toml | 2 +- common/src/lib.rs | 1 + server/Cargo.toml | 2 +- server/src/lib.rs | 1 + 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 472dc346..dd215653 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -18,7 +18,7 @@ winit = "0.27.2" ash-window = "0.11.0" directories = "4.0.1" vk-shader-macros = "0.2.5" -na = { package = "nalgebra", version = "0.31.2" } +nalgebra = "0.31.2" tokio = { version = "1.18.2", features = ["rt-multi-thread", "sync", "macros"] } png = "0.17.5" anyhow = "1.0.26" diff --git a/client/src/lib.rs b/client/src/lib.rs index aada2c8e..5e81b3ce 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -9,6 +9,7 @@ macro_rules! cstr { }}; } +extern crate nalgebra as na; mod config; pub mod graphics; mod lahar_deprecated; diff --git a/common/Cargo.toml b/common/Cargo.toml index 2eb76972..e72cab4e 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -10,7 +10,7 @@ license = "Apache-2.0 OR Zlib" [dependencies] serde = { version = "1.0.104", features = ["derive"] } -na = { package = "nalgebra", version = "0.31.2", features = ["rand", "serde-serialize"] } +nalgebra = { version = "0.31.2", features = ["rand", "serde-serialize"] } bincode = "1.2.1" anyhow = "1.0.26" quinn = "0.8.3" diff --git a/common/src/lib.rs b/common/src/lib.rs index 003833bd..36307361 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -6,6 +6,7 @@ use rand::{ #[macro_use] mod id; +extern crate nalgebra as na; mod chunks; pub mod codec; pub mod cursor; diff --git a/server/Cargo.toml b/server/Cargo.toml index ac94900c..838a5ddb 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -23,7 +23,7 @@ futures = "0.3.1" hecs = "0.9.0" rand = { version = "0.8.5", features = [ "small_rng" ] } fxhash = "0.2.1" -na = { package = "nalgebra", version = "0.31.2" } +nalgebra = "0.31.2" slotmap = "1.0.6" rustls = "0.20.6" rustls-pemfile = "1.0.0" diff --git a/server/src/lib.rs b/server/src/lib.rs index 2b818e2e..58e61658 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,3 +1,4 @@ +extern crate nalgebra as na; mod input_queue; mod sim; From 0cd762636ecbf655604402f635c969c08a895ff2 Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 9 Oct 2022 16:55:39 -0400 Subject: [PATCH 13/13] Upgrade ash-window and rcgen --- client/Cargo.toml | 5 +++-- client/src/graphics/window.rs | 13 +++++++++++-- server/Cargo.toml | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index dd215653..ffc99e34 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -15,7 +15,8 @@ tracing = "0.1.10" ash = { version = "0.37.0", features = ["loaded"] } lahar = { git = "https://github.com/Ralith/lahar", rev = "88abd75e41d04c3a4199d95f581cb135f5962844" } winit = "0.27.2" -ash-window = "0.11.0" +ash-window = "0.12.0" +raw-window-handle = "0.5.0" directories = "4.0.1" vk-shader-macros = "0.2.5" nalgebra = "0.31.2" @@ -32,7 +33,7 @@ futures-util = "0.3.1" rustls = { version = "0.20.6", features = ["dangerous_configuration"] } webpki = "0.22.0" hecs = "0.9.0" -rcgen = { version = "0.9.2", default-features = false } +rcgen = { version = "0.10.0", default-features = false } memoffset = "0.6" gltf = { version = "1.0.0", default-features = false, features = ["utils"] } metrics = { version = "0.20.1" } diff --git a/client/src/graphics/window.rs b/client/src/graphics/window.rs index 4227b8d8..fb48fc81 100644 --- a/client/src/graphics/window.rs +++ b/client/src/graphics/window.rs @@ -4,6 +4,7 @@ use std::{f32, os::raw::c_char}; use ash::{extensions::khr, vk}; use lahar::DedicatedImage; +use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use tracing::info; use winit::{ dpi::PhysicalSize, @@ -35,7 +36,8 @@ impl EarlyWindow { /// Identify the Vulkan extension needed to render to this window pub fn required_extensions(&self) -> &'static [*const c_char] { - ash_window::enumerate_required_extensions(&self.window).expect("unsupported platform") + ash_window::enumerate_required_extensions(self.event_loop.raw_display_handle()) + .expect("unsupported platform") } } @@ -64,7 +66,14 @@ impl Window { sim: Sim, ) -> Self { let surface = unsafe { - ash_window::create_surface(&core.entry, &core.instance, &early.window, None).unwrap() + ash_window::create_surface( + &core.entry, + &core.instance, + early.window.raw_display_handle(), + early.window.raw_window_handle(), + None, + ) + .unwrap() }; let surface_fn = khr::Surface::new(&core.entry, &core.instance); diff --git a/server/Cargo.toml b/server/Cargo.toml index 838a5ddb..2e8c5be5 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -17,7 +17,7 @@ quinn = { version = "0.8.3", features = ["rustls"] } serde = { version = "1.0.104", features = ["derive", "rc"] } toml = "0.5.5" anyhow = "1.0.26" -rcgen = { version = "0.9.2", default-features = false } +rcgen = { version = "0.10.0", default-features = false } hostname = "0.3.0" futures = "0.3.1" hecs = "0.9.0"