1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:23:52 +00:00

[General] Modernize packet style for PlayerCellState

This commit is contained in:
David Cernat 2019-10-23 17:46:21 +03:00
parent 96a71c1ced
commit 4f9e6b0e3e
5 changed files with 20 additions and 28 deletions

View file

@ -162,7 +162,7 @@ void CellController::update(Player *player)
{ {
std::vector<Cell*> toDelete; std::vector<Cell*> toDelete;
for (auto &&cell : player->cellStateChanges.cellStates) for (auto &&cell : player->cellStateChanges)
{ {
if (cell.type == mwmp::CellState::LOAD) if (cell.type == mwmp::CellState::LOAD)
{ {

View file

@ -17,7 +17,7 @@ unsigned int CellFunctions::GetCellStateChangesSize(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->cellStateChanges.count; return player->cellStateChanges.size();
} }
unsigned int CellFunctions::GetCellStateType(unsigned short pid, unsigned int index) noexcept unsigned int CellFunctions::GetCellStateType(unsigned short pid, unsigned int index) noexcept
@ -25,7 +25,7 @@ unsigned int CellFunctions::GetCellStateType(unsigned short pid, unsigned int in
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->cellStateChanges.cellStates.at(index).type; return player->cellStateChanges.at(index).type;
} }
const char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned int index) noexcept const char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned int index) noexcept
@ -33,10 +33,10 @@ const char *CellFunctions::GetCellStateDescription(unsigned short pid, unsigned
Player *player; Player *player;
GET_PLAYER(pid, player, ""); GET_PLAYER(pid, player, "");
if (index >= player->cellStateChanges.count) if (index >= player->cellStateChanges.size())
return "invalid"; return "invalid";
tempCellDescription = player->cellStateChanges.cellStates.at(index).cell.getDescription(); tempCellDescription = player->cellStateChanges.at(index).cell.getDescription();
return tempCellDescription.c_str(); return tempCellDescription.c_str();
} }

View file

@ -1675,7 +1675,7 @@ void LocalPlayer::sendCellStates()
void LocalPlayer::clearCellStates() void LocalPlayer::clearCellStates()
{ {
cellStateChanges.cellStates.clear(); cellStateChanges.clear();
} }
void LocalPlayer::clearCurrentContainer() void LocalPlayer::clearCurrentContainer()
@ -1689,12 +1689,12 @@ void LocalPlayer::storeCellState(const ESM::Cell& cell, int stateType)
{ {
std::vector<CellState>::iterator iter; std::vector<CellState>::iterator iter;
for (iter = cellStateChanges.cellStates.begin(); iter != cellStateChanges.cellStates.end(); ) for (iter = cellStateChanges.begin(); iter != cellStateChanges.end(); )
{ {
// If there's already a cell state recorded for this particular cell, // If there's already a cell state recorded for this particular cell,
// remove it // remove it
if (cell.getDescription() == (*iter).cell.getDescription()) if (cell.getDescription() == (*iter).cell.getDescription())
iter = cellStateChanges.cellStates.erase(iter); iter = cellStateChanges.erase(iter);
else else
++iter; ++iter;
} }
@ -1703,7 +1703,7 @@ void LocalPlayer::storeCellState(const ESM::Cell& cell, int stateType)
cellState.cell = cell; cellState.cell = cell;
cellState.type = stateType; cellState.type = stateType;
cellStateChanges.cellStates.push_back(cellState); cellStateChanges.push_back(cellState);
} }
void LocalPlayer::storeCurrentContainer(const MWWorld::Ptr &container) void LocalPlayer::storeCurrentContainer(const MWWorld::Ptr &container)

View file

@ -129,12 +129,6 @@ namespace mwmp
int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell
}; };
struct CellStateChanges
{
std::vector<CellState> cellStates;
unsigned int count;
};
enum RESURRECT_TYPE enum RESURRECT_TYPE
{ {
REGULAR = 0, REGULAR = 0,
@ -225,7 +219,7 @@ namespace mwmp
FactionChanges factionChanges; FactionChanges factionChanges;
std::vector<Topic> topicChanges; std::vector<Topic> topicChanges;
std::vector<Book> bookChanges; std::vector<Book> bookChanges;
CellStateChanges cellStateChanges; std::vector<CellState> cellStateChanges;
ESM::ActiveSpells activeSpells; ESM::ActiveSpells activeSpells;
CurrentContainer currentContainer; CurrentContainer currentContainer;

View file

@ -13,25 +13,23 @@ void mwmp::PacketPlayerCellState::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count;
if (send) if (send)
player->cellStateChanges.count = (unsigned int)(player->cellStateChanges.cellStates.size()); count = static_cast<uint32_t>(player->cellStateChanges.size());
else
player->cellStateChanges.cellStates.clear();
RW(player->cellStateChanges.count, send); RW(count, send);
for (unsigned int i = 0; i < player->cellStateChanges.count; i++) if (!send)
{ {
CellState cellState; player->cellStateChanges.clear();
player->cellStateChanges.resize(count);
}
if (send) for (auto &&cellState : player->cellStateChanges)
cellState = player->cellStateChanges.cellStates.at(i); {
RW(cellState.type, send); RW(cellState.type, send);
RW(cellState.cell.mData, send, true); RW(cellState.cell.mData, send, true);
RW(cellState.cell.mName, send, true); RW(cellState.cell.mName, send, true);
if (!send)
player->cellStateChanges.cellStates.push_back(cellState);
} }
} }