mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 21:09:40 +00:00
[Client] Add and use mwmp::Cell class
This commit is contained in:
parent
9beaf9b7a1
commit
0d766a7a04
9 changed files with 150 additions and 35 deletions
|
@ -96,7 +96,7 @@ add_openmw_dir (mwbase
|
||||||
inputmanager windowmanager statemanager
|
inputmanager windowmanager statemanager
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor WorldEvent CellController GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList)
|
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor WorldEvent Cell CellController GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList)
|
||||||
|
|
||||||
# Main executable
|
# Main executable
|
||||||
|
|
||||||
|
|
79
apps/openmw/mwmp/Cell.cpp
Normal file
79
apps/openmw/mwmp/Cell.cpp
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#include "../mwworld/worldimp.hpp"
|
||||||
|
#include <components/esm/cellid.hpp>
|
||||||
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
|
||||||
|
#include "Cell.hpp"
|
||||||
|
#include "Main.hpp"
|
||||||
|
#include "LocalPlayer.hpp"
|
||||||
|
using namespace mwmp;
|
||||||
|
|
||||||
|
mwmp::Cell::Cell(MWWorld::CellStore* cellStore)
|
||||||
|
{
|
||||||
|
store = cellStore;
|
||||||
|
|
||||||
|
std::map<std::string, LocalActor *> localActors;
|
||||||
|
std::map<std::string, DedicatedActor *> dedicatedActors;
|
||||||
|
}
|
||||||
|
|
||||||
|
mwmp::Cell::~Cell()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cell::update()
|
||||||
|
{
|
||||||
|
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();)
|
||||||
|
{
|
||||||
|
LocalActor *actor = it->second;
|
||||||
|
|
||||||
|
// TODO:: Make sure this condition actually works
|
||||||
|
if (actor->getPtr().getCell() != nullptr && actor->getPtr().getCell() != store)
|
||||||
|
{
|
||||||
|
LOG_APPEND(Log::LOG_INFO, "- Removing LocalActor %s which is no longer in this cell", it->first.c_str());
|
||||||
|
localActors.erase(it++);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
|
||||||
|
actor->update();
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cell::initializeLocalActors()
|
||||||
|
{
|
||||||
|
ESM::Cell esmCell = *store->getCell();
|
||||||
|
MWWorld::CellRefList<ESM::NPC> *npcList = store->getNpcs();
|
||||||
|
|
||||||
|
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
|
||||||
|
listIter != npcList->mList.end(); ++listIter)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr ptr(&*listIter, 0);
|
||||||
|
|
||||||
|
std::string mapIndex = generateMapIndex(ptr);
|
||||||
|
localActors[mapIndex] = new LocalActor();
|
||||||
|
localActors[mapIndex]->cell = esmCell;
|
||||||
|
localActors[mapIndex]->setPtr(ptr);
|
||||||
|
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Cell::generateMapIndex(MWWorld::Ptr ptr)
|
||||||
|
{
|
||||||
|
std::string mapIndex = "";
|
||||||
|
mapIndex += ptr.getCellRef().getRefId();
|
||||||
|
mapIndex += "-" + std::to_string(ptr.getCellRef().getRefNum().mIndex);
|
||||||
|
mapIndex += "-" + std::to_string(ptr.getCellRef().getMpNum());
|
||||||
|
return mapIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::CellStore *mwmp::Cell::getCellStore()
|
||||||
|
{
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string mwmp::Cell::getDescription()
|
||||||
|
{
|
||||||
|
return store->getCell()->getDescription();
|
||||||
|
}
|
32
apps/openmw/mwmp/Cell.hpp
Normal file
32
apps/openmw/mwmp/Cell.hpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef OPENMW_CELL_HPP
|
||||||
|
#define OPENMW_CELL_HPP
|
||||||
|
|
||||||
|
#include "LocalActor.hpp"
|
||||||
|
#include "DedicatedActor.hpp"
|
||||||
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
|
||||||
|
namespace mwmp
|
||||||
|
{
|
||||||
|
class Cell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Cell(MWWorld::CellStore* cellStore);
|
||||||
|
~Cell();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
void initializeLocalActors();
|
||||||
|
|
||||||
|
std::string generateMapIndex(MWWorld::Ptr ptr);
|
||||||
|
|
||||||
|
MWWorld::CellStore* getCellStore();
|
||||||
|
std::string getDescription();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MWWorld::CellStore* store;
|
||||||
|
std::map<std::string, mwmp::LocalActor *> localActors;
|
||||||
|
std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //OPENMW_CELL_HPP
|
|
@ -10,8 +10,7 @@
|
||||||
#include "LocalPlayer.hpp"
|
#include "LocalPlayer.hpp"
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
|
||||||
std::map<std::string, LocalActor *> CellController::localActors;
|
std::deque<mwmp::Cell *> CellController::cellsActive;
|
||||||
std::map<std::string, DedicatedActor *> CellController::dedicatedActors;
|
|
||||||
|
|
||||||
mwmp::CellController::CellController()
|
mwmp::CellController::CellController()
|
||||||
{
|
{
|
||||||
|
@ -25,49 +24,36 @@ mwmp::CellController::~CellController()
|
||||||
|
|
||||||
void CellController::update()
|
void CellController::update()
|
||||||
{
|
{
|
||||||
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();)
|
for (std::deque<mwmp::Cell *>::iterator it = cellsActive.begin(); it != cellsActive.end();)
|
||||||
{
|
{
|
||||||
LocalActor *actor = it->second;
|
mwmp::Cell *mpCell = *it;
|
||||||
|
|
||||||
if (!MWBase::Environment::get().getWorld()->isCellActive(getCell(actor->cell)))
|
if (!MWBase::Environment::get().getWorld()->isCellActive(mpCell->getCellStore()))
|
||||||
{
|
{
|
||||||
localActors.erase(it++);
|
it = cellsActive.erase(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Updating %s\n", it->first.c_str());
|
//LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Updating mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||||
|
mpCell->update();
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellController::initializeLocalActors(const ESM::Cell& cell)
|
void CellController::initializeCell(const ESM::Cell& cell)
|
||||||
{
|
{
|
||||||
|
|
||||||
MWWorld::CellStore *cellStore = getCell(cell);
|
MWWorld::CellStore *cellStore = getCell(cell);
|
||||||
|
|
||||||
if (!cellStore) return;
|
if (!cellStore) return;
|
||||||
|
|
||||||
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs();
|
mwmp::Cell *mpCell = new mwmp::Cell(cellStore);
|
||||||
|
|
||||||
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Initialized mwmp::Cell %s", mpCell->getDescription().c_str());
|
||||||
|
|
||||||
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
|
mpCell->initializeLocalActors();
|
||||||
listIter != npcList->mList.end(); ++listIter)
|
cellsActive.push_back(mpCell);
|
||||||
{
|
|
||||||
MWWorld::Ptr ptr(&*listIter, 0);
|
|
||||||
|
|
||||||
std::string mapIndex = generateMapIndex(ptr);
|
|
||||||
localActors[mapIndex] = new LocalActor();
|
|
||||||
localActors[mapIndex]->cell = cell;
|
|
||||||
printf("Initialized local actor %s\n", mapIndex.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CellController::generateMapIndex(MWWorld::Ptr ptr)
|
|
||||||
{
|
|
||||||
std::string mapIndex = "";
|
|
||||||
mapIndex += ptr.getCellRef().getRefId();
|
|
||||||
mapIndex += "-" + std::to_string(ptr.getCellRef().getRefNum().mIndex);
|
|
||||||
mapIndex += "-" + std::to_string(ptr.getCellRef().getMpNum());
|
|
||||||
return mapIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mwmp::CellController::getCellSize() const
|
int mwmp::CellController::getCellSize() const
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef OPENMW_CELLCONTROLLER_HPP
|
#ifndef OPENMW_CELLCONTROLLER_HPP
|
||||||
#define OPENMW_CELLCONTROLLER_HPP
|
#define OPENMW_CELLCONTROLLER_HPP
|
||||||
|
|
||||||
|
#include "Cell.hpp"
|
||||||
#include "LocalActor.hpp"
|
#include "LocalActor.hpp"
|
||||||
#include "DedicatedActor.hpp"
|
#include "DedicatedActor.hpp"
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
@ -15,9 +16,8 @@ namespace mwmp
|
||||||
~CellController();
|
~CellController();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
void initializeLocalActors(const ESM::Cell& cell);
|
void initializeCell(const ESM::Cell& cell);
|
||||||
|
|
||||||
std::string generateMapIndex(MWWorld::Ptr ptr);
|
|
||||||
int getCellSize() const;
|
int getCellSize() const;
|
||||||
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ namespace mwmp
|
||||||
void closeContainer(const MWWorld::Ptr& container);
|
void closeContainer(const MWWorld::Ptr& container);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::map<std::string, mwmp::LocalActor *> localActors;
|
static std::deque<mwmp::Cell *> cellsActive;
|
||||||
static std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <components/openmw-mp/Log.hpp>
|
||||||
|
|
||||||
#include "LocalActor.hpp"
|
#include "LocalActor.hpp"
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
@ -17,3 +19,13 @@ void LocalActor::update()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWWorld::Ptr LocalActor::getPtr()
|
||||||
|
{
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalActor::setPtr(const MWWorld::Ptr& newPtr)
|
||||||
|
{
|
||||||
|
ptr = newPtr;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define OPENMW_LOCALACTOR_HPP
|
#define OPENMW_LOCALACTOR_HPP
|
||||||
|
|
||||||
#include <components/openmw-mp/Base/BaseActor.hpp>
|
#include <components/openmw-mp/Base/BaseActor.hpp>
|
||||||
|
#include "../mwworld/manualref.hpp"
|
||||||
|
|
||||||
namespace mwmp
|
namespace mwmp
|
||||||
{
|
{
|
||||||
|
@ -13,6 +14,12 @@ namespace mwmp
|
||||||
virtual ~LocalActor();
|
virtual ~LocalActor();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
MWWorld::Ptr getPtr();
|
||||||
|
void setPtr(const MWWorld::Ptr& newPtr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MWWorld::Ptr ptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -859,7 +859,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str());
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str());
|
||||||
|
|
||||||
Main::get().getCellController()->initializeLocalActors(worldEvent.cell);
|
Main::get().getCellController()->initializeCell(worldEvent.cell);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,7 +539,7 @@ namespace MWWorld
|
||||||
|
|
||||||
Make it possible to check whether a cell is active
|
Make it possible to check whether a cell is active
|
||||||
*/
|
*/
|
||||||
virtual bool isCellActive(MWWorld::CellStore* cell);
|
virtual bool isCellActive(MWWorld::CellStore* cell);
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue