Minor refactor

This commit is contained in:
MihailRis
2024-01-03 22:51:48 +03:00
parent 2ad115a2a8
commit e7e2c16ee6
3 changed files with 14 additions and 15 deletions
+8 -12
View File
@@ -14,22 +14,18 @@
#include "../lighting/Lightmap.h"
#include "../typedefs.h"
using glm::ivec2;
using std::unique_ptr;
using std::shared_ptr;
ChunksStorage::ChunksStorage(Level* level) : level(level) {
}
ChunksStorage::~ChunksStorage() {
}
void ChunksStorage::store(shared_ptr<Chunk> chunk) {
chunksMap[ivec2(chunk->x, chunk->z)] = chunk;
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
}
shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(ivec2(x, z));
std::shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
auto found = chunksMap.find(glm::ivec2(x, z));
if (found == chunksMap.end()) {
return nullptr;
}
@@ -37,7 +33,7 @@ shared_ptr<Chunk> ChunksStorage::get(int x, int z) const {
}
void ChunksStorage::remove(int x, int z) {
auto found = chunksMap.find(ivec2(x, z));
auto found = chunksMap.find(glm::ivec2(x, z));
if (found != chunksMap.end()) {
chunksMap.erase(found->first);
}
@@ -46,9 +42,9 @@ void ChunksStorage::remove(int x, int z) {
std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
World* world = level->world;
auto chunk = shared_ptr<Chunk>(new Chunk(x, z));
auto chunk = std::shared_ptr<Chunk>(new Chunk(x, z));
store(chunk);
unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
std::unique_ptr<ubyte> data(world->wfile->getChunk(chunk->x, chunk->z));
if (data) {
chunk->decode(data.get());
chunk->setLoaded(true);
@@ -100,7 +96,7 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
// cw*ch chunks will be scanned
for (int cz = scz; cz < scz + ch; cz++) {
for (int cx = scx; cx < scx + cw; cx++) {
auto found = chunksMap.find(ivec2(cx, cz));
auto found = chunksMap.find(glm::ivec2(cx, cz));
if (found == chunksMap.end()) {
// no chunk loaded -> filling with BLOCK_VOID
for (int ly = y; ly < y + h; ly++) {