From 38c48317f752813d9a456af4cf4eec0b8a2f4da7 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 19 Jan 2020 18:14:07 -0500 Subject: [PATCH 1/2] Fix lighting calc bug, lower meshing bench sample size --- voxygen/benches/meshing_benchmark.rs | 2 ++ voxygen/src/mesh/terrain.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/voxygen/benches/meshing_benchmark.rs b/voxygen/benches/meshing_benchmark.rs index 4025e9f031..50454d5171 100644 --- a/voxygen/benches/meshing_benchmark.rs +++ b/voxygen/benches/meshing_benchmark.rs @@ -12,6 +12,8 @@ const CENTER: Vec2 = Vec2 { x: 512, y: 512 }; const GEN_SIZE: i32 = 4; pub fn criterion_benchmark(c: &mut Criterion) { + // Lower sample size to save time + c = c.sample_size(15); // Generate chunks here to test let mut terrain = TerrainGrid::new().unwrap(); let world = World::generate(42); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index d98c27dd2c..1594209ad7 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -64,7 +64,7 @@ fn calc_light + ReadVol + Debug>( .map_or(false, |b| b.is_air()) { light_map[lm_idx(x, y, z - 1)] = SUNLIGHT; - prop_que.push_back(Vec3::new(x as u8, y as u8, z as u8)); + prop_que.push_back((x as u8, y as u8, z as u16)); } SUNLIGHT } else { @@ -89,7 +89,7 @@ fn calc_light + ReadVol + Debug>( *dest = src - 1; // Can't propagate further if *dest > 1 { - prop_que.push_back(Vec3::new(pos.x as u8, pos.y as u8, pos.z as u8)); + prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16)); } } else { *dest = OPAQUE; @@ -98,7 +98,7 @@ fn calc_light + ReadVol + Debug>( *dest = src - 1; // Can't propagate further if *dest > 1 { - prop_que.push_back(Vec3::new(pos.x as u8, pos.y as u8, pos.z as u8)); + prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16)); } } } @@ -106,7 +106,7 @@ fn calc_light + ReadVol + Debug>( // Propage light while let Some(pos) = prop_que.pop_front() { - let pos = pos.map(|e| e as i32); + let pos = Vec3::new(pos.0 as i32, pos.1 as i32, pos.2 as i32); let light = light_map[lm_idx(pos.x, pos.y, pos.z)]; // If ray propagate downwards at full strength @@ -119,10 +119,10 @@ fn calc_light + ReadVol + Debug>( .ok() .map_or((false, false), |b| (b.is_air(), b.is_fluid())); light_map[lm_idx(pos.x, pos.y, pos.z)] = if is_air { - prop_que.push_back(Vec3::new(pos.x as u8, pos.y as u8, pos.z as u8)); + prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16)); SUNLIGHT } else if is_fluid { - prop_que.push_back(Vec3::new(pos.x as u8, pos.y as u8, pos.z as u8)); + prop_que.push_back((pos.x as u8, pos.y as u8, pos.z as u16)); SUNLIGHT - 1 } else { OPAQUE From 63d74eb8baac0e1688490c63885ec98e685fc306 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 2 Jan 2020 23:23:38 -0500 Subject: [PATCH 2/2] Don't panic if a region can't be found for a deleted entity --- server/src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 7a7f85eeed..bc49da988f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -32,7 +32,7 @@ use common::{ terrain::{block::Block, TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize, Vox}, }; -use log::{debug, error}; +use log::{debug, error, warn}; use metrics::ServerMetrics; use rand::Rng; use specs::{ @@ -1221,14 +1221,20 @@ impl StateExt for State { let res = self.ecs_mut().delete_entity(entity); if res.is_ok() { if let (Some(uid), Some(pos)) = (maybe_uid, maybe_pos) { - let region_key = self + if let Some(region_key) = self .ecs() .read_resource::() .find_region(entity, pos.0) - .expect("Failed to find region containing entity during entity deletion"); - self.ecs() - .write_resource::() - .record_deleted_entity(uid, region_key); + { + self.ecs() + .write_resource::() + .record_deleted_entity(uid, region_key); + } else { + // Don't panic if the entity wasn't found in a region maybe it was just created + // and then deleted before the region manager had a chance to assign it a + // region + warn!("Failed to find region containing entity during entity deletion, assuming it wasn't sent to any clients and so deletion doesn't need to be recorded for sync purposes"); + } } } res