mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'master' into 'master'
Massively increased efficiency of terrain meshing, chunks generate from centre See merge request veloren/veloren!133 Former-commit-id: 71c0903b7e037fd087c06613e992cd77fc2d3f96
This commit is contained in:
commit
d56a47c0bb
@ -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 {
|
||||
// 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)
|
||||
&& self.pending_chunks.len() < 4
|
||||
{
|
||||
if self.pending_chunks.len() < 4 {
|
||||
self.postbox
|
||||
.send_message(ClientMsg::TerrainChunkRequest { key });
|
||||
self.pending_chunks.insert(key);
|
||||
} else {
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -37,6 +37,7 @@ impl Meshable for Segment {
|
||||
offs + pos.map(|e| e as f32),
|
||||
col,
|
||||
create_vertex,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ impl<M> Meshable for Dyna<Block, M> {
|
||||
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<S: VolSize + Clone, M: Clone> Meshable for VolMap<Block, S, M> {
|
||||
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<S: VolSize + Clone, M: Clone> Meshable for VolMap<Block, S, M> {
|
||||
offs,
|
||||
col,
|
||||
TerrainVertex::new,
|
||||
false,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@ -96,6 +97,7 @@ impl<S: VolSize + Clone, M: Clone> Meshable for VolMap<Block, S, M> {
|
||||
offs,
|
||||
col,
|
||||
TerrainVertex::new,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ pub fn push_vox_verts<
|
||||
offs: Vec3<f32>,
|
||||
col: Rgb<f32>,
|
||||
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(),
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user