use unique_ptr when dumping intervalmap to array
parent
383fb60686
commit
f7eb04a5f1
|
@ -15,7 +15,7 @@
|
|||
#include "intervalmap.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
#define CHUNK_SIZE 16
|
||||
#define CHUNK_SIZE 2
|
||||
#define CHUNK_VOLUME (CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE)
|
||||
#define CHUNK_MAX_INDEX (CHUNK_VOLUME - 1)
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace Chunk
|
|||
void setBlocks(int start, int end, Block b);
|
||||
Block getBlock(int x, int y, int z);
|
||||
IntervalMap<Block>& getBlocks() { return (this->blocks); }
|
||||
Block* getBlocksArray(int* len) { return (this->blocks.toArray(len)); }
|
||||
std::unique_ptr<Block[]> getBlocksArray(int* len) { return (this->blocks.toArray(len)); }
|
||||
|
||||
public:
|
||||
GLuint VAO{0}, VBO{0}, EBO{0}, colorBuffer{0}, vIndex{0};
|
||||
|
@ -66,4 +66,4 @@ namespace Chunk
|
|||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
std::cout << "end key: " << std::prev(treemap.end())->first << "\n";
|
||||
}
|
||||
|
||||
V *toArray(int *length)
|
||||
std::unique_ptr<V[]> toArray(int *length)
|
||||
{
|
||||
if (treemap.empty())
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
if(*length == 0) return nullptr;
|
||||
|
||||
// std::cout << "Length: " << *length << "\n";
|
||||
V *arr{new V[*length]};
|
||||
std::unique_ptr<V[]> arr(new V[*length]);
|
||||
|
||||
auto start = treemap.begin();
|
||||
for (auto i = std::next(treemap.begin()); i != treemap.end(); i++)
|
||||
|
@ -117,4 +117,4 @@ private:
|
|||
std::map<int, V> treemap{};
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -42,8 +42,10 @@ void mesh(Chunk::Chunk* chunk)
|
|||
|
||||
// convert tree to array since it is easier to work with it
|
||||
int length{0};
|
||||
Block *blocks = chunk->getBlocksArray(&length);
|
||||
if(length == 0) return;
|
||||
std::unique_ptr<Block[]> blocks = chunk->getBlocksArray(&length);
|
||||
if(length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int k, l, u, v, w, h, n, j, i;
|
||||
int x[]{0, 0, 0};
|
||||
|
@ -179,9 +181,6 @@ void mesh(Chunk::Chunk* chunk)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] blocks;
|
||||
|
||||
}
|
||||
|
||||
void draw(Chunk::Chunk* chunk, glm::mat4 model)
|
||||
|
|
Loading…
Reference in New Issue