mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
[Server] Iterate only through updated players on each frame
This commit is contained in:
parent
4ab338bbb1
commit
8f5d31cb03
33 changed files with 260 additions and 212 deletions
26
apps/openmw-mp/BaseMgr.cpp
Normal file
26
apps/openmw-mp/BaseMgr.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Created by koncord on 02.01.18.
|
||||
//
|
||||
|
||||
#include "BaseMgr.hpp"
|
||||
#include "Player.hpp"
|
||||
|
||||
BaseMgr::BaseMgr(Player *player) : player(player), changed(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BaseMgr::update()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
processUpdate();
|
||||
}
|
||||
|
||||
void BaseMgr::setChanged()
|
||||
{
|
||||
changed = true;
|
||||
player->addToUpdateQueue();
|
||||
}
|
21
apps/openmw-mp/BaseMgr.hpp
Normal file
21
apps/openmw-mp/BaseMgr.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by koncord on 02.01.18.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
class Player;
|
||||
|
||||
class BaseMgr
|
||||
{
|
||||
public:
|
||||
explicit BaseMgr(Player *player);
|
||||
void update();
|
||||
protected:
|
||||
bool isChanged() const { return changed; };
|
||||
void setChanged();
|
||||
virtual void processUpdate() = 0;
|
||||
Player *player;
|
||||
private:
|
||||
bool changed;
|
||||
};
|
|
@ -20,22 +20,16 @@ void Books::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
Books::Books(Player *player) : player(player), changed(false)
|
||||
Books::Books(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Books::~Books()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Books::addBook(const std::string &bookId)
|
||||
{
|
||||
if (!changed)
|
||||
if (!isChanged())
|
||||
reset();
|
||||
player->bookChanges.books.push_back({bookId});
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::string Books::getBookId(unsigned i) const
|
||||
|
@ -56,14 +50,10 @@ void Books::reset()
|
|||
player->bookChanges.books.clear();
|
||||
}
|
||||
|
||||
void Books::update()
|
||||
void Books::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK);
|
||||
|
||||
packet->setPlayer(player);
|
||||
packet->Send(/*toOthers*/ false);
|
||||
}
|
||||
}
|
|
@ -5,28 +5,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
||||
class Books
|
||||
class Books final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
|
||||
explicit Books(Player *player);
|
||||
~Books();
|
||||
|
||||
void addBook(const std::string &bookId);
|
||||
std::string getBookId(unsigned i) const;
|
||||
unsigned getChanges() const;
|
||||
void reset();
|
||||
|
||||
void update();
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ set(SERVER
|
|||
stacktrace.cpp
|
||||
Window.cpp
|
||||
Weather.cpp
|
||||
BaseMgr.cpp
|
||||
Script/CommandController.cpp Script/EventController.cpp Script/LuaState.cpp Script/luaUtils.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
#include "Script/LuaState.hpp"
|
||||
#include "Player.hpp"
|
||||
#include "Networking.hpp"
|
||||
|
||||
#include "Cells.hpp"
|
||||
|
@ -45,13 +46,20 @@ std::string Cells::getDescription() const
|
|||
return netActor->getNetCreature()->cell.getDescription();
|
||||
}
|
||||
|
||||
inline void Cells::setChanged()
|
||||
{
|
||||
if (!changedCell && netActor->isPlayer())
|
||||
netActor->toPlayer()->addToUpdateQueue();
|
||||
changedCell = true;
|
||||
}
|
||||
|
||||
void Cells::setDescription(const std::string &cellDescription)
|
||||
{
|
||||
/*LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Script is moving %s from %s to %s", netActor->getNetCreature()->npc.mName.c_str(),
|
||||
netActor->getNetCreature()->cell.getDescription().c_str(), cellDescription.c_str());*/
|
||||
|
||||
netActor->getNetCreature()->cell = Utils::getCellFromDescription(cellDescription);
|
||||
changedCell = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::tuple<int, int> Cells::getExterior() const
|
||||
|
@ -70,7 +78,7 @@ void Cells::setExterior(int x, int y)
|
|||
|
||||
netActor->getNetCreature()->cell.mData.mX = x;
|
||||
netActor->getNetCreature()->cell.mData.mY = y;
|
||||
changedCell = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
bool Cells::isExterior() const
|
||||
|
|
|
@ -35,9 +35,11 @@ public:
|
|||
bool isChangedCell() const;
|
||||
void resetChangedCell();
|
||||
|
||||
|
||||
private:
|
||||
NetActor *netActor;
|
||||
bool changedCell;
|
||||
void setChanged();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -35,14 +35,8 @@ void CharClass::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
CharClass::CharClass(Player *player) : player(player), changed(false)
|
||||
CharClass::CharClass(Player *player) : BaseMgr(player)
|
||||
{
|
||||
printf("CharClass::CharClass()\n");
|
||||
}
|
||||
|
||||
CharClass::~CharClass()
|
||||
{
|
||||
printf("CharClass::~CharClass()\n");
|
||||
}
|
||||
|
||||
string CharClass::getDefault() const
|
||||
|
@ -53,7 +47,7 @@ string CharClass::getDefault() const
|
|||
void CharClass::setDefault(const string &className)
|
||||
{
|
||||
player->charClass.mId = className;
|
||||
changed = true;
|
||||
setChanged();
|
||||
printf("CharClass::setDefault()\n");
|
||||
}
|
||||
|
||||
|
@ -65,7 +59,7 @@ bool CharClass::isCustom() const
|
|||
void CharClass::setName(const string &className)
|
||||
{
|
||||
player->charClass.mName = className;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
string CharClass::getName() const
|
||||
|
@ -81,7 +75,7 @@ std::string CharClass::getDescription() const
|
|||
void CharClass::setDescription(const string &desc)
|
||||
{
|
||||
player->charClass.mDescription = desc;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::tuple<int, int> CharClass::getMajorAttributes() const
|
||||
|
@ -95,7 +89,7 @@ void CharClass::setMajorAttributes(int first, int second)
|
|||
auto &data = player->charClass.mData;
|
||||
data.mAttribute[0] = first;
|
||||
data.mAttribute[1] = second;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
int CharClass::getSpecialization() const
|
||||
|
@ -107,7 +101,7 @@ void CharClass::setSpecialization(int spec)
|
|||
{
|
||||
auto &data = player->charClass.mData;
|
||||
data.mSpecialization = spec;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::tuple<int, int, int, int, int> CharClass::getMinorSkills() const
|
||||
|
@ -124,7 +118,7 @@ void CharClass::setMinorSkills(int first, int second, int third, int fourth, int
|
|||
data.mSkills[2][0] = third;
|
||||
data.mSkills[3][0] = fourth;
|
||||
data.mSkills[4][0] = fifth;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::tuple<int, int, int, int, int> CharClass::getMajorSkills() const
|
||||
|
@ -141,14 +135,11 @@ void CharClass::setMajorSkills(int first, int second, int third, int fourth, int
|
|||
data.mSkills[2][1] = third;
|
||||
data.mSkills[3][1] = fourth;
|
||||
data.mSkills[4][1] = fifth;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void CharClass::update()
|
||||
void CharClass::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
printf("CharClass::update()\n");
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARCLASS);
|
||||
packet->setPlayer(player);
|
||||
|
|
|
@ -6,19 +6,18 @@
|
|||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
||||
class CharClass
|
||||
class CharClass final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
|
||||
public:
|
||||
explicit CharClass(Player *player);
|
||||
~CharClass();
|
||||
void update();
|
||||
|
||||
std::string getDefault() const;
|
||||
void setDefault(const std::string &className);
|
||||
|
@ -41,10 +40,9 @@ public:
|
|||
|
||||
std::tuple<int, int, int, int, int> getMajorSkills() const;
|
||||
void setMajorSkills(int fisrt, int second, int third, int fourth, int fifth);
|
||||
|
||||
private:
|
||||
// not controlled pointer
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ void Dialogue::Init(LuaState &lua)
|
|||
|
||||
|
||||
|
||||
Dialogue::Dialogue(Player *player) : player(player), changed(false)
|
||||
Dialogue::Dialogue(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -32,12 +32,8 @@ void Dialogue::reset()
|
|||
player->topicChanges.topics.clear();
|
||||
}
|
||||
|
||||
void Dialogue::update()
|
||||
void Dialogue::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_TOPIC);
|
||||
|
||||
packet->setPlayer(player);
|
||||
|
@ -46,9 +42,9 @@ void Dialogue::update()
|
|||
|
||||
void Dialogue::addTopic(const std::string &topicId)
|
||||
{
|
||||
if (!changed)
|
||||
if (!isChanged())
|
||||
reset();
|
||||
changed = true;
|
||||
setChanged();
|
||||
player->topicChanges.topics.push_back({topicId});
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
||||
class Dialogue
|
||||
class Dialogue final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
|
@ -24,10 +25,8 @@ public:
|
|||
void playSpeech(const std::string &sound);
|
||||
|
||||
void reset();
|
||||
void update();
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ void Factions::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
Factions::Factions(Player *player): player(player), changed(false)
|
||||
Factions::Factions(Player *player): BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -32,12 +32,8 @@ Factions::~Factions()
|
|||
|
||||
}
|
||||
|
||||
void Factions::update()
|
||||
void Factions::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet =mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION);
|
||||
packet->setPlayer(player);
|
||||
packet->Send(/*toOthers*/ false);
|
||||
|
@ -52,13 +48,13 @@ int Factions::getFactionChangesAction() const
|
|||
void Factions::setFactionChangesAction(int action)
|
||||
{
|
||||
player->factionChanges.action = action;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void Factions::addFaction(Faction faction)
|
||||
{
|
||||
player->factionChanges.factions.push_back(faction.faction);
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,13 +66,13 @@ Faction Factions::getFaction(int id) const
|
|||
void Factions::setFaction(int id, Faction faction)
|
||||
{
|
||||
player->factionChanges.factions.at(id) = faction.faction;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void Factions::clear()
|
||||
{
|
||||
player->factionChanges.factions.clear();
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
size_t Factions::size() const
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
@ -33,7 +34,7 @@ public:
|
|||
mwmp::Faction faction;
|
||||
};
|
||||
|
||||
class Factions
|
||||
class Factions final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
|
@ -41,7 +42,6 @@ public:
|
|||
explicit Factions(Player *player);
|
||||
~Factions();
|
||||
|
||||
void update();
|
||||
|
||||
int getFactionChangesAction() const;
|
||||
void setFactionChangesAction(int action);
|
||||
|
@ -53,7 +53,5 @@ public:
|
|||
void clear();
|
||||
|
||||
private:
|
||||
mwmp::Faction tempFaction;
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
|
|
@ -23,22 +23,13 @@ void GUI::Init(LuaState &lua)
|
|||
Window::Init(lua);
|
||||
}
|
||||
|
||||
GUI::GUI(Player *player): player(player), changed(false)
|
||||
GUI::GUI(Player *player): BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GUI::~GUI()
|
||||
void GUI::processUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GUI::update()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX);
|
||||
packet->setPlayer(player);
|
||||
packet->Send(false);
|
||||
|
@ -50,7 +41,7 @@ void GUI::messageBox(int id, const char *label)
|
|||
player->guiMessageBox.label = label;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::MessageBox;
|
||||
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GUI::customMessageBox(int id, const char *label, const char *buttons)
|
||||
|
@ -60,7 +51,7 @@ void GUI::customMessageBox(int id, const char *label, const char *buttons)
|
|||
player->guiMessageBox.buttons = buttons;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox;
|
||||
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GUI::inputDialog(int id, const char *label)
|
||||
|
@ -69,7 +60,7 @@ void GUI::inputDialog(int id, const char *label)
|
|||
player->guiMessageBox.label = label;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::InputDialog;
|
||||
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GUI::passwordDialog(int id, const char *label, const char *note)
|
||||
|
@ -79,7 +70,7 @@ void GUI::passwordDialog(int id, const char *label, const char *note)
|
|||
player->guiMessageBox.note = note;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::PasswordDialog;
|
||||
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GUI::listBox(int id, const char *label, const char *items)
|
||||
|
@ -89,7 +80,7 @@ void GUI::listBox(int id, const char *label, const char *items)
|
|||
player->guiMessageBox.data = items;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::ListBox;
|
||||
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GUI::setMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state)
|
||||
|
@ -155,32 +146,23 @@ void QuickKeys::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
QuickKeys::QuickKeys(Player *player) : player(player), changed(false)
|
||||
QuickKeys::QuickKeys(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QuickKeys::~QuickKeys()
|
||||
void QuickKeys::processUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QuickKeys::update()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_QUICKKEYS);
|
||||
packet->setPlayer(player);
|
||||
packet->Send(false);
|
||||
clear();
|
||||
}
|
||||
|
||||
void QuickKeys::addQuickKey(QuickKey quickKey)
|
||||
void QuickKeys::addQuickKey(const QuickKey &quickKey)
|
||||
{
|
||||
player->quickKeyChanges.quickKeys.push_back(quickKey.quickKey);
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
||||
|
@ -192,13 +174,13 @@ QuickKey QuickKeys::getQuickKey(int id) const
|
|||
void QuickKeys::setQuickKey(int id, const QuickKey &quickKey)
|
||||
{
|
||||
player->quickKeyChanges.quickKeys.at(id) = quickKey.quickKey;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void QuickKeys::clear()
|
||||
{
|
||||
player->quickKeyChanges.quickKeys.clear();
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
size_t QuickKeys::size() const
|
||||
|
|
|
@ -5,19 +5,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "Window.hpp"
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
||||
class GUI
|
||||
class GUI final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
explicit GUI(Player *player);
|
||||
~GUI();
|
||||
|
||||
void update();
|
||||
|
||||
void messageBox(int id, const char *label);
|
||||
|
||||
|
@ -40,8 +38,7 @@ public:
|
|||
unsigned int getChanges() const;
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
std::unordered_map<int, std::shared_ptr<Window>> windows;
|
||||
int lastWindowId;
|
||||
};
|
||||
|
@ -57,8 +54,8 @@ public:
|
|||
int getSlot() const;
|
||||
void setSlot(unsigned short slot);
|
||||
|
||||
int getType() const;
|
||||
void setType(int slot);
|
||||
mwmp::QuickKey::Type getType() const;
|
||||
void setType(mwmp::QuickKey::Type slot);
|
||||
|
||||
std::string getItemId() const;
|
||||
void setItemId(const std::string &itemId);
|
||||
|
@ -66,15 +63,12 @@ public:
|
|||
mwmp::QuickKey quickKey;
|
||||
};
|
||||
|
||||
class QuickKeys
|
||||
class QuickKeys final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
explicit QuickKeys(Player *player);
|
||||
~QuickKeys();
|
||||
|
||||
void update();
|
||||
|
||||
void addQuickKey(const QuickKey &quickKey);
|
||||
QuickKey getQuickKey(int id) const;
|
||||
|
@ -83,6 +77,5 @@ public:
|
|||
void clear();
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "Inventory.hpp"
|
||||
#include "NetActor.hpp"
|
||||
#include <Player.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -45,6 +46,26 @@ Inventory::~Inventory()
|
|||
void Inventory::update()
|
||||
{
|
||||
printf("Inventory::update()");
|
||||
/*if(isEquipmentChanged())
|
||||
{
|
||||
if (netActor->isPlayer())
|
||||
{
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT);
|
||||
packet->setPlayer(dynamic_cast<Player *>(netActor));
|
||||
packet->Send(false);
|
||||
packet->Send(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto packet = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT);
|
||||
packet->setActorList(&actorList);
|
||||
packet->Send(actorList.guid);
|
||||
|
||||
if (sendToAll)
|
||||
serverCell->sendToLoaded(packet, &actorList);
|
||||
}
|
||||
resetEquipmentFlag();
|
||||
}*/
|
||||
/*if (equipmentChanged)
|
||||
{
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT);
|
||||
|
@ -86,6 +107,9 @@ void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigne
|
|||
if (!Utils::vectorContains(&netActor->getNetCreature()->equipmentIndexChanges, slot))
|
||||
netActor->getNetCreature()->equipmentIndexChanges.push_back(slot);
|
||||
|
||||
if(!equipmentChanged && netActor->isPlayer())
|
||||
netActor->toPlayer()->addToUpdateQueue();
|
||||
|
||||
equipmentChanged = true;
|
||||
}
|
||||
|
||||
|
@ -110,6 +134,8 @@ void Inventory::addItem(const std::string &refId, unsigned int count, int charge
|
|||
|
||||
netActor->getNetCreature()->inventoryChanges.items.push_back(item);
|
||||
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::ADD;
|
||||
if (inventoryChanged == 0 && netActor->isPlayer())
|
||||
netActor->toPlayer()->addToUpdateQueue();
|
||||
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action;
|
||||
}
|
||||
|
||||
|
@ -126,6 +152,8 @@ void Inventory::removeItem(const std::string &refId, unsigned short count)
|
|||
|
||||
netActor->getNetCreature()->inventoryChanges.items.push_back(item);
|
||||
netActor->getNetCreature()->inventoryChanges.action = mwmp::InventoryChanges::REMOVE;
|
||||
if (inventoryChanged == 0 && netActor->isPlayer())
|
||||
netActor->toPlayer()->addToUpdateQueue();
|
||||
inventoryChanged = netActor->getNetCreature()->inventoryChanges.action;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
#include "Networking.hpp"
|
||||
|
||||
#include "NetActor.hpp"
|
||||
#include "Player.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
NetActor::NetActor() : inventory(this), cellAPI(this)
|
||||
NetActor::NetActor() : inventory(this), cellAPI(this), isActorPlayer(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -37,6 +38,9 @@ void NetActor::setPosition(float x, float y, float z)
|
|||
netCreature->position.pos[0] = x;
|
||||
netCreature->position.pos[1] = y;
|
||||
netCreature->position.pos[2] = z;
|
||||
|
||||
if(!positionChanged && isPlayer())
|
||||
toPlayer()->addToUpdateQueue();
|
||||
positionChanged = true;
|
||||
}
|
||||
|
||||
|
@ -49,6 +53,9 @@ void NetActor::setRotation(float x, float z)
|
|||
{
|
||||
netCreature->position.rot[0] = x;
|
||||
netCreature->position.rot[2] = z;
|
||||
|
||||
if (!positionChanged && isPlayer())
|
||||
toPlayer()->addToUpdateQueue();
|
||||
positionChanged = true;
|
||||
}
|
||||
|
||||
|
@ -65,6 +72,8 @@ void NetActor::setHealth(float base, float current)
|
|||
if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 0))
|
||||
netCreature->statsDynamicIndexChanges.push_back(0);
|
||||
|
||||
if (!statsChanged && isPlayer())
|
||||
toPlayer()->addToUpdateQueue();
|
||||
statsChanged = true;
|
||||
}
|
||||
|
||||
|
@ -81,6 +90,8 @@ void NetActor::setMagicka(float base, float current)
|
|||
if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 1))
|
||||
netCreature->statsDynamicIndexChanges.push_back(1);
|
||||
|
||||
if (!statsChanged && isPlayer())
|
||||
toPlayer()->addToUpdateQueue();
|
||||
statsChanged = true;
|
||||
}
|
||||
|
||||
|
@ -97,6 +108,8 @@ void NetActor::setFatigue(float base, float current)
|
|||
if (!Utils::vectorContains(&netCreature->statsDynamicIndexChanges, 2))
|
||||
netCreature->statsDynamicIndexChanges.push_back(2);
|
||||
|
||||
if (!statsChanged && isPlayer())
|
||||
toPlayer()->addToUpdateQueue();
|
||||
statsChanged = true;
|
||||
}
|
||||
|
||||
|
@ -109,3 +122,10 @@ Cells &NetActor::getCell()
|
|||
{
|
||||
return cellAPI;
|
||||
}
|
||||
|
||||
Player *NetActor::toPlayer()
|
||||
{
|
||||
if (isPlayer())
|
||||
return dynamic_cast<Player*>(this);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class NetActor
|
|||
{
|
||||
public:
|
||||
NetActor();
|
||||
virtual ~NetActor() = default;
|
||||
|
||||
void resetUpdateFlags();
|
||||
|
||||
|
@ -63,13 +64,18 @@ public:
|
|||
Cells &getCell();
|
||||
|
||||
mwmp::BaseNetCreature *getNetCreature() { return netCreature; }
|
||||
|
||||
bool isPlayer() const { return isActorPlayer; }
|
||||
Player *toPlayer();
|
||||
protected:
|
||||
bool baseInfoChanged, levelChanged, statsChanged, positionChanged, attributesChanged, skillsChanged;
|
||||
|
||||
mwmp::BasePlayer *basePlayer;
|
||||
mwmp::BaseNetCreature *netCreature;
|
||||
|
||||
Inventory inventory;
|
||||
Cells cellAPI;
|
||||
bool isActorPlayer;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -474,13 +474,7 @@ int Networking::mainLoop()
|
|||
}
|
||||
timerCtrl.tick();
|
||||
if (updated)
|
||||
{
|
||||
// fixme: not good to call for_each every frame. Maybe for_each_Updated will be better
|
||||
Players::for_each([](shared_ptr<Player> pl) {
|
||||
pl->update();
|
||||
});
|
||||
}
|
||||
this_thread::sleep_for (chrono::milliseconds(1));
|
||||
Players::processUpdated();
|
||||
}
|
||||
|
||||
timerCtrl.terminate();
|
||||
|
|
|
@ -123,6 +123,7 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid), NetActor(), changedM
|
|||
markedForDeletion = false;
|
||||
storedData = mwmp::Networking::get().getState().getState()->create_table();
|
||||
customData = mwmp::Networking::get().getState().getState()->create_table();
|
||||
isActorPlayer = true;
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
|
@ -131,6 +132,14 @@ Player::~Player()
|
|||
CellController::get().deletePlayer(this);
|
||||
}
|
||||
|
||||
void Player::addToUpdateQueue()
|
||||
{
|
||||
if (inUpdateQueue)
|
||||
return;
|
||||
inUpdateQueue = true;
|
||||
Players::addToQueue(this);
|
||||
}
|
||||
|
||||
void Player::update()
|
||||
{
|
||||
auto plPCtrl = mwmp::Networking::get().getPlayerPacketController();
|
||||
|
@ -236,6 +245,7 @@ void Player::update()
|
|||
weatherMgr.update();
|
||||
|
||||
resetUpdateFlags();
|
||||
inUpdateQueue = false;
|
||||
}
|
||||
|
||||
unsigned short Player::getId()
|
||||
|
|
|
@ -191,6 +191,8 @@ public:
|
|||
|
||||
bool isMarkedForDeleteion() const;
|
||||
|
||||
void addToUpdateQueue();
|
||||
|
||||
private:
|
||||
CellController::TContainer cells;
|
||||
int handshakeCounter;
|
||||
|
@ -209,6 +211,7 @@ private:
|
|||
sol::table storedData;
|
||||
sol::table customData;
|
||||
bool markedForDeletion;
|
||||
bool inUpdateQueue;
|
||||
};
|
||||
|
||||
#endif //OPENMW_PLAYER_HPP
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
using namespace std;
|
||||
|
||||
Players::Store Players::store;
|
||||
std::queue<Player*> Players::updateQueue;
|
||||
|
||||
void Players::Init(LuaState &lua)
|
||||
{
|
||||
|
@ -124,3 +125,19 @@ size_t Players::size()
|
|||
{
|
||||
return store.size();
|
||||
}
|
||||
|
||||
void Players::processUpdated()
|
||||
{
|
||||
while (!updateQueue.empty())
|
||||
{
|
||||
Player *player = updateQueue.front();
|
||||
updateQueue.pop();
|
||||
player->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Players::addToQueue(Player *player)
|
||||
{
|
||||
updateQueue.push(player);
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
#include <boost/multi_index/global_fun.hpp>
|
||||
#include <boost/multi_index/mem_fun.hpp>
|
||||
#include <boost/multi_index/random_access_index.hpp>
|
||||
#include <queue>
|
||||
#include "Player.hpp"
|
||||
|
||||
class LuaState;
|
||||
|
@ -18,6 +19,7 @@ class LuaState;
|
|||
|
||||
class Players
|
||||
{
|
||||
friend class Player;
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
|
@ -47,7 +49,11 @@ public:
|
|||
|
||||
static void for_each(std::function<void(std::shared_ptr<Player>)> func);
|
||||
|
||||
static void processUpdated();
|
||||
private:
|
||||
static void addToQueue(Player *player);
|
||||
|
||||
static Store store;
|
||||
static std::queue<Player*> updateQueue;
|
||||
};
|
||||
|
||||
|
|
|
@ -85,17 +85,12 @@ void Quests::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
Quests::Quests(Player *player) : player(player), changedKills(false), changedJournal(false)
|
||||
Quests::Quests(Player *player) : BaseMgr(player), changedKills(false), changedJournal(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Quests::~Quests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Quests::update()
|
||||
void Quests::processUpdate()
|
||||
{
|
||||
if (changedJournal)
|
||||
{
|
||||
|
@ -130,13 +125,14 @@ void Quests::addJournalItem(JournalItem item)
|
|||
{
|
||||
player->journalChanges.journalItems.push_back(item.item);
|
||||
changedJournal = true;
|
||||
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void Quests::setJournalItem(unsigned int id, JournalItem item)
|
||||
{
|
||||
player->journalChanges.journalItems.at(id) = item.item;
|
||||
changedJournal = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
JournalItem Quests::getJournalItem(unsigned int id)
|
||||
|
@ -148,6 +144,7 @@ void Quests::addKill(const std::string &refId, int number)
|
|||
{
|
||||
player->killChanges.kills.push_back({refId, number});
|
||||
changedKills = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
std::tuple<std::string, int> Quests::getKill(unsigned int i) const
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
@ -34,15 +35,13 @@ public:
|
|||
mwmp::JournalItem item;
|
||||
};
|
||||
|
||||
class Quests
|
||||
class Quests final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
explicit Quests(Player *player);
|
||||
~Quests();
|
||||
|
||||
void update();
|
||||
|
||||
size_t getJournalChangesSize() const;
|
||||
size_t getKillChangesSize() const;
|
||||
|
@ -55,7 +54,7 @@ public:
|
|||
std::tuple<std::string, int> getKill(unsigned int i) const;
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
void processUpdate() final;
|
||||
bool changedKills, changedJournal;
|
||||
};
|
||||
|
||||
|
|
|
@ -21,51 +21,43 @@ void GameSettings::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
GameSettings::GameSettings(Player *player) : player(player), changed(false)
|
||||
GameSettings::GameSettings(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GameSettings::~GameSettings()
|
||||
{
|
||||
}
|
||||
|
||||
void GameSettings::setConsoleAllowed(bool state)
|
||||
{
|
||||
player->consoleAllowed = state;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GameSettings::setDifficulty(int difficulty)
|
||||
{
|
||||
player->difficulty = difficulty;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GameSettings::setBedRestAllowed(bool state)
|
||||
{
|
||||
player->bedRestAllowed = state;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GameSettings::setWildernessRestAllowed(bool state)
|
||||
{
|
||||
player->wildernessRestAllowed = state;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GameSettings::setWaitAllowed(bool state)
|
||||
{
|
||||
player->waitAllowed = state;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void GameSettings::update()
|
||||
void GameSettings::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS);
|
||||
packet->setPlayer(player);
|
||||
packet->Send(false);
|
||||
|
|
|
@ -4,18 +4,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
||||
|
||||
class GameSettings
|
||||
class GameSettings final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
|
||||
explicit GameSettings(Player *player);
|
||||
~GameSettings();
|
||||
|
||||
void setConsoleAllowed(bool state);
|
||||
|
||||
|
@ -27,8 +28,7 @@ public:
|
|||
|
||||
void setWaitAllowed(bool state);
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
|
@ -217,22 +217,13 @@ void Spells::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
Spells::Spells(Player *player) : player(player), changed(false)
|
||||
Spells::Spells(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Spells::~Spells()
|
||||
void Spells::processUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Spells::update()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK);
|
||||
packet->setPlayer(player);
|
||||
packet->Send(false);
|
||||
|
@ -240,18 +231,18 @@ void Spells::update()
|
|||
|
||||
void Spells::addCustomSpell(Spell spell)
|
||||
{
|
||||
if (!changed)
|
||||
if (!isChanged())
|
||||
clear();
|
||||
changed = true;
|
||||
setChanged();
|
||||
|
||||
player->spellbookChanges.spells.push_back(spell.spell);
|
||||
}
|
||||
|
||||
void Spells::addDefaultSpell(const std::string &spell)
|
||||
{
|
||||
if (!changed)
|
||||
if (!isChanged())
|
||||
clear();
|
||||
changed = true;
|
||||
setChanged();
|
||||
|
||||
ESM::Spell s;
|
||||
s.mId = spell;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <components/esm/records.hpp>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class LuaState;
|
||||
class Player;
|
||||
|
@ -72,15 +73,12 @@ public:
|
|||
ESM::Spell spell;
|
||||
};
|
||||
|
||||
class Spells
|
||||
class Spells final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
explicit Spells(Player *player);
|
||||
~Spells();
|
||||
|
||||
void update();
|
||||
|
||||
void addCustomSpell(Spell spell);
|
||||
Spell getCustomSpell(unsigned int i);
|
||||
|
@ -90,9 +88,7 @@ public:
|
|||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -25,25 +25,22 @@ void WeatherMgr::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
WeatherMgr::WeatherMgr(Player *player) : player(player), changed(false)
|
||||
WeatherMgr::WeatherMgr(Player *player) : BaseMgr(player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WeatherMgr::setWeather(int weather)
|
||||
{
|
||||
changed = true;
|
||||
setChanged();
|
||||
|
||||
player->weather.nextWeather = weather;
|
||||
player->weather.transitionFactor = 0.0f;
|
||||
player->weather.updateTime = 0.0f;
|
||||
}
|
||||
|
||||
void WeatherMgr::update()
|
||||
void WeatherMgr::processUpdate()
|
||||
{
|
||||
if (!changed)
|
||||
return;
|
||||
changed = false;
|
||||
|
||||
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_WEATHER);
|
||||
|
||||
|
@ -55,7 +52,7 @@ void WeatherMgr::update()
|
|||
void WeatherMgr::setCurrent(int weather)
|
||||
{
|
||||
player->weather.currentWeather = weather;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
int WeatherMgr::getCurrent() const
|
||||
|
@ -66,7 +63,7 @@ int WeatherMgr::getCurrent() const
|
|||
void WeatherMgr::setNext(int weather)
|
||||
{
|
||||
player->weather.nextWeather = weather;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
int WeatherMgr::getNext() const
|
||||
|
@ -77,7 +74,7 @@ int WeatherMgr::getNext() const
|
|||
void WeatherMgr::setTransition(float time)
|
||||
{
|
||||
player->weather.transitionFactor = time;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
float WeatherMgr::getTransition() const
|
||||
|
@ -88,7 +85,7 @@ float WeatherMgr::getTransition() const
|
|||
void WeatherMgr::setUpdate(float time)
|
||||
{
|
||||
player->weather.updateTime = time;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
float WeatherMgr::getUpdate() const
|
||||
|
@ -104,8 +101,8 @@ void WeatherMgr::requestWeather()
|
|||
|
||||
void WeatherMgr::copy(const WeatherMgr &other)
|
||||
{
|
||||
if(other.player == player)
|
||||
if (other.player == player)
|
||||
return;
|
||||
player->weather = other.player->weather;
|
||||
changed = true;
|
||||
setChanged();
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include <apps/openmw-mp/Script/LuaState.hpp>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class Player;
|
||||
|
||||
class WeatherMgr
|
||||
class WeatherMgr final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
|
@ -17,8 +18,6 @@ public:
|
|||
explicit WeatherMgr(Player *player);
|
||||
~WeatherMgr() = default;
|
||||
|
||||
void update();
|
||||
|
||||
void setWeather(int weather);
|
||||
|
||||
void setCurrent(int weather);
|
||||
|
@ -38,8 +37,7 @@ public:
|
|||
void copy(const WeatherMgr &other);
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
void processUpdate() final;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -26,16 +26,11 @@ void Window::Init(LuaState &lua)
|
|||
);
|
||||
}
|
||||
|
||||
Window::Window(Player *player, int id) : player(player)
|
||||
Window::Window(Player *player, int id) : BaseMgr(player)
|
||||
{
|
||||
guiWindow.id = id;
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Window::show()
|
||||
{
|
||||
printf("Trying to show window: %d\n", guiWindow.id);
|
||||
|
@ -213,3 +208,8 @@ void Window::addSlider(short x, short y, short w, short h, const std::string &id
|
|||
widget.disabled = false;
|
||||
guiWindow.widgets.push_back(widget);
|
||||
}
|
||||
|
||||
void Window::processUpdate()
|
||||
{
|
||||
// Currently not used
|
||||
}
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include <apps/openmw-mp/Script/LuaState.hpp>
|
||||
#include "BaseMgr.hpp"
|
||||
|
||||
class Player;
|
||||
|
||||
class Window
|
||||
class Window final: public BaseMgr
|
||||
{
|
||||
public:
|
||||
static void Init(LuaState &lua);
|
||||
public:
|
||||
Window(Player *player, int id);
|
||||
~Window();
|
||||
|
||||
|
||||
void setSize(short x, short y);
|
||||
|
@ -34,10 +34,9 @@ public:
|
|||
void addPassiveListBox(short x, short y, short w, short h,const std::string &id, sol::table data, sol::optional<bool> active);
|
||||
void addActiveListBox(short x, short y, short w, short h,const std::string &id, sol::table data, sol::optional<bool> active);
|
||||
void addSlider(short x, short y, short w, short h,const std::string &id, sol::optional<bool> active);
|
||||
private:
|
||||
Player *player;
|
||||
bool changed;
|
||||
|
||||
private:
|
||||
void processUpdate() final;
|
||||
sol::function callback;
|
||||
mwmp::BasePlayer::GUIWindow guiWindow;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue