mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Fix playback of shooter animations at max speed
This commit is contained in:
@@ -711,6 +711,13 @@ void RangedAttackAnimation::nextFrame()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool stackHasProjectile = owner.projectilesController->hasActiveProjectile(stack, true);
|
||||||
|
|
||||||
|
if (!projectileEmitted || stackHasProjectile)
|
||||||
|
stackAnimation(attackingStack)->playUntil(getAttackClimaxFrame());
|
||||||
|
else
|
||||||
|
stackAnimation(attackingStack)->playUntil(static_cast<size_t>(-1));
|
||||||
|
|
||||||
AttackAnimation::nextFrame();
|
AttackAnimation::nextFrame();
|
||||||
|
|
||||||
if (!projectileEmitted)
|
if (!projectileEmitted)
|
||||||
|
@@ -329,13 +329,6 @@ void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)
|
|||||||
fullFilter = ColorFilter::genCombined(fullFilter, filter.effect);
|
fullFilter = ColorFilter::genCombined(fullFilter, filter.effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool stackHasProjectile = owner.projectilesController->hasActiveProjectile(stack, true);
|
|
||||||
|
|
||||||
if (stackHasProjectile)
|
|
||||||
stackAnimation[stack->ID]->pause();
|
|
||||||
else
|
|
||||||
stackAnimation[stack->ID]->play();
|
|
||||||
|
|
||||||
stackAnimation[stack->ID]->nextFrame(canvas, fullFilter, facingRight(stack)); // do actual blit
|
stackAnimation[stack->ID]->nextFrame(canvas, fullFilter, facingRight(stack)); // do actual blit
|
||||||
stackAnimation[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
|
stackAnimation[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
|
||||||
}
|
}
|
||||||
|
@@ -183,7 +183,7 @@ void CreatureAnimation::setType(ECreatureAnimType type)
|
|||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
once = false;
|
once = false;
|
||||||
|
|
||||||
play();
|
speed = speedController(this, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureAnimation::CreatureAnimation(const std::string & name_, TSpeedController controller)
|
CreatureAnimation::CreatureAnimation(const std::string & name_, TSpeedController controller)
|
||||||
@@ -191,6 +191,7 @@ CreatureAnimation::CreatureAnimation(const std::string & name_, TSpeedController
|
|||||||
speed(0.1f),
|
speed(0.1f),
|
||||||
shadowAlpha(128),
|
shadowAlpha(128),
|
||||||
currentFrame(0),
|
currentFrame(0),
|
||||||
|
animationEnd(-1),
|
||||||
elapsedTime(0),
|
elapsedTime(0),
|
||||||
type(ECreatureAnimType::HOLDING),
|
type(ECreatureAnimType::HOLDING),
|
||||||
border(CSDL_Ext::makeColor(0, 0, 0, 0)),
|
border(CSDL_Ext::makeColor(0, 0, 0, 0)),
|
||||||
@@ -248,7 +249,7 @@ CreatureAnimation::CreatureAnimation(const std::string & name_, TSpeedController
|
|||||||
|
|
||||||
reverse->verticalFlip();
|
reverse->verticalFlip();
|
||||||
|
|
||||||
play();
|
speed = speedController(this, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureAnimation::endAnimation()
|
void CreatureAnimation::endAnimation()
|
||||||
@@ -263,6 +264,9 @@ bool CreatureAnimation::incrementFrame(float timePassed)
|
|||||||
{
|
{
|
||||||
elapsedTime += timePassed;
|
elapsedTime += timePassed;
|
||||||
currentFrame += timePassed * speed;
|
currentFrame += timePassed * speed;
|
||||||
|
if (animationEnd >= 0)
|
||||||
|
currentFrame = std::min(currentFrame, animationEnd);
|
||||||
|
|
||||||
const auto framesNumber = framesInGroup(type);
|
const auto framesNumber = framesInGroup(type);
|
||||||
|
|
||||||
if(framesNumber <= 0)
|
if(framesNumber <= 0)
|
||||||
@@ -375,6 +379,11 @@ void CreatureAnimation::nextFrame(Canvas & canvas, const ColorFilter & shifter,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreatureAnimation::playUntil(size_t frameIndex)
|
||||||
|
{
|
||||||
|
animationEnd = frameIndex;
|
||||||
|
}
|
||||||
|
|
||||||
int CreatureAnimation::framesInGroup(ECreatureAnimType group) const
|
int CreatureAnimation::framesInGroup(ECreatureAnimType group) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(forward->size(size_t(group)));
|
return static_cast<int>(forward->size(size_t(group)));
|
||||||
@@ -421,14 +430,3 @@ bool CreatureAnimation::isShooting() const
|
|||||||
|| getType() == ECreatureAnimType::SHOOT_FRONT
|
|| getType() == ECreatureAnimType::SHOOT_FRONT
|
||||||
|| getType() == ECreatureAnimType::SHOOT_DOWN;
|
|| getType() == ECreatureAnimType::SHOOT_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureAnimation::pause()
|
|
||||||
{
|
|
||||||
speed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreatureAnimation::play()
|
|
||||||
{
|
|
||||||
//logAnim->trace("Play %s group %d at %d:%d", name, static_cast<int>(getType()), pos.x, pos.y);
|
|
||||||
speed = speedController(this, type);
|
|
||||||
}
|
|
||||||
|
@@ -88,6 +88,7 @@ private:
|
|||||||
/// currently displayed frame. Float to allow H3-style animations where frames
|
/// currently displayed frame. Float to allow H3-style animations where frames
|
||||||
/// don't display for integer number of frames
|
/// don't display for integer number of frames
|
||||||
float currentFrame;
|
float currentFrame;
|
||||||
|
float animationEnd;
|
||||||
|
|
||||||
/// cumulative, real-time duration of animation. Used for effects like selection border
|
/// cumulative, real-time duration of animation. Used for effects like selection border
|
||||||
float elapsedTime;
|
float elapsedTime;
|
||||||
@@ -146,8 +147,7 @@ public:
|
|||||||
/// returns number of frames in selected animation type
|
/// returns number of frames in selected animation type
|
||||||
int framesInGroup(ECreatureAnimType group) const;
|
int framesInGroup(ECreatureAnimType group) const;
|
||||||
|
|
||||||
void pause();
|
void playUntil(size_t frameIndex);
|
||||||
void play();
|
|
||||||
|
|
||||||
/// helpers to classify current type of animation
|
/// helpers to classify current type of animation
|
||||||
bool isDead() const;
|
bool isDead() const;
|
||||||
|
Reference in New Issue
Block a user