mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-04 22:40:05 +00:00
Possibly fixed all chunking desyncs
* Players/NPCs that initialize chunks now correctly pull their main chunk into their viewdata. * Tested on the public server, seems to have solved the chunking issues.
This commit is contained in:
parent
3b5af415fb
commit
cc06fdcf60
@ -14,7 +14,10 @@ void ChunkManager::newChunk(std::tuple<int, int, uint64_t> pos) {
|
||||
chunk->players = std::set<CNSocket*>();
|
||||
chunk->NPCs = std::set<int32_t>();
|
||||
|
||||
// add the new chunk to every player and mob that's near it
|
||||
chunks[pos] = chunk;
|
||||
}
|
||||
|
||||
void ChunkManager::populateNewChunk(Chunk* chunk, std::tuple<int, int, uint64_t> pos) {// add the new chunk to every player and mob that's near it
|
||||
for (Chunk *c : grabChunks(pos)) {
|
||||
if (c == chunk)
|
||||
continue;
|
||||
@ -25,32 +28,52 @@ void ChunkManager::newChunk(std::tuple<int, int, uint64_t> pos) {
|
||||
for (int32_t id : c->NPCs)
|
||||
NPCManager::NPCs[id]->currentChunks.push_back(chunk);
|
||||
}
|
||||
|
||||
chunks[pos] = chunk;
|
||||
}
|
||||
|
||||
void ChunkManager::addNPC(int posX, int posY, uint64_t instanceID, int32_t id) {
|
||||
std::tuple<int, int, uint64_t> pos = grabChunk(posX, posY, instanceID);
|
||||
|
||||
bool newChunkUsed = false;
|
||||
|
||||
// make chunk if it doesn't exist!
|
||||
if (chunks.find(pos) == chunks.end())
|
||||
if (chunks.find(pos) == chunks.end()) {
|
||||
newChunk(pos);
|
||||
newChunkUsed = true;
|
||||
}
|
||||
|
||||
Chunk* chunk = chunks[pos];
|
||||
|
||||
if (newChunkUsed)
|
||||
NPCManager::NPCs[id]->currentChunks.push_back(chunk);
|
||||
|
||||
chunk->NPCs.insert(id);
|
||||
|
||||
// we must update other players after the NPC is added to chunk
|
||||
if (newChunkUsed)
|
||||
populateNewChunk(chunk, pos);
|
||||
}
|
||||
|
||||
void ChunkManager::addPlayer(int posX, int posY, uint64_t instanceID, CNSocket* sock) {
|
||||
std::tuple<int, int, uint64_t> pos = grabChunk(posX, posY, instanceID);
|
||||
|
||||
bool newChunkUsed = false;
|
||||
|
||||
// make chunk if it doesn't exist!
|
||||
if (chunks.find(pos) == chunks.end())
|
||||
if (chunks.find(pos) == chunks.end()) {
|
||||
newChunk(pos);
|
||||
newChunkUsed = true;
|
||||
}
|
||||
|
||||
Chunk* chunk = chunks[pos];
|
||||
|
||||
if (newChunkUsed)
|
||||
PlayerManager::players[sock].currentChunks.push_back(chunk);
|
||||
|
||||
chunk->players.insert(sock);
|
||||
|
||||
// we must update other players after this player is added to chunk
|
||||
if (newChunkUsed)
|
||||
populateNewChunk(chunk, pos);
|
||||
}
|
||||
|
||||
bool ChunkManager::removePlayer(std::tuple<int, int, uint64_t> chunkPos, CNSocket* sock) {
|
||||
|
@ -27,6 +27,7 @@ namespace ChunkManager {
|
||||
extern std::map<std::tuple<int, int, uint64_t>, Chunk*> chunks;
|
||||
|
||||
void newChunk(std::tuple<int, int, uint64_t> pos);
|
||||
void populateNewChunk(Chunk* chunk, std::tuple<int, int, uint64_t> pos);
|
||||
void addNPC(int posX, int posY, uint64_t instanceID, int32_t id);
|
||||
void addPlayer(int posX, int posY, uint64_t instanceID, CNSocket* sock);
|
||||
bool removePlayer(std::tuple<int, int, uint64_t> chunkPos, CNSocket* sock);
|
||||
|
@ -222,9 +222,9 @@ void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y, uint64_t ins
|
||||
// now, add all the new npcs & players!
|
||||
addPlayerToChunks(ChunkManager::getDeltaChunks(allChunks, view.currentChunks), sock);
|
||||
|
||||
ChunkManager::addPlayer(X, Y, view.plr->instanceID, sock); // takes care of adding the player to the chunk if it exists or not
|
||||
view.chunkPos = newPos;
|
||||
view.currentChunks = allChunks;
|
||||
ChunkManager::addPlayer(X, Y, view.plr->instanceID, sock); // takes care of adding the player to the chunk if it exists or not
|
||||
}
|
||||
|
||||
void PlayerManager::sendPlayerTo(CNSocket* sock, int X, int Y, int Z, uint64_t I) {
|
||||
|
Loading…
Reference in New Issue
Block a user