chunkmanager: chunkmesh on the stack
parent
9f82a17bd2
commit
ec2feb919f
|
@ -12,7 +12,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
std::unordered_map<std::uint32_t, ChunkMesh *> chunks;
|
std::unordered_map<std::uint32_t, ChunkMesh> chunks;
|
||||||
|
|
||||||
namespace chunkmanager
|
namespace chunkmanager
|
||||||
{
|
{
|
||||||
|
@ -88,21 +88,21 @@ namespace chunkmanager
|
||||||
// std::cout << "Checking" << i << ", " << j << ", " << k <<std::endl;
|
// std::cout << "Checking" << i << ", " << j << ", " << k <<std::endl;
|
||||||
if (chunks.find(index) == chunks.end())
|
if (chunks.find(index) == chunks.end())
|
||||||
{
|
{
|
||||||
chunks.insert(std::make_pair(index, new ChunkMesh(new Chunk::Chunk(glm::vec3(i, j, k)))));
|
chunks.insert(std::make_pair(index, ChunkMesh(new Chunk::Chunk(glm::vec3(i, j, k)))));
|
||||||
generateChunk(chunks.at(index)->chunk);
|
generateChunk(chunks.at(index).chunk);
|
||||||
chunks.at(index)->mesh();
|
chunks.at(index).mesh();
|
||||||
// std::cout << "Creating new chunk" << i << ", " << j << ", " << k <<std::endl;
|
// std::cout << "Creating new chunk" << i << ", " << j << ", " << k <<std::endl;
|
||||||
}
|
}
|
||||||
else
|
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++;
|
total++;
|
||||||
|
|
||||||
int a{0};
|
int a{0};
|
||||||
for (int i = 0; i < 8; i++)
|
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);
|
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*/);
|
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)
|
if (a)
|
||||||
{
|
{
|
||||||
toGpu++;
|
toGpu++;
|
||||||
chunks.at(index)->draw();
|
chunks.at(index).draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy()
|
void destroy()
|
||||||
{
|
{
|
||||||
for (auto &n : chunks)
|
// for (auto &n : chunks)
|
||||||
delete n.second;
|
// delete n.second;
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -10,12 +10,12 @@
|
||||||
|
|
||||||
ChunkMesh::~ChunkMesh()
|
ChunkMesh::~ChunkMesh()
|
||||||
{
|
{
|
||||||
if(this->VAO) glDeleteVertexArrays(1, &(this->VAO));
|
// if(this->VAO) glDeleteVertexArrays(1, &(this->VAO));
|
||||||
if(this->EBO) glDeleteBuffers(1, &(this->EBO));
|
// if(this->EBO) glDeleteBuffers(1, &(this->EBO));
|
||||||
if(this->VBO) glDeleteBuffers(1, &(this->VBO));
|
// if(this->VBO) glDeleteBuffers(1, &(this->VBO));
|
||||||
if(this->colorBuffer) glDeleteBuffers(1, &(this->colorBuffer));
|
// if(this->colorBuffer) glDeleteBuffers(1, &(this->colorBuffer));
|
||||||
|
|
||||||
delete this->chunk;
|
// if(this->chunk) delete this->chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunkMesh::ChunkMesh(Chunk::Chunk *c)
|
ChunkMesh::ChunkMesh(Chunk::Chunk *c)
|
||||||
|
|
Loading…
Reference in New Issue