mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
[Client] Initialize and update LocalActors while their cells are active
This commit is contained in:
parent
8df9d55331
commit
9beaf9b7a1
7 changed files with 98 additions and 5 deletions
|
@ -418,6 +418,16 @@ namespace MWBase
|
|||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
/*
|
||||
Start of tes3mp addition
|
||||
|
||||
Make it possible to check whether a cell is active
|
||||
*/
|
||||
virtual bool isCellActive(MWWorld::CellStore* cell) = 0;
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is standing on \a object
|
||||
virtual bool getActorStandingOn (const MWWorld::ConstPtr& object) = 0; ///< @return true if any actor is standing on \a object
|
||||
virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object) = 0; ///< @return true if the player is colliding with \a object
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
#include "CellController.hpp"
|
||||
#include "Main.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
using namespace mwmp;
|
||||
|
||||
std::map<std::string, LocalActor *> CellController::localActors;
|
||||
std::map<std::string, DedicatedActor *> CellController::dedicatedActors;
|
||||
|
||||
mwmp::CellController::CellController()
|
||||
{
|
||||
|
@ -19,6 +23,53 @@ mwmp::CellController::~CellController()
|
|||
|
||||
}
|
||||
|
||||
void CellController::update()
|
||||
{
|
||||
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();)
|
||||
{
|
||||
LocalActor *actor = it->second;
|
||||
|
||||
if (!MWBase::Environment::get().getWorld()->isCellActive(getCell(actor->cell)))
|
||||
{
|
||||
localActors.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Updating %s\n", it->first.c_str());
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CellController::initializeLocalActors(const ESM::Cell& cell)
|
||||
{
|
||||
MWWorld::CellStore *cellStore = getCell(cell);
|
||||
|
||||
if (!cellStore) return;
|
||||
|
||||
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->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 = 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
|
||||
{
|
||||
return 8192;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef OPENMW_CELLCONTROLLER_HPP
|
||||
#define OPENMW_CELLCONTROLLER_HPP
|
||||
|
||||
#include "LocalActor.hpp"
|
||||
#include "DedicatedActor.hpp"
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
|
||||
namespace mwmp
|
||||
|
@ -12,12 +14,19 @@ namespace mwmp
|
|||
CellController();
|
||||
~CellController();
|
||||
|
||||
void update();
|
||||
void initializeLocalActors(const ESM::Cell& cell);
|
||||
|
||||
std::string generateMapIndex(MWWorld::Ptr ptr);
|
||||
int getCellSize() const;
|
||||
|
||||
virtual MWWorld::CellStore *getCell(const ESM::Cell& cell);
|
||||
|
||||
void openContainer(const MWWorld::Ptr& container, bool loot);
|
||||
void closeContainer(const MWWorld::Ptr& container);
|
||||
|
||||
private:
|
||||
static std::map<std::string, mwmp::LocalActor *> localActors;
|
||||
static std::map<std::string, mwmp::DedicatedActor *> dedicatedActors;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -210,6 +210,7 @@ void Main::updateWorld(float dt) const
|
|||
else
|
||||
{
|
||||
mLocalPlayer->update();
|
||||
mCellController->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -857,11 +857,10 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
|
|||
}
|
||||
case ID_ACTOR_AUTHORITY:
|
||||
{
|
||||
MWWorld::CellStore *ptrCellStore = Main::get().getCellController()->getCell(worldEvent.cell);
|
||||
|
||||
if (!ptrCellStore) return;
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_AUTHORITY about %s", worldEvent.cell.getDescription().c_str());
|
||||
|
||||
Main::get().getCellController()->initializeLocalActors(worldEvent.cell);
|
||||
|
||||
break;
|
||||
}
|
||||
case ID_ACTOR_FRAME:
|
||||
|
|
|
@ -2368,6 +2368,19 @@ namespace MWWorld
|
|||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
/*
|
||||
Start of tes3mp addition
|
||||
|
||||
Make it possible to check whether a cell is active
|
||||
*/
|
||||
bool World::isCellActive(MWWorld::CellStore* cell)
|
||||
{
|
||||
return mWorldScene->isCellActive(*cell);
|
||||
}
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
bool World::getPlayerStandingOn (const MWWorld::ConstPtr& object)
|
||||
{
|
||||
MWWorld::Ptr player = getPlayerPtr();
|
||||
|
|
|
@ -534,6 +534,16 @@ namespace MWWorld
|
|||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
/*
|
||||
Start of tes3mp addition
|
||||
|
||||
Make it possible to check whether a cell is active
|
||||
*/
|
||||
virtual bool isCellActive(MWWorld::CellStore* cell);
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
||||
virtual bool getPlayerStandingOn (const MWWorld::ConstPtr& object); ///< @return true if the player is standing on \a object
|
||||
virtual bool getActorStandingOn (const MWWorld::ConstPtr& object); ///< @return true if any actor is standing on \a object
|
||||
virtual bool getPlayerCollidingWith(const MWWorld::ConstPtr& object); ///< @return true if the player is colliding with \a object
|
||||
|
|
Loading…
Reference in a new issue