diff --git a/client/src/lib.rs b/client/src/lib.rs index 2d73602fc3..a4cd2cb0f4 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -212,17 +212,23 @@ impl Client { } // Request chunks from the server - for i in chunk_pos.x - 4..chunk_pos.x + 5 { - for j in chunk_pos.y - 4..chunk_pos.y + 5 { - for k in 0..2 { - let key = Vec3::new(i, j, k); - if self.state.terrain().get_key(key).is_none() - && !self.pending_chunks.contains(&key) - && self.pending_chunks.len() < 4 - { - self.postbox - .send_message(ClientMsg::TerrainChunkRequest { key }); - self.pending_chunks.insert(key); + // TODO: This is really not very efficient + 'outer: for dist in 0..9 { + for i in chunk_pos.x - dist..chunk_pos.x + dist + 1 { + for j in chunk_pos.y - dist..chunk_pos.y + dist + 1 { + for k in 0..3 { + let key = Vec3::new(i, j, k); + if self.state.terrain().get_key(key).is_none() + && !self.pending_chunks.contains(&key) + { + if self.pending_chunks.len() < 4 { + self.postbox + .send_message(ClientMsg::TerrainChunkRequest { key }); + self.pending_chunks.insert(key); + } else { + break 'outer; + } + } } } } diff --git a/server/src/lib.rs b/server/src/lib.rs index f25962deb5..1430a7f5e1 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -205,7 +205,7 @@ impl Server { .map(|e: i32| e.abs()) .reduce_max(); - if dist < 7 { + if dist < 10 { self.clients.notify( entity, ServerMsg::TerrainChunkUpdate { @@ -239,7 +239,7 @@ impl Server { min_dist = min_dist.min(dist); } - if min_dist > 7 { + if min_dist > 10 { chunks_to_remove.push(key); } }); diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 620adcfc30..7422c98c71 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -37,6 +37,7 @@ impl Meshable for Segment { offs + pos.map(|e| e as f32), col, create_vertex, + true, ); } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index ff6272e856..69a443404b 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -36,7 +36,7 @@ impl Meshable for Dyna { if let Some(col) = self.get(pos).ok().and_then(|vox| vox.get_color()) { let col = col.map(|e| e as f32 / 255.0); - vol::push_vox_verts(&mut mesh, self, pos, offs, col, TerrainVertex::new); + vol::push_vox_verts(&mut mesh, self, pos, offs, col, TerrainVertex::new, true); } } @@ -55,9 +55,9 @@ impl Meshable for VolMap { let mut last_chunk = self.get_key(last_chunk_pos); let size = range.max - range.min; - for x in 0..size.x { - for y in 0..size.y { - for z in 0..size.z { + for x in 1..size.x - 1 { + for y in 1..size.y - 1 { + for z in 1..size.z - 1 { let pos = Vec3::new(x, y, z); let new_chunk_pos = self.pos_key(range.min + pos); @@ -79,6 +79,7 @@ impl Meshable for VolMap { offs, col, TerrainVertex::new, + false, ); } } else { @@ -96,6 +97,7 @@ impl Meshable for VolMap { offs, col, TerrainVertex::new, + false, ); } } diff --git a/voxygen/src/mesh/vol.rs b/voxygen/src/mesh/vol.rs index d78dd231af..6e318cd88c 100644 --- a/voxygen/src/mesh/vol.rs +++ b/voxygen/src/mesh/vol.rs @@ -81,6 +81,7 @@ pub fn push_vox_verts< offs: Vec3, col: Rgb, vcons: F, + error_makes_face: bool, ) { let (x, y, z) = (Vec3::unit_x(), Vec3::unit_y(), Vec3::unit_z()); @@ -88,7 +89,7 @@ pub fn push_vox_verts< if vol .get(pos - Vec3::unit_x()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs, @@ -104,7 +105,7 @@ pub fn push_vox_verts< if vol .get(pos + Vec3::unit_x()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs + Vec3::unit_x(), @@ -120,7 +121,7 @@ pub fn push_vox_verts< if vol .get(pos - Vec3::unit_y()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs, @@ -136,7 +137,7 @@ pub fn push_vox_verts< if vol .get(pos + Vec3::unit_y()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs + Vec3::unit_y(), @@ -152,7 +153,7 @@ pub fn push_vox_verts< if vol .get(pos - Vec3::unit_z()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs, @@ -168,7 +169,7 @@ pub fn push_vox_verts< if vol .get(pos + Vec3::unit_z()) .map(|v| v.is_empty()) - .unwrap_or(true) + .unwrap_or(error_makes_face) { mesh.push_quad(create_quad( offs + Vec3::unit_z(), diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index f15d730d72..2a53e879b9 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -93,9 +93,19 @@ impl Terrain { for k in -1..2 { let pos = pos + Vec3::new(i, j, k); - if client.state().terrain().get_key(pos).is_some() { - // re-mesh loaded chunks that border new/changed chunks - if self.chunks.contains_key(&pos) || (i, j, k) == (0, 0, 0) { + if !self.chunks.contains_key(&pos) { + let mut neighbours = true; + for i in -1..2 { + for j in -1..2 { + neighbours &= client + .state() + .terrain() + .get_key(pos + Vec2::new(i, j)) + .is_some(); + } + } + + if neighbours { self.mesh_todo.entry(pos).or_insert(ChunkMeshState { pos, started_tick: current_tick,