memory related refactor
This commit is contained in:
@@ -92,8 +92,8 @@ std::unique_ptr<Chunk> Chunk::clone() const {
|
||||
|
||||
Total size: (CHUNK_VOL * 4) bytes
|
||||
*/
|
||||
ubyte* Chunk::encode() const {
|
||||
ubyte* buffer = new ubyte[CHUNK_DATA_LEN];
|
||||
std::unique_ptr<ubyte[]> Chunk::encode() const {
|
||||
auto buffer = std::make_unique<ubyte[]>(CHUNK_DATA_LEN);
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
buffer[i] = voxels[i].id >> 8;
|
||||
buffer[CHUNK_VOL+i] = voxels[i].id & 0xFF;
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public:
|
||||
|
||||
inline void setReady(bool newState) {setFlags(ChunkFlag::READY, newState);}
|
||||
|
||||
ubyte* encode() const;
|
||||
std::unique_ptr<ubyte[]> encode() const;
|
||||
|
||||
/**
|
||||
* @return true if all is fine
|
||||
|
||||
@@ -55,7 +55,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||
|
||||
auto chunk = std::make_shared<Chunk>(x, z);
|
||||
store(chunk);
|
||||
std::unique_ptr<ubyte[]> data(wfile->getChunk(chunk->x, chunk->z));
|
||||
auto data = wfile->getChunk(chunk->x, chunk->z);
|
||||
if (data) {
|
||||
chunk->decode(data.get());
|
||||
auto invs = wfile->fetchInventories(chunk->x, chunk->z);
|
||||
@@ -67,7 +67,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||
verifyLoadedChunk(level->content->getIndices(), chunk.get());
|
||||
}
|
||||
|
||||
std::unique_ptr<light_t[]> lights (wfile->getLights(chunk->x, chunk->z));
|
||||
auto lights = wfile->getLights(chunk->x, chunk->z);
|
||||
if (lights) {
|
||||
chunk->lightmap.set(lights.get());
|
||||
chunk->setLoadedLights(true);
|
||||
|
||||
Reference in New Issue
Block a user