Skip to content

Commit

Permalink
Change heroes animation speed (before and after casting a spell) on t…
Browse files Browse the repository at this point in the history
…he battlefield, fix lack of the first (and sometimes only) animation frame. (#7420)
  • Loading branch information
Districh-ru authored Jul 22, 2023
1 parent d17aeda commit 0bbb429
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/fheroes2/battle/battle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,33 +3312,38 @@ void Battle::Interface::AnimateUnitWithDelay( Unit & unit, const bool skipLastFr
}
}

void Battle::Interface::AnimateOpponents( OpponentSprite * target )
void Battle::Interface::AnimateOpponents( OpponentSprite * hero )
{
if ( target == nullptr || target->isFinishFrame() ) // nothing to animate
if ( hero == nullptr ) {
return;
}

// Render the first animation frame. We do it here not to skip small animations with duration for 1 frame.
// For such (one frame) animations we are already ad the end of animation and `isFinishFrame()` always will return true.
Redraw();

LocalEvent & le = LocalEvent::Get();

// We need to wait this delay before rendering the first frame of hero animation.
Game::AnimateResetDelay( Game::DelayType::BATTLE_OPPONENTS_DELAY );

// 'BATTLE_OPPONENTS_DELAY' is more than 2 times the value of 'BATTLE_IDLE_DELAY', so we need to handle the idle animation separately in this loop.
// 'BATTLE_OPPONENTS_DELAY' is different than 'BATTLE_IDLE_DELAY', so we handle the idle animation separately in this loop.
while ( le.HandleEvents( Game::isDelayNeeded( { Game::BATTLE_OPPONENTS_DELAY, Game::BATTLE_IDLE_DELAY } ) ) ) {
// Animate the idling units.
if ( IdleTroopsAnimation() ) {
Redraw();
}

if ( Game::validateAnimationDelay( Game::BATTLE_OPPONENTS_DELAY ) ) {
// Render before switching to the next frame.
Redraw();

if ( target->isFinishFrame() ) {
if ( hero->isFinishFrame() ) {
// We have reached the end of animation.
break;
}

target->IncreaseAnimFrame();
hero->IncreaseAnimFrame();

// Render the next frame and then wait a delay before checking if it is the last frame in the animation.
Redraw();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/battle/battle_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ namespace Battle
// Use this if a function may be called from other functions with different render delay types.
void WaitForAllActionDelays();

void AnimateOpponents( OpponentSprite * target );
void AnimateOpponents( OpponentSprite * hero );
void AnimateUnitWithDelay( Unit & unit, const bool skipLastFrameRender = false );
void RedrawTroopDefaultDelay( Unit & unit );
void RedrawTroopWithFrameAnimation( Unit & unit, const int icn, const int m82, const CreatureSpellAnimation animation );
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/game/game_delays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void Game::AnimateDelaysInitialize()
delays[BATTLE_CATAPULT_CLOUD_DELAY].setDelay( 40 );
delays[BATTLE_BRIDGE_DELAY].setDelay( 90 );
delays[BATTLE_IDLE_DELAY].setDelay( 150 );
delays[BATTLE_OPPONENTS_DELAY].setDelay( 350 );
delays[BATTLE_OPPONENTS_DELAY].setDelay( 75 );
delays[BATTLE_FLAGS_DELAY].setDelay( 250 );
delays[BATTLE_POPUP_DELAY].setDelay( 800 );
delays[BATTLE_COLOR_CYCLE_DELAY].setDelay( 220 );
Expand Down Expand Up @@ -200,7 +200,7 @@ void Game::UpdateGameSpeed()
delays[BATTLE_CATAPULT_CLOUD_DELAY].setDelay( static_cast<uint64_t>( 40 * adjustedBattleSpeed ) );
delays[BATTLE_BRIDGE_DELAY].setDelay( static_cast<uint64_t>( 90 * adjustedBattleSpeed ) );
delays[BATTLE_IDLE_DELAY].setDelay( static_cast<uint64_t>( 150 * adjustedIdleAnimationSpeed ) );
delays[BATTLE_OPPONENTS_DELAY].setDelay( static_cast<uint64_t>( 350 * adjustedBattleSpeed ) );
delays[BATTLE_OPPONENTS_DELAY].setDelay( static_cast<uint64_t>( 75 * adjustedIdleAnimationSpeed ) );
delays[BATTLE_FLAGS_DELAY].setDelay( static_cast<uint64_t>( 250 * adjustedIdleAnimationSpeed ) );
}

Expand Down

0 comments on commit 0bbb429

Please sign in to comment.