forked from mirror/openmw-tes3mp
[Client] Turn CellController's cellsActive into a map instead of a deque
This commit is contained in:
parent
d829d219c3
commit
e89265e469
3 changed files with 33 additions and 37 deletions
|
@ -78,11 +78,14 @@ void Cell::initializeLocalActors()
|
|||
{
|
||||
MWWorld::Ptr ptr(&*listIter, 0);
|
||||
|
||||
std::string mapIndex = generateMapIndex(ptr);
|
||||
localActors[mapIndex] = new LocalActor();
|
||||
localActors[mapIndex]->cell = esmCell;
|
||||
LocalActor *actor = new LocalActor();
|
||||
actor->cell = esmCell;
|
||||
ptr.getBase()->isLocalActor = true;
|
||||
localActors[mapIndex]->setPtr(ptr);
|
||||
actor->setPtr(ptr);
|
||||
|
||||
std::string mapIndex = generateMapIndex(ptr);
|
||||
localActors[mapIndex] = actor;
|
||||
|
||||
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -112,13 +115,14 @@ void Cell::readCellFrame(mwmp::WorldEvent& worldEvent)
|
|||
{
|
||||
MWWorld::Ptr ptrFound = store->searchExact(worldObject.refId, worldObject.refNumIndex, worldObject.mpNum);
|
||||
|
||||
if (ptrFound)
|
||||
{
|
||||
dedicatedActors[mapIndex] = new DedicatedActor();
|
||||
dedicatedActors[mapIndex]->cell = worldEvent.cell;
|
||||
dedicatedActors[mapIndex]->setPtr(ptrFound);
|
||||
LOG_APPEND(Log::LOG_INFO, "- Initialized DedicatedActor %s", mapIndex.c_str());
|
||||
}
|
||||
if (!ptrFound) return;
|
||||
|
||||
DedicatedActor *actor = new DedicatedActor();
|
||||
actor->cell = worldEvent.cell;
|
||||
actor->setPtr(ptrFound);
|
||||
dedicatedActors[mapIndex] = actor;
|
||||
|
||||
LOG_APPEND(Log::LOG_INFO, "- Initialized DedicatedActor %s", mapIndex.c_str());
|
||||
}
|
||||
|
||||
// If this now exists, set its details
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "LocalPlayer.hpp"
|
||||
using namespace mwmp;
|
||||
|
||||
std::deque<mwmp::Cell *> CellController::cellsActive;
|
||||
std::map<std::string, mwmp::Cell *> CellController::cellsActive;
|
||||
|
||||
mwmp::CellController::CellController()
|
||||
{
|
||||
|
@ -24,14 +24,14 @@ mwmp::CellController::~CellController()
|
|||
|
||||
void CellController::updateLocal()
|
||||
{
|
||||
for (std::deque<mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end();)
|
||||
for (std::map<std::string, mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end();)
|
||||
{
|
||||
mwmp::Cell *mpCell = *it;
|
||||
mwmp::Cell *mpCell = it->second;
|
||||
|
||||
if (!MWBase::Environment::get().getWorld()->isCellActive(mpCell->getCellStore()))
|
||||
{
|
||||
mpCell->uninitializeLocalActors();
|
||||
it = cellsActive.erase(it);
|
||||
cellsActive.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -49,42 +49,34 @@ void CellController::initializeCellLocal(const ESM::Cell& cell)
|
|||
if (!cellStore) return;
|
||||
|
||||
mwmp::Cell *mpCell = new mwmp::Cell(cellStore);
|
||||
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Initialized mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||
|
||||
mpCell->initializeLocalActors();
|
||||
cellsActive.push_back(mpCell);
|
||||
|
||||
std::string mapIndex = mpCell->getDescription();
|
||||
cellsActive[mapIndex] = mpCell;
|
||||
}
|
||||
|
||||
void CellController::readCellFrame(mwmp::WorldEvent& worldEvent)
|
||||
{
|
||||
bool cellExisted = false;
|
||||
std::string mapIndex = worldEvent.cell.getDescription();
|
||||
|
||||
// Check if this cell already exists
|
||||
for (std::deque<mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end(); ++it)
|
||||
{
|
||||
mwmp::Cell *mpCell = *it;
|
||||
|
||||
if (worldEvent.cell.getDescription() == mpCell->getDescription())
|
||||
{
|
||||
mpCell->readCellFrame(worldEvent);
|
||||
cellExisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cellExisted)
|
||||
// If this key doesn't exist, create it
|
||||
if (cellsActive.count(mapIndex) == 0)
|
||||
{
|
||||
MWWorld::CellStore *cellStore = getCell(worldEvent.cell);
|
||||
|
||||
if (!cellStore) return;
|
||||
|
||||
mwmp::Cell *mpCell = new mwmp::Cell(cellStore);
|
||||
cellsActive[mapIndex] = mpCell;
|
||||
}
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Initialized mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||
|
||||
cellsActive.push_back(mpCell);
|
||||
mpCell->readCellFrame(worldEvent);
|
||||
// If this now exists, send it the data
|
||||
if (cellsActive.count(mapIndex) > 0)
|
||||
{
|
||||
cellsActive[mapIndex]->readCellFrame(worldEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mwmp
|
|||
void closeContainer(const MWWorld::Ptr& container);
|
||||
|
||||
private:
|
||||
static std::deque<mwmp::Cell *> cellsActive;
|
||||
static std::map<std::string, mwmp::Cell *> cellsActive;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue