mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:23:52 +00:00
[Client] Split off DedicatedPlayer and PlayerList into different files
This commit is contained in:
parent
f2ec6ce02c
commit
809b4d78ba
19 changed files with 279 additions and 230 deletions
|
@ -96,8 +96,8 @@ add_openmw_dir (mwbase
|
|||
inputmanager windowmanager statemanager
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell
|
||||
CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList
|
||||
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList WorldEvent
|
||||
Cell CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList
|
||||
BaseClientPacketProcessor PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer)
|
||||
|
||||
add_openmw_dir (mwmp\\processors\\actor ProcessorActorAnimFlags ProcessorActorAnimPlay ProcessorActorAttack
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/LocalActor.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
Include additional headers for multiplayer purposes
|
||||
*/
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/CellController.hpp"
|
||||
/*
|
||||
End of tes3mp addition
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/MechanicsHelper.hpp"
|
||||
/*
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
using namespace mwmp;
|
||||
using namespace std;
|
||||
|
||||
std::map<RakNet::RakNetGUID, DedicatedPlayer *> PlayerList::players;
|
||||
|
||||
DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
|
||||
{
|
||||
attack.pressed = 0;
|
||||
|
@ -52,200 +50,6 @@ DedicatedPlayer::~DedicatedPlayer()
|
|||
|
||||
}
|
||||
|
||||
void PlayerList::update(float dt)
|
||||
{
|
||||
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
||||
{
|
||||
DedicatedPlayer *player = it->second;
|
||||
if (player == 0) continue;
|
||||
|
||||
player->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerList::createPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Setting up character info");
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
DedicatedPlayer *dedicPlayer = players[guid];
|
||||
|
||||
ESM::Creature creature;
|
||||
ESM::NPC npc;
|
||||
if (!dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(dedicPlayer->creatureModel);
|
||||
if(tmpCreature == 0)
|
||||
{
|
||||
dedicPlayer->creatureModel = "";
|
||||
createPlayer(guid);
|
||||
return;
|
||||
}
|
||||
creature = *tmpCreature;
|
||||
creature.mScript = "";
|
||||
if(!dedicPlayer->useCreatureName)
|
||||
creature.mName = dedicPlayer->npc.mName;
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
npc = *player.get<ESM::NPC>()->mBase;
|
||||
|
||||
// To avoid freezes caused by invalid races, only set race if we find it
|
||||
// on our client
|
||||
if (world->getStore().get<ESM::Race>().search(dedicPlayer->npc.mRace) != 0)
|
||||
npc.mRace = dedicPlayer->npc.mRace;
|
||||
|
||||
npc.mHead = dedicPlayer->npc.mHead;
|
||||
npc.mHair = dedicPlayer->npc.mHair;
|
||||
npc.mClass = dedicPlayer->npc.mClass;
|
||||
npc.mName = dedicPlayer->npc.mName;
|
||||
npc.mFlags = dedicPlayer->npc.mFlags;
|
||||
}
|
||||
|
||||
if (dedicPlayer->state == 0)
|
||||
{
|
||||
string recid;
|
||||
if (dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
npc.mId = "Dedicated Player";
|
||||
recid = world->createRecord(npc)->mId;
|
||||
}
|
||||
else
|
||||
{
|
||||
creature.mId = "Dedicated Player";
|
||||
recid = world->createRecord(creature)->mId;
|
||||
}
|
||||
|
||||
dedicPlayer->reference = new MWWorld::ManualRef(world->getStore(), recid, 1);
|
||||
}
|
||||
|
||||
// Temporarily spawn or move player to the center of exterior 0,0 whenever setting base info
|
||||
ESM::Position spawnPos;
|
||||
spawnPos.pos[0] = spawnPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
||||
spawnPos.pos[2] = 0;
|
||||
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
||||
|
||||
if (dedicPlayer->state == 0)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Creating new reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
||||
|
||||
MWWorld::Ptr tmp = world->placeObject(dedicPlayer->reference->getPtr(), cellStore, spawnPos);
|
||||
|
||||
dedicPlayer->ptr.mCell = tmp.mCell;
|
||||
dedicPlayer->ptr.mRef = tmp.mRef;
|
||||
|
||||
dedicPlayer->cell = *dedicPlayer->ptr.getCell()->getCell();
|
||||
dedicPlayer->position = dedicPlayer->ptr.getRefData().getPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
||||
|
||||
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
|
||||
|
||||
if (!dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
creature.mId = players[guid]->ptr.get<ESM::Creature>()->mBase->mId;
|
||||
MWWorld::Store<ESM::Creature> *esm_store = const_cast<MWWorld::Store<ESM::Creature> *> (&store->get<ESM::Creature>());
|
||||
esm_store->insert(creature);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
|
||||
MWWorld::Store<ESM::NPC> *esm_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::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();
|
||||
|
||||
ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(guid);
|
||||
dedicPlayer->marker = mEditingMarker;
|
||||
dedicPlayer->setMarkerState(true);
|
||||
}
|
||||
|
||||
dedicPlayer->guid = guid;
|
||||
dedicPlayer->state = 2;
|
||||
|
||||
// Give this new character a fatigue of at least 1 so it doesn't spawn
|
||||
// on the ground
|
||||
dedicPlayer->creatureStats.mDynamic[2].mBase = 1;
|
||||
|
||||
world->enable(players[guid]->ptr);
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::newPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu", guid.g);
|
||||
|
||||
players[guid] = new DedicatedPlayer(guid);
|
||||
players[guid]->state = 0;
|
||||
return players[guid];
|
||||
}
|
||||
|
||||
void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
if (players[guid]->state > 1)
|
||||
{
|
||||
players[guid]->state = 1;
|
||||
|
||||
// Remove player's marker
|
||||
players[guid]->setMarkerState(false);
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
world->disable(players[guid]->getPtr());
|
||||
|
||||
// Move player to exterior 0,0
|
||||
ESM::Position newPos;
|
||||
newPos.pos[0] = newPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
||||
newPos.pos[2] = 0;
|
||||
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
||||
|
||||
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerList::cleanUp()
|
||||
{
|
||||
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
return players[guid];
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin();
|
||||
|
||||
for (; it != players.end(); it++)
|
||||
{
|
||||
if (it->second == 0 || it->second->getPtr().mRef == 0)
|
||||
continue;
|
||||
string refid = ptr.getCellRef().getRefId();
|
||||
if (it->second->getPtr().getCellRef().getRefId() == refid)
|
||||
return it->second;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
if (ptr.mRef == NULL)
|
||||
return false;
|
||||
|
||||
return (getPlayer(ptr) != 0);
|
||||
}
|
||||
|
||||
void DedicatedPlayer::update(float dt)
|
||||
{
|
||||
MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr);
|
||||
|
|
|
@ -25,28 +25,6 @@ namespace mwmp
|
|||
{
|
||||
struct DedicatedPlayer;
|
||||
|
||||
class PlayerList
|
||||
{
|
||||
public:
|
||||
|
||||
static void update(float dt);
|
||||
|
||||
static void createPlayer(RakNet::RakNetGUID guid);
|
||||
static DedicatedPlayer *newPlayer(RakNet::RakNetGUID guid);
|
||||
|
||||
static void disconnectPlayer(RakNet::RakNetGUID guid);
|
||||
static void cleanUp();
|
||||
|
||||
static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid);
|
||||
static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr);
|
||||
|
||||
static bool isDedicatedPlayer(const MWWorld::Ptr &ptr);
|
||||
|
||||
private:
|
||||
|
||||
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;
|
||||
};
|
||||
|
||||
class DedicatedPlayer : public BasePlayer
|
||||
{
|
||||
friend class PlayerList;
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "GUIChat.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "PlayerList.hpp"
|
||||
|
||||
|
||||
mwmp::GUIController::GUIController(): mInputBox(0), mListBox(0)
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "Networking.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "PlayerList.hpp"
|
||||
#include "GUIController.hpp"
|
||||
#include "CellController.hpp"
|
||||
#include "MechanicsHelper.hpp"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "Main.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "PlayerList.hpp"
|
||||
#include "CellController.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
|
217
apps/openmw/mwmp/PlayerList.cpp
Normal file
217
apps/openmw/mwmp/PlayerList.cpp
Normal file
|
@ -0,0 +1,217 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
|
||||
#include "../mwclass/npc.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
|
||||
#include "../mwworld/cellstore.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/worldimp.hpp"
|
||||
|
||||
#include "PlayerList.hpp"
|
||||
#include "Main.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "CellController.hpp"
|
||||
#include "GUIController.hpp"
|
||||
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace std;
|
||||
|
||||
std::map<RakNet::RakNetGUID, DedicatedPlayer *> PlayerList::players;
|
||||
|
||||
void PlayerList::update(float dt)
|
||||
{
|
||||
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
||||
{
|
||||
DedicatedPlayer *player = it->second;
|
||||
if (player == 0) continue;
|
||||
|
||||
player->update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerList::createPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Setting up character info");
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
DedicatedPlayer *dedicPlayer = players[guid];
|
||||
|
||||
ESM::Creature creature;
|
||||
ESM::NPC npc;
|
||||
if (!dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(dedicPlayer->creatureModel);
|
||||
if(tmpCreature == 0)
|
||||
{
|
||||
dedicPlayer->creatureModel = "";
|
||||
createPlayer(guid);
|
||||
return;
|
||||
}
|
||||
creature = *tmpCreature;
|
||||
creature.mScript = "";
|
||||
if(!dedicPlayer->useCreatureName)
|
||||
creature.mName = dedicPlayer->npc.mName;
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr player = world->getPlayerPtr();
|
||||
|
||||
npc = *player.get<ESM::NPC>()->mBase;
|
||||
|
||||
// To avoid freezes caused by invalid races, only set race if we find it
|
||||
// on our client
|
||||
if (world->getStore().get<ESM::Race>().search(dedicPlayer->npc.mRace) != 0)
|
||||
npc.mRace = dedicPlayer->npc.mRace;
|
||||
|
||||
npc.mHead = dedicPlayer->npc.mHead;
|
||||
npc.mHair = dedicPlayer->npc.mHair;
|
||||
npc.mClass = dedicPlayer->npc.mClass;
|
||||
npc.mName = dedicPlayer->npc.mName;
|
||||
npc.mFlags = dedicPlayer->npc.mFlags;
|
||||
}
|
||||
|
||||
if (dedicPlayer->state == 0)
|
||||
{
|
||||
string recid;
|
||||
if (dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
npc.mId = "Dedicated Player";
|
||||
recid = world->createRecord(npc)->mId;
|
||||
}
|
||||
else
|
||||
{
|
||||
creature.mId = "Dedicated Player";
|
||||
recid = world->createRecord(creature)->mId;
|
||||
}
|
||||
|
||||
dedicPlayer->reference = new MWWorld::ManualRef(world->getStore(), recid, 1);
|
||||
}
|
||||
|
||||
// Temporarily spawn or move player to the center of exterior 0,0 whenever setting base info
|
||||
ESM::Position spawnPos;
|
||||
spawnPos.pos[0] = spawnPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
||||
spawnPos.pos[2] = 0;
|
||||
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
||||
|
||||
if (dedicPlayer->state == 0)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Creating new reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
||||
|
||||
MWWorld::Ptr tmp = world->placeObject(dedicPlayer->reference->getPtr(), cellStore, spawnPos);
|
||||
|
||||
dedicPlayer->ptr.mCell = tmp.mCell;
|
||||
dedicPlayer->ptr.mRef = tmp.mRef;
|
||||
|
||||
dedicPlayer->cell = *dedicPlayer->ptr.getCell()->getCell();
|
||||
dedicPlayer->position = dedicPlayer->ptr.getRefData().getPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
||||
|
||||
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
|
||||
|
||||
if (!dedicPlayer->creatureModel.empty())
|
||||
{
|
||||
creature.mId = players[guid]->ptr.get<ESM::Creature>()->mBase->mId;
|
||||
MWWorld::Store<ESM::Creature> *esm_store = const_cast<MWWorld::Store<ESM::Creature> *> (&store->get<ESM::Creature>());
|
||||
esm_store->insert(creature);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
|
||||
MWWorld::Store<ESM::NPC> *esm_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::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();
|
||||
|
||||
ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(guid);
|
||||
dedicPlayer->marker = mEditingMarker;
|
||||
dedicPlayer->setMarkerState(true);
|
||||
}
|
||||
|
||||
dedicPlayer->guid = guid;
|
||||
dedicPlayer->state = 2;
|
||||
|
||||
// Give this new character a fatigue of at least 1 so it doesn't spawn
|
||||
// on the ground
|
||||
dedicPlayer->creatureStats.mDynamic[2].mBase = 1;
|
||||
|
||||
world->enable(players[guid]->ptr);
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::newPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu", guid.g);
|
||||
|
||||
players[guid] = new DedicatedPlayer(guid);
|
||||
players[guid]->state = 0;
|
||||
return players[guid];
|
||||
}
|
||||
|
||||
void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
if (players[guid]->state > 1)
|
||||
{
|
||||
players[guid]->state = 1;
|
||||
|
||||
// Remove player's marker
|
||||
players[guid]->setMarkerState(false);
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
world->disable(players[guid]->getPtr());
|
||||
|
||||
// Move player to exterior 0,0
|
||||
ESM::Position newPos;
|
||||
newPos.pos[0] = newPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
||||
newPos.pos[2] = 0;
|
||||
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
||||
|
||||
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerList::cleanUp()
|
||||
{
|
||||
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid)
|
||||
{
|
||||
return players[guid];
|
||||
}
|
||||
|
||||
DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin();
|
||||
|
||||
for (; it != players.end(); it++)
|
||||
{
|
||||
if (it->second == 0 || it->second->getPtr().mRef == 0)
|
||||
continue;
|
||||
string refid = ptr.getCellRef().getRefId();
|
||||
if (it->second->getPtr().getCellRef().getRefId() == refid)
|
||||
return it->second;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
||||
{
|
||||
if (ptr.mRef == NULL)
|
||||
return false;
|
||||
|
||||
return (getPlayer(ptr) != 0);
|
||||
}
|
47
apps/openmw/mwmp/PlayerList.hpp
Normal file
47
apps/openmw/mwmp/PlayerList.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef OPENMW_PLAYERLIST_HPP
|
||||
#define OPENMW_PLAYERLIST_HPP
|
||||
|
||||
#include <components/esm/custommarkerstate.hpp>
|
||||
#include <components/esm/loadnpc.hpp>
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
|
||||
#include "../mwmechanics/aisequence.hpp"
|
||||
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <RakNetTypes.h>
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
class Actor;
|
||||
}
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
struct DedicatedPlayer;
|
||||
|
||||
class PlayerList
|
||||
{
|
||||
public:
|
||||
|
||||
static void update(float dt);
|
||||
|
||||
static void createPlayer(RakNet::RakNetGUID guid);
|
||||
static DedicatedPlayer *newPlayer(RakNet::RakNetGUID guid);
|
||||
|
||||
static void disconnectPlayer(RakNet::RakNetGUID guid);
|
||||
static void cleanUp();
|
||||
|
||||
static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid);
|
||||
static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr);
|
||||
|
||||
static bool isDedicatedPlayer(const MWWorld::Ptr &ptr);
|
||||
|
||||
private:
|
||||
|
||||
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PLAYERLIST_HPP
|
|
@ -5,8 +5,6 @@
|
|||
#include <boost/foreach.hpp>
|
||||
#include "Networking.hpp"
|
||||
#include "PlayerProcessor.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "Main.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
|
||||
#include "LocalPlayer.hpp"
|
||||
#include "DedicatedPlayer.hpp"
|
||||
#include "PlayerList.hpp"
|
||||
#include "BaseClientPacketProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
Include additional headers for multiplayer purposes
|
||||
*/
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/Networking.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/DedicatedPlayer.hpp"
|
||||
#include "../mwmp/LocalActor.hpp"
|
||||
#include "../mwmp/DedicatedActor.hpp"
|
||||
|
|
Loading…
Reference in a new issue