forked from teamnwah/openmw-tes3coop
[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
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
|
|
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"
|
||||
using namespace mwmp;
|
||||
|
||||
std::map<std::string, LocalActor *> CellController::localActors;
|
||||
std::map<std::string, DedicatedActor *> CellController::dedicatedActors;
|
||||
std::deque<mwmp::Cell *> CellController::cellsActive;
|
||||
|
||||
mwmp::CellController::CellController()
|
||||
{
|
||||
|
@ -25,49 +24,36 @@ mwmp::CellController::~CellController()
|
|||
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CellController::initializeLocalActors(const ESM::Cell& cell)
|
||||
void CellController::initializeCell(const ESM::Cell& cell)
|
||||
{
|
||||
|
||||
MWWorld::CellStore *cellStore = getCell(cell);
|
||||
|
||||
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());
|
||||
listIter != npcList->mList.end(); ++listIter)
|
||||
{
|
||||
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;
|
||||
mpCell->initializeLocalActors();
|
||||
cellsActive.push_back(mpCell);
|
||||
}
|
||||
|
||||
int mwmp::CellController::getCellSize() const
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef OPENMW_CELLCONTROLLER_HPP
|
||||
#define OPENMW_CELLCONTROLLER_HPP
|
||||
|
||||
#include "Cell.hpp"
|
||||
#include "LocalActor.hpp"
|
||||
#include "DedicatedActor.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
|
@ -15,9 +16,8 @@ namespace mwmp
|
|||
~CellController();
|
||||
|
||||
void update();
|
||||
void initializeLocalActors(const ESM::Cell& cell);
|
||||
void initializeCell(const ESM::Cell& cell);
|
||||
|
||||
std::string generateMapIndex(MWWorld::Ptr ptr);
|
||||
int getCellSize() const;
|
||||
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
||||
|
||||
|
@ -25,8 +25,7 @@ namespace mwmp
|
|||
void closeContainer(const MWWorld::Ptr& container);
|
||||
|
||||
private:
|
||||
static std::map<std::string, mwmp::LocalActor *> localActors;
|
||||
static std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
||||
static std::deque<mwmp::Cell *> cellsActive;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
|
||||
#include "LocalActor.hpp"
|
||||
|
||||
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
|
||||
|
||||
#include <components/openmw-mp/Base/BaseActor.hpp>
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
|
@ -13,6 +14,12 @@ namespace mwmp
|
|||
virtual ~LocalActor();
|
||||
|
||||
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());
|
||||
|
||||
Main::get().getCellController()->initializeLocalActors(worldEvent.cell);
|
||||
Main::get().getCellController()->initializeCell(worldEvent.cell);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -539,7 +539,7 @@ namespace MWWorld
|
|||
|
||||
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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue