forked from teamnwah/openmw-tes3coop
[Client] Clean up & simplify logic for DedicatedPlayer cell transitions
This commit is contained in:
parent
87ada3e763
commit
4e86d8781f
5 changed files with 45 additions and 46 deletions
|
@ -148,9 +148,6 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
||||||
|
|
||||||
dedicPlayer->ptr.getBase()->canChangeCell = true;
|
|
||||||
dedicPlayer->updatePtr(world->moveObject(dedicPlayer->ptr, cellStore, spawnPos.pos[0], spawnPos.pos[1], spawnPos.pos[2]));
|
|
||||||
|
|
||||||
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
|
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
|
||||||
|
|
||||||
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
|
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
|
||||||
|
@ -158,6 +155,10 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
|
||||||
|
|
||||||
esm_store->insert(npc);
|
esm_store->insert(npc);
|
||||||
|
|
||||||
|
// Disable Ptr to avoid graphical glitches caused by race changes
|
||||||
|
world->disable(players[guid]->ptr);
|
||||||
|
|
||||||
|
dedicPlayer->setPtr(world->moveObject(dedicPlayer->ptr, cellStore, spawnPos.pos[0], spawnPos.pos[1], spawnPos.pos[2]));
|
||||||
dedicPlayer->updateCell();
|
dedicPlayer->updateCell();
|
||||||
|
|
||||||
ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(guid);
|
ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(guid);
|
||||||
|
@ -202,7 +203,6 @@ void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid)
|
||||||
newPos.pos[2] = 0;
|
newPos.pos[2] = 0;
|
||||||
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
||||||
|
|
||||||
players[guid]->getPtr().getBase()->canChangeCell = true;
|
|
||||||
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ void DedicatedPlayer::updateCell()
|
||||||
MWWorld::CellStore *cellStore;
|
MWWorld::CellStore *cellStore;
|
||||||
|
|
||||||
|
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says %s (%s) moved to %s", ptr.getBase()->mRef.getRefId().c_str(),
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says DedicatedPlayer %s moved to %s",
|
||||||
this->npc.mName.c_str(), cell.getDescription().c_str());
|
this->npc.mName.c_str(), cell.getDescription().c_str());
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -371,8 +371,7 @@ void DedicatedPlayer::updateCell()
|
||||||
|
|
||||||
// Allow this player's reference to move across a cell now that a manual cell
|
// Allow this player's reference to move across a cell now that a manual cell
|
||||||
// update has been called
|
// update has been called
|
||||||
ptr.getBase()->canChangeCell = true;
|
setPtr(world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]));
|
||||||
updatePtr(world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]));
|
|
||||||
|
|
||||||
// If this player is now in a cell that is active for us, we should send them all
|
// If this player is now in a cell that is active for us, we should send them all
|
||||||
// NPC data in that cell
|
// NPC data in that cell
|
||||||
|
@ -435,13 +434,7 @@ MWWorld::ManualRef *DedicatedPlayer::getRef()
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DedicatedPlayer::updatePtr(MWWorld::Ptr newPtr)
|
void DedicatedPlayer::setPtr(const MWWorld::Ptr& newPtr)
|
||||||
{
|
{
|
||||||
ptr.mCell = newPtr.mCell;
|
ptr = newPtr;
|
||||||
ptr.mRef = newPtr.mRef;
|
|
||||||
ptr.mContainerStore = newPtr.mContainerStore;
|
|
||||||
|
|
||||||
// Disallow this player's reference from moving across cells until
|
|
||||||
// the correct packet is sent by the player
|
|
||||||
ptr.getBase()->canChangeCell = false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,13 +66,13 @@ namespace mwmp
|
||||||
MWWorld::Ptr getLiveCellPtr();
|
MWWorld::Ptr getLiveCellPtr();
|
||||||
MWWorld::ManualRef* getRef();
|
MWWorld::ManualRef* getRef();
|
||||||
|
|
||||||
|
void setPtr(const MWWorld::Ptr& newPtr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DedicatedPlayer(RakNet::RakNetGUID guid);
|
DedicatedPlayer(RakNet::RakNetGUID guid);
|
||||||
virtual ~DedicatedPlayer();
|
virtual ~DedicatedPlayer();
|
||||||
|
|
||||||
void updatePtr(MWWorld::Ptr newPtr);
|
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
MWWorld::ManualRef* reference;
|
MWWorld::ManualRef* reference;
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,6 @@
|
||||||
MWWorld::LiveCellRefBase::LiveCellRefBase(const std::string& type, const ESM::CellRef &cref)
|
MWWorld::LiveCellRefBase::LiveCellRefBase(const std::string& type, const ESM::CellRef &cref)
|
||||||
: mClass(&Class::get(type)), mRef(cref), mData(cref)
|
: mClass(&Class::get(type)), mRef(cref), mData(cref)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
Start of tes3mp addition
|
|
||||||
|
|
||||||
Set default values for tes3mp-only booleans
|
|
||||||
*/
|
|
||||||
canChangeCell = true;
|
|
||||||
/*
|
|
||||||
End of tes3mp addition
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state)
|
void MWWorld::LiveCellRefBase::loadImp (const ESM::ObjectState& state)
|
||||||
|
|
|
@ -28,16 +28,6 @@ namespace MWWorld
|
||||||
*/
|
*/
|
||||||
MWWorld::CellRef mRef;
|
MWWorld::CellRef mRef;
|
||||||
|
|
||||||
/*
|
|
||||||
Start of tes3mp addition
|
|
||||||
|
|
||||||
Useful boolean for stopping momentum-based cell changes not approved by server
|
|
||||||
*/
|
|
||||||
bool canChangeCell;
|
|
||||||
/*
|
|
||||||
End of tes3mp addition
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** runtime-data */
|
/** runtime-data */
|
||||||
RefData mData;
|
RefData mData;
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,19 @@
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
#include <osg/ComputeBoundsVisitor>
|
#include <osg/ComputeBoundsVisitor>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Include additional headers for multiplayer purposes
|
||||||
|
*/
|
||||||
#include "../mwmp/Main.hpp"
|
#include "../mwmp/Main.hpp"
|
||||||
#include "../mwmp/Networking.hpp"
|
#include "../mwmp/Networking.hpp"
|
||||||
|
#include "../mwmp/DedicatedPlayer.hpp"
|
||||||
#include "../mwmp/WorldEvent.hpp"
|
#include "../mwmp/WorldEvent.hpp"
|
||||||
|
#include "../mwmp/CellController.hpp"
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
#include <components/esm/esmreader.hpp>
|
#include <components/esm/esmreader.hpp>
|
||||||
#include <components/esm/esmwriter.hpp>
|
#include <components/esm/esmwriter.hpp>
|
||||||
|
@ -1170,17 +1180,20 @@ namespace MWWorld
|
||||||
bool haveToMove = isPlayer || (currCell && mWorldScene->isCellActive(*currCell));
|
bool haveToMove = isPlayer || (currCell && mWorldScene->isCellActive(*currCell));
|
||||||
MWWorld::Ptr newPtr = ptr;
|
MWWorld::Ptr newPtr = ptr;
|
||||||
|
|
||||||
// tes3mp debug start
|
if (currCell != newCell)
|
||||||
if (currCell != newCell) {
|
|
||||||
|
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Tick: %s was %s move from %s to %s", ptr.getBase()->mRef.getRefId().c_str(),
|
|
||||||
ptr.getBase()->canChangeCell ? "allowed" : "denied", currCell->getCell()->getDescription().c_str(),
|
|
||||||
newCell->getCell()->getDescription().c_str());
|
|
||||||
}
|
|
||||||
// tes3mp debug end
|
|
||||||
|
|
||||||
if (currCell != newCell && ptr.getBase()->canChangeCell)
|
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Check if DedicatedPlayer's new Ptr cell is the same as their packet cell, and deny the Ptr's cell change if it is not
|
||||||
|
*/
|
||||||
|
if (mwmp::PlayerList::isDedicatedPlayer(ptr) &&
|
||||||
|
!mwmp::Main::get().getCellController()->isSameCell(mwmp::PlayerList::getPlayer(ptr)->cell, *newCell->getCell()))
|
||||||
|
return ptr;
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
|
|
||||||
removeContainerScripts(ptr);
|
removeContainerScripts(ptr);
|
||||||
|
|
||||||
if (isPlayer)
|
if (isPlayer)
|
||||||
|
@ -1245,6 +1258,17 @@ namespace MWWorld
|
||||||
addContainerScripts (newPtr, newCell);
|
addContainerScripts (newPtr, newCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Update the Ptrs of DedicatedPlayers
|
||||||
|
*/
|
||||||
|
if (mwmp::PlayerList::isDedicatedPlayer(ptr))
|
||||||
|
mwmp::PlayerList::getPlayer(ptr)->setPtr(newPtr);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (haveToMove && newPtr.getRefData().getBaseNode())
|
if (haveToMove && newPtr.getRefData().getBaseNode())
|
||||||
|
@ -1257,6 +1281,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
mWorldScene->playerMoved(vec);
|
mWorldScene->playerMoved(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPtr;
|
return newPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue