eeee it doesnt work 😭

This commit is contained in:
InviseDivine
2026-04-27 22:18:18 +02:00
parent 4023d70687
commit 0645905fc6
7 changed files with 60 additions and 40 deletions

View File

@@ -12,6 +12,7 @@
#include "../client/Minecraft.h" #include "../client/Minecraft.h"
#include "../client/gamemode/GameMode.h" #include "../client/gamemode/GameMode.h"
#include "world/item/ItemInstance.h" #include "world/item/ItemInstance.h"
#include "world/level/LevelConstants.h"
#ifndef STANDALONE_SERVER #ifndef STANDALONE_SERVER
#include "../client/gui/screens/DisconnectionScreen.h" #include "../client/gui/screens/DisconnectionScreen.h"
#endif #endif
@@ -99,6 +100,10 @@ void ClientSideNetworkHandler::onUnableToConnect()
void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid) 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 // TODO: Good disconnecting
LOGI("onDisconnect\n"); LOGI("onDisconnect\n");
if (level) if (level)
@@ -155,6 +160,19 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, StartGam
} }
#endif #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; const std::string& levelId = LevelStorageSource::TempLevelId;
LevelStorageSource* storageSource = minecraft->getLevelSource(); LevelStorageSource* storageSource = minecraft->getLevelSource();
storageSource->deleteLevel(levelId); storageSource->deleteLevel(levelId);
@@ -696,7 +714,7 @@ void ClientSideNetworkHandler::arrangeRequestChunkOrder() {
} }
_ChunkSorter sorter(cx, cz); _ChunkSorter sorter(cx, cz);
std::sort(requestNextChunkIndexList, requestNextChunkIndexList + NumRequestChunks, sorter); std::sort(requestNextChunkIndexList.begin(), requestNextChunkIndexList.end(), sorter);
} }
void ClientSideNetworkHandler::levelGenerated(Level* level) void ClientSideNetworkHandler::levelGenerated(Level* level)

View File

@@ -102,11 +102,11 @@ private:
BlockUpdateList bufferedBlockUpdates; BlockUpdateList bufferedBlockUpdates;
int requestNextChunkPosition; int requestNextChunkPosition;
static const int NumRequestChunks = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; int NumRequestChunks;
int requestNextChunkIndex; int requestNextChunkIndex;
IntPair requestNextChunkIndexList[NumRequestChunks]; std::vector<IntPair> requestNextChunkIndexList;
bool chunksLoaded[NumRequestChunks]; std::vector<bool> chunksLoaded;
}; };
#endif #endif

View File

@@ -27,6 +27,7 @@
#include "util/Mth.h" #include "util/Mth.h"
#include "util/StringUtils.h" #include "util/StringUtils.h"
#include "world/item/ItemInstance.h" #include "world/item/ItemInstance.h"
#include "world/level/LevelConstants.h"
#include "world/level/storage/LevelStorage.h" #include "world/level/storage/LevelStorage.h"
#include "world/phys/Vec3.h" #include "world/phys/Vec3.h"
#include "world/item/crafting/Recipe.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 oldClient = packet->clientNetworkVersion < SharedConstants::NetworkProtocolLowestSupportedVersion;
bool oldServer = packet->clientNetworkLowestSupportedVersion > SharedConstants::NetworkProtocolVersion; bool oldServer = packet->clientNetworkLowestSupportedVersion > SharedConstants::NetworkProtocolVersion;
if (oldClient || oldServer) if (oldClient || oldServer || !packet->newProto)
loginStatus = oldClient? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld; loginStatus = oldClient || !packet->newProto? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld;
for (int i = 0; i < level->players.size(); i++) { for (int i = 0; i < level->players.size(); i++) {
ServerPlayer* player = (ServerPlayer*) level->players.at(i); ServerPlayer* player = (ServerPlayer*) level->players.at(i);
@@ -272,15 +273,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
level->getLevelData()->getGeneratorVersion(), level->getLevelData()->getGeneratorVersion(),
gameType, gameType,
newPlayer->entityId, newPlayer->entityId,
newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z,
CHUNK_CACHE_WIDTH
).write(&bitStream); ).write(&bitStream);
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false); 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);
}
} }
} }

View File

@@ -2,6 +2,7 @@
#define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__ #define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__
#include "../Packet.h" #include "../Packet.h"
#include "world/level/LevelConstants.h"
#include <cstdint> #include <cstdint>
class StartGamePacket : public Packet class StartGamePacket : public Packet
@@ -14,18 +15,20 @@ public:
int entityId; int entityId;
float x, y, z; float x, y, z;
int chunkCacheWidth = 0;
StartGamePacket() 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), : levelSeed((int32_t)seed),
levelGeneratorVersion(levelGeneratorVersion), levelGeneratorVersion(levelGeneratorVersion),
gameType(gameType), gameType(gameType),
entityId(entityId), entityId(entityId),
x(x), x(x),
y(y), y(y),
z(z) z(z),
chunkCacheWidth(chunkCacheWidth)
{ {
} }
@@ -40,6 +43,7 @@ public:
bitStream->Write(x); bitStream->Write(x);
bitStream->Write(y); bitStream->Write(y);
bitStream->Write(z); bitStream->Write(z);
bitStream->Write(CHUNK_CACHE_WIDTH);
} }
void read(RakNet::BitStream* bitStream) void read(RakNet::BitStream* bitStream)
@@ -51,6 +55,10 @@ public:
bitStream->Read(x); bitStream->Read(x);
bitStream->Read(y); bitStream->Read(y);
bitStream->Read(z); bitStream->Read(z);
if (bitStream->GetNumberOfUnreadBits() > 0) {
bitStream->Read(chunkCacheWidth);
}
} }
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback) void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)

