[Server] Optimize CellController

sol2-server-rewrite
Koncord 7 years ago
parent ff8b5061b4
commit 585c24cee8

@ -175,7 +175,7 @@ void ActorController::sendActors(std::shared_ptr<Player> player, std::vector<std
Cell *serverCell = nullptr;
if (sendToAll)
serverCell = CellController::get().getCell(&actorList.cell);
serverCell = CellController::get().getCell(actorList.cell);
if (positionChanged)
{
@ -250,7 +250,7 @@ void ActorController::sendList(std::shared_ptr<Player> player, std::vector<std::
packet->setActorList(&actorList);
packet->Send(actorList.guid);
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)
@ -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)
{
Cell *serverCell = CellController::get().getCell(&player->cell);
Cell *serverCell = CellController::get().getCell(player->cell);
std::vector<std::shared_ptr<Actor>> actorList;

@ -57,7 +57,7 @@ void Cell::addPlayer(Player *player)
void Cell::removePlayer(Player *player)
{
for (Iterator it = begin(); it != end(); it++)
for (auto it = begin(); it != end(); it++)
{
if (*it == player)
{
@ -82,14 +82,12 @@ void Cell::removePlayer(Player *player)
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))
{
cellActor = getActor(newActor->refNumIndex, newActor->mpNum);
mwmp::BaseActor *cellActor = getActor(newActor->refNumIndex, newActor->mpNum);
switch (packetID)
{
@ -135,7 +133,7 @@ mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum)
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();)
{
@ -144,10 +142,8 @@ void Cell::removeActors(const mwmp::BaseActorList *newActorList)
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)
{
it = cellActorList.baseActors.erase(it);
@ -190,7 +186,7 @@ void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *bas
std::list <Player*> plList;
for (auto pl : players)
for (auto &pl : players)
{
if (pl != nullptr && !pl->npc.mName.empty())
plList.push_back(pl);
@ -199,7 +195,7 @@ void Cell::sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *bas
plList.sort();
plList.unique();
for (auto pl : plList)
for (auto &pl : plList)
{
if (pl->guid == baseActorList->guid) continue;
@ -217,7 +213,7 @@ void Cell::sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEve
std::list <Player*> plList;
for (auto pl : players)
for (auto &pl : players)
{
if (pl != nullptr && !pl->npc.mName.empty())
plList.push_back(pl);
@ -226,7 +222,7 @@ void Cell::sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEve
plList.sort();
plList.unique();
for (auto pl : plList)
for (auto &pl : plList)
{
if (pl->guid == baseEvent->guid) continue;

@ -33,7 +33,7 @@ public:
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
bool containsActor(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();
void setAuthority(const RakNet::RakNetGUID& guid);

@ -21,12 +21,12 @@ CellController &CellController::get()
return cellCtrl;
}
Cell *CellController::getCell(ESM::Cell *esmCell)
Cell *CellController::getCell(const ESM::Cell &esmCell)
{
if (esmCell->isExterior())
return getCellByXY(esmCell->mData.mX, esmCell->mData.mY);
if (esmCell.isExterior())
return getCellByXY(esmCell.mData.mX, esmCell.mData.mY);
else
return getCellByName(esmCell->mName);
return getCellByName(esmCell.mName);
}
@ -46,7 +46,7 @@ Cell *CellController::getCellByXY(int x, int y)
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)
{
@ -62,7 +62,7 @@ Cell *CellController::getCellByName(std::string cellName)
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());
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());
for (auto it = player->getCells()->begin(); player->getCells()->size() != 0; ++it)
for (auto it = player->getCells()->begin(); !player->getCells()->empty(); ++it)
removePlayer(*it, player);
}

@ -28,15 +28,15 @@ public:
typedef std::deque<Cell*> TContainer;
typedef TContainer::iterator TIter;
Cell * addCell(ESM::Cell cell);
Cell *addCell(const ESM::Cell &cellData);
void removeCell(Cell *);
void removePlayer(Cell *cell, Player *player);
void deletePlayer(Player *player);
Cell *getCell(ESM::Cell *esmCell);
Cell *getCell(const ESM::Cell &esmCell);
Cell *getCellByXY(int x, int y);
Cell *getCellByName(std::string cellName);
Cell *getCellByName(const std::string &cellName);
void update(Player *player);

@ -299,8 +299,8 @@ void Player::sendToLoaded(mwmp::PlayerPacket *myPacket)
{
std::list <Player*> plList;
for (auto cell : cells)
for (auto pl : *cell)
for (auto &cell : cells)
for (auto &pl : *cell)
plList.push_back(pl);
plList.sort();
@ -796,7 +796,7 @@ void Player::setAuthority()
writeActorList.cell = cell;
writeActorList.guid = guid;
Cell *serverCell = CellController::get().getCell(&cell);
Cell *serverCell = CellController::get().getCell(cell);
if (serverCell != nullptr)
{
serverCell->setAuthority(guid);

Loading…
Cancel
Save