[Server] Modernize CellController singleton

sol2-server-rewrite
Koncord 7 years ago
parent e97dac7793
commit ff8b5061b4

@ -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;

@ -9,36 +9,16 @@
using namespace std;
CellController::CellController()
{
}
CellController::~CellController()
{
for (auto cell : cells)
delete cell;
}
CellController *CellController::sThis = nullptr;
void CellController::create()
{
assert(!sThis);
sThis = new CellController;
}
void CellController::destroy()
{
assert(sThis);
delete sThis;
sThis = nullptr;
}
CellController *CellController::get()
CellController &CellController::get()
{
assert(sThis);
return sThis;
static CellController cellCtrl;
return cellCtrl;
}
Cell *CellController::getCell(ESM::Cell *esmCell)

@ -15,14 +15,15 @@ class Cell;
class CellController
{
private:
CellController();
CellController() = default;
~CellController();
CellController(CellController&); // not used
public:
static void create();
static void destroy();
static CellController *get();
CellController(const CellController&) = delete;
CellController(CellController&&) = delete;
CellController& operator=(const CellController&) = delete;
CellController& operator=(CellController&&) = delete;
static CellController &get();
public:
typedef std::deque<Cell*> TContainer;
typedef TContainer::iterator TIter;
@ -40,7 +41,6 @@ public:
void update(Player *player);
private:
static CellController *sThis;
TContainer cells;
};

@ -40,8 +40,6 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
sThis = this;
this->peer = peer;
CellController::create();
playerPacketController = new PlayerPacketController(peer);
actorPacketController = new ActorPacketController(peer);
worldPacketController = new WorldPacketController(peer);
@ -63,10 +61,7 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
Networking::~Networking()
{
luaState.getEventCtrl().Call<CoreEvent::ON_EXIT>(false);
CellController::destroy();
sThis = nullptr;
delete playerPacketController;
delete actorPacketController;
delete worldPacketController;

@ -124,7 +124,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM
Player::~Player()
{
printf("Player::~Player()\n");
CellController::get()->deletePlayer(this);
CellController::get().deletePlayer(this);
}
void Player::update()
@ -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);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -15,7 +15,7 @@ namespace mwmp
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)
{

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
{

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
serverCell->sendToLoaded(&packet, &actorList);

@ -16,7 +16,7 @@ namespace mwmp
void Do(ActorPacket &packet, const std::shared_ptr<Player> &player, BaseActorList &actorList) override
{
// 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)
{

@ -21,7 +21,7 @@ namespace mwmp
{
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
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)
serverCell->sendToLoaded(&packet, &event);

Loading…
Cancel
Save