1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Fix flips for terrains

This commit is contained in:
nordsoft
2022-08-30 04:48:44 +04:00
parent 822e6a858b
commit ea3845e8dd
3 changed files with 12 additions and 33 deletions

View File

@ -95,7 +95,7 @@ MainWindow::~MainWindow()
void MainWindow::on_actionOpen_triggered()
{
/*auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), QString::fromStdString(VCMIDirs::get().userCachePath().native()), tr("Homm3 Files (*.vmap *.h3m)"));
auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), QString::fromStdString(VCMIDirs::get().userCachePath().native()), tr("Homm3 Files (*.vmap *.h3m)"));
if(filename.isNull())
return;
@ -103,8 +103,8 @@ void MainWindow::on_actionOpen_triggered()
QFileInfo fi(filename);
std::string fname = fi.fileName().toStdString();
std::string fdir = fi.dir().path().toStdString();
ResourceID resId("MAPS/" + fname, EResType::MAP);*/
ResourceID resId("MAPS/SomeMap.vmap", EResType::MAP);
ResourceID resId("MAPS/" + fname, EResType::MAP);
//ResourceID resId("MAPS/SomeMap.vmap", EResType::MAP);
if(!CResourceHandler::get()->existsResource(resId))
{

View File

@ -43,38 +43,15 @@ void MapHandler::initTerrainGraphics()
auto loadFlipped = [](TFlippedAnimations & animation, TFlippedCache & cache, const std::map<std::string, std::string> & files)
{
//no rotation and basic setup
for(auto & type : files)
{
animation[type.first][0] = make_unique<Animation>(type.second);
animation[type.first][0]->preload();
const size_t views = animation[type.first][0]->size(0);
animation[type.first] = make_unique<Animation>(type.second);
animation[type.first]->preload();
const size_t views = animation[type.first]->size(0);
cache[type.first].resize(views);
for(int j = 0; j < views; j++)
cache[type.first][j][0] = animation[type.first][0]->getImage(j);
}
for(int rotation = 1; rotation < 4; rotation++)
{
for(auto & type : files)
{
animation[type.first][rotation] = make_unique<Animation>(type.second);
animation[type.first][rotation]->preload();
const size_t views = animation[type.first][rotation]->size(0);
for(int j = 0; j < views; j++)
{
auto image = animation[type.first][rotation]->getImage(j);
//if(rotation == 2 || rotation == 3)
//image->horizontalFlip();
//if(rotation == 1 || rotation == 3)
//image->verticalFlip();
cache[type.first][j][rotation] = image;
}
}
cache[type.first][j] = animation[type.first]->getImage(j);
}
};
@ -98,7 +75,9 @@ void MapHandler::drawTerrainTile(int x, int y, const TerrainTile & tinfo)
if(terrainImages.at(tinfo.terType).size() <= tinfo.terView)
return;
painter.drawImage(x * tileSize, y * tileSize, *terrainImages.at(tinfo.terType)[tinfo.terView][rotation]);
bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3);
painter.drawImage(x * tileSize, y * tileSize, terrainImages.at(tinfo.terType)[tinfo.terView]->mirrored(hflip, vflip));
}
void MapHandler::initObjectRects()

View File

@ -27,8 +27,8 @@ public:
//terrain graphics
//FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013
typedef std::map<std::string, std::array<std::shared_ptr<Animation>, 4>> TFlippedAnimations; //[type, rotation]
typedef std::map<std::string, std::vector<std::array<std::shared_ptr<QImage>, 4>>> TFlippedCache;//[type, view type, rotation]
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]
typedef std::map<std::string, std::vector<std::shared_ptr<QImage>>> TFlippedCache;//[type, view type, rotation]
TFlippedAnimations terrainAnimations;//[terrain type, rotation]
TFlippedCache terrainImages;//[terrain type, view type, rotation]