mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-24 04:48:21 -06:00
wip block queue
This commit is contained in:
parent
5914d10498
commit
f05e221658
|
@ -13,6 +13,7 @@ pub mod loading;
|
||||||
pub mod mesh;
|
pub mod mesh;
|
||||||
pub mod neighbors;
|
pub mod neighbors;
|
||||||
pub mod raycast;
|
pub mod raycast;
|
||||||
|
pub mod queue;
|
||||||
|
|
||||||
use chunk::{Chunk, ChunkMesh};
|
use chunk::{Chunk, ChunkMesh};
|
||||||
use tasks::ChunkTaskManager;
|
use tasks::ChunkTaskManager;
|
||||||
|
|
45
kubi/src/world/queue.rs
Normal file
45
kubi/src/world/queue.rs
Normal file
|
@ -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<BlockUpdateEvent>
|
||||||
|
}
|
||||||
|
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<BlockUpdateEvent> {
|
||||||
|
self.queue.pop_front()
|
||||||
|
}
|
||||||
|
pub fn clear(&mut self) {
|
||||||
|
self.queue.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply_events(
|
||||||
|
mut queue: UniqueViewMut<BlockUpdateQueue>,
|
||||||
|
mut world: UniqueViewMut<ChunkStorage>
|
||||||
|
) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue