1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 20:23:54 +00:00

Merge pull request #2716 from akortunov/png

Store fog of war as a PNG image instead of TGA
This commit is contained in:
Bret Curtis 2020-05-12 11:52:23 +02:00 committed by GitHub
commit 42cba092b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 6 deletions

View file

@ -170,6 +170,7 @@
Bug #5103: Sneaking state behavior is still inconsistent Bug #5103: Sneaking state behavior is still inconsistent
Bug #5104: Black Dart's enchantment doesn't trigger at low Enchant levels Bug #5104: Black Dart's enchantment doesn't trigger at low Enchant levels
Bug #5106: Still can jump even when encumbered Bug #5106: Still can jump even when encumbered
Bug #5108: Savegame bloating due to inefficient fog textures format
Bug #5110: ModRegion with a redundant numerical argument breaks script execution Bug #5110: ModRegion with a redundant numerical argument breaks script execution
Bug #5112: Insufficient magicka for current spell not reflected on HUD icon Bug #5112: Insufficient magicka for current spell not reflected on HUD icon
Bug #5113: Unknown alchemy question mark not centered Bug #5113: Unknown alchemy question mark not centered

View file

@ -209,6 +209,7 @@ namespace MWGui
MyGUI::IntCoord(mx*mMapWidgetSize, my*mMapWidgetSize, mMapWidgetSize, mMapWidgetSize), MyGUI::IntCoord(mx*mMapWidgetSize, my*mMapWidgetSize, mMapWidgetSize, mMapWidgetSize),
MyGUI::Align::Top | MyGUI::Align::Left); MyGUI::Align::Top | MyGUI::Align::Left);
fog->setDepth(Local_FogLayer); fog->setDepth(Local_FogLayer);
fog->setColour(MyGUI::Colour(0, 0, 0));
map->setNeedMouseFocus(false); map->setNeedMouseFocus(false);
fog->setNeedMouseFocus(false); fog->setNeedMouseFocus(false);

View file

@ -693,12 +693,10 @@ void LocalMap::MapSegment::loadFogOfWar(const ESM::FogTexture &esm)
return; return;
} }
// TODO: deprecate tga and use raw data instead osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("tga");
if (!readerwriter) if (!readerwriter)
{ {
Log(Debug::Error) << "Error: Unable to load fog, can't find a tga ReaderWriter" ; Log(Debug::Error) << "Error: Unable to load fog, can't find a png ReaderWriter" ;
return; return;
} }
@ -727,10 +725,10 @@ void LocalMap::MapSegment::saveFogOfWar(ESM::FogTexture &fog) const
std::ostringstream ostream; std::ostringstream ostream;
osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("tga"); osgDB::ReaderWriter* readerwriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
if (!readerwriter) if (!readerwriter)
{ {
Log(Debug::Error) << "Error: Unable to write fog, can't find a tga ReaderWriter"; Log(Debug::Error) << "Error: Unable to write fog, can't find a png ReaderWriter";
return; return;
} }

View file

@ -3,10 +3,60 @@
#include "esmreader.hpp" #include "esmreader.hpp"
#include "esmwriter.hpp" #include "esmwriter.hpp"
#include <osgDB/ReadFile>
#include <components/debug/debuglog.hpp>
#include <components/files/memorystream.hpp>
#include "savedgame.hpp"
void convertFogOfWar(std::vector<char>& imageData)
{
if (imageData.empty())
{
return;
}
osgDB::ReaderWriter* tgaReader = osgDB::Registry::instance()->getReaderWriterForExtension("tga");
if (!tgaReader)
{
Log(Debug::Error) << "Error: Unable to load fog, can't find a tga ReaderWriter";
return;
}
Files::IMemStream in(&imageData[0], imageData.size());
osgDB::ReaderWriter::ReadResult result = tgaReader->readImage(in);
if (!result.success())
{
Log(Debug::Error) << "Error: Failed to read fog: " << result.message() << " code " << result.status();
return;
}
osgDB::ReaderWriter* pngWriter = osgDB::Registry::instance()->getReaderWriterForExtension("png");
if (!pngWriter)
{
Log(Debug::Error) << "Error: Unable to write fog, can't find a png ReaderWriter";
return;
}
std::ostringstream ostream;
osgDB::ReaderWriter::WriteResult png = pngWriter->writeImage(*result.getImage(), ostream);
if (!png.success())
{
Log(Debug::Error) << "Error: Unable to write fog: " << png.message() << " code " << png.status();
return;
}
std::string str = ostream.str();
imageData = std::vector<char>(str.begin(), str.end());
}
void ESM::FogState::load (ESMReader &esm) void ESM::FogState::load (ESMReader &esm)
{ {
esm.getHNOT(mBounds, "BOUN"); esm.getHNOT(mBounds, "BOUN");
esm.getHNOT(mNorthMarkerAngle, "ANGL"); esm.getHNOT(mNorthMarkerAngle, "ANGL");
int dataFormat = esm.getFormat();
while (esm.isNextSub("FTEX")) while (esm.isNextSub("FTEX"))
{ {
esm.getSubHeader(); esm.getSubHeader();
@ -18,6 +68,10 @@ void ESM::FogState::load (ESMReader &esm)
size_t imageSize = esm.getSubSize()-sizeof(int)*2; size_t imageSize = esm.getSubSize()-sizeof(int)*2;
tex.mImageData.resize(imageSize); tex.mImageData.resize(imageSize);
esm.getExact(&tex.mImageData[0], imageSize); esm.getExact(&tex.mImageData[0], imageSize);
if (dataFormat < 6)
convertFogOfWar(tex.mImageData);
mFogTextures.push_back(tex); mFogTextures.push_back(tex);
} }
} }