From 0645905fc618075dc643f93b22df9790b73f9e99 Mon Sep 17 00:00:00 2001 From: InviseDivine Date: Mon, 27 Apr 2026 22:18:18 +0200 Subject: [PATCH] eeee it doesnt work :sob: --- src/network/ClientSideNetworkHandler.cpp | 20 +++++++++++++- src/network/ClientSideNetworkHandler.h | 6 ++--- src/network/ServerSideNetworkHandler.cpp | 13 ++++------ src/network/packet/StartGamePacket.h | 12 +++++++-- src/world/level/LevelConstants.h | 12 +++------ src/world/level/chunk/ChunkCache.h | 33 ++++++++++++------------ src/world/level/chunk/LevelChunk.h | 4 +-- 7 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/network/ClientSideNetworkHandler.cpp b/src/network/ClientSideNetworkHandler.cpp index ecfc12d..14e87cf 100755 --- a/src/network/ClientSideNetworkHandler.cpp +++ b/src/network/ClientSideNetworkHandler.cpp @@ -12,6 +12,7 @@ #include "../client/Minecraft.h" #include "../client/gamemode/GameMode.h" #include "world/item/ItemInstance.h" +#include "world/level/LevelConstants.h" #ifndef STANDALONE_SERVER #include "../client/gui/screens/DisconnectionScreen.h" #endif @@ -99,6 +100,10 @@ void ClientSideNetworkHandler::onUnableToConnect() void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid) { + CHUNK_CACHE_WIDTH = 16; + LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; + LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; + // TODO: Good disconnecting LOGI("onDisconnect\n"); if (level) @@ -155,6 +160,19 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, StartGam } #endif + // @todo @note i think its trash + // we can put it directly to selectLevel? + if (packet->chunkCacheWidth != 0) { + printf("lol \n"); + CHUNK_CACHE_WIDTH = packet->chunkCacheWidth; + LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; + LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; + + } + NumRequestChunks = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; + requestNextChunkIndexList.resize(NumRequestChunks); + chunksLoaded.resize(NumRequestChunks); + const std::string& levelId = LevelStorageSource::TempLevelId; LevelStorageSource* storageSource = minecraft->getLevelSource(); storageSource->deleteLevel(levelId); @@ -696,7 +714,7 @@ void ClientSideNetworkHandler::arrangeRequestChunkOrder() { } _ChunkSorter sorter(cx, cz); - std::sort(requestNextChunkIndexList, requestNextChunkIndexList + NumRequestChunks, sorter); + std::sort(requestNextChunkIndexList.begin(), requestNextChunkIndexList.end(), sorter); } void ClientSideNetworkHandler::levelGenerated(Level* level) diff --git a/src/network/ClientSideNetworkHandler.h b/src/network/ClientSideNetworkHandler.h index 4847c74..57e0d81 100755 --- a/src/network/ClientSideNetworkHandler.h +++ b/src/network/ClientSideNetworkHandler.h @@ -102,11 +102,11 @@ private: BlockUpdateList bufferedBlockUpdates; int requestNextChunkPosition; - static const int NumRequestChunks = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; + int NumRequestChunks; int requestNextChunkIndex; - IntPair requestNextChunkIndexList[NumRequestChunks]; - bool chunksLoaded[NumRequestChunks]; + std::vector requestNextChunkIndexList; + std::vector chunksLoaded; }; #endif diff --git a/src/network/ServerSideNetworkHandler.cpp b/src/network/ServerSideNetworkHandler.cpp index 69793b4..0a70530 100755 --- a/src/network/ServerSideNetworkHandler.cpp +++ b/src/network/ServerSideNetworkHandler.cpp @@ -27,6 +27,7 @@ #include "util/Mth.h" #include "util/StringUtils.h" #include "world/item/ItemInstance.h" +#include "world/level/LevelConstants.h" #include "world/level/storage/LevelStorage.h" #include "world/phys/Vec3.h" #include "world/item/crafting/Recipe.h" @@ -219,8 +220,8 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac // bool oldClient = packet->clientNetworkVersion < SharedConstants::NetworkProtocolLowestSupportedVersion; bool oldServer = packet->clientNetworkLowestSupportedVersion > SharedConstants::NetworkProtocolVersion; - if (oldClient || oldServer) - loginStatus = oldClient? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld; + if (oldClient || oldServer || !packet->newProto) + loginStatus = oldClient || !packet->newProto? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld; for (int i = 0; i < level->players.size(); i++) { ServerPlayer* player = (ServerPlayer*) level->players.at(i); @@ -272,15 +273,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac level->getLevelData()->getGeneratorVersion(), gameType, newPlayer->entityId, - newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z + newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z, + CHUNK_CACHE_WIDTH ).write(&bitStream); rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false); - - if (!packet->newProto) { - MessagePacket packet("You're using outdated client. Some features disabled."); - raknetInstance->send(packet); - } } } diff --git a/src/network/packet/StartGamePacket.h b/src/network/packet/StartGamePacket.h index 24adead..e1b037e 100755 --- a/src/network/packet/StartGamePacket.h +++ b/src/network/packet/StartGamePacket.h @@ -2,6 +2,7 @@ #define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__ #include "../Packet.h" +#include "world/level/LevelConstants.h" #include class StartGamePacket : public Packet @@ -14,18 +15,20 @@ public: int entityId; float x, y, z; + int chunkCacheWidth = 0; StartGamePacket() { } - StartGamePacket(long seed, int levelGeneratorVersion, int gameType, int entityId, float x, float y, float z) + StartGamePacket(long seed, int levelGeneratorVersion, int gameType, int entityId, float x, float y, float z, int chunkCacheWidth) : levelSeed((int32_t)seed), levelGeneratorVersion(levelGeneratorVersion), gameType(gameType), entityId(entityId), x(x), y(y), - z(z) + z(z), + chunkCacheWidth(chunkCacheWidth) { } @@ -40,6 +43,7 @@ public: bitStream->Write(x); bitStream->Write(y); bitStream->Write(z); + bitStream->Write(CHUNK_CACHE_WIDTH); } void read(RakNet::BitStream* bitStream) @@ -51,6 +55,10 @@ public: bitStream->Read(x); bitStream->Read(y); bitStream->Read(z); + + if (bitStream->GetNumberOfUnreadBits() > 0) { + bitStream->Read(chunkCacheWidth); + } } void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) diff --git a/src/world/level/LevelConstants.h b/src/world/level/LevelConstants.h index 4d6865b..18f3a0b 100755 --- a/src/world/level/LevelConstants.h +++ b/src/world/level/LevelConstants.h @@ -1,14 +1,10 @@ -#ifndef _MINECRAFT_WORLD_LEVELCONSTANTS_H_ -#define _MINECRAFT_WORLD_LEVELCONSTANTS_H_ - +#pragma once const int LEVEL_HEIGHT = 128; -const int CHUNK_CACHE_WIDTH = 16; // in chunks +int CHUNK_CACHE_WIDTH = 16; // in chunks const int CHUNK_WIDTH = 16; // in blocks const int CHUNK_DEPTH = 16; -const int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; -const int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; +int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; +int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; const int CHUNK_COLUMNS = CHUNK_WIDTH * CHUNK_DEPTH; const int CHUNK_BLOCK_COUNT = CHUNK_COLUMNS * LEVEL_HEIGHT; - -#endif diff --git a/src/world/level/chunk/ChunkCache.h b/src/world/level/chunk/ChunkCache.h index b1b16fe..1401905 100755 --- a/src/world/level/chunk/ChunkCache.h +++ b/src/world/level/chunk/ChunkCache.h @@ -24,7 +24,8 @@ public: isChunkCache = true; //emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0); emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0); - memset(chunks, 0, sizeof(LevelChunk*) * CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH); + + chunks = (LevelChunk *)malloc(CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH); } ~ChunkCache() { @@ -33,10 +34,10 @@ public: for (int i = 0; i < CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; i++) { - if (chunks[i]) + if (&chunks[i]) { - chunks[i]->deleteBlockData(); - delete chunks[i]; + chunks[i].deleteBlockData(); + delete &chunks[i]; } } } @@ -55,7 +56,7 @@ public: int xs = x & (CHUNK_CACHE_WIDTH - 1); int zs = z & (CHUNK_CACHE_WIDTH - 1); int slot = xs + zs * 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) { @@ -75,10 +76,10 @@ public: int zs = z & (CHUNK_CACHE_WIDTH - 1); int slot = xs + zs * 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); @@ -93,7 +94,7 @@ public: //return emptyChunk; updateLights = true; } - chunks[slot] = newChunk; + chunks[slot] = *newChunk; newChunk->lightLava(); if (updateLights) @@ -114,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) { @@ -254,7 +255,7 @@ private: LevelChunk* emptyChunk; ChunkSource* source; ChunkStorage* storage; - LevelChunk* chunks[CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH]; + LevelChunk* chunks; Level* level; LevelChunk* last; diff --git a/src/world/level/chunk/LevelChunk.h b/src/world/level/chunk/LevelChunk.h index 5735744..c06819e 100755 --- a/src/world/level/chunk/LevelChunk.h +++ b/src/world/level/chunk/LevelChunk.h @@ -122,8 +122,8 @@ public: unsigned char updateMap[CHUNK_COLUMNS]; // marks regions within block columns that have been modified int minHeight; - const int x, z; - const int xt, zt; + int x, z; + int xt, zt; bool terrainPopulated; bool unsaved;