mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
[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();
|
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();
|
mapChanges.mapTiles.clear();
|
||||||
|
|
||||||
mwmp::MapTile mapTile;
|
mwmp::MapTile mapTile;
|
||||||
mapTile.x = x;
|
mapTile.x = cellX;
|
||||||
mapTile.y = y;
|
mapTile.y = cellY;
|
||||||
mapTile.imageData = imageData;
|
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);
|
mapChanges.mapTiles.push_back(mapTile);
|
||||||
|
|
||||||
getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this);
|
getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->setWorldstate(this);
|
||||||
getNetworking()->getWorldstatePacket(ID_WORLD_MAP)->Send();
|
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()
|
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()->addVisitedLocation(cellStore->getCell()->mName, mapTile.x, mapTile.y);
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->setGlobalMapImage(mapTile.x, mapTile.y, mapTile.imageData);
|
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();
|
Worldstate();
|
||||||
virtual ~Worldstate();
|
virtual ~Worldstate();
|
||||||
|
|
||||||
|
bool containsExploredMapTile(int cellX, int cellY);
|
||||||
|
|
||||||
|
void markExploredMapTile(int cellX, int cellY);
|
||||||
|
|
||||||
void setMapExplored();
|
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:
|
private:
|
||||||
|
|
||||||
|
std::vector<MapTile> exploredMapTiles;
|
||||||
|
|
||||||
Networking *getNetworking();
|
Networking *getNetworking();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -636,11 +636,20 @@ namespace MWRender
|
||||||
/*
|
/*
|
||||||
Start of tes3mp addition
|
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)
|
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);
|
||||||
|
|
||||||
|
mwmp::Worldstate *worldstate = mwmp::Main::get().getNetworking()->getWorldstate();
|
||||||
|
|
||||||
|
if (!worldstate->containsExploredMapTile(cellX, cellY))
|
||||||
|
{
|
||||||
|
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");
|
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
|
||||||
if (!readerwriter)
|
if (!readerwriter)
|
||||||
|
@ -661,7 +670,8 @@ namespace MWRender
|
||||||
std::string stringData = ostream.str();
|
std::string stringData = ostream.str();
|
||||||
std::vector<char> vectorData = std::vector<char>(stringData.begin(), stringData.end());
|
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);
|
worldstate->sendMapExplored(cellX, cellY, vectorData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
|
|
Loading…
Reference in a new issue