chunkmanager: chunkmesh on the stack
parent
9f82a17bd2
commit
ec2feb919f
|
@ -12,7 +12,7 @@
|
|||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
std::unordered_map<std::uint32_t, ChunkMesh *> chunks;
|
||||
std::unordered_map<std::uint32_t, ChunkMesh> chunks;
|
||||
|
||||
namespace chunkmanager
|
||||
{
|
||||
|
@ -88,21 +88,21 @@ namespace chunkmanager
|
|||
// std::cout << "Checking" << i << ", " << j << ", " << k <<std::endl;
|
||||
if (chunks.find(index) == chunks.end())
|
||||
{
|
||||
chunks.insert(std::make_pair(index, new ChunkMesh(new Chunk::Chunk(glm::vec3(i, j, k)))));
|
||||
generateChunk(chunks.at(index)->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 <<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
glm::vec3 chunk = chunks.at(index)->chunk->getPosition() /*+ glm::vec3(static_cast<float>(CHUNK_SIZE))*/;
|
||||
glm::vec3 chunk = chunks.at(index).chunk->getPosition() /*+ glm::vec3(static_cast<float>(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;
|
||||
}
|
||||
};
|
|
@ -10,12 +10,12 @@
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue