From f05e221658fcea7f23fbb7afbb63162db8479c4b Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sun, 5 Feb 2023 00:42:37 +0100 Subject: [PATCH] wip block queue --- kubi/src/world.rs | 1 + kubi/src/world/queue.rs | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 kubi/src/world/queue.rs diff --git a/kubi/src/world.rs b/kubi/src/world.rs index 518fee7..355d33b 100644 --- a/kubi/src/world.rs +++ b/kubi/src/world.rs @@ -13,6 +13,7 @@ pub mod loading; pub mod mesh; pub mod neighbors; pub mod raycast; +pub mod queue; use chunk::{Chunk, ChunkMesh}; use tasks::ChunkTaskManager; diff --git a/kubi/src/world/queue.rs b/kubi/src/world/queue.rs new file mode 100644 index 0000000..31c9f79 --- /dev/null +++ b/kubi/src/world/queue.rs @@ -0,0 +1,45 @@ +use std::collections::VecDeque; +use glam::IVec3; +use kubi_shared::blocks::Block; +use shipyard::{UniqueViewMut, Unique}; + +use super::ChunkStorage; + +#[derive(Clone, Copy, Debug)] +pub struct BlockUpdateEvent { + pub position: IVec3, + pub value: Block +} + +#[derive(Unique, Default, Clone)] +pub struct BlockUpdateQueue { + queue: VecDeque +} +impl BlockUpdateQueue { + pub fn new() -> Self { + Self::default() + } + pub fn push(&mut self, event: BlockUpdateEvent) { + self.queue.push_back(event) + } + pub fn pop(&mut self) -> Option { + self.queue.pop_front() + } + pub fn clear(&mut self) { + self.queue.clear(); + } +} + +pub fn apply_events( + mut queue: UniqueViewMut, + mut world: UniqueViewMut +) { + while let Some(event) = queue.pop() { + if let Some(block) = world.get_block_mut(event.position) { + let (chunk_pos, _) = ChunkStorage::to_chunk_coords(event.position); + let chunk = world.chunks.get_mut(&chunk_pos).expect("This error should never happen, if it does then something is super fucked up and the whole project needs to be burnt down."); + chunk.dirty = true; + } + + } +}