mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 13:53:51 +00:00
[Server] Modernize CellController singleton
This commit is contained in:
parent
e97dac7793
commit
ff8b5061b4
16 changed files with 27 additions and 52 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;
|
||||||
|
|
||||||
|
|
|
@ -9,36 +9,16 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
CellController::CellController()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
CellController::~CellController()
|
CellController::~CellController()
|
||||||
{
|
{
|
||||||
for (auto cell : cells)
|
for (auto cell : cells)
|
||||||
delete cell;
|
delete cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
CellController *CellController::sThis = nullptr;
|
CellController &CellController::get()
|
||||||
|
|
||||||
void CellController::create()
|
|
||||||
{
|
{
|
||||||
assert(!sThis);
|
static CellController cellCtrl;
|
||||||
sThis = new CellController;
|
return cellCtrl;
|
||||||
}
|
|
||||||
|
|
||||||
void CellController::destroy()
|
|
||||||
{
|
|
||||||
assert(sThis);
|
|
||||||
delete sThis;
|
|
||||||
sThis = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CellController *CellController::get()
|
|
||||||
{
|
|
||||||
assert(sThis);
|
|
||||||
return sThis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::getCell(ESM::Cell *esmCell)
|
Cell *CellController::getCell(ESM::Cell *esmCell)
|
||||||
|
|
|
@ -15,14 +15,15 @@ class Cell;
|
||||||
class CellController
|
class CellController
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CellController();
|
CellController() = default;
|
||||||
~CellController();
|
~CellController();
|
||||||
|
|
||||||
CellController(CellController&); // not used
|
|
||||||
public:
|
public:
|
||||||
static void create();
|
CellController(const CellController&) = delete;
|
||||||
static void destroy();
|
CellController(CellController&&) = delete;
|
||||||
static CellController *get();
|
CellController& operator=(const CellController&) = delete;
|
||||||
|
CellController& operator=(CellController&&) = delete;
|
||||||
|
|
||||||
|
static CellController &get();
|
||||||
public:
|
public:
|
||||||
typedef std::deque<Cell*> TContainer;
|
typedef std::deque<Cell*> TContainer;
|
||||||
typedef TContainer::iterator TIter;
|
typedef TContainer::iterator TIter;
|
||||||
|
@ -40,7 +41,6 @@ public:
|
||||||
void update(Player *player);
|
void update(Player *player);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CellController *sThis;
|
|
||||||
TContainer cells;
|
TContainer cells;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,6 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
|
||||||
sThis = this;
|
sThis = this;
|
||||||
this->peer = peer;
|
this->peer = peer;
|
||||||
|
|
||||||
CellController::create();
|
|
||||||
|
|
||||||
playerPacketController = new PlayerPacketController(peer);
|
playerPacketController = new PlayerPacketController(peer);
|
||||||
actorPacketController = new ActorPacketController(peer);
|
actorPacketController = new ActorPacketController(peer);
|
||||||
worldPacketController = new WorldPacketController(peer);
|
worldPacketController = new WorldPacketController(peer);
|
||||||
|
@ -64,9 +62,6 @@ Networking::~Networking()
|
||||||
{
|
{
|
||||||
luaState.getEventCtrl().Call<CoreEvent::ON_EXIT>(false);
|
luaState.getEventCtrl().Call<CoreEvent::ON_EXIT>(false);
|
||||||
|
|
||||||
CellController::destroy();
|
|
||||||
|
|
||||||
sThis = nullptr;
|
|
||||||
delete playerPacketController;
|
delete playerPacketController;
|
||||||
delete actorPacketController;
|
delete actorPacketController;
|
||||||
delete worldPacketController;
|
delete worldPacketController;
|
||||||
|
|
|
@ -124,7 +124,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
printf("Player::~Player()\n");
|
printf("Player::~Player()\n");
|
||||||
CellController::get()->deletePlayer(this);
|
CellController::get().deletePlayer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::update()
|
void Player::update()
|
||||||
|
@ -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);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace mwmp
|
||||||
|
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
serverCell->sendToLoaded(&packet, &actorList);
|
serverCell->sendToLoaded(&packet, &actorList);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace mwmp
|
||||||
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send only to players who have the cell loaded
|
// Send only to players who have the cell loaded
|
||||||
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
Cell *serverCell = CellController::get().getCell(&actorList.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player->npc.mName.c_str());
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player->npc.mName.c_str());
|
||||||
|
|
||||||
CellController::get()->update(player.get());
|
CellController::get().update(player.get());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace mwmp
|
||||||
// only to players who have the container's cell loaded
|
// only to players who have the container's cell loaded
|
||||||
if (event.action == BaseEvent::SET && event.worldObjectCount > 1)
|
if (event.action == BaseEvent::SET && event.worldObjectCount > 1)
|
||||||
{
|
{
|
||||||
Cell *serverCell = CellController::get()->getCell(&event.cell);
|
Cell *serverCell = CellController::get().getCell(&event.cell);
|
||||||
|
|
||||||
if (serverCell != nullptr)
|
if (serverCell != nullptr)
|
||||||
serverCell->sendToLoaded(&packet, &event);
|
serverCell->sendToLoaded(&packet, &event);
|
||||||
|
|
Loading…
Reference in a new issue