1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-08 00:39:47 +02:00

animations working

This commit is contained in:
Laserlicht 2024-11-30 15:44:09 +01:00
parent 3967c70bf2
commit 6795c9afb6
5 changed files with 24 additions and 15 deletions

View File

@ -121,15 +121,25 @@ void MapTileStorage::load(size_t index, const AnimationPath & filename, EImageBl
terrainAnimations[3]->horizontalFlip();
}
std::shared_ptr<IImage> MapTileStorage::find(size_t fileIndex, size_t rotationIndex, size_t imageIndex)
std::shared_ptr<IImage> MapTileStorage::find(size_t fileIndex, size_t rotationIndex, size_t imageIndex, size_t groupIndex)
{
const auto & animation = animations[fileIndex][rotationIndex];
if (animation)
return animation->getImage(imageIndex); // ask for group
return animation->getImage(imageIndex, groupIndex); // ask for group
else
return nullptr;
}
int MapTileStorage::groupCount(size_t fileIndex, size_t rotationIndex, size_t imageIndex)
{
const auto & animation = animations[fileIndex][rotationIndex];
if (animation)
for(int i = 0; true; i++)
if(!animation->getImage(imageIndex, i, false))
return i;
return 1;
}
MapRendererTerrain::MapRendererTerrain()
: storage(VLC->terrainTypeHandler->objects.size())
{
@ -147,7 +157,8 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ
int32_t imageIndex = mapTile.terView;
int32_t rotationIndex = mapTile.extTileFlags % 4;
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
int groupCount = storage.groupCount(terrainIndex, rotationIndex, imageIndex);
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex, groupCount > 1 ? context.terrainImageIndex(groupCount) : 0);
assert(image);
if (!image)
@ -156,9 +167,6 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ
return;
}
for( auto const & element : mapTile.getTerrain()->paletteAnimation)
image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
target.draw(image, Point(0, 0));
}
@ -191,10 +199,8 @@ void MapRendererRiver::renderTile(IMapRendererContext & context, Canvas & target
int32_t imageIndex = mapTile.riverDir;
int32_t rotationIndex = (mapTile.extTileFlags >> 2) % 4;
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
for( auto const & element : mapTile.getRiver()->paletteAnimation)
image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
int groupCount = storage.groupCount(terrainIndex, rotationIndex, imageIndex);
const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex, groupCount > 1 ? context.terrainImageIndex(groupCount) : 0);
target.draw(image, Point(0, 0));
}

View File

@ -33,7 +33,8 @@ class MapTileStorage
public:
explicit MapTileStorage(size_t capacity);
void load(size_t index, const AnimationPath & filename, EImageBlitMode blitMode);
std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex);
std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex, size_t groupIndex = 0);
int groupCount(size_t fileIndex, size_t rotationIndex, size_t imageIndex);
};
class MapRendererTerrain

View File

@ -409,6 +409,7 @@ void AssetGenerator::createPaletteShiftedSprites()
img->shiftPalette(tmp.start, tmp.length, l % tmp.length);
}
}
Canvas canvas = Canvas(Point(32, 32), CanvasScalingPolicy::IGNORE);
canvas.draw(img, Point((32 - img->dimensions().x) / 2, (32 - img->dimensions().y) / 2));
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());

View File

@ -18,10 +18,11 @@
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/json/JsonUtils.h"
bool CAnimation::loadFrame(size_t frame, size_t group)
bool CAnimation::loadFrame(size_t frame, size_t group, bool verbose)
{
if(size(group) <= frame)
{
if(verbose)
printError(frame, group, "LoadFrame");
return false;
}
@ -119,7 +120,7 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
std::shared_ptr<IImage> CAnimation::getImage(size_t frame, size_t group, bool verbose)
{
if (!loadFrame(frame, group))
if (!loadFrame(frame, group, verbose))
return nullptr;
return getImageImpl(frame, group, verbose);
}

View File

@ -41,7 +41,7 @@ private:
PlayerColor player = PlayerColor::CANNOT_DETERMINE;
//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
bool loadFrame(size_t frame, size_t group);
bool loadFrame(size_t frame, size_t group, bool verbose = true);
//unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
bool unloadFrame(size_t frame, size_t group);