Browse Source

Simplify GetFrameToUseForRendering (remove local variables and use member variables)

pull/1753/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
26601c98dc
  1. 19
      Source/engine/animationinfo.cpp
  2. 2
      Source/engine/animationinfo.h

19
Source/engine/animationinfo.cpp

@ -11,35 +11,32 @@
namespace devilution {
int AnimationInfo::GetFrameToUseForRendering()
int AnimationInfo::GetFrameToUseForRendering() const
{
// Normal logic is used,
// - if no frame-skipping is required and so we have exactly one Animationframe per GameTick
// or
// - if we load from a savegame where the new variables are not stored (we don't want to break savegame compatiblity because of smoother rendering of one animation)
int relevantAnimationFramesForDistributing = RelevantFramesForDistributing;
if (relevantAnimationFramesForDistributing <= 0)
if (RelevantFramesForDistributing <= 0)
return CurrentFrame;
if (CurrentFrame > relevantAnimationFramesForDistributing)
if (CurrentFrame > RelevantFramesForDistributing)
return CurrentFrame;
assert(GameTicksSinceSequenceStarted >= 0);
float progressToNextGameTick = gfProgressToNextGameTick;
// we don't use the processed game ticks alone but also the fragtion of the next game tick (if a rendering happens between game ticks). This helps to smooth the animations.
float totalGameTicksForCurrentAnimationSequence = progressToNextGameTick + (float)GameTicksSinceSequenceStarted;
float totalGameTicksForCurrentAnimationSequence = gfProgressToNextGameTick + (float)GameTicksSinceSequenceStarted;
// 1 added for rounding reasons. float to int cast always truncate.
int absoluteAnimationFrame = 1 + (int)(totalGameTicksForCurrentAnimationSequence * GameTickModifier);
if (absoluteAnimationFrame > relevantAnimationFramesForDistributing) {
if (absoluteAnimationFrame > RelevantFramesForDistributing) {
// this can happen if we are at the last frame and the next game tick is due (nthread_GetProgressToNextGameTick returns 1.0f)
if (absoluteAnimationFrame > (relevantAnimationFramesForDistributing + 1)) {
if (absoluteAnimationFrame > (RelevantFramesForDistributing + 1)) {
// we should never have +2 frames even if next game tick is due
Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {} MaxFrame {})", absoluteAnimationFrame, relevantAnimationFramesForDistributing);
Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {} MaxFrame {})", absoluteAnimationFrame, RelevantFramesForDistributing);
}
return relevantAnimationFramesForDistributing;
return RelevantFramesForDistributing;
}
if (absoluteAnimationFrame <= 0) {
Log("GetFrameToUseForRendering: Calculated an invalid Animation Frame (Calculated {})", absoluteAnimationFrame);

2
Source/engine/animationinfo.h

@ -54,7 +54,7 @@ public:
* @brief Calculates the Frame to use for the Animation rendering
* @return The Frame to use for rendering
*/
int GetFrameToUseForRendering();
int GetFrameToUseForRendering() const;
/**
* @brief Sets the new Animation with all relevant information for rendering

Loading…
Cancel
Save