forked from mirror/openmw-tes3mp
[Client] Don't send WorldMap packets for already explored map tiles
This commit is contained in:
parent
d53bd05424
commit
deda6ec071
3 changed files with 67 additions and 25 deletions
|
@ -31,21 +31,43 @@ Networking *Worldstate::getNetworking()
|
|||
return mwmp::Main::get().getNetworking();
|
||||
}
|
||||
|
||||
void Worldstate::sendMapExplored(int x, int y, const std::vector<char>& 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<char>& 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<char>& imageData);
|
||||
void sendMapExplored(int cellX, int cellY, const std::vector<char>& imageData);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<MapTile> exploredMapTiles;
|
||||
|
||||
Networking *getNetworking();
|
||||
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::ostringstream ostream;
|
||||
|
||||
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::string stringData = ostream.str();
|
||||
std::vector<char> vectorData = std::vector<char>(stringData.begin(), stringData.end());
|
||||
|
||||
worldstate->sendMapExplored(cellX, cellY, vectorData);
|
||||
}
|
||||
|
||||
std::ostringstream ostream;
|
||||
|
||||
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::string stringData = ostream.str();
|
||||
std::vector<char> vectorData = std::vector<char>(stringData.begin(), stringData.end());
|
||||
|
||||
mwmp::Main::get().getNetworking()->getWorldstate()->sendMapExplored(originToCellX.at(imageDest.mX), originToCellY.at(imageDest.mY), vectorData);
|
||||
}
|
||||
/*
|
||||
End of tes3mp addition
|
||||
|
|
Loading…
Reference in a new issue