diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index 6177c9dac..8b08a810b 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -31,21 +31,43 @@ Networking *Worldstate::getNetworking() return mwmp::Main::get().getNetworking(); } -void Worldstate::sendMapExplored(int x, int y, const std::vector& imageData) +bool Worldstate::containsExploredMapTile(int cellX, int cellY) +{ + for (const auto &mapTile : exploredMapTiles) + { + if (mapTile.x == cellX && mapTile.y == cellY) + return true; + } + + return false; +} + +void Worldstate::markExploredMapTile(int cellX, int cellY) +{ + mwmp::MapTile exploredTile; + exploredTile.x = cellX; + exploredTile.y = cellY; + exploredMapTiles.push_back(exploredTile); +} + +void Worldstate::sendMapExplored(int cellX, int cellY, const std::vector& imageData) { mapChanges.mapTiles.clear(); mwmp::MapTile mapTile; - mapTile.x = x; - mapTile.y = y; + mapTile.x = cellX; + mapTile.y = cellY; mapTile.imageData = imageData; - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_MAP with x: %i, y: %i", x, y); + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Sending ID_PLAYER_MAP with x: %i, y: %i", cellX, cellY); mapChanges.mapTiles.push_back(mapTile); getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this); getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->Send(); + + // Keep this tile marked as explored so we don't send any more packets for it + markExploredMapTile(mapTile.x, mapTile.y); } void Worldstate::setMapExplored() @@ -58,5 +80,8 @@ void Worldstate::setMapExplored() MWBase::Environment::get().getWindowManager()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y); MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData); + + // Keep this tile marked as explored so we don't send any more packets for it + markExploredMapTile(mapTile.x, mapTile.y); } } diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index df44372c1..e1f7a0d0d 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -13,11 +13,18 @@ namespace mwmp Worldstate(); virtual ~Worldstate(); + bool containsExploredMapTile(int cellX, int cellY); + + void markExploredMapTile(int cellX, int cellY); + void setMapExplored(); - void sendMapExplored(int x, int y, const std::vector& imageData); + void sendMapExplored(int cellX, int cellY, const std::vector& imageData); private: + + std::vector exploredMapTiles; + Networking *getNetworking(); }; diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index 218ef7704..7f088b94e 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -636,32 +636,42 @@ namespace MWRender /* Start of tes3mp addition - Send an ID_PLAYER_MAP packet with this map tile to the server + Send an ID_PLAYER_MAP packet with this map tile to the server, but only if: + 1) We have recorded the exterior cell corresponding to this tile's coordinates + 2) The tile has not previously been marked as explored in this client's mwmp::Worldstate */ if (originToCellX.count(imageDest.mX) > 0 && originToCellY.count(imageDest.mY) > 0) { - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "New global map tile corresponds to cell %i, %i", originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY)); + int cellX = originToCellX.at(imageDest.mX); + int cellY = originToCellY.at(imageDest.mY); - osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png"); - if (!readerwriter) + mwmp::Worldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate(); + + if (!worldstate->containsExploredMapTile(cellX, cellY)) { - std::cerr << "Error: Can't write temporary map image, no '" << "png" << "' readerwriter found" << std::endl; - return; - } + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "New global map tile corresponds to cell %i, %i", originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY)); - std::ostringstream ostream; + osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png"); + if (!readerwriter) + { + std::cerr << "Error: Can't write temporary map image, no '" << "png" << "' readerwriter found" << std::endl; + return; + } - osgDB::ReaderWriter::WriteResult result = readerwriter->writeImage(*imageDest.mImage, ostream); - - if (!result.success()) - { - std::cerr << "Error: Can't write temporary map image: " << result.message() << " code " << result.status() << std::endl; - } + std::ostringstream ostream; - std::string stringData = ostream.str(); - std::vector vectorData = std::vector(stringData.begin(), stringData.end()); + osgDB::ReaderWriter::WriteResult result = readerwriter->writeImage(*imageDest.mImage, ostream); - mwmp::Main::get().getNetworking()->getWorldstate()->sendMapExplored(originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY), vectorData); + if (!result.success()) + { + std::cerr << "Error: Can't write temporary map image: " << result.message() << " code " << result.status() << std::endl; + } + + std::string stringData = ostream.str(); + std::vector vectorData = std::vector(stringData.begin(), stringData.end()); + + worldstate->sendMapExplored(cellX, cellY, vectorData); + } } /* End of tes3mp addition