View File

@@ -1,14 +1,10 @@
#ifndef _MINECRAFT_WORLD_LEVELCONSTANTS_H_ #pragma once
#define _MINECRAFT_WORLD_LEVELCONSTANTS_H_
const int LEVEL_HEIGHT = 128; 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_WIDTH = 16; // in blocks
const int CHUNK_DEPTH = 16; const int CHUNK_DEPTH = 16;
const int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH; int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH;
const int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH; int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH;
const int CHUNK_COLUMNS = CHUNK_WIDTH * CHUNK_DEPTH; const int CHUNK_COLUMNS = CHUNK_WIDTH * CHUNK_DEPTH;
const int CHUNK_BLOCK_COUNT = CHUNK_COLUMNS * LEVEL_HEIGHT; const int CHUNK_BLOCK_COUNT = CHUNK_COLUMNS * LEVEL_HEIGHT;
#endif

View File

@@ -24,7 +24,8 @@ public:
isChunkCache = true; isChunkCache = true;
//emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0); //emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0);
emptyChunk = new EmptyLevelChunk(level_, NULL, 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() { ~ChunkCache() {
@@ -33,10 +34,10 @@ public:
for (int i = 0; i < CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; i++) for (int i = 0; i < CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; i++)
{ {
if (chunks[i]) if (&chunks[i])
{ {
chunks[i]->deleteBlockData(); chunks[i].deleteBlockData();
delete chunks[i]; delete &chunks[i];
} }
} }
} }
@@ -55,7 +56,7 @@ public:
int xs = x & (CHUNK_CACHE_WIDTH - 1); int xs = x & (CHUNK_CACHE_WIDTH - 1);
int zs = z & (CHUNK_CACHE_WIDTH - 1); int zs = z & (CHUNK_CACHE_WIDTH - 1);
int slot = xs + zs * CHUNK_CACHE_WIDTH; 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) { LevelChunk* create(int x, int z) {
@@ -75,10 +76,10 @@ public:
int zs = z & (CHUNK_CACHE_WIDTH - 1); int zs = z & (CHUNK_CACHE_WIDTH - 1);
int slot = xs + zs * CHUNK_CACHE_WIDTH; int slot = xs + zs * CHUNK_CACHE_WIDTH;
if (!hasChunk(x, z)) { if (!hasChunk(x, z)) {
if (chunks[slot] != NULL) { if (&chunks[slot] != NULL) {
chunks[slot]->unload(); chunks[slot].unload();
save(chunks[slot]); save(&chunks[slot]);
saveEntities(chunks[slot]); saveEntities(&chunks[slot]);
} }
LevelChunk* newChunk = load(x, z); LevelChunk* newChunk = load(x, z);
@@ -93,7 +94,7 @@ public:
//return emptyChunk; //return emptyChunk;
updateLights = true; updateLights = true;
} }
chunks[slot] = newChunk; chunks[slot] = *newChunk;
newChunk->lightLava(); newChunk->lightLava();
if (updateLights) if (updateLights)
@@ -114,23 +115,23 @@ public:
//level->updateLight(LightLayer::Block, x * 16, 0, z * 16, x * 16 + 15, 128, z * 16 + 15); //level->updateLight(LightLayer::Block, x * 16, 0, z * 16, x * 16 + 15, 128, z * 16 + 15);
} }
if (chunks[slot] != NULL) { if (&chunks[slot] != NULL) {
chunks[slot]->load(); 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 - 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, 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); 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; xLast = x;
zLast = z; zLast = z;
last = chunks[slot]; last = &chunks[slot];
//sw.stop(); //sw.stop();
//sw.printEvery(500000, "ChunkCache::load: "); //sw.printEvery(500000, "ChunkCache::load: ");
return chunks[slot]; return &chunks[slot];
} }
Biome::MobList getMobsAt(const MobCategory& mobCategory, int x, int y, int z) { Biome::MobList getMobsAt(const MobCategory& mobCategory, int x, int y, int z) {
@@ -254,7 +255,7 @@ private:
LevelChunk* emptyChunk; LevelChunk* emptyChunk;
ChunkSource* source; ChunkSource* source;
ChunkStorage* storage; ChunkStorage* storage;
LevelChunk* chunks[CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH]; LevelChunk* chunks;
Level* level; Level* level;
LevelChunk* last; LevelChunk* last;

View File

@@ -122,8 +122,8 @@ public:
unsigned char updateMap[CHUNK_COLUMNS]; // marks regions within block columns that have been modified unsigned char updateMap[CHUNK_COLUMNS]; // marks regions within block columns that have been modified
int minHeight; int minHeight;
const int x, z; int x, z;
const int xt, zt; int xt, zt;
bool terrainPopulated; bool terrainPopulated;
bool unsaved; bool unsaved;