diff --git a/src/chunkmanager.cpp b/src/chunkmanager.cpp index 6eedb5f..241ac9a 100644 --- a/src/chunkmanager.cpp +++ b/src/chunkmanager.cpp @@ -12,7 +12,7 @@ #include #include -std::unordered_map chunks; +std::unordered_map chunks; namespace chunkmanager { @@ -88,21 +88,21 @@ namespace chunkmanager // std::cout << "Checking" << i << ", " << j << ", " << k <chunk); - chunks.at(index)->mesh(); + chunks.insert(std::make_pair(index, ChunkMesh(new Chunk::Chunk(glm::vec3(i, j, k))))); + generateChunk(chunks.at(index).chunk); + chunks.at(index).mesh(); // std::cout << "Creating new chunk" << i << ", " << j << ", " << k <chunk->getPosition() /*+ glm::vec3(static_cast(CHUNK_SIZE))*/; + glm::vec3 chunk = chunks.at(index).chunk->getPosition() /*+ glm::vec3(static_cast(CHUNK_SIZE))*/; total++; int a{0}; for (int i = 0; i < 8; i++) { - glm::vec4 vertex = glm::vec4(chunk.x + (float)(i & 1), chunk.y + (float)((i & 2) >> 1), chunk.z + (float)((i & 4) >> 2), 500.0f) * (theCamera.getProjection() * theCamera.getView() * chunks.at(index)->model); + glm::vec4 vertex = glm::vec4(chunk.x + (float)(i & 1), chunk.y + (float)((i & 2) >> 1), chunk.z + (float)((i & 4) >> 2), 500.0f) * (theCamera.getProjection() * theCamera.getView() * chunks.at(index).model); vertex = glm::normalize(vertex); a += (-vertex.w <= vertex.x && vertex.x <= vertex.w && -vertex.w <= vertex.y && vertex.y <= vertex.w /*&& -vertex.w < vertex.z && vertex.z < vertex.w*/); @@ -110,14 +110,14 @@ namespace chunkmanager if (a) { toGpu++; - chunks.at(index)->draw(); + chunks.at(index).draw(); } } } void destroy() { - for (auto &n : chunks) - delete n.second; + // for (auto &n : chunks) + // delete n.second; } }; \ No newline at end of file diff --git a/src/chunkmesh.cpp b/src/chunkmesh.cpp index b83907f..259ef0d 100755 --- a/src/chunkmesh.cpp +++ b/src/chunkmesh.cpp @@ -10,13 +10,13 @@ ChunkMesh::~ChunkMesh() { - if(this->VAO) glDeleteVertexArrays(1, &(this->VAO)); - if(this->EBO) glDeleteBuffers(1, &(this->EBO)); - if(this->VBO) glDeleteBuffers(1, &(this->VBO)); - if(this->colorBuffer) glDeleteBuffers(1, &(this->colorBuffer)); + // if(this->VAO) glDeleteVertexArrays(1, &(this->VAO)); + // if(this->EBO) glDeleteBuffers(1, &(this->EBO)); + // if(this->VBO) glDeleteBuffers(1, &(this->VBO)); + // if(this->colorBuffer) glDeleteBuffers(1, &(this->colorBuffer)); - delete this->chunk; - } + // if(this->chunk) delete this->chunk; +} ChunkMesh::ChunkMesh(Chunk::Chunk *c) {