From 04a202534085186d93911c7195489e79c384e596 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 5 Jun 2018 18:09:10 +0300 Subject: [PATCH 1/3] Fix crash when adding items to certain disabled creatures (bug #4441) --- apps/openmw/mwrender/objects.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index f0a3d2e38..db6772eaa 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -123,11 +123,12 @@ bool Objects::removeObject (const MWWorld::Ptr& ptr) mObjects.erase(iter); - if (ptr.getClass().isNpc()) + if (ptr.getClass().isActor()) { - MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); - store.setInvListener(NULL, ptr); - store.setContListener(NULL); + if (ptr.getClass().hasInventoryStore(ptr)) + ptr.getClass().getInventoryStore(ptr).setInvListener(NULL, ptr); + + ptr.getClass().getContainerStore(ptr).setContListener(NULL); } ptr.getRefData().getBaseNode()->getParent(0)->removeChild(ptr.getRefData().getBaseNode()); From 98063c5afcd4b967dd66b83f1fb1c37288c95031 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 6 Jun 2018 09:50:33 +0200 Subject: [PATCH 2/3] updated changelog with last-minute crash-bug fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c0f3ef3..7a958fbc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ Bug #4413: Moving with 0 strength uses all of your fatigue Bug #4420: Camera flickering when I open up and close menus while sneaking Bug #4435: Item health is considered a signed integer + Bug #4441: Adding items to currently disabled weapon-wielding creatures crashes the game Feature #1786: Round up encumbrance value in the encumbrance bar Feature #2694: Editor: rename "model" column to make its purpose clear Feature #3870: Editor: Terrain Texture Brush Button From 72862dc25521ec6d686dd648a6b9d76d2c6ea7de Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 7 Jun 2018 12:49:12 +0300 Subject: [PATCH 3/3] [General] Turn PlayerMap into WorldMap, now a Worldstate packet --- apps/openmw-mp/CMakeLists.txt | 16 +-- apps/openmw-mp/Script/Functions/Cells.cpp | 69 --------- apps/openmw-mp/Script/Functions/Cells.hpp | 82 +---------- .../openmw-mp/Script/Functions/Worldstate.cpp | 72 +++++++++- .../openmw-mp/Script/Functions/Worldstate.hpp | 132 +++++++++++++++--- apps/openmw-mp/Script/ScriptFunctions.hpp | 2 +- .../processors/ProcessorInitializer.cpp | 4 +- .../processors/player/ProcessorPlayerMap.hpp | 25 ---- .../worldstate/ProcessorWorldMap.hpp | 25 ++++ apps/openmw/CMakeLists.txt | 10 +- apps/openmw/mwmp/LocalPlayer.cpp | 33 ----- apps/openmw/mwmp/LocalPlayer.hpp | 2 - apps/openmw/mwmp/Worldstate.cpp | 38 +++++ apps/openmw/mwmp/Worldstate.hpp | 4 + .../mwmp/processors/ProcessorInitializer.cpp | 4 +- .../mwmp/processors/WorldstateProcessor.cpp | 2 +- .../mwmp/processors/WorldstateProcessor.hpp | 4 +- .../processors/player/ProcessorPlayerMap.hpp | 26 ---- .../worldstate/ProcessorRecordDynamic.hpp | 2 +- .../ProcessorWorldCollisionOverride.hpp | 2 +- .../worldstate/ProcessorWorldMap.hpp | 23 +++ .../worldstate/ProcessorWorldTime.hpp | 2 +- apps/openmw/mwrender/globalmap.cpp | 5 +- components/CMakeLists.txt | 9 +- components/openmw-mp/Base/BasePlayer.hpp | 13 -- components/openmw-mp/Base/BaseWorldstate.hpp | 15 ++ .../Controllers/PlayerPacketController.cpp | 2 - .../WorldstatePacketController.cpp | 2 + components/openmw-mp/NetworkMessages.hpp | 2 +- .../openmw-mp/Packets/PacketPreInit.cpp | 4 - .../openmw-mp/Packets/PacketPreInit.hpp | 4 - .../Packets/Player/PacketPlayerAnimFlags.cpp | 4 - .../Packets/Player/PacketPlayerAnimFlags.hpp | 4 - .../Packets/Player/PacketPlayerMap.hpp | 17 --- .../PacketWorldMap.cpp} | 18 +-- .../Packets/Worldstate/PacketWorldMap.hpp | 17 +++ .../Packets/Worldstate/PacketWorldTime.cpp | 2 +- 37 files changed, 349 insertions(+), 348 deletions(-) delete mode 100644 apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp create mode 100644 apps/openmw-mp/processors/worldstate/ProcessorWorldMap.hpp delete mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp create mode 100644 apps/openmw/mwmp/processors/worldstate/ProcessorWorldMap.hpp delete mode 100644 components/openmw-mp/Packets/Player/PacketPlayerMap.hpp rename components/openmw-mp/Packets/{Player/PacketPlayerMap.cpp => Worldstate/PacketWorldMap.cpp} (57%) create mode 100644 components/openmw-mp/Packets/Worldstate/PacketWorldMap.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index b887d1088..65eb032b9 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -133,12 +133,12 @@ set(PROCESSORS_PLAYER processors/player/ProcessorPlayerFaction.hpp processors/player/ProcessorPlayerInteraction.hpp processors/player/ProcessorPlayerInventory.hpp processors/player/ProcessorPlayerJournal.hpp processors/player/ProcessorPlayerKillCount.hpp processors/player/ProcessorPlayerLevel.hpp - processors/player/ProcessorPlayerMap.hpp processors/player/ProcessorPlayerMiscellaneous.hpp - processors/player/ProcessorPlayerPosition.hpp processors/player/ProcessorPlayerQuickKeys.hpp - processors/player/ProcessorPlayerRest.hpp processors/player/ProcessorPlayerResurrect.hpp - processors/player/ProcessorPlayerShapeshift.hpp processors/player/ProcessorPlayerSkill.hpp - processors/player/ProcessorPlayerSpeech.hpp processors/player/ProcessorPlayerSpellbook.hpp - processors/player/ProcessorPlayerStatsDynamic.hpp processors/player/ProcessorPlayerTopic.hpp + processors/player/ProcessorPlayerMiscellaneous.hpp processors/player/ProcessorPlayerPosition.hpp + processors/player/ProcessorPlayerQuickKeys.hpp processors/player/ProcessorPlayerRest.hpp + processors/player/ProcessorPlayerResurrect.hpp processors/player/ProcessorPlayerShapeshift.hpp + processors/player/ProcessorPlayerSkill.hpp processors/player/ProcessorPlayerSpeech.hpp + processors/player/ProcessorPlayerSpellbook.hpp processors/player/ProcessorPlayerStatsDynamic.hpp + processors/player/ProcessorPlayerTopic.hpp ) source_group(tes3mp-server\\processors\\player FILES ${PROCESSORS_PLAYER}) @@ -159,7 +159,7 @@ set(PROCESSORS_OBJECT source_group(tes3mp-server\\processors\\object FILES ${PROCESSORS_OBJECT}) set(PROCESSORS_WORLDSTATE - processors/worldstate/ProcessorRecordDynamic.hpp + processors/worldstate/ProcessorRecordDynamic.hpp processors/worldstate/ProcessorWorldMap.hpp ) source_group(tes3mp-server\\processors\\worldstate FILES ${PROCESSORS_WORLDSTATE}) @@ -180,7 +180,7 @@ include_directories("./") add_executable(tes3mp-server ${SERVER} ${SERVER_HEADER} - ${PROCESSORS_ACTOR} ${PROCESSORS_PLAYER} ${PROCESSORS_OBJECT} ${PROCESSORS} + ${PROCESSORS_ACTOR} ${PROCESSORS_PLAYER} ${PROCESSORS_OBJECT} ${PROCESSORS_WORLDSTATE} ${PROCESSORS} ${APPLE_BUNDLE_RESOURCES} ) add_definitions(-std=gnu++14 -Wno-ignored-qualifiers) diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp index 6e3c5d239..b82bff541 100644 --- a/apps/openmw-mp/Script/Functions/Cells.cpp +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -12,14 +12,6 @@ using namespace std; static std::string tempCellDescription; -void CellFunctions::InitializeMapChanges(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->mapChanges.mapTiles.clear(); -} - unsigned int CellFunctions::GetCellStateChangesSize(unsigned short pid) noexcept { Player *player; @@ -28,14 +20,6 @@ unsigned int CellFunctions::GetCellStateChangesSize(unsigned short pid) noexcept return player->cellStateChanges.count; } -unsigned int CellFunctions::GetMapChangesSize(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->mapChanges.mapTiles.size(); -} - unsigned int CellFunctions::GetCellStateType(unsigned short pid, unsigned int i) noexcept { Player *player; @@ -103,35 +87,6 @@ bool CellFunctions::IsChangingRegion(unsigned short pid) noexcept return player->isChangingRegion; } -void CellFunctions::SaveMapTileImageFile(unsigned short pid, unsigned int i, const char *filePath) noexcept -{ - Player *player; - GET_PLAYER(pid, player,); - - if (i >= player->mapChanges.mapTiles.size()) - return; - - const std::vector& imageData = player->mapChanges.mapTiles.at(i).imageData; - - std::ofstream outputFile(filePath, std::ios::binary); - std::ostream_iterator outputIterator(outputFile); - std::copy(imageData.begin(), imageData.end(), outputIterator); -} - -int CellFunctions::GetMapTileCellX(unsigned short pid, unsigned int i) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - return player->mapChanges.mapTiles.at(i).x; -} - -int CellFunctions::GetMapTileCellY(unsigned short pid, unsigned int i) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - return player->mapChanges.mapTiles.at(i).y; -} - void CellFunctions::SetCell(unsigned short pid, const char *cellDescription) noexcept { Player *player; @@ -160,21 +115,6 @@ void CellFunctions::SetExteriorCell(unsigned short pid, int x, int y) noexcept player->cell.mData.mY = y; } -void CellFunctions::LoadMapTileImageFile(unsigned short pid, int cellX, int cellY, const char* filePath) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::MapTile mapTile; - mapTile.x = cellX; - mapTile.y = cellY; - - std::ifstream inputFile(filePath, std::ios::binary); - mapTile.imageData = std::vector(std::istreambuf_iterator(inputFile), std::istreambuf_iterator()); - - player->mapChanges.mapTiles.push_back(mapTile); -} - void CellFunctions::SendCell(unsigned short pid) noexcept { Player *player; @@ -183,12 +123,3 @@ void CellFunctions::SendCell(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(false); } - -void CellFunctions::SendMapChanges(unsigned short pid, bool toOthers) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MAP)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MAP)->Send(toOthers); -} diff --git a/apps/openmw-mp/Script/Functions/Cells.hpp b/apps/openmw-mp/Script/Functions/Cells.hpp index c5731a40a..88d35b119 100644 --- a/apps/openmw-mp/Script/Functions/Cells.hpp +++ b/apps/openmw-mp/Script/Functions/Cells.hpp @@ -4,10 +4,7 @@ #include "../Types.hpp" #define CELLAPI \ - {"InitializeMapChanges", CellFunctions::InitializeMapChanges},\ - \ {"GetCellStateChangesSize", CellFunctions::GetCellStateChangesSize},\ - {"GetMapChangesSize", CellFunctions::GetMapChangesSize},\ \ {"GetCellStateType", CellFunctions::GetCellStateType},\ {"GetCellStateDescription", CellFunctions::GetCellStateDescription},\ @@ -20,33 +17,16 @@ {"GetRegion", CellFunctions::GetRegion},\ {"IsChangingRegion", CellFunctions::IsChangingRegion},\ \ - {"GetMapTileCellX", CellFunctions::GetMapTileCellX},\ - {"GetMapTileCellY", CellFunctions::GetMapTileCellY},\ - {"SaveMapTileImageFile", CellFunctions::SaveMapTileImageFile},\ - \ {"SetCell", CellFunctions::SetCell},\ {"SetExteriorCell", CellFunctions::SetExteriorCell},\ \ - {"LoadMapTileImageFile", CellFunctions::LoadMapTileImageFile},\ - \ - {"SendCell", CellFunctions::SendCell},\ - {"SendMapChanges", CellFunctions::SendMapChanges} + {"SendCell", CellFunctions::SendCell} class CellFunctions { public: - /** - * \brief Clear the last recorded map changes for a player. - * - * This is used to initialize the sending of new PlayerMap packets. - * - * \param pid The player ID whose map changes should be used. - * \return void - */ - static void InitializeMapChanges(unsigned short pid) noexcept; - /** * \brief Get the number of indexes in a player's latest cell state changes. * @@ -55,14 +35,6 @@ public: */ static unsigned int GetCellStateChangesSize(unsigned short pid) noexcept; - /** - * \brief Get the number of indexes in a player's latest map changes. - * - * \param pid The player ID whose map changes should be used. - * \return The number of indexes. - */ - static unsigned int GetMapChangesSize(unsigned short pid) noexcept; - /** * \brief Get the cell state type at a certain index in a player's latest cell state changes. * @@ -131,37 +103,6 @@ public: */ static bool IsChangingRegion(unsigned short pid) noexcept; - /** - * \brief Get the X coordinate of the cell corresponding to the map tile at a certain index in a - * player's latest map changes. - * - * \param pid The player ID whose map changes should be used. - * \param i The index of the map tile. - * \return The X coordinate of the cell. - */ - static int GetMapTileCellX(unsigned short pid, unsigned int i) noexcept; - - /** - * \brief Get the Y coordinate of the cell corresponding to the map tile at a certain index in a - * player's latest map changes. - * - * \param pid The player ID whose map changes should be used. - * \param i The index of the map tile. - * \return The Y coordinate of the cell. - */ - static int GetMapTileCellY(unsigned short pid, unsigned int i) noexcept; - - /** - * \brief Save the .png image data of the map tile at a certain index in a player's latest map changes - * to a file. - * - * \param pid The player ID whose map changes should be used. - * \param i The index of the map tile. - * \param filePath The file path of the resulting file. - * \return void - */ - static void SaveMapTileImageFile(unsigned short pid, unsigned int i, const char *filePath) noexcept; - /** * \brief Set the cell of a player. * @@ -190,18 +131,6 @@ public: */ static void SetExteriorCell(unsigned short pid, int x, int y) noexcept; - /** - * \brief Load a .png file as the image data for a map tile and add it to the map changes for - * a player. - * - * \param pid The player ID whose map changes should be used. - * \param cellX The X coordinate of the cell corresponding to the map tile. - * \param cellY The Y coordinate of the cell corresponding to the map tile. - * \param filePath The file path of the loaded file. - * \return void - */ - static void LoadMapTileImageFile(unsigned short pid, int cellX, int cellY, const char* filePath) noexcept; - /** * \brief Send a PlayerCellChange packet about a player. * @@ -212,15 +141,6 @@ public: */ static void SendCell(unsigned short pid) noexcept; - /** - * \brief Send a PlayerMap packet with a player's recorded map changes. - * - * \param pid The player ID whose map changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. - * \return void - */ - static void SendMapChanges(unsigned short pid, bool toOthers = false) noexcept; }; #endif //OPENMW_CELLAPI_HPP diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index 2210d4a6c..51bcb75b9 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -11,6 +11,56 @@ using namespace std; using namespace mwmp; BaseWorldstate writeWorldstate; +BaseWorldstate *readWorldstate; + +void WorldstateFunctions::ReadLastWorldstate() noexcept +{ + readWorldstate = mwmp::Networking::getPtr()->getLastWorldstate(); +} + +void WorldstateFunctions::ClearMapChanges() noexcept +{ + writeWorldstate.mapChanges.mapTiles.clear(); +} + +unsigned int WorldstateFunctions::GetMapChangesSize() noexcept +{ + return readWorldstate->mapChanges.mapTiles.size(); +} + +int WorldstateFunctions::GetMapTileCellX(unsigned int index) noexcept +{ + return readWorldstate->mapChanges.mapTiles.at(index).x; +} + +int WorldstateFunctions::GetMapTileCellY(unsigned int index) noexcept +{ + return readWorldstate->mapChanges.mapTiles.at(index).y; +} + +void WorldstateFunctions::SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept +{ + if (index >= readWorldstate->mapChanges.mapTiles.size()) + return; + + const std::vector& imageData = readWorldstate->mapChanges.mapTiles.at(index).imageData; + + std::ofstream outputFile(filePath, std::ios::binary); + std::ostream_iterator outputIterator(outputFile); + std::copy(imageData.begin(), imageData.end(), outputIterator); +} + +void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept +{ + mwmp::MapTile mapTile; + mapTile.x = cellX; + mapTile.y = cellY; + + std::ifstream inputFile(filePath, std::ios::binary); + mapTile.imageData = std::vector(std::istreambuf_iterator(inputFile), std::istreambuf_iterator()); + + writeWorldstate.mapChanges.mapTiles.push_back(mapTile); +} void WorldstateFunctions::SetHour(double hour) noexcept { @@ -62,7 +112,21 @@ void WorldstateFunctions::UseActorCollisionForPlacedObjects(bool useActorCollisi writeWorldstate.useActorCollisionForPlacedObjects = useActorCollision; } -void WorldstateFunctions::SendWorldTime(unsigned short pid, bool toOthers) noexcept +void WorldstateFunctions::SendWorldMap(unsigned short pid, bool broadcast) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + writeWorldstate.guid = player->guid; + + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->setWorldstate(&writeWorldstate); + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->Send(false); + + if (broadcast) + mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->Send(true); +} + +void WorldstateFunctions::SendWorldTime(unsigned short pid, bool broadcast) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -72,11 +136,11 @@ void WorldstateFunctions::SendWorldTime(unsigned short pid, bool toOthers) noexc mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); - if (toOthers) + if (broadcast) mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(true); } -void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool toOthers) noexcept +void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool broadcast) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -86,6 +150,6 @@ void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool to mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->setWorldstate(&writeWorldstate); mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->Send(false); - if (toOthers) + if (broadcast) mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index bbc82e3ea..7f19de142 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -4,6 +4,18 @@ #include "../Types.hpp" #define WORLDSTATEAPI \ + {"ReadLastWorldstate", WorldstateFunctions::ReadLastWorldstate},\ + \ + {"ClearMapChanges", WorldstateFunctions::ClearMapChanges},\ + \ + {"GetMapChangesSize", WorldstateFunctions::GetMapChangesSize},\ + \ + {"GetMapTileCellX", WorldstateFunctions::GetMapTileCellX},\ + {"GetMapTileCellY", WorldstateFunctions::GetMapTileCellY},\ + \ + {"SaveMapTileImageFile", WorldstateFunctions::SaveMapTileImageFile},\ + {"LoadMapTileImageFile", WorldstateFunctions::LoadMapTileImageFile},\ + \ {"SetHour", WorldstateFunctions::SetHour},\ {"SetDay", WorldstateFunctions::SetDay},\ {"SetMonth", WorldstateFunctions::SetMonth},\ @@ -16,6 +28,7 @@ {"SetPlacedObjectCollisionState", WorldstateFunctions::SetPlacedObjectCollisionState},\ {"UseActorCollisionForPlacedObjects", WorldstateFunctions::UseActorCollisionForPlacedObjects},\ \ + {"SendWorldMap", WorldstateFunctions::SendWorldMap},\ {"SendWorldTime", WorldstateFunctions::SendWorldTime},\ {"SendWorldCollisionOverride", WorldstateFunctions::SendWorldCollisionOverride} @@ -24,7 +37,69 @@ class WorldstateFunctions public: /** - * \brief Set the world's hour in the worldstate stored on the server. + * \brief Use the last worldstate received by the server as the one being read. + * + * \return void + */ + static void ReadLastWorldstate() noexcept; + + /** + * \brief Clear the map changes for the write-only worldstate. + * + * This is used to initialize the sending of new WorldMap packets. + * + * \return void + */ + static void ClearMapChanges() noexcept; + + /** + * \brief Get the number of indexes in the read worldstate's map changes. + * + * \return The number of indexes. + */ + static unsigned int GetMapChangesSize() noexcept; + + /** + * \brief Get the X coordinate of the cell corresponding to the map tile at a certain index in + * the read worldstate's map changes. + * + * \param i The index of the map tile. + * \return The X coordinate of the cell. + */ + static int GetMapTileCellX(unsigned int index) noexcept; + + /** + * \brief Get the Y coordinate of the cell corresponding to the map tile at a certain index in + * the read worldstate's map changes. + * + * \param i The index of the map tile. + * \return The Y coordinate of the cell. + */ + static int GetMapTileCellY(unsigned int index) noexcept; + + /** + * \brief Save the .png image data of the map tile at a certain index in the read worldstate's + * map changes. + * + * \param i The index of the map tile. + * \param filePath The file path of the resulting file. + * \return void + */ + static void SaveMapTileImageFile(unsigned int index, const char *filePath) noexcept; + + /** + * \brief Load a .png file as the image data for a map tile and add it to the write-only worldstate + * stored on the server. + * + * \param cellX The X coordinate of the cell corresponding to the map tile. + * \param cellY The Y coordinate of the cell corresponding to the map tile. + * \param filePath The file path of the loaded file. + * \return void + */ + static void LoadMapTileImageFile(int cellX, int cellY, const char* filePath) noexcept; + + /** + * \brief Set the world's hour in the write-only worldstate stored on the server. * * \param hour The hour. * \return void @@ -32,7 +107,7 @@ public: static void SetHour(double hour) noexcept; /** - * \brief Set the world's day in the worldstate stored on the server. + * \brief Set the world's day in the write-only worldstate stored on the server. * * \param day The day. * \return void @@ -40,7 +115,7 @@ public: static void SetDay(int day) noexcept; /** - * \brief Set the world's month in the worldstate stored on the server. + * \brief Set the world's month in the write-only worldstate stored on the server. * * \param month The month. * \return void @@ -48,7 +123,7 @@ public: static void SetMonth(int month) noexcept; /** - * \brief Set the world's year in the worldstate stored on the server. + * \brief Set the world's year in the write-only worldstate stored on the server. * * \param year The year. * \return void @@ -56,7 +131,7 @@ public: static void SetYear(int year) noexcept; /** - * \brief Set the world's days passed in the worldstate stored on the server. + * \brief Set the world's days passed in the write-only worldstate stored on the server. * * \param daysPassed The days passed. * \return void @@ -64,7 +139,7 @@ public: static void SetDaysPassed(int daysPassed) noexcept; /** - * \brief Set the world's time scale in the worldstate stored on the server. + * \brief Set the world's time scale in the write-only worldstate stored on the server. * * \param pid The player ID. * \param timeScale The time scale. @@ -73,7 +148,8 @@ public: static void SetTimeScale(double timeScale) noexcept; /** - * \brief Set the collision state for other players. + * \brief Set the collision state for other players in the write-only worldstate stored + * on the server. * * \param state The collision state. * \return void @@ -81,7 +157,8 @@ public: static void SetPlayerCollisionState(bool state) noexcept; /** - * \brief Set the collision state for actors. + * \brief Set the collision state for actors in the write-only worldstate stored on the + * server. * * \param state The collision state. * \return void @@ -89,7 +166,8 @@ public: static void SetActorCollisionState(bool state) noexcept; /** - * \brief Set the collision state for placed objects. + * \brief Set the collision state for placed objects in the write-only worldstate stored + * on the server. * * \param state The collision state. * \return void @@ -97,9 +175,8 @@ public: static void SetPlacedObjectCollisionState(bool state) noexcept; /** - * \brief Whether placed objects with collision turned on should use - * actor collision, i.e. whether they should be slippery - * and prevent players from standing on them. + * \brief Whether placed objects with collision turned on should use actor collision, i.e. + * whether they should be slippery and prevent players from standing on them. * * \param useActorCollision Whether to use actor collision. * \return void @@ -107,22 +184,37 @@ public: static void UseActorCollisionForPlacedObjects(bool useActorCollision) noexcept; /** - * \brief Send a WorldTime packet with the current time and time scale - * to a specific player or to all players. + * \brief Send a WorldMap packet with the current set of map changes in the write-only + * worldstate. * - * \param pid The player ID. + * \param pid The player ID attached to the packet. + * \param broadcast Whether this packet should be sent only to the attached player + * or to all players on the server. * \return void */ - static void SendWorldTime(unsigned short pid, bool toOthers = false) noexcept; + static void SendWorldMap(unsigned short pid, bool broadcast = false) noexcept; /** - * \brief Send a WorldCollisionOverride packet with the current collision overrides - * to a specific player or to all players. + * \brief Send a WorldTime packet with the current time and time scale in the write-only + * worldstate. * - * \param pid The player ID. + * \param pid The player ID attached to the packet. + * \param broadcast Whether this packet should be sent only to the attached player + * or to all players on the server. + * \return void + */ + static void SendWorldTime(unsigned short pid, bool broadcast = false) noexcept; + + /** + * \brief Send a WorldCollisionOverride packet with the current collision overrides in + * the write-only worldstate. + * + * \param pid The player ID attached to the packet. + * \param broadcast Whether this packet should be sent only to the attached player + * or to all players on the server. * \return void */ - static void SendWorldCollisionOverride(unsigned short pid, bool toOthers = false) noexcept; + static void SendWorldCollisionOverride(unsigned short pid, bool broadcast = false) noexcept; }; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index f110bd8bb..21a6323e4 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -323,7 +323,6 @@ public: {"OnPlayerDisposition", Function()}, {"OnPlayerBook", Function()}, {"OnPlayerMiscellaneous", Function()}, - {"OnPlayerMap", Function()}, {"OnPlayerInteraction", Function()}, {"OnPlayerRest", Function()}, {"OnRecordDynamic", Function()}, @@ -346,6 +345,7 @@ public: {"OnPlayerSendMessage", Function()}, {"OnPlayerEndCharGen", Function()}, {"OnGUIAction", Function()}, + {"OnWorldMap", Function()}, {"OnMpNumIncrement", Function()}, {"OnRequestPluginList", Function()} }; diff --git a/apps/openmw-mp/processors/ProcessorInitializer.cpp b/apps/openmw-mp/processors/ProcessorInitializer.cpp index c5d365dec..9557a0c9b 100644 --- a/apps/openmw-mp/processors/ProcessorInitializer.cpp +++ b/apps/openmw-mp/processors/ProcessorInitializer.cpp @@ -26,7 +26,6 @@ #include "player/ProcessorPlayerKillCount.hpp" #include "player/ProcessorPlayerInteraction.hpp" #include "player/ProcessorPlayerLevel.hpp" -#include "player/ProcessorPlayerMap.hpp" #include "player/ProcessorPlayerMiscellaneous.hpp" #include "player/ProcessorPlayerPosition.hpp" #include "player/ProcessorPlayerQuickKeys.hpp" @@ -76,6 +75,7 @@ #include "object/ProcessorVideoPlay.hpp" #include "WorldstateProcessor.hpp" #include "worldstate/ProcessorRecordDynamic.hpp" +#include "worldstate/ProcessorWorldMap.hpp" using namespace mwmp; @@ -103,7 +103,6 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerKillCount()); PlayerProcessor::AddProcessor(new ProcessorPlayerInteraction()); PlayerProcessor::AddProcessor(new ProcessorPlayerLevel()); - PlayerProcessor::AddProcessor(new ProcessorPlayerMap()); PlayerProcessor::AddProcessor(new ProcessorPlayerMiscellaneous()); PlayerProcessor::AddProcessor(new ProcessorPlayerPosition()); PlayerProcessor::AddProcessor(new ProcessorPlayerQuickKeys()); @@ -153,4 +152,5 @@ void ProcessorInitializer() ObjectProcessor::AddProcessor(new ProcessorVideoPlay()); WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); + WorldstateProcessor::AddProcessor(new ProcessorWorldMap()); } diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp deleted file mode 100644 index d3a985fb6..000000000 --- a/apps/openmw-mp/processors/player/ProcessorPlayerMap.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef OPENMW_PROCESSORPLAYERMAP_HPP -#define OPENMW_PROCESSORPLAYERMAP_HPP - -#include "../PlayerProcessor.hpp" - -namespace mwmp -{ - class ProcessorPlayerMap : public PlayerProcessor - { - public: - ProcessorPlayerMap() - { - BPP_INIT(ID_PLAYER_MAP) - } - - void Do(PlayerPacket &packet, Player &player) override - { - DEBUG_PRINTF(strPacketID.c_str()); - - Script::Call(player.getId()); - } - }; -} - -#endif //OPENMW_PROCESSORPLAYERMAP_HPP diff --git a/apps/openmw-mp/processors/worldstate/ProcessorWorldMap.hpp b/apps/openmw-mp/processors/worldstate/ProcessorWorldMap.hpp new file mode 100644 index 000000000..2bdc3120b --- /dev/null +++ b/apps/openmw-mp/processors/worldstate/ProcessorWorldMap.hpp @@ -0,0 +1,25 @@ +#ifndef OPENMW_PROCESSORWORLDMAP_HPP +#define OPENMW_PROCESSORWORLDMAP_HPP + +#include "../WorldstateProcessor.hpp" + +namespace mwmp +{ + class ProcessorWorldMap : public WorldstateProcessor + { + public: + ProcessorWorldMap() + { + BPP_INIT(ID_WORLD_MAP) + } + + void Do(WorldstatePacket &packet, Player &player, BaseWorldstate &worldstate) override + { + DEBUG_PRINTF(strPacketID.c_str()); + + Script::Call(player.getId()); + } + }; +} + +#endif //OPENMW_PROCESSORWORLDMAP_HPP diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 0fd44261a..de344409a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -119,9 +119,10 @@ add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageB ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInteraction ProcessorPlayerInventory ProcessorPlayerJail ProcessorPlayerJournal - ProcessorPlayerKillCount ProcessorPlayerLevel ProcessorPlayerMap ProcessorPlayerMiscellaneous ProcessorPlayerMomentum - ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift - ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic + ProcessorPlayerKillCount ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum + ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation ProcessorPlayerResurrect + ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic + ProcessorPlayerTopic ) add_openmw_dir (mwmp/processors/object BaseObjectProcessor ProcessorConsoleCommand ProcessorContainer @@ -132,7 +133,8 @@ add_openmw_dir (mwmp/processors/object BaseObjectProcessor ProcessorConsoleComma ProcessorScriptMemberShort ProcessorScriptMemberFloat ProcessorScriptGlobalShort ProcessorScriptGlobalFloat ) -add_openmw_dir (mwmp/processors/worldstate ProcessorRecordDynamic ProcessorWorldCollisionOverride ProcessorWorldTime +add_openmw_dir (mwmp/processors/worldstate ProcessorRecordDynamic ProcessorWorldCollisionOverride ProcessorWorldMap + ProcessorWorldTime ) # Main executable diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index cfafe2e7e..283fdfbe4 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1289,22 +1289,6 @@ void LocalPlayer::setBooks() ptrNpcStats.flagAsUsed(book.bookId); } -void LocalPlayer::setMapExplored() -{ - MWWorld::Ptr ptrPlayer = getPlayerPtr(); - MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); - - for (const auto &mapTile : mapChanges.mapTiles) - { - const MWWorld::CellStore *cellStore = MWBase::Environment::get().getWorld()->getExterior(mapTile.x, mapTile.y); - - if (!cellStore->getCell()->mName.empty()) - MWBase::Environment::get().getWindowManager()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y); - - MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData); - } -} - void LocalPlayer::setShapeshift() { MWWorld::Ptr ptrPlayer = getPlayerPtr(); @@ -1650,23 +1634,6 @@ void LocalPlayer::sendSelectedSpell(const std::string& newSelectedSpellId) getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->Send(); } -void LocalPlayer::sendMapExplored(int x, int y, const std::vector& imageData) -{ - mapChanges.mapTiles.clear(); - - mwmp::MapTile mapTile; - mapTile.x = x; - mapTile.y = y; - mapTile.imageData = imageData; - - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_MAP with x: %i, y: %i", x, y); - - mapChanges.mapTiles.push_back(mapTile); - - getNetworking()->getPlayerPacket(ID_PLAYER_MAP)->setPlayer(this); - getNetworking()->getPlayerPacket(ID_PLAYER_MAP)->Send(); -} - void LocalPlayer::clearCellStates() { cellStateChanges.cellStates.clear(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index c51645136..0231ccc4b 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -67,7 +67,6 @@ namespace mwmp void setShapeshift(); void setMarkLocation(); void setSelectedSpell(); - void setMapExplored(); void sendClass(); void sendInventory(); @@ -90,7 +89,6 @@ namespace mwmp void sendWerewolfState(bool isWerewolf); void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition); void sendSelectedSpell(const std::string& newSelectedSpellId); - void sendMapExplored(int x, int y, const std::vector& imageData); void clearCellStates(); void clearCurrentContainer(); diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index e3c487445..6177c9dac 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -1,3 +1,11 @@ +#include + +#include "../mwbase/environment.hpp" + +#include "../mwgui/windowmanagerimp.hpp" + +#include "../mwworld/worldimp.hpp" + #include "Worldstate.hpp" #include "Main.hpp" #include "Networking.hpp" @@ -22,3 +30,33 @@ Networking *Worldstate::getNetworking() { return mwmp::Main::get().getNetworking(); } + +void Worldstate::sendMapExplored(int x, int y, const std::vector& imageData) +{ + mapChanges.mapTiles.clear(); + + mwmp::MapTile mapTile; + mapTile.x = x; + mapTile.y = y; + mapTile.imageData = imageData; + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_MAP with x: %i, y: %i", x, y); + + mapChanges.mapTiles.push_back(mapTile); + + getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this); + getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->Send(); +} + +void Worldstate::setMapExplored() +{ + for (const auto &mapTile : mapChanges.mapTiles) + { + const MWWorld::CellStore *cellStore = MWBase::Environment::get().getWorld()->getExterior(mapTile.x, mapTile.y); + + if (!cellStore->getCell()->mName.empty()) + MWBase::Environment::get().getWindowManager()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y); + + MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData); + } +} diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index 97b89375d..df44372c1 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -13,6 +13,10 @@ namespace mwmp Worldstate(); virtual ~Worldstate(); + void setMapExplored(); + + void sendMapExplored(int x, int y, const std::vector& imageData); + private: Networking *getNetworking(); diff --git a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp index c437b4381..6624fed0a 100644 --- a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp +++ b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp @@ -30,7 +30,6 @@ #include "player/ProcessorPlayerJournal.hpp" #include "player/ProcessorPlayerKillCount.hpp" #include "player/ProcessorPlayerLevel.hpp" -#include "player/ProcessorPlayerMap.hpp" #include "player/ProcessorPlayerMiscellaneous.hpp" #include "player/ProcessorPlayerMomentum.hpp" #include "player/ProcessorPlayerPosition.hpp" @@ -92,6 +91,7 @@ #include "WorldstateProcessor.hpp" #include "worldstate/ProcessorRecordDynamic.hpp" #include "worldstate/ProcessorWorldCollisionOverride.hpp" +#include "worldstate/ProcessorWorldMap.hpp" #include "worldstate/ProcessorWorldTime.hpp" using namespace mwmp; @@ -127,7 +127,6 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerJournal()); PlayerProcessor::AddProcessor(new ProcessorPlayerKillCount()); PlayerProcessor::AddProcessor(new ProcessorPlayerLevel()); - PlayerProcessor::AddProcessor(new ProcessorPlayerMap()); PlayerProcessor::AddProcessor(new ProcessorPlayerMiscellaneous()); PlayerProcessor::AddProcessor(new ProcessorPlayerMomentum()); PlayerProcessor::AddProcessor(new ProcessorPlayerPosition()); @@ -186,5 +185,6 @@ void ProcessorInitializer() WorldstateProcessor::AddProcessor(new ProcessorRecordDynamic()); WorldstateProcessor::AddProcessor(new ProcessorWorldCollisionOverride()); + WorldstateProcessor::AddProcessor(new ProcessorWorldMap()); WorldstateProcessor::AddProcessor(new ProcessorWorldTime()); } diff --git a/apps/openmw/mwmp/processors/WorldstateProcessor.cpp b/apps/openmw/mwmp/processors/WorldstateProcessor.cpp index 693241ace..210815c58 100644 --- a/apps/openmw/mwmp/processors/WorldstateProcessor.cpp +++ b/apps/openmw/mwmp/processors/WorldstateProcessor.cpp @@ -8,7 +8,7 @@ using namespace mwmp; template typename BasePacketProcessor::processors_t BasePacketProcessor::processors; -bool WorldstateProcessor::Process(RakNet::Packet &packet, BaseWorldstate &worldstate) +bool WorldstateProcessor::Process(RakNet::Packet &packet, Worldstate &worldstate) { RakNet::BitStream bsIn(&packet.data[1], packet.length, false); bsIn.Read(guid); diff --git a/apps/openmw/mwmp/processors/WorldstateProcessor.hpp b/apps/openmw/mwmp/processors/WorldstateProcessor.hpp index 77a888e0d..faf523896 100644 --- a/apps/openmw/mwmp/processors/WorldstateProcessor.hpp +++ b/apps/openmw/mwmp/processors/WorldstateProcessor.hpp @@ -11,9 +11,9 @@ namespace mwmp class WorldstateProcessor : public BasePacketProcessor, public BaseClientPacketProcessor { public: - virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) = 0; + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) = 0; - static bool Process(RakNet::Packet &packet, BaseWorldstate &worldstate); + static bool Process(RakNet::Packet &packet, Worldstate &worldstate); }; } diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp deleted file mode 100644 index 803c7e10d..000000000 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerMap.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef OPENMW_PROCESSORPLAYERMAP_HPP -#define OPENMW_PROCESSORPLAYERMAP_HPP - -#include "../PlayerProcessor.hpp" - -namespace mwmp -{ - class ProcessorPlayerMap : public PlayerProcessor - { - public: - ProcessorPlayerMap() - { - BPP_INIT(ID_PLAYER_MAP) - } - - virtual void Do(PlayerPacket &packet, BasePlayer *player) - { - if (isLocal()) - { - static_cast(player)->setMapExplored(); - } - } - }; -} - -#endif //OPENMW_PROCESSORPLAYERMAP_HPP diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorRecordDynamic.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorRecordDynamic.hpp index ef7a1df11..8b05e57ab 100644 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorRecordDynamic.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorRecordDynamic.hpp @@ -13,7 +13,7 @@ namespace mwmp BPP_INIT(ID_RECORD_DYNAMIC) } - virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) { // Placeholder } diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldCollisionOverride.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldCollisionOverride.hpp index e918e7d09..aab6fc3de 100644 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldCollisionOverride.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldCollisionOverride.hpp @@ -16,7 +16,7 @@ namespace mwmp BPP_INIT(ID_WORLD_COLLISION_OVERRIDE) } - virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) { // Placeholder } diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldMap.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldMap.hpp new file mode 100644 index 000000000..388f9a17e --- /dev/null +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldMap.hpp @@ -0,0 +1,23 @@ +#ifndef OPENMW_PROCESSORWORLDMAP_HPP +#define OPENMW_PROCESSORWORLDMAP_HPP + +#include "../WorldstateProcessor.hpp" + +namespace mwmp +{ + class ProcessorWorldMap : public WorldstateProcessor + { + public: + ProcessorWorldMap() + { + BPP_INIT(ID_WORLD_MAP) + } + + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) + { + worldstate.setMapExplored(); + } + }; +} + +#endif //OPENMW_PROCESSORWORLDMAP_HPP diff --git a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp index 46ff93d11..d39a2aa81 100644 --- a/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp +++ b/apps/openmw/mwmp/processors/worldstate/ProcessorWorldTime.hpp @@ -16,7 +16,7 @@ namespace mwmp BPP_INIT(ID_WORLD_TIME) } - virtual void Do(WorldstatePacket &packet, BaseWorldstate &worldstate) + virtual void Do(WorldstatePacket &packet, Worldstate &worldstate) { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 2ce6517ba..218ef7704 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -26,7 +26,8 @@ */ #include #include "../mwmp/Main.hpp" -#include "../mwmp/LocalPlayer.hpp" +#include "../mwmp/Networking.hpp" +#include "../mwmp/Worldstate.hpp" /* End of tes3mp addition */ @@ -660,7 +661,7 @@ namespace MWRender std::string stringData = ostream.str(); std::vector vectorData = std::vector(stringData.begin(), stringData.end()); - mwmp::Main::get().getLocalPlayer()->sendMapExplored(originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY), vectorData); + mwmp::Main::get().getNetworking()->getWorldstate()->sendMapExplored(originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY), vectorData); } /* End of tes3mp addition diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index a3950edcd..9f2686025 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -184,9 +184,10 @@ add_component_dir (openmw-mp/Packets/Player PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty PacketPlayerCellChange PacketPlayerCellState PacketPlayerClass PacketPlayerDeath PacketPlayerEquipment PacketPlayerFaction PacketPlayerInteraction PacketPlayerInventory PacketPlayerJail PacketPlayerJournal - PacketPlayerKillCount PacketPlayerLevel PacketPlayerMap PacketPlayerMiscellaneous PacketPlayerMomentum - PacketPlayerPosition PacketPlayerQuickKeys PacketPlayerRegionAuthority PacketPlayerReputation PacketPlayerRest - PacketPlayerResurrect PacketPlayerShapeshift PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic PacketPlayerTopic + PacketPlayerKillCount PacketPlayerLevel PacketPlayerMiscellaneous PacketPlayerMomentum PacketPlayerPosition + PacketPlayerQuickKeys PacketPlayerRegionAuthority PacketPlayerReputation PacketPlayerRest PacketPlayerResurrect + PacketPlayerShapeshift PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic + PacketPlayerTopic ) add_component_dir (openmw-mp/Packets/Object @@ -202,7 +203,7 @@ add_component_dir (openmw-mp/Packets/Object add_component_dir (openmw-mp/Packets/Worldstate WorldstatePacket - PacketRecordDynamic PacketWorldCollisionOverride PacketWorldTime + PacketRecordDynamic PacketWorldCollisionOverride PacketWorldMap PacketWorldTime ) add_component_dir (fallback diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 30d62a73d..bc3fd578b 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -91,13 +91,6 @@ namespace mwmp int type; // 0 - Cell load, 1 - Cell unload }; - struct MapTile - { - int x; - int y; - std::vector imageData; - }; - struct JournalChanges { std::vector journalItems; @@ -137,11 +130,6 @@ namespace mwmp unsigned int count; }; - struct MapChanges - { - std::vector mapTiles; - }; - struct InventoryChanges { std::vector items; @@ -269,7 +257,6 @@ namespace mwmp TopicChanges topicChanges; KillChanges killChanges; BookChanges bookChanges; - MapChanges mapChanges; CellStateChanges cellStateChanges; ESM::ActiveSpells activeSpells; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 6e2518c0f..b4d56d867 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -1,12 +1,25 @@ #ifndef OPENMW_BASEWORLDSTATE_HPP #define OPENMW_BASEWORLDSTATE_HPP +#include + #include #include namespace mwmp { + struct MapTile + { + int x; + int y; + std::vector imageData; + }; + + struct MapChanges + { + std::vector mapTiles; + }; class BaseWorldstate { @@ -37,6 +50,8 @@ namespace mwmp bool hasPlacedObjectCollision; bool useActorCollisionForPlacedObjects; + MapChanges mapChanges; + bool isValid; }; } diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index 71962b298..a9315b700 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -28,7 +28,6 @@ #include "../Packets/Player/PacketPlayerJournal.hpp" #include "../Packets/Player/PacketPlayerKillCount.hpp" #include "../Packets/Player/PacketPlayerLevel.hpp" -#include "../Packets/Player/PacketPlayerMap.hpp" #include "../Packets/Player/PacketPlayerMiscellaneous.hpp" #include "../Packets/Player/PacketPlayerMomentum.hpp" #include "../Packets/Player/PacketPlayerPosition.hpp" @@ -87,7 +86,6 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); - AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/Controllers/WorldstatePacketController.cpp b/components/openmw-mp/Controllers/WorldstatePacketController.cpp index 991029439..7e54ceade 100644 --- a/components/openmw-mp/Controllers/WorldstatePacketController.cpp +++ b/components/openmw-mp/Controllers/WorldstatePacketController.cpp @@ -1,5 +1,6 @@ #include "../Packets/Worldstate/PacketRecordDynamic.hpp" #include "../Packets/Worldstate/PacketWorldCollisionOverride.hpp" +#include "../Packets/Worldstate/PacketWorldMap.hpp" #include "../Packets/Worldstate/PacketWorldTime.hpp" #include "WorldstatePacketController.hpp" @@ -16,6 +17,7 @@ mwmp::WorldstatePacketController::WorldstatePacketController(RakNet::RakPeerInte { AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index b66786f71..70ccef260 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -43,7 +43,6 @@ enum GameMessages ID_PLAYER_JOURNAL, ID_PLAYER_KILL_COUNT, ID_PLAYER_LEVEL, - ID_PLAYER_MAP, ID_PLAYER_MISCELLANEOUS, ID_PLAYER_MOMENTUM, ID_PLAYER_POSITION, @@ -109,6 +108,7 @@ enum GameMessages ID_RECORD_DYNAMIC, ID_WORLD_COLLISION_OVERRIDE, + ID_WORLD_MAP, ID_WORLD_TIME, }; diff --git a/components/openmw-mp/Packets/PacketPreInit.cpp b/components/openmw-mp/Packets/PacketPreInit.cpp index cc5e2c95e..5fd4433af 100644 --- a/components/openmw-mp/Packets/PacketPreInit.cpp +++ b/components/openmw-mp/Packets/PacketPreInit.cpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 05.03.17. -// - #include #include #include "PacketPreInit.hpp" diff --git a/components/openmw-mp/Packets/PacketPreInit.hpp b/components/openmw-mp/Packets/PacketPreInit.hpp index ff1281752..505992523 100644 --- a/components/openmw-mp/Packets/PacketPreInit.hpp +++ b/components/openmw-mp/Packets/PacketPreInit.hpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 05.03.17. -// - #ifndef OPENMW_PACKETPREINIT_HPP #define OPENMW_PACKETPREINIT_HPP diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.cpp index 0173dd8df..73d2361e6 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.cpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 15.01.16. -// - #include #include "PacketPlayerAnimFlags.hpp" diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.hpp b/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.hpp index 7cae56aec..536ddeaf0 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.hpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAnimFlags.hpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 15.01.16. -// - #ifndef OPENMW_PACKETPLAYERANIMFLAGS_HPP #define OPENMW_PACKETPLAYERANIMFLAGS_HPP diff --git a/components/openmw-mp/Packets/Player/PacketPlayerMap.hpp b/components/openmw-mp/Packets/Player/PacketPlayerMap.hpp deleted file mode 100644 index bc351989a..000000000 --- a/components/openmw-mp/Packets/Player/PacketPlayerMap.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OPENMW_PACKETPLAYERMAP_HPP -#define OPENMW_PACKETPLAYERMAP_HPP - -#include - -namespace mwmp -{ - class PacketPlayerMap : public PlayerPacket - { - public: - PacketPlayerMap(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, bool send); - }; -} - -#endif //OPENMW_PACKETPLAYERMAP_HPP diff --git a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldMap.cpp similarity index 57% rename from components/openmw-mp/Packets/Player/PacketPlayerMap.cpp rename to components/openmw-mp/Packets/Worldstate/PacketWorldMap.cpp index 5d65858c5..36b5c4303 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerMap.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldMap.cpp @@ -1,32 +1,32 @@ #include -#include "PacketPlayerMap.hpp" +#include "PacketWorldMap.hpp" using namespace std; using namespace mwmp; -PacketPlayerMap::PacketPlayerMap(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) +PacketWorldMap::PacketWorldMap(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer) { - packetID = ID_PLAYER_MAP; + packetID = ID_WORLD_MAP; } -void PacketPlayerMap::Packet(RakNet::BitStream *bs, bool send) +void PacketWorldMap::Packet(RakNet::BitStream *bs, bool send) { - PlayerPacket::Packet(bs, send); + WorldstatePacket::Packet(bs, send); uint32_t changesCount; if (send) - changesCount = static_cast(player->mapChanges.mapTiles.size()); + changesCount = static_cast(worldstate->mapChanges.mapTiles.size()); RW(changesCount, send); if (!send) { - player->mapChanges.mapTiles.clear(); - player->mapChanges.mapTiles.resize(changesCount); + worldstate->mapChanges.mapTiles.clear(); + worldstate->mapChanges.mapTiles.resize(changesCount); } - for (auto &&mapTile : player->mapChanges.mapTiles) + for (auto &&mapTile : worldstate->mapChanges.mapTiles) { RW(mapTile.x, send); RW(mapTile.y, send); diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldMap.hpp b/components/openmw-mp/Packets/Worldstate/PacketWorldMap.hpp new file mode 100644 index 000000000..b5496f58d --- /dev/null +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldMap.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETWORLDMAP_HPP +#define OPENMW_PACKETWORLDMAP_HPP + +#include + +namespace mwmp +{ + class PacketWorldMap : public WorldstatePacket + { + public: + PacketWorldMap(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, bool send); + }; +} + +#endif //OPENMW_PACKETWORLDMAP_HPP diff --git a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp index d19831d90..62f5ff2ee 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketWorldTime.cpp @@ -1,5 +1,5 @@ -#include "PacketWorldTime.hpp" #include +#include "PacketWorldTime.hpp" using namespace mwmp;