From 2c86971d18f2996971bc937dcdc536fb1d99c73c Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 16 Jan 2023 20:36:39 +0100 Subject: [PATCH] uwu --- src/game/world/chunk.rs | 16 ++++------------ src/game/world/thread.rs | 8 +++++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/game/world/chunk.rs b/src/game/world/chunk.rs index 8910d71..1830b61 100644 --- a/src/game/world/chunk.rs +++ b/src/game/world/chunk.rs @@ -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, pub vertex_buffer: Option, 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, } } } diff --git a/src/game/world/thread.rs b/src/game/world/thread.rs index 3cba978..0b01299 100644 --- a/src/game/world/thread.rs +++ b/src/game/world/thread.rs @@ -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 }); }