From 3e48c7fabd69ddd098b719d4726678e7ad67fedf Mon Sep 17 00:00:00 2001 From: Kolyah35 Date: Sat, 2 May 2026 21:31:48 +0300 Subject: [PATCH] FIX: compilation --- src/network/ClientSideNetworkHandler.cpp | 7 ++++-- src/world/level/Level.cpp | 3 +++ src/world/level/Level.h | 4 ++-- src/world/level/LevelConstants.cpp | 3 +++ src/world/level/LevelConstants.h | 2 +- src/world/level/chunk/ChunkCache.h | 30 ++++++++++++------------ src/world/level/chunk/LevelChunk.cpp | 5 ++-- src/world/level/chunk/LevelChunk.h | 2 +- 8 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/network/ClientSideNetworkHandler.cpp b/src/network/ClientSideNetworkHandler.cpp index c1515f7..f988fdd 100755 --- a/src/network/ClientSideNetworkHandler.cpp +++ b/src/network/ClientSideNetworkHandler.cpp @@ -560,8 +560,8 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat int rx = packet->x << 4; int rz = packet->z << 4; - unsigned char readBlockBuffer[setSize]; - unsigned char readDataBuffer[setSize / 2]; + unsigned char* readBlockBuffer = new unsigned char[setSize]; + unsigned char* readDataBuffer = new unsigned char[setSize / 2]; for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; i++) { @@ -631,6 +631,9 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat } } + delete[] readBlockBuffer; + delete[] readDataBuffer; + if (recalcHeight) { // chunk->recalcHeightmap(); diff --git a/src/world/level/Level.cpp b/src/world/level/Level.cpp index 35fbd7e..cb6d688 100755 --- a/src/world/level/Level.cpp +++ b/src/world/level/Level.cpp @@ -29,6 +29,9 @@ #include "../Difficulty.h" #include "../../network/packet/ExplodePacket.h" +const int Level::DEPTH = LevelConstants::LEVEL_HEIGHT; +const int Level::SEA_LEVEL = Level::DEPTH / 2 - 1; + Level::Level(LevelStorage* levelStorage, const std::string& levelName, const LevelSettings& settings, int generatorVersion, Dimension* fixedDimension /* = NULL */) : levelStorage(levelStorage), isClientSide(false), diff --git a/src/world/level/Level.h b/src/world/level/Level.h index 082cb07..edf1747 100755 --- a/src/world/level/Level.h +++ b/src/world/level/Level.h @@ -67,8 +67,8 @@ class Level: public LevelSource public: static const int MAX_LEVEL_SIZE = 32000000; - const short DEPTH = LevelConstants::LEVEL_HEIGHT; - const short SEA_LEVEL = DEPTH / 2 - 1; + static const int DEPTH; + static const int SEA_LEVEL; static const int MAX_BRIGHTNESS = 15; static const int TICKS_PER_DAY = SharedConstants::TicksPerSecond * 60 * 16;// SharedConstants::TicksPerSecond * 60 * 12; // ORG:20*60*20 diff --git a/src/world/level/LevelConstants.cpp b/src/world/level/LevelConstants.cpp index 864ce32..6a36246 100644 --- a/src/world/level/LevelConstants.cpp +++ b/src/world/level/LevelConstants.cpp @@ -1,7 +1,10 @@ #include "LevelConstants.h" int LevelConstants::LEVEL_HEIGHT = 128; +int LevelConstants::CHUNK_CACHE_WIDTH = 16; // in chunks int LevelConstants::CHUNK_WIDTH = 16; // in blocks int LevelConstants::CHUNK_DEPTH = 16; +int LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * CHUNK_WIDTH; +int LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * CHUNK_DEPTH; int LevelConstants::CHUNK_COLUMNS = LevelConstants::CHUNK_WIDTH * LevelConstants::CHUNK_DEPTH; int LevelConstants::CHUNK_BLOCK_COUNT = LevelConstants::CHUNK_COLUMNS * LevelConstants::LEVEL_HEIGHT; \ No newline at end of file diff --git a/src/world/level/LevelConstants.h b/src/world/level/LevelConstants.h index 0b00053..ed77861 100755 --- a/src/world/level/LevelConstants.h +++ b/src/world/level/LevelConstants.h @@ -5,8 +5,8 @@ public: static int CHUNK_CACHE_WIDTH; // in chunks static int LEVEL_WIDTH; static int LEVEL_DEPTH; - static int LEVEL_HEIGHT; + static int CHUNK_WIDTH; // in blocks static int CHUNK_DEPTH; static int CHUNK_COLUMNS; diff --git a/src/world/level/chunk/ChunkCache.h b/src/world/level/chunk/ChunkCache.h index 13f81e9..ee5fc49 100755 --- a/src/world/level/chunk/ChunkCache.h +++ b/src/world/level/chunk/ChunkCache.h @@ -25,7 +25,7 @@ public: //emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0); emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0); - chunks = (LevelChunk *)malloc(LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH); + chunks = new LevelChunk *[LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH]; } ~ChunkCache() { @@ -36,8 +36,8 @@ public: { if (&chunks[i]) { - chunks[i].deleteBlockData(); - delete &chunks[i]; + chunks[i]->deleteBlockData(); + delete chunks[i]; } } } @@ -56,7 +56,7 @@ public: int xs = x & (LevelConstants::CHUNK_CACHE_WIDTH - 1); int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1); int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH; - return &chunks[slot] != NULL && (&chunks[slot] == emptyChunk || chunks[slot].isAt(x, z)); + return chunks[slot] != NULL && (chunks[slot] == emptyChunk || chunks[slot]->isAt(x, z)); } LevelChunk* create(int x, int z) { @@ -76,10 +76,10 @@ public: int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1); int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH; if (!hasChunk(x, z)) { - if (&chunks[slot] != NULL) { - chunks[slot].unload(); - save(&chunks[slot]); - saveEntities(&chunks[slot]); + if (chunks[slot] != NULL) { + chunks[slot]->unload(); + save(chunks[slot]); + saveEntities(chunks[slot]); } LevelChunk* newChunk = load(x, z); @@ -94,7 +94,7 @@ public: //return emptyChunk; updateLights = true; } - chunks[slot] = *newChunk; + chunks[slot] = newChunk; newChunk->lightLava(); if (updateLights) @@ -115,23 +115,23 @@ public: //level->updateLight(LightLayer::Block, x * 16, 0, z * 16, x * 16 + 15, 128, z * 16 + 15); } - if (&chunks[slot] != NULL) { - chunks[slot].load(); + if (chunks[slot] != NULL) { + chunks[slot]->load(); } - if (!chunks[slot].terrainPopulated && hasChunk(x + 1, z + 1) && hasChunk(x, z + 1) && hasChunk(x + 1, z)) postProcess(this, x, z); + if (!chunks[slot]->terrainPopulated && hasChunk(x + 1, z + 1) && hasChunk(x, z + 1) && hasChunk(x + 1, z)) postProcess(this, x, z); if (hasChunk(x - 1, z) && !getChunk(x - 1, z)->terrainPopulated && hasChunk(x - 1, z + 1) && hasChunk(x, z + 1) && hasChunk(x - 1, z)) postProcess(this, x - 1, z); if (hasChunk(x, z - 1) && !getChunk(x, z - 1)->terrainPopulated && hasChunk(x + 1, z - 1) && hasChunk(x, z - 1) && hasChunk(x + 1, z)) postProcess(this, x, z - 1); if (hasChunk(x - 1, z - 1) && !getChunk(x - 1, z - 1)->terrainPopulated && hasChunk(x - 1, z - 1) && hasChunk(x, z - 1) && hasChunk(x - 1, z)) postProcess(this, x - 1, z - 1); } xLast = x; zLast = z; - last = &chunks[slot]; + last = chunks[slot]; //sw.stop(); //sw.printEvery(500000, "ChunkCache::load: "); - return &chunks[slot]; + return chunks[slot]; } Biome::MobList getMobsAt(const MobCategory& mobCategory, int x, int y, int z) { @@ -255,7 +255,7 @@ private: LevelChunk* emptyChunk; ChunkSource* source; ChunkStorage* storage; - LevelChunk* chunks; + LevelChunk** chunks; Level* level; LevelChunk* last; diff --git a/src/world/level/chunk/LevelChunk.cpp b/src/world/level/chunk/LevelChunk.cpp index 2710f21..5cf3ae6 100755 --- a/src/world/level/chunk/LevelChunk.cpp +++ b/src/world/level/chunk/LevelChunk.cpp @@ -12,6 +12,7 @@ /*static*/ bool LevelChunk::touchedSky = false; +const int LevelChunk::ChunkBlockCount = LevelConstants::CHUNK_BLOCK_COUNT; LevelChunk::LevelChunk( Level* level, int x, int z ) : level(level), @@ -45,8 +46,8 @@ LevelChunk::~LevelChunk() void LevelChunk::init() { - heightmap = (char*)malloc(LevelConstants::CHUNK_COLUMNS * sizeof(char)); - updateMap = (unsigned char*)malloc(LevelConstants::CHUNK_COLUMNS * sizeof(unsigned char)); + heightmap = new char[LevelConstants::CHUNK_COLUMNS]; + updateMap = new unsigned char[LevelConstants::CHUNK_COLUMNS]; terrainPopulated = false; dontSave = false; diff --git a/src/world/level/chunk/LevelChunk.h b/src/world/level/chunk/LevelChunk.h index 0ab8d68..b88cb7a 100755 --- a/src/world/level/chunk/LevelChunk.h +++ b/src/world/level/chunk/LevelChunk.h @@ -106,7 +106,7 @@ private: void recalcHeight(int x, int yStart, int z); public: static bool touchedSky; - const int ChunkBlockCount = LevelConstants::CHUNK_BLOCK_COUNT; + static const int ChunkBlockCount; const int ChunkSize = ChunkBlockCount; static const int UpdateMapBitShift = 4; // power of (LevelConstants::LEVEL_HEIGHT / 8) == 16