added basework for instancing

This commit is contained in:
2020-09-30 20:44:37 -05:00
parent 8ff97ec0b3
commit 4cd7b7cb53
11 changed files with 61 additions and 47 deletions

View File

@@ -47,7 +47,7 @@ void PlayerManager::addPlayer(CNSocket* key, Player plr) {
memcpy(p, &plr, sizeof(Player));
players[key] = PlayerView();
players[key].chunkPos = std::make_pair<int, int>(0, 0);
players[key].chunkPos = std::make_tuple(0, 0, p->instanceID);
players[key].currentChunks = std::vector<Chunk*>();
players[key].plr = p;
players[key].lastHeartbeat = 0;
@@ -191,7 +191,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) {
void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y) {
PlayerView& view = players[sock];
std::pair<int, int> newPos = ChunkManager::grabChunk(X, Y);
std::tuple<int, int, int> newPos = ChunkManager::grabChunk(X, Y, view.plr->instanceID);
// nothing to be done
if (newPos == view.chunkPos)
@@ -206,7 +206,7 @@ void PlayerManager::updatePlayerChunk(CNSocket* sock, int X, int Y) {
// now, add all the new npcs & players!
addPlayerToChunks(ChunkManager::getDeltaChunks(allChunks, view.currentChunks), sock);
ChunkManager::addPlayer(X, Y, sock); // takes care of adding the player to the chunk if it exists or not
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;
}
@@ -309,6 +309,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
response.PCLoadData2CL.iFirstUseFlag2 = UINT64_MAX;
plr.SerialKey = enter->iEnterSerialKey;
plr.instanceID = INSTANCE_OVERWORLD; // TODO: load this from the database (as long as it's not a unique instance)
motd.iType = 1;
U8toU16(settings::MOTDSTRING, (char16_t*)motd.szSystemMsg);
@@ -647,7 +648,7 @@ void PlayerManager::gotoPlayer(CNSocket* sock, CNPacketData* data) {
// force player & NPC reload
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
plrv.currentChunks.clear();
plrv.chunkPos = std::make_pair<int, int>(0, 0);
plrv.chunkPos = std::make_tuple(0, 0, plrv.plr->instanceID);
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_GOTO_SUCC, sizeof(sP_FE2CL_REP_PC_GOTO_SUCC));
}