This commit is contained in:
griffi-gh 2023-01-16 20:36:39 +01:00
parent 77f388dd75
commit 2c86971d18
2 changed files with 9 additions and 15 deletions

View file

@ -9,15 +9,7 @@ pub const CHUNK_SIZE: usize = 16;
pub const CHUNK_HEIGHT: usize = 255;
pub enum ChunkState {
AwaitsLoading,
Loaded,
AwaitsMesh,
Rendered,
AwaitsUnload
}
pub enum DesiredState {
Unloaded,
Nothing,
Loaded,
Rendered,
}
@ -30,7 +22,7 @@ pub struct Chunk {
pub block_data: Option<ChunkData>,
pub vertex_buffer: Option<ChunkMesh>,
pub state: ChunkState,
pub desired: DesiredState,
pub desired: ChunkState,
}
impl Chunk {
pub fn new(position: IVec2) -> Self {
@ -38,8 +30,8 @@ impl Chunk {
position,
block_data: None,
vertex_buffer: None,
state: ChunkState::AwaitsLoading,
desired: DesiredState::Loaded,
state: ChunkState::Nothing,
desired: ChunkState::Nothing,
}
}
}

View file

@ -4,7 +4,7 @@ use std::{
collections::HashMap,
mem
};
use super::chunk::{ChunkData, Chunk, DesiredState};
use super::chunk::{Chunk, ChunkData, ChunkState};
mod world_gen;
mod mesh_gen;
@ -38,7 +38,7 @@ impl WorldThreading {
log::warn!("load: discarded {}, reason: chunk no longer exists", position);
return false
}
if !matches!(chunks.get(position).unwrap().desired, DesiredState::Loaded | DesiredState::Rendered) {
if !matches!(chunks.get(position).unwrap().desired, ChunkState::Loaded | ChunkState::Rendered) {
log::warn!("load: discarded {}, reason: state undesired", position);
return false
}
@ -49,7 +49,9 @@ impl WorldThreading {
log::info!("load: done {}", position);
let handle = mem::take(handle).unwrap();
let data = handle.join().unwrap();
chunks.get_mut(position).unwrap().block_data = Some(data);
let chunk = chunks.get_mut(position).unwrap();
chunk.block_data = Some(data);
chunk.state = ChunkState::Loaded;
false
});
}