mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 20:15:32 +00:00
Merge pull request #452 from TES3MP/0.6.3 while resolving conflicts
Conflicts: apps/openmw-mp/Script/Functions/Worldstate.cpp apps/openmw/mwmp/Worldstate.cpp components/openmw-mp/Base/BaseWorldstate.hpp
This commit is contained in:
commit
d5b3d08ec9
7 changed files with 94 additions and 31 deletions
|
@ -173,8 +173,17 @@ void MapTiles::processUpdate()
|
|||
|
||||
void MapTiles::addMapTile(const MapTile &mapTile)
|
||||
{
|
||||
mwmp::Networking::get().get().getServerWorldstate()->mapChanges.mapTiles.push_back(mapTile.mapTile);
|
||||
setChanged();
|
||||
if (mapTile.mapTile.imageData.size() > mwmp::maxImageDataSize)
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Error loading image file for map tile: "
|
||||
"%i, %i has a size of %i, which is over the maximum allowed of %i!",
|
||||
mapTile.mapTile.x, mapTile.mapTile.y, mapTile.mapTile.imageData.size(), mwmp::maxImageDataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
mwmp::Networking::get().get().getServerWorldstate()->mapChanges.mapTiles.push_back(mapTile.mapTile);
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
MapTile MapTiles::getMapTile(int id) const
|
||||
|
|
|
@ -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::BaseMapTile 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::BaseMapTile 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<BaseMapTile> 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
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
namespace mwmp
|
||||
{
|
||||
static const int maxImageDataSize = 1800;
|
||||
|
||||
struct BaseMapTile
|
||||
{
|
||||
int x;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "PacketWorldMap.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
@ -31,17 +32,25 @@ void PacketWorldMap::Packet(RakNet::BitStream *bs, bool send)
|
|||
RW(mapTile.x, send);
|
||||
RW(mapTile.y, send);
|
||||
|
||||
uint32_t imageDataCount;
|
||||
uint32_t imageDataSize;
|
||||
|
||||
if (send)
|
||||
imageDataCount = static_cast<uint32_t>(mapTile.imageData.size());
|
||||
imageDataSize = static_cast<uint32_t>(mapTile.imageData.size());
|
||||
|
||||
RW(imageDataCount, send);
|
||||
RW(imageDataSize, send);
|
||||
|
||||
if (imageDataSize > mwmp::maxImageDataSize)
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Processed invalid ID_WORLD_MAP packet where tile %i, %i had an imageDataSize of %i",
|
||||
mapTile.x, mapTile.y, imageDataSize);
|
||||
LOG_APPEND(Log::LOG_ERROR, "- The packet was ignored after that point");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!send)
|
||||
{
|
||||
mapTile.imageData.clear();
|
||||
mapTile.imageData.resize(imageDataCount);
|
||||
mapTile.imageData.resize(imageDataSize);
|
||||
}
|
||||
|
||||
for (auto &&imageChar : mapTile.imageData)
|
||||
|
|
|
@ -49,6 +49,7 @@ Special thanks (in alphabetical order)
|
|||
Camul
|
||||
David Wery
|
||||
DestinedToDie
|
||||
Donovan Ando
|
||||
Gluka
|
||||
Goodevil
|
||||
greetasdf
|
||||
|
|
Loading…
Reference in a new issue