mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
start fixing chunk rendering, noticed stack overflow crash
Former-commit-id: 334904276580cd78f5d5e3bf010a86fcd822cfdf
This commit is contained in:
parent
592477752e
commit
f600eca072
@ -36,7 +36,7 @@ impl<V: Vox + Clone, S: VolSize + Clone, M: Clone> VolMap<V, S, M> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn chunk_offs(pos: Vec3<i32>) -> Vec3<i32> {
|
||||
pub fn chunk_offs(pos: Vec3<i32>) -> Vec3<i32> {
|
||||
pos.map2(S::SIZE, |e, sz| e.rem_euclid(sz as i32))
|
||||
}
|
||||
}
|
||||
@ -121,12 +121,11 @@ impl<V: Vox + Clone, S: VolSize + Clone, M: Clone> SampleVol for VolMap<V, S, M>
|
||||
for z in chunk_min.z..=chunk_max.z {
|
||||
let chunk_key = Vec3::new(x, y, z);
|
||||
|
||||
let chunk = self
|
||||
.get_key(chunk_key)
|
||||
.map(|v| v.clone())
|
||||
.ok_or(VolMapErr::NoSuchChunk)?;
|
||||
let chunk = self.get_key_arc(chunk_key).map(|v| v.clone());
|
||||
|
||||
sample.insert(chunk_key, Arc::new(chunk));
|
||||
if let Some(chunk) = chunk {
|
||||
sample.insert(chunk_key, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -177,6 +176,10 @@ impl<V: Vox + Clone, S: VolSize + Clone, M: Clone> VolMap<V, S, M> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_key_arc(&self, key: Vec3<i32>) -> Option<&Arc<Chunk<V, S, M>>> {
|
||||
self.chunks.get(&key)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, key: Vec3<i32>) -> Option<Arc<Chunk<V, S, M>>> {
|
||||
self.chunks.remove(&key)
|
||||
}
|
||||
|
@ -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 1..(size.x - 1) {
|
||||
for y in 1..(size.y - 1) {
|
||||
for z in 1..(size.z - 1) {
|
||||
for x in 0..size.x {
|
||||
for y in 0..size.y {
|
||||
for z in 0..size.z {
|
||||
let pos = Vec3::new(x, y, z);
|
||||
|
||||
let new_chunk_pos = self.pos_key(range.min + pos);
|
||||
@ -66,15 +66,42 @@ impl<S: VolSize + Clone, M: Clone> Meshable for VolMap<Block, S, M> {
|
||||
last_chunk_pos = new_chunk_pos;
|
||||
}
|
||||
let offs = pos.map(|e| e as f32 - 1.0);
|
||||
if let Some(col) = self.get(pos).ok().and_then(|vox| vox.get_color()) {
|
||||
let col = col.map(|e| e as f32 / 255.0);
|
||||
if let Some(chunk) = last_chunk {
|
||||
let chunk_pos = Self::chunk_offs(range.min + pos);
|
||||
if let Some(col) = chunk.get(chunk_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,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if let Some(col) = self
|
||||
.get(range.min + 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mesh
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user