From ffead444dbc2cb03aa0ca3f0516fdb463fd96a0d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 14 Feb 2020 11:51:31 +0200 Subject: [PATCH] [Server] Use consistent order for WorldstateFunctions --- .../openmw-mp/Script/Functions/Worldstate.cpp | 85 +++++++++---------- .../openmw-mp/Script/Functions/Worldstate.hpp | 52 ++++++------ 2 files changed, 67 insertions(+), 70 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index 3afec8de3..dcbe1ef42 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -250,6 +250,12 @@ void WorldstateFunctions::AddEnforcedCollisionRefId(const char *refId) noexcept writeWorldstate.enforcedCollisionRefIds.push_back(refId); } +void WorldstateFunctions::AddCellToReset(const char *cellDescription) noexcept +{ + ESM::Cell cell = Utils::getCellFromDescription(cellDescription); + writeWorldstate.cellsToReset.push_back(cell); +} + void WorldstateFunctions::AddDestinationOverride(const char *oldCellDescription, const char *newCellDescription) noexcept { writeWorldstate.destinationOverrides[oldCellDescription] = newCellDescription; @@ -265,27 +271,21 @@ void WorldstateFunctions::ClearSynchronizedClientGlobalIds() noexcept writeWorldstate.synchronizedClientGlobalIds.clear(); } -void WorldstateFunctions::AddCellToReset(const char *cellDescription) noexcept -{ - ESM::Cell cell = Utils::getCellFromDescription(cellDescription); - writeWorldstate.cellsToReset.push_back(cell); -} - void WorldstateFunctions::ClearEnforcedCollisionRefIds() noexcept { writeWorldstate.enforcedCollisionRefIds.clear(); } -void WorldstateFunctions::ClearDestinationOverrides() noexcept -{ - writeWorldstate.destinationOverrides.clear(); -} - void WorldstateFunctions::ClearCellsToReset() noexcept { writeWorldstate.cellsToReset.clear(); } +void WorldstateFunctions::ClearDestinationOverrides() noexcept +{ + writeWorldstate.destinationOverrides.clear(); +} + void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept { if (index >= readWorldstate->mapTiles.size()) @@ -431,38 +431,6 @@ void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool se packet->Send(true); } -void WorldstateFunctions::SendWorldDestinationOverride(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - writeWorldstate.guid = player->guid; - - mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_DESTINATION_OVERRIDE); - packet->setWorldstate(&writeWorldstate); - - if (!skipAttachedPlayer) - packet->Send(false); - if (sendToOtherPlayers) - packet->Send(true); -} - -void WorldstateFunctions::SendWorldRegionAuthority(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - writeWorldstate.guid = player->guid; - - mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_REGION_AUTHORITY); - packet->setWorldstate(&writeWorldstate); - - packet->Send(false); - - // This packet should always be sent to all other players - packet->Send(true); -} - void WorldstateFunctions::SendCellReset(unsigned short pid, bool sendToOtherPlayers) noexcept { mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_CELL_RESET); @@ -498,6 +466,37 @@ void WorldstateFunctions::SendCellReset(unsigned short pid, bool sendToOtherPlay } } +void WorldstateFunctions::SendWorldDestinationOverride(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + writeWorldstate.guid = player->guid; + + mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_DESTINATION_OVERRIDE); + packet->setWorldstate(&writeWorldstate); + + if (!skipAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); +} + +void WorldstateFunctions::SendWorldRegionAuthority(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + writeWorldstate.guid = player->guid; + + mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_REGION_AUTHORITY); + packet->setWorldstate(&writeWorldstate); + + packet->Send(false); + + // This packet should always be sent to all other players + packet->Send(true); +} // All methods below are deprecated versions of methods from above diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index 8f5d4782f..601e6d12b 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -61,11 +61,13 @@ {"AddSynchronizedClientScriptId", WorldstateFunctions::AddSynchronizedClientScriptId},\ {"AddSynchronizedClientGlobalId", WorldstateFunctions::AddSynchronizedClientGlobalId},\ {"AddEnforcedCollisionRefId", WorldstateFunctions::AddEnforcedCollisionRefId},\ + {"AddCellToReset", WorldstateFunctions::AddCellToReset},\ {"AddDestinationOverride", WorldstateFunctions::AddDestinationOverride},\ \ {"ClearSynchronizedClientScriptIds", WorldstateFunctions::ClearSynchronizedClientScriptIds},\ {"ClearSynchronizedClientGlobalIds", WorldstateFunctions::ClearSynchronizedClientGlobalIds},\ {"ClearEnforcedCollisionRefIds", WorldstateFunctions::ClearEnforcedCollisionRefIds},\ + {"ClearCellsToReset", WorldstateFunctions::ClearCellsToReset},\ {"ClearDestinationOverrides", WorldstateFunctions::ClearDestinationOverrides},\ \ {"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\ @@ -78,13 +80,10 @@ {"SendWorldTime", WorldstateFunctions::SendWorldTime},\ {"SendWorldWeather", WorldstateFunctions::SendWorldWeather},\ {"SendWorldCollisionOverride", WorldstateFunctions::SendWorldCollisionOverride},\ + {"SendCellReset", WorldstateFunctions::SendCellReset},\ {"SendWorldDestinationOverride", WorldstateFunctions::SendWorldDestinationOverride},\ {"SendWorldRegionAuthority", WorldstateFunctions::SendWorldRegionAuthority},\ \ - {"AddCellToReset", WorldstateFunctions::AddCellToReset},\ - {"ClearCellsToReset", WorldstateFunctions::ClearCellsToReset},\ - {"SendCellReset", WorldstateFunctions::SendCellReset},\ - \ {"ReadLastWorldstate", WorldstateFunctions::ReadLastWorldstate},\ {"CopyLastWorldstateToStore", WorldstateFunctions::CopyLastWorldstateToStore} @@ -461,6 +460,13 @@ public: */ static void AddEnforcedCollisionRefId(const char* refId) noexcept; + /** + * \brief Add a cell with given cellDescription to the list of cells that should be reset on the client. + * + * \return void + */ + static void AddCellToReset(const char * cellDescription) noexcept; + /** * \brief Add a destination override containing the cell description for the old cell * and the new cell. @@ -489,27 +495,12 @@ public: /** * \brief Clear the list of refIds for which collision should be enforced irrespective - * \brief Add a cell with given cellDescription to the list of cells that should be reset on the client. - * - * \return void - */ - static void AddCellToReset(const char * cellDescription) noexcept; - - /** - * \brief Clear the list of refIdsd for which collision should be enforced irrespective * of other settings. * * \return void */ static void ClearEnforcedCollisionRefIds() noexcept; - /** - * \brief Clear the list of destination overrides. - * - * \return void - */ - static void ClearDestinationOverrides() noexcept; - /** * \brief Clear the list of cells which should be reset on the client. * @@ -517,6 +508,13 @@ public: */ static void ClearCellsToReset() noexcept; + /** + * \brief Clear the list of destination overrides. + * + * \return void + */ + static void ClearDestinationOverrides() noexcept; + /** * \brief Save the .png image data of the map tile at a certain index in the read worldstate's * map changes. @@ -588,14 +586,6 @@ public: */ static void SendWorldRegionAuthority(unsigned short pid) noexcept; - /** - * \brief Send a CellReset packet with a list of cells, - * - * \param pid The player ID attached to the packet. - * \return void - */ - static void SendCellReset(unsigned short pid, bool sendToOtherPlayers) noexcept; - /** * \brief Send a WorldMap packet with the current set of map changes in the write-only * worldstate. @@ -645,6 +635,14 @@ public: */ static void SendWorldCollisionOverride(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept; + /** + * \brief Send a CellReset packet with a list of cells, + * + * \param pid The player ID attached to the packet. + * \return void + */ + static void SendCellReset(unsigned short pid, bool sendToOtherPlayers) noexcept; + /** * \brief Send a WorldDestinationOverride packet with the current destination overrides in * the write-only worldstate.