mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:53:51 +00:00
[Server] Optimize CellController
This commit is contained in:
parent
ff8b5061b4
commit
585c24cee8
6 changed files with 26 additions and 30 deletions
|
@ -175,7 +175,7 @@ void ActorController::sendActors(std::shared_ptr<Player> player, std::vector<std
|
||||||
Cell *serverCell = nullptr;
|
Cell *serverCell = nullptr;
|
||||||
|
|
||||||
if (sendToAll)
|
if (sendToAll)
|
||||||
serverCell = CellController::get().getCell(&actorList.cell);
|
serverCell = CellController::get().getCell(actorList.cell);
|
||||||
|
|
||||||
if (positionChanged)
|
if (positionChanged)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +250,7 @@ void ActorController::sendList(std::shared_ptr<Player> player, std::vector<std::
|
||||||
packet->setActorList(&actorList);
|
packet->setActorList(&actorList);
|
||||||
packet->Send(actorList.guid);
|
packet->Send(actorList.guid);
|
||||||
if (sendToAll)
|
if (sendToAll)
|
||||||
CellController::get().getCell(&actorList.cell)->sendToLoaded(packet, &actorList);
|
CellController::get().getCell(actorList.cell)->sendToLoaded(packet, &actorList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActorController::requestList(std::shared_ptr<Player> player, const ESM::Cell &cell)
|
void ActorController::requestList(std::shared_ptr<Player> player, const ESM::Cell &cell)
|
||||||
|
@ -266,7 +266,7 @@ void ActorController::requestList(std::shared_ptr<Player> player, const ESM::Cel
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Actor>> ActorController::getActors(std::shared_ptr<Player> player, const ESM::Cell &cell)
|
std::vector<std::shared_ptr<Actor>> ActorController::getActors(std::shared_ptr<Player> player, const ESM::Cell &cell)
|
||||||
{
|
{
|
||||||
Cell *serverCell = CellController::get().getCell(&player->cell);
|
Cell *serverCell = CellController::get().getCell(player->cell);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Actor>> actorList;
|
std::vector<std::shared_ptr<Actor>> actorList;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ void Cell::addPlayer(Player *player)
|
||||||
|
|
||||||
void Cell::removePlayer(Player *player)
|
void Cell::removePlayer(Player *player)
|
||||||
{
|
{
|
||||||
for (Iterator it = begin(); it != end(); it++)
|
for (auto it = begin(); it != end(); it++)
|
||||||
{
|
{
|
||||||
if (*it == player)
|
if (*it == player)
|
||||||
{
|
{
|
||||||
|
@ -82,14 +82,12 @@ void Cell::removePlayer(Player *player)
|
||||||
|
|
||||||
void Cell::readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList)
|
void Cell::readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < newActorList->count; i++)
|
for (auto &newActor : newActorList->baseActors)
|
||||||
{
|
{
|
||||||
auto &newActor = newActorList->baseActors.at(i);
|
|
||||||
mwmp::BaseActor *cellActor;
|
|
||||||
|
|
||||||
if (containsActor(newActor->refNumIndex, newActor->mpNum))
|
if (containsActor(newActor->refNumIndex, newActor->mpNum))
|
||||||
{
|
{
|
||||||
cellActor = getActor(newActor->refNumIndex, newActor->mpNum);
|
mwmp::BaseActor *cellActor = getActor(newActor->refNumIndex, newActor->mpNum);
|
||||||
|
|
||||||
switch (packetID)
|
switch (packetID)
|
||||||
{
|
{
|
||||||
|
@ -135,7 +133,7 @@ mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cell::removeActors(const mwmp::BaseActorList *newActorList)
|
void Cell::removeActors(const mwmp::BaseActorList &newActorList)
|
||||||
{
|
{
|
||||||
for (auto it = cellActorList.baseActors.begin(); it != cellActorList.baseActors.end();)
|
for (auto it = cellActorList.baseActors.begin(); it != cellActorList.baseActors.end();)
|
||||||
{
|
{
|
||||||
|
@ -144,10 +142,8 @@ void Cell::removeActors(const mwmp::BaseActorList *newActorList)
|
||||||
|
|
||||||
bool foundActor = false;
|
bool foundActor = false;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < newActorList->count; i++)
|
for (const auto &newActor : newActorList.baseActors)
|
||||||
{
|
{
|
||||||
auto &newActor = newActorList->baseActors.at(i);
|
|
||||||
|
|
||||||
if (newActor->refNumIndex == refNumIndex && newActor->mpNum == mpNum)
|
if (newActor->refNumIndex == refNumIndex && newActor->mpNum == mpNum)
|
||||||
{
|
{
|
||||||
it = cellActorList.baseActors.erase(it);
|
it = cellActorList.baseActors.erase(it);
|
||||||
|
@ -190,7 +186,7 @@ void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *bas
|
||||||
|
|
||||||
std::list <Player*> plList;
|
std::list <Player*> plList;
|
||||||
|
|
||||||
for (auto pl : players)
|
for (auto &pl : players)
|
||||||
{
|
{
|
||||||
if (pl != nullptr && !pl->npc.mName.empty())
|
if (pl != nullptr && !pl->npc.mName.empty())
|
||||||
plList.push_back(pl);
|
plList.push_back(pl);
|
||||||
|
@ -199,7 +195,7 @@ void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *bas
|
||||||
plList.sort();
|
plList.sort();
|
||||||
plList.unique();
|
plList.unique();
|
||||||
|
|
||||||
for (auto pl : plList)
|
for (auto &pl : plList)
|
||||||
{
|
{
|
||||||
if (pl->guid == baseActorList->guid) continue;
|
if (pl->guid == baseActorList->guid) continue;
|
||||||
|
|
||||||
|
@ -217,7 +213,7 @@ void Cell::sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEve
|
||||||
|
|
||||||
std::list <Player*> plList;
|
std::list <Player*> plList;
|
||||||
|
|
||||||
for (auto pl : players)
|
for (auto &pl : players)
|
||||||
{
|
{
|
||||||
if (pl != nullptr && !pl->npc.mName.empty())
|
if (pl != nullptr && !pl->npc.mName.empty())
|
||||||
plList.push_back(pl);
|
plList.push_back(pl);
|
||||||
|
@ -226,7 +222,7 @@ void Cell::sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEve
|
||||||
plList.sort();
|
plList.sort();
|
||||||
plList.unique();
|
plList.unique();
|
||||||
|
|
||||||
for (auto pl : plList)
|
for (auto &pl : plList)
|
||||||
{
|
{
|
||||||
if (pl->guid == baseEvent->guid) continue;
|
if (pl->guid == baseEvent->guid) continue;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
|
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
|
||||||
bool containsActor(int refNumIndex, int mpNum);
|
bool containsActor(int refNumIndex, int mpNum);
|
||||||
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
|
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
|
||||||
void removeActors(const mwmp::BaseActorList *newActorList);
|
void removeActors(const mwmp::BaseActorList &newActorList);
|
||||||
|
|
||||||
RakNet::RakNetGUID *getAuthority();
|
RakNet::RakNetGUID *getAuthority();
|
||||||
void setAuthority(const RakNet::RakNetGUID& guid);
|
void setAuthority(const RakNet::RakNetGUID& guid);
|
||||||
|
|
|
@ -21,12 +21,12 @@ CellController &CellController::get()
|
||||||
return cellCtrl;
|
return cellCtrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::getCell(ESM::Cell *esmCell)
|
Cell *CellController::getCell(const ESM::Cell &esmCell)
|
||||||
{
|
{
|
||||||
if (esmCell->isExterior())
|
if (esmCell.isExterior())
|
||||||
return getCellByXY(esmCell->mData.mX, esmCell->mData.mY);
|
return getCellByXY(esmCell.mData.mX, esmCell.mData.mY);
|
||||||
else
|
else
|
||||||
return getCellByName(esmCell->mName);
|
return getCellByName(esmCell.mName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ Cell *CellController::getCellByXY(int x, int y)
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::getCellByName(std::string cellName)
|
Cell *CellController::getCellByName(const std::string &cellName)
|
||||||
{
|
{
|
||||||
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c)
|
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ Cell *CellController::getCellByName(std::string cellName)
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::addCell(ESM::Cell cellData)
|
Cell *CellController::addCell(const ESM::Cell &cellData)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Loaded cells: %d", cells.size());
|
LOG_APPEND(Log::LOG_INFO, "- Loaded cells: %d", cells.size());
|
||||||
auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) {
|
auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) {
|
||||||
|
@ -132,7 +132,7 @@ void CellController::deletePlayer(Player *player)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Iterating through Cells from Player %s", player->npc.mName.c_str());
|
LOG_APPEND(Log::LOG_INFO, "- Iterating through Cells from Player %s", player->npc.mName.c_str());
|
||||||
|
|
||||||
for (auto it = player->getCells()->begin(); player->getCells()->size() != 0; ++it)
|
for (auto it = player->getCells()->begin(); !player->getCells()->empty(); ++it)
|
||||||
removePlayer(*it, player);
|
removePlayer(*it, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ public:
|
||||||
typedef std::deque<Cell*> TContainer;
|
typedef std::deque<Cell*> TContainer;
|
||||||
typedef TContainer::iterator TIter;
|
typedef TContainer::iterator TIter;
|
||||||
|
|
||||||
Cell * addCell(ESM::Cell cell);
|
Cell *addCell(const ESM::Cell &cellData);
|
||||||
void removeCell(Cell *);
|
void removeCell(Cell *);
|
||||||
|
|
||||||
void removePlayer(Cell *cell, Player *player);
|
void removePlayer(Cell *cell, Player *player);
|
||||||
void deletePlayer(Player *player);
|
void deletePlayer(Player *player);
|
||||||
|
|
||||||
Cell *getCell(ESM::Cell *esmCell);
|
Cell *getCell(const ESM::Cell &esmCell);
|
||||||
Cell *getCellByXY(int x, int y);
|
Cell *getCellByXY(int x, int y);
|
||||||
Cell *getCellByName(std::string cellName);
|
Cell *getCellByName(const std::string &cellName);
|
||||||
|
|
||||||
void update(Player *player);
|
void update(Player *player);
|
||||||
|
|
||||||
|
|
|
@ -299,8 +299,8 @@ void Player::sendToLoaded(mwmp::PlayerPacket *myPacket)
|
||||||
{
|
{
|
||||||
std::list <Player*> plList;
|
std::list <Player*> plList;
|
||||||
|
|
||||||
for (auto cell : cells)
|
for (auto &cell : cells)
|
||||||
for (auto pl : *cell)
|
for (auto &pl : *cell)
|
||||||
plList.push_back(pl);
|
plList.push_back(pl);
|
||||||
|
|
||||||
plList.sort();
|
plList.sort();
|
||||||
|
@ -796,7 +796,7 @@ void Player::setAuthority()
|
||||||
writeActorList.cell = cell;
|
writeActorList.cell = cell;
|
||||||
writeActorList.guid = guid;
|
writeActorList.guid = guid;
|
||||||
|
|
||||||
Cell *serverCell = CellController::get().getCell(&cell);
|
Cell *serverCell = CellController::get().getCell(cell);
|
||||||
if (serverCell != nullptr)
|
if (serverCell != nullptr)
|
||||||
{
|
{
|
||||||
serverCell->setAuthority(guid);
|
serverCell->setAuthority(guid);
|
||||||
|
|
Loading…
Reference in a new issue