forked from mirror/openmw-tes3mp
[Client] Add localActorsToCells map to more easily find LocalActors
This commit is contained in:
parent
e89265e469
commit
10be52d40d
4 changed files with 67 additions and 39 deletions
|
@ -1,9 +1,9 @@
|
||||||
#include "../mwworld/worldimp.hpp"
|
#include "../mwworld/worldimp.hpp"
|
||||||
#include <components/esm/cellid.hpp>
|
#include <components/esm/cellid.hpp>
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
#include <components/openmw-mp/Utils.hpp>
|
|
||||||
|
|
||||||
#include "Cell.hpp"
|
#include "Cell.hpp"
|
||||||
|
#include "CellController.hpp"
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
#include "Networking.hpp"
|
#include "Networking.hpp"
|
||||||
#include "LocalPlayer.hpp"
|
#include "LocalPlayer.hpp"
|
||||||
|
@ -26,7 +26,7 @@ void Cell::updateLocal()
|
||||||
{
|
{
|
||||||
if (localActors.empty()) return;
|
if (localActors.empty()) return;
|
||||||
|
|
||||||
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||||
worldEvent->reset();
|
worldEvent->reset();
|
||||||
worldEvent->cell = *store->getCell();
|
worldEvent->cell = *store->getCell();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void Cell::updateLocal()
|
||||||
actor->update();
|
actor->update();
|
||||||
MWWorld::Ptr ptr = actor->getPtr();
|
MWWorld::Ptr ptr = actor->getPtr();
|
||||||
|
|
||||||
mwmp::WorldObject worldObject;
|
WorldObject worldObject;
|
||||||
worldObject.refId = ptr.getCellRef().getRefId();
|
worldObject.refId = ptr.getCellRef().getRefId();
|
||||||
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
|
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
|
||||||
worldObject.mpNum = ptr.getCellRef().getMpNum();
|
worldObject.mpNum = ptr.getCellRef().getMpNum();
|
||||||
|
@ -64,8 +64,8 @@ void Cell::updateLocal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_FRAME)->setEvent(worldEvent);
|
Main::get().getNetworking()->getWorldPacket(ID_ACTOR_FRAME)->setEvent(worldEvent);
|
||||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_FRAME)->Send();
|
Main::get().getNetworking()->getWorldPacket(ID_ACTOR_FRAME)->Send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cell::initializeLocalActors()
|
void Cell::initializeLocalActors()
|
||||||
|
@ -83,9 +83,11 @@ void Cell::initializeLocalActors()
|
||||||
ptr.getBase()->isLocalActor = true;
|
ptr.getBase()->isLocalActor = true;
|
||||||
actor->setPtr(ptr);
|
actor->setPtr(ptr);
|
||||||
|
|
||||||
std::string mapIndex = generateMapIndex(ptr);
|
std::string mapIndex = Main::get().getCellController()->generateMapIndex(ptr);
|
||||||
localActors[mapIndex] = actor;
|
localActors[mapIndex] = actor;
|
||||||
|
|
||||||
|
Main::get().getCellController()->setLocalActorRecord(mapIndex, getDescription());
|
||||||
|
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
|
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,19 +98,21 @@ void Cell::uninitializeLocalActors()
|
||||||
{
|
{
|
||||||
LocalActor *actor = it->second;
|
LocalActor *actor = it->second;
|
||||||
actor->getPtr().getBase()->isLocalActor = false;
|
actor->getPtr().getBase()->isLocalActor = false;
|
||||||
|
|
||||||
|
Main::get().getCellController()->removeLocalActorRecord(it->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
localActors.clear();
|
localActors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cell::readCellFrame(mwmp::WorldEvent& worldEvent)
|
void Cell::readCellFrame(WorldEvent& worldEvent)
|
||||||
{
|
{
|
||||||
WorldObject worldObject;
|
WorldObject worldObject;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < worldEvent.objectChanges.count; i++)
|
for (unsigned int i = 0; i < worldEvent.objectChanges.count; i++)
|
||||||
{
|
{
|
||||||
worldObject = worldEvent.objectChanges.objects.at(i);
|
worldObject = worldEvent.objectChanges.objects.at(i);
|
||||||
std::string mapIndex = generateMapIndex(worldObject);
|
std::string mapIndex = Main::get().getCellController()->generateMapIndex(worldObject);
|
||||||
|
|
||||||
// If this key doesn't exist, create it
|
// If this key doesn't exist, create it
|
||||||
if (dedicatedActors.count(mapIndex) == 0)
|
if (dedicatedActors.count(mapIndex) == 0)
|
||||||
|
@ -143,30 +147,12 @@ void Cell::readCellFrame(mwmp::WorldEvent& worldEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Cell::generateMapIndex(MWWorld::Ptr ptr)
|
MWWorld::CellStore *Cell::getCellStore()
|
||||||
{
|
|
||||||
std::string mapIndex = "";
|
|
||||||
mapIndex += ptr.getCellRef().getRefId();
|
|
||||||
mapIndex += "-" + Utils::toString(ptr.getCellRef().getRefNum().mIndex);
|
|
||||||
mapIndex += "-" + Utils::toString(ptr.getCellRef().getMpNum());
|
|
||||||
return mapIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Cell::generateMapIndex(mwmp::WorldObject object)
|
|
||||||
{
|
|
||||||
std::string mapIndex = "";
|
|
||||||
mapIndex += object.refId;
|
|
||||||
mapIndex += "-" + Utils::toString(object.refNumIndex);
|
|
||||||
mapIndex += "-" + Utils::toString(object.mpNum);
|
|
||||||
return mapIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWWorld::CellStore *mwmp::Cell::getCellStore()
|
|
||||||
{
|
{
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string mwmp::Cell::getDescription()
|
std::string Cell::getDescription()
|
||||||
{
|
{
|
||||||
return store->getCell()->getDescription();
|
return store->getCell()->getDescription();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,6 @@ namespace mwmp
|
||||||
void uninitializeLocalActors();
|
void uninitializeLocalActors();
|
||||||
void readCellFrame(mwmp::WorldEvent& worldEvent);
|
void readCellFrame(mwmp::WorldEvent& worldEvent);
|
||||||
|
|
||||||
std::string generateMapIndex(MWWorld::Ptr ptr);
|
|
||||||
std::string generateMapIndex(mwmp::WorldObject object);
|
|
||||||
|
|
||||||
MWWorld::CellStore* getCellStore();
|
MWWorld::CellStore* getCellStore();
|
||||||
std::string getDescription();
|
std::string getDescription();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "../mwworld/worldimp.hpp"
|
#include "../mwworld/worldimp.hpp"
|
||||||
#include <components/esm/cellid.hpp>
|
#include <components/esm/cellid.hpp>
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
#include <components/openmw-mp/Utils.hpp>
|
||||||
#include "../mwworld/containerstore.hpp"
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
|
||||||
std::map<std::string, mwmp::Cell *> CellController::cellsActive;
|
std::map<std::string, mwmp::Cell *> CellController::cellsActive;
|
||||||
|
std::map<std::string, std::string> CellController::localActorsToCells;
|
||||||
|
|
||||||
mwmp::CellController::CellController()
|
mwmp::CellController::CellController()
|
||||||
{
|
{
|
||||||
|
@ -58,7 +60,7 @@ void CellController::initializeCellLocal(const ESM::Cell& cell)
|
||||||
cellsActive[mapIndex] = mpCell;
|
cellsActive[mapIndex] = mpCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellController::readCellFrame(mwmp::WorldEvent& worldEvent)
|
void CellController::readCellFrame(WorldEvent& worldEvent)
|
||||||
{
|
{
|
||||||
std::string mapIndex = worldEvent.cell.getDescription();
|
std::string mapIndex = worldEvent.cell.getDescription();
|
||||||
|
|
||||||
|
@ -80,12 +82,47 @@ void CellController::readCellFrame(mwmp::WorldEvent& worldEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int mwmp::CellController::getCellSize() const
|
void CellController::setLocalActorRecord(std::string actorIndex, std::string cellIndex)
|
||||||
|
{
|
||||||
|
localActorsToCells[actorIndex] = cellIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CellController::removeLocalActorRecord(std::string actorIndex)
|
||||||
|
{
|
||||||
|
localActorsToCells.erase(actorIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CellController::hasLocalActorRecord(MWWorld::Ptr ptr)
|
||||||
|
{
|
||||||
|
std::string mapIndex = generateMapIndex(ptr);
|
||||||
|
|
||||||
|
return (localActorsToCells.count(mapIndex) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CellController::generateMapIndex(MWWorld::Ptr ptr)
|
||||||
|
{
|
||||||
|
std::string mapIndex = "";
|
||||||
|
mapIndex += ptr.getCellRef().getRefId();
|
||||||
|
mapIndex += "-" + Utils::toString(ptr.getCellRef().getRefNum().mIndex);
|
||||||
|
mapIndex += "-" + Utils::toString(ptr.getCellRef().getMpNum());
|
||||||
|
return mapIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CellController::generateMapIndex(WorldObject object)
|
||||||
|
{
|
||||||
|
std::string mapIndex = "";
|
||||||
|
mapIndex += object.refId;
|
||||||
|
mapIndex += "-" + Utils::toString(object.refNumIndex);
|
||||||
|
mapIndex += "-" + Utils::toString(object.mpNum);
|
||||||
|
return mapIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CellController::getCellSize() const
|
||||||
{
|
{
|
||||||
return 8192;
|
return 8192;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::CellStore *mwmp::CellController::getCell(const ESM::Cell& cell)
|
MWWorld::CellStore *CellController::getCell(const ESM::Cell& cell)
|
||||||
{
|
{
|
||||||
MWWorld::CellStore *cellStore;
|
MWWorld::CellStore *cellStore;
|
||||||
|
|
||||||
|
@ -107,10 +144,10 @@ MWWorld::CellStore *mwmp::CellController::getCell(const ESM::Cell& cell)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mwmp::CellController::openContainer(const MWWorld::Ptr &container, bool loot)
|
void CellController::openContainer(const MWWorld::Ptr &container, bool loot)
|
||||||
{
|
{
|
||||||
// Record this as the player's current open container
|
// Record this as the player's current open container
|
||||||
mwmp::Main::get().getLocalPlayer()->storeCurrentContainer(container, loot);
|
Main::get().getLocalPlayer()->storeCurrentContainer(container, loot);
|
||||||
|
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s",
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s",
|
||||||
container.getCellRef().getRefId().c_str(), container.getCellRef().getRefNum().mIndex,
|
container.getCellRef().getRefId().c_str(), container.getCellRef().getRefNum().mIndex,
|
||||||
|
@ -130,9 +167,9 @@ void mwmp::CellController::openContainer(const MWWorld::Ptr &container, bool loo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mwmp::CellController::closeContainer(const MWWorld::Ptr &container)
|
void CellController::closeContainer(const MWWorld::Ptr &container)
|
||||||
{
|
{
|
||||||
mwmp::Main::get().getLocalPlayer()->clearCurrentContainer();
|
Main::get().getLocalPlayer()->clearCurrentContainer();
|
||||||
|
|
||||||
// If the player died while in a container, the container's Ptr could be invalid now
|
// If the player died while in a container, the container's Ptr could be invalid now
|
||||||
if (!container.isEmpty())
|
if (!container.isEmpty())
|
||||||
|
@ -148,5 +185,5 @@ void mwmp::CellController::closeContainer(const MWWorld::Ptr &container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mwmp::Main::get().getLocalPlayer()->updateInventory();
|
Main::get().getLocalPlayer()->updateInventory();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,13 @@ namespace mwmp
|
||||||
void initializeCellLocal(const ESM::Cell& cell);
|
void initializeCellLocal(const ESM::Cell& cell);
|
||||||
void readCellFrame(mwmp::WorldEvent& worldEvent);
|
void readCellFrame(mwmp::WorldEvent& worldEvent);
|
||||||
|
|
||||||
|
void setLocalActorRecord(std::string actorIndex, std::string cellIndex);
|
||||||
|
void removeLocalActorRecord(std::string actorIndex);
|
||||||
|
bool hasLocalActorRecord(MWWorld::Ptr ptr);
|
||||||
|
|
||||||
|
std::string generateMapIndex(MWWorld::Ptr ptr);
|
||||||
|
std::string generateMapIndex(mwmp::WorldObject object);
|
||||||
|
|
||||||
int getCellSize() const;
|
int getCellSize() const;
|
||||||
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
||||||
|
|
||||||
|
@ -28,6 +35,7 @@ namespace mwmp
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::map<std::string, mwmp::Cell *> cellsActive;
|
static std::map<std::string, mwmp::Cell *> cellsActive;
|
||||||
|
static std::map<std::string, std::string> localActorsToCells;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue