From 3acee297be46d0b936c20d056dc9fdd55888fd22 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 27 Jan 2023 12:22:48 +0200 Subject: [PATCH] CShowableAnim is now time-based with timing matching H3 --- client/widgets/AdventureMapClasses.cpp | 8 ++++---- client/widgets/Images.cpp | 20 +++++++++++--------- client/widgets/Images.h | 8 ++++---- client/windows/CCastleInterface.cpp | 2 +- client/windows/CCastleInterface.h | 4 +++- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index e507e99ff..53f121e60 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -690,7 +690,7 @@ CInfoBar::VisibleDateInfo::VisibleDateInfo() { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); - animation = std::make_shared(1, 0, getNewDayName(), CShowableAnim::PLAY_ONCE); + animation = std::make_shared(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("ADSTATNX"); banner = std::make_shared("CREST58", player.getNum(), 0, 20, 51); - sand = std::make_shared(99, 51, "HOURSAND"); - glass = std::make_shared(99, 51, "HOURGLAS", CShowableAnim::PLAY_ONCE, 40); + sand = std::make_shared(99, 51, "HOURSAND", 0, 100); // H3 uses around 100 ms per frame + glass = std::make_shared(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(); - setTimer(3000); + setTimer(3000); // confirmed to match H3 redraw(); } diff --git a/client/widgets/Images.cpp b/client/widgets/Images.cpp index 88bced4b5..37e8e41d7 100644 --- a/client/widgets/Images.cpp +++ b/client/widgets/Images.cpp @@ -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(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; diff --git a/client/widgets/Images.h b/client/widgets/Images.h index 2b4b1bd24..166ba45d9 100644 --- a/client/widgets/Images.h +++ b/client/widgets/Images.h @@ -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 diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 1dafce97f..dc8403735 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -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), diff --git a/client/windows/CCastleInterface.h b/client/windows/CCastleInterface.h index 6b9f7f7e8..6f87599d6 100644 --- a/client/windows/CCastleInterface.h +++ b/client/windows/CCastleInterface.h @@ -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