1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +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));
}