From 4e7fadd2b9f5be2a750bc48a7ab983022ee39f5c Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Wed, 4 Oct 2023 11:23:38 +0200 Subject: [PATCH] chunk: use chunk state to mark presence of chunk in thread communication queues --- include/chunk.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/chunk.hpp b/include/chunk.hpp index 81339a3..19a9dc6 100644 --- a/include/chunk.hpp +++ b/include/chunk.hpp @@ -38,6 +38,9 @@ namespace Chunk constexpr chunk_state_t CHUNK_STATE_OUTOFVISION = 16; constexpr chunk_state_t CHUNK_STATE_UNLOADED = 32; constexpr chunk_state_t CHUNK_STATE_EMPTY = 64; + constexpr chunk_state_t CHUNK_STATE_IN_GENERATION_QUEUE = 128; + constexpr chunk_state_t CHUNK_STATE_IN_MESHING_QUEUE = 256; + constexpr chunk_state_t CHUNK_STATE_IN_DELETING_QUEUE = 512; int coord3DTo1D(int x, int y, int z); @@ -53,9 +56,14 @@ namespace Chunk void deleteBuffers(); glm::vec3 getPosition() { return this->position; } - chunk_state_t getTotalState() { return this->state; } - bool getState(chunk_state_t n) { return (this->state & n) == n; } void setState(chunk_state_t nstate, bool value); + bool getState(chunk_state_t n) { return (this->state & n) == n; } + bool isFree(){ return !( + this->getState(CHUNK_STATE_IN_GENERATION_QUEUE) || + this->getState(CHUNK_STATE_IN_MESHING_QUEUE) || + this->getState(CHUNK_STATE_IN_DELETING_QUEUE) + ); } + chunk_state_t getTotalState() { return this->state; } void setBlock(Block b, int x, int y, int z); void setBlocks(int start, int end, Block b);