This commit is contained in:
MihailRis
2024-03-03 12:56:50 +03:00
parent a8402340b1
commit c4a07bdb14
2 changed files with 15 additions and 15 deletions
+12 -12
View File
@@ -38,7 +38,7 @@ voxel* Chunks::get(int32_t x, int32_t y, int32_t z) {
int cx = floordiv(x, CHUNK_W); int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H); int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D); int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= w || cy >= 1 || cz >= d) if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
return nullptr; return nullptr;
std::shared_ptr<Chunk> chunk = chunks[cz * w + cx]; std::shared_ptr<Chunk> chunk = chunks[cz * w + cx];
if (chunk == nullptr) if (chunk == nullptr)
@@ -98,7 +98,7 @@ ubyte Chunks::getLight(int32_t x, int32_t y, int32_t z, int channel){
int cx = floordiv(x, CHUNK_W); int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H); int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D); int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= w || cy >= 1 || cz >= d) if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
return 0; return 0;
auto chunk = chunks[(cy * d + cz) * w + cx]; auto chunk = chunks[(cy * d + cz) * w + cx];
if (chunk == nullptr) if (chunk == nullptr)
@@ -115,7 +115,7 @@ light_t Chunks::getLight(int32_t x, int32_t y, int32_t z){
int cx = floordiv(x, CHUNK_W); int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H); int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D); int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= w || cy >= 1 || cz >= d) if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
return 0; return 0;
auto chunk = chunks[(cy * d + cz) * w + cx]; auto chunk = chunks[(cy * d + cz) * w + cx];
if (chunk == nullptr) if (chunk == nullptr)
@@ -133,7 +133,7 @@ Chunk* Chunks::getChunkByVoxel(int32_t x, int32_t y, int32_t z){
z -= oz * CHUNK_D; z -= oz * CHUNK_D;
int cx = floordiv(x, CHUNK_W); int cx = floordiv(x, CHUNK_W);
int cz = floordiv(z, CHUNK_D); int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cz < 0 || cx >= w || cz >= d) if (cx < 0 || cz < 0 || cx >= int(w) || cz >= int(d))
return nullptr; return nullptr;
return chunks[cz * w + cx].get(); return chunks[cz * w + cx].get();
} }
@@ -141,7 +141,7 @@ Chunk* Chunks::getChunkByVoxel(int32_t x, int32_t y, int32_t z){
Chunk* Chunks::getChunk(int x, int z){ Chunk* Chunks::getChunk(int x, int z){
x -= ox; x -= ox;
z -= oz; z -= oz;
if (x < 0 || z < 0 || x >= w || z >= d) if (x < 0 || z < 0 || x >= int(w) || z >= int(d))
return nullptr; return nullptr;
return chunks[z * w + x].get(); return chunks[z * w + x].get();
} }
@@ -153,7 +153,7 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states){
z -= oz * CHUNK_D; z -= oz * CHUNK_D;
int cx = floordiv(x, CHUNK_W); int cx = floordiv(x, CHUNK_W);
int cz = floordiv(z, CHUNK_D); int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cz < 0 || cx >= w || cz >= d) if (cx < 0 || cz < 0 || cx >= int(w) || cz >= int(d))
return; return;
Chunk* chunk = chunks[cz * w + cx].get(); Chunk* chunk = chunks[cz * w + cx].get();
if (chunk == nullptr) if (chunk == nullptr)
@@ -410,14 +410,14 @@ void Chunks::translate(int32_t dx, int32_t dz) {
for (uint i = 0; i < volume; i++){ for (uint i = 0; i < volume; i++){
chunksSecond[i] = nullptr; chunksSecond[i] = nullptr;
} }
for (int z = 0; z < d; z++){ for (uint32_t z = 0; z < d; z++){
for (int x = 0; x < w; x++){ for (uint32_t x = 0; x < w; x++){
auto chunk = chunks[z * w + x]; auto chunk = chunks[z * w + x];
int nx = x - dx; int nx = x - dx;
int nz = z - dz; int nz = z - dz;
if (chunk == nullptr) if (chunk == nullptr)
continue; continue;
if (nx < 0 || nz < 0 || nx >= w || nz >= d){ if (nx < 0 || nz < 0 || nx >= int(w) || nz >= int(d)){
events->trigger(EVT_CHUNK_HIDDEN, chunk.get()); events->trigger(EVT_CHUNK_HIDDEN, chunk.get());
if (worldFiles) if (worldFiles)
worldFiles->put(chunk.get()); worldFiles->put(chunk.get());
@@ -449,8 +449,8 @@ void Chunks::resize(uint32_t newW, uint32_t newD) {
const int newVolume = newW * newD; const int newVolume = newW * newD;
std::vector<std::shared_ptr<Chunk>> newChunks(newVolume); std::vector<std::shared_ptr<Chunk>> newChunks(newVolume);
std::vector<std::shared_ptr<Chunk>> newChunksSecond(newVolume); std::vector<std::shared_ptr<Chunk>> newChunksSecond(newVolume);
for (int z = 0; z < d && z < newD; z++) { for (int z = 0; z < int(d) && z < int(newD); z++) {
for (int x = 0; x < w && x < newW; x++) { for (int x = 0; x < int(w) && x < int(newW); x++) {
newChunks[z * newW + x] = chunks[z * w + x]; newChunks[z * newW + x] = chunks[z * w + x];
} }
} }
@@ -471,7 +471,7 @@ bool Chunks::putChunk(std::shared_ptr<Chunk> chunk) {
int z = chunk->z; int z = chunk->z;
x -= ox; x -= ox;
z -= oz; z -= oz;
if (x < 0 || z < 0 || x >= w || z >= d) if (x < 0 || z < 0 || x >= int(w) || z >= int(d))
return false; return false;
chunks[z * w + x] = chunk; chunks[z * w + x] = chunk;
chunksCount++; chunksCount++;
+3 -3
View File
@@ -44,9 +44,9 @@ Level::~Level(){
void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) { void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) {
chunks->setCenter(x, z); chunks->setCenter(x, z);
radius = std::min(radius, settings.chunks.loadDistance + settings.chunks.padding * 2); uint32_t diameter = std::min(radius*2, (settings.chunks.loadDistance + settings.chunks.padding) * 2);
if (chunks->w != radius) { if (chunks->w != diameter) {
chunks->resize(radius, radius); chunks->resize(diameter, diameter);
} }
} }