diff --git a/include/chunk.hpp b/include/chunk.hpp index 1be54e2..67ca681 100644 --- a/include/chunk.hpp +++ b/include/chunk.hpp @@ -33,6 +33,8 @@ namespace Chunk constexpr uint16_t CHUNK_STATE_IN_DELETING_QUEUE = 128; int coord3DTo1D(int x, int y, int z); + int32_t calculateIndex(int16_t x, int16_t y, int16_t z); + int32_t calculateIndex(glm::vec3 pos); class Chunk { @@ -59,8 +61,9 @@ namespace Chunk public: GLuint VAO{0}, VBO{0}, extentsBuffer{0}, texinfoBuffer{0}, numVertices{0}; - int32_t getIndex(){ return index; } std::atomic unload_timer{0}; + // uint32_t is fine, since i'm limiting the coordinate to only use up to ten bits (1023). There's actually two spare bits + int32_t getIndex(){ return index; } private: glm::vec3 position{}; diff --git a/include/chunkmanager.hpp b/include/chunkmanager.hpp index c7b26f8..aa1bf3a 100644 --- a/include/chunkmanager.hpp +++ b/include/chunkmanager.hpp @@ -36,9 +36,6 @@ namespace chunkmanager void init(); void blockpick(bool place); - int32_t calculateIndex(int16_t i, int16_t j, int16_t k); - int32_t calculateIndex(Chunk::Chunk* c); - int32_t calculateIndex(glm::vec3 position); void stop(); void destroy(); diff --git a/src/chunk.cpp b/src/chunk.cpp index bdf6940..b701b76 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -15,16 +15,20 @@ namespace Chunk return utils::coord3DTo1D(x, y, z, CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE); } + int32_t calculateIndex(glm::vec3 pos){ + return calculateIndex(static_cast(pos.x), static_cast(pos.y), + static_cast(pos.z)); + } + int32_t calculateIndex(int16_t x, int16_t y, int16_t z){ + return x | (y << 10) | (z << 20); + } + Chunk::Chunk(glm::vec3 pos) { this->position = pos; this->setState(CHUNK_STATE_EMPTY, true); this->setBlocks(0, CHUNK_MAX_INDEX, Block::AIR); - - int16_t i = static_cast(pos.x); - int16_t j = static_cast(pos.y); - int16_t k = static_cast(pos.z); - index = i | (j << 10) | (k << 20); + this->index = calculateIndex(pos); } Block Chunk::getBlock(int x, int y, int z) diff --git a/src/chunkmanager.cpp b/src/chunkmanager.cpp index e951d4e..4a1e8cf 100644 --- a/src/chunkmanager.cpp +++ b/src/chunkmanager.cpp @@ -122,7 +122,7 @@ namespace chunkmanager if(x < 0 || y < 0 || z < 0 || x > 1023 || y > 1023 || z > 1023) continue; nExplored++; - const int32_t index = calculateIndex(x, y, z); + const int32_t index = Chunk::calculateIndex(x, y, z); ChunkTable::accessor a; if(!chunks.find(a, index)) chunks.emplace(a, std::make_pair(index, new Chunk::Chunk(glm::vec3(x,y,z)))); @@ -214,18 +214,6 @@ namespace chunkmanager } } - // uint32_t is fine, since i'm limiting the coordinate to only use up to ten bits (1023). There's actually two spare bits - int32_t calculateIndex(Chunk::Chunk* c){ - return calculateIndex(c->getPosition()); - } - int32_t calculateIndex(glm::vec3 position){ - return calculateIndex(static_cast(position.x), static_cast(position.y), - static_cast(position.z)); - } - int32_t calculateIndex(int16_t i, int16_t j, int16_t k){ - return i | (j << 10) | (k << 20); - } - std::array, chunks_volume>& getChunksIndices(){ return chunks_indices; } void stop() {