chunkmgr: avoid call of chunkmesh default ctor

intervalmaps-array-y
EmaMaker 2022-11-11 19:16:04 +01:00 committed by emamaker
parent 93adf73777
commit a5ddb0e37f
3 changed files with 11 additions and 16 deletions

View File

@ -13,7 +13,6 @@ class ChunkMesh
{ {
public: public:
ChunkMesh();
ChunkMesh(Chunk::Chunk *c); ChunkMesh(Chunk::Chunk *c);
void mesh(); void mesh();
void draw(); void draw();

View File

@ -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
{ {
@ -86,16 +86,14 @@ 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())
{ {
ChunkMesh c(new Chunk::Chunk(glm::vec3(i, j, k))); chunks.insert(std::make_pair(index, ChunkMesh(new Chunk::Chunk(glm::vec3(i, j, k)))));
chunks[index] = c; generateChunk(chunks.at(index) .chunk);
chunks.at(index).mesh();
generateChunk(chunks[index].chunk);
chunks[index].mesh();
// std::cout << "Creating new chunk" << i << ", " << j << ", " << k <<std::endl; // std::cout << "Creating new chunk" << i << ", " << j << ", " << k <<std::endl;
} }
else
chunks[index].draw(); chunks.at(index).draw();
} }
void destroy() void destroy()

View File

@ -7,9 +7,11 @@
#include "spacefilling.hpp" #include "spacefilling.hpp"
#include "utils.hpp" #include "utils.hpp"
ChunkMesh::ChunkMesh() ChunkMesh::~ChunkMesh(){
{ // std::cout << "Destroy" << this->chunk << std::endl;
// std::cout << "CHUNK MESH " << std::endl; // if(this->chunk != nullptr) delete this->chunk;
// this->chunk = nullptr;
// delete[] (this->theShader);
} }
ChunkMesh::ChunkMesh(Chunk::Chunk *c) ChunkMesh::ChunkMesh(Chunk::Chunk *c)
@ -30,8 +32,6 @@ ChunkMesh::ChunkMesh(Chunk::Chunk *c)
void ChunkMesh::mesh() void ChunkMesh::mesh()
{ {
if (!(this->chunk))
return;
/* /*
* Taking inspiration from 0fps and the jme3 porting at * Taking inspiration from 0fps and the jme3 porting at
* https://github.com/roboleary/GreedyMesh/blob/master/src/mygame/Main.java * https://github.com/roboleary/GreedyMesh/blob/master/src/mygame/Main.java
@ -227,8 +227,6 @@ void ChunkMesh::mesh()
void ChunkMesh::draw() void ChunkMesh::draw()
{ {
if (!(this->chunk))
return;
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // wireframe mode // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // wireframe mode