1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CShowableAnim is now time-based with timing matching H3

This commit is contained in:
Ivan Savenko 2023-01-27 12:22:48 +02:00
parent a9fefffc65
commit 3acee297be
5 changed files with 23 additions and 19 deletions

View File

@ -690,7 +690,7 @@ CInfoBar::VisibleDateInfo::VisibleDateInfo()
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
animation = std::make_shared<CShowableAnim>(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE);
animation = std::make_shared<CShowableAnim>(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE, 180);// H3 uses around 175-180 ms per frame
std::string labelText;
if(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK) == 1 && LOCPLINT->cb->getDate(Date::DAY) != 1) // monday of any week but first - show new week info
@ -731,8 +731,8 @@ CInfoBar::VisibleEnemyTurnInfo::VisibleEnemyTurnInfo(PlayerColor player)
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
background = std::make_shared<CPicture>("ADSTATNX");
banner = std::make_shared<CAnimImage>("CREST58", player.getNum(), 0, 20, 51);
sand = std::make_shared<CShowableAnim>(99, 51, "HOURSAND");
glass = std::make_shared<CShowableAnim>(99, 51, "HOURGLAS", CShowableAnim::PLAY_ONCE, 40);
sand = std::make_shared<CShowableAnim>(99, 51, "HOURSAND", 0, 100); // H3 uses around 100 ms per frame
glass = std::make_shared<CShowableAnim>(99, 51, "HOURGLAS", CShowableAnim::PLAY_ONCE, 1000); // H3 scales this nicely for AI turn duration, don't have anything like that in vcmi
}
CInfoBar::VisibleGameStatusInfo::VisibleGameStatusInfo()
@ -890,7 +890,7 @@ void CInfoBar::showDate()
playNewDaySound();
state = DATE;
visibleInfo = std::make_shared<VisibleDateInfo>();
setTimer(3000);
setTimer(3000); // confirmed to match H3
redraw();
}

View File

@ -333,13 +333,13 @@ void CAnimImage::playerColored(PlayerColor currPlayer)
anim->getImage(0, group)->playerColored(player);
}
CShowableAnim::CShowableAnim(int x, int y, std::string name, ui8 Flags, ui32 Delay, size_t Group, uint8_t alpha):
CShowableAnim::CShowableAnim(int x, int y, std::string name, ui8 Flags, ui32 frameTime, size_t Group, uint8_t alpha):
anim(std::make_shared<CAnimation>(name)),
group(Group),
frame(0),
first(0),
frameDelay(Delay),
value(0),
frameTimeTotal(frameTime),
frameTimePassed(0),
flags(Flags),
xOffset(0),
yOffset(0),
@ -380,7 +380,7 @@ bool CShowableAnim::set(size_t Group, size_t from, size_t to)
group = Group;
frame = first = from;
last = max;
value = 0;
frameTimePassed = 0;
return true;
}
@ -397,13 +397,13 @@ bool CShowableAnim::set(size_t Group)
group = Group;
last = anim->size(Group);
}
frame = value = 0;
frame = 0;
frameTimePassed = 0;
return true;
}
void CShowableAnim::reset()
{
value = 0;
frame = first;
if (callback)
@ -427,9 +427,11 @@ void CShowableAnim::show(SDL_Surface * to)
if ((flags & PLAY_ONCE) && frame + 1 == last)
return;
if ( ++value == frameDelay )
frameTimePassed += GH.mainFPSmng->getElapsedMilliseconds();
if(frameTimePassed >= frameTimeTotal)
{
value = 0;
frameTimePassed -= frameTimeTotal;
if ( ++frame >= last)
reset();
}
@ -466,7 +468,7 @@ void CShowableAnim::rotate(bool on, bool vertical)
}
CCreatureAnim::CCreatureAnim(int x, int y, std::string name, ui8 flags, ECreatureAnimType type):
CShowableAnim(x,y,name,flags,4,size_t(type))
CShowableAnim(x, y, name, flags, 100, size_t(type)) // H3 uses 100 ms per frame, irregardless of battle speed settings
{
xOffset = 0;
yOffset = 0;

View File

@ -125,9 +125,9 @@ protected:
size_t first, last; //animation range
//TODO: replace with time delay(needed for battles)
ui32 frameDelay;//delay in frames of each image
ui32 value;//how many times current frame was showed
/// how long (in milliseconds) should
ui32 frameTimeTotal;
ui32 frameTimePassed;
ui8 flags;//Flags from EFlags enum
@ -146,7 +146,7 @@ public:
//Set per-surface alpha, 0 = transparent, 255 = opaque
void setAlpha(ui32 alphaValue);
CShowableAnim(int x, int y, std::string name, ui8 flags=0, ui32 Delay=4, size_t Group=0, uint8_t alpha = UINT8_MAX);
CShowableAnim(int x, int y, std::string name, ui8 flags, ui32 frameTime, size_t Group=0, uint8_t alpha = UINT8_MAX);
~CShowableAnim();
//set animation to group or part of group

View File

@ -43,7 +43,7 @@
#include "../../lib/mapObjects/CGTownInstance.h"
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE),
: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
parent(Par),
town(Town),
str(Str),

View File

@ -47,7 +47,9 @@ public:
BUILDING_APPEAR_TIMEPOINT = 500, //500 msec building appears: 0->100% transparency
BUILDING_WHITE_BORDER_TIMEPOINT = 1000, //500 msec border glows from white to yellow
BUILDING_YELLOW_BORDER_TIMEPOINT = 1500, //500 msec border glows from yellow to normal
BUILD_ANIMATION_FINISHED_TIMEPOINT = 2500 //1000 msec delay, nothing happens
BUILD_ANIMATION_FINISHED_TIMEPOINT = 2500, //1000 msec delay, nothing happens
BUILDING_FRAME_TIME = 150 // confirmed H3 timing: 150 ms for each building animation frame
};
/// returns building associated with this structure