Skip to content

Commit

Permalink
Merge pull request #111 from thearst3rd/animation-fix
Browse files Browse the repository at this point in the history
Make finish pad animation framerate-independant
  • Loading branch information
HumanGamer authored Dec 20, 2021
2 parents 2b99d0f + 9275608 commit 04a09e2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions engine/source/core/torqueConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
// Define me to use MBG physics
//#define MBG_PHYSICS

// Define me to use a framerate-independant finish pad animation
#define MBU_FINISH_PAD_FIX

// TEMP: Define me for a temporary fix for moving platform jitter
#define MBU_TEMP_MP_DESYNC_FIX

Expand Down
10 changes: 10 additions & 0 deletions engine/source/game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ static U32 gFrameSkip = 0;
static U32 gFrameCount = 0;
static bool gGamePaused = false;

#ifdef MBU_FINISH_PAD_FIX
// TODO: Figure out how to remove this global variable and access dt from Marble::getCameraTransform
F32 gTimeDelta = 0.0f;
#endif // MBU_FINISH_PAD_FIX

// Executes an entry script; can be controlled by command-line options.
bool runEntryScript(int argc, const char** argv)
{
Expand Down Expand Up @@ -731,6 +736,11 @@ void DemoGame::processTimeEvent(TimeEvent* event)
else
timeDelta = (U32)(elapsedTime * gTimeScale);

#ifdef MBU_FINISH_PAD_FIX
// TODO: Figure out how to remove this global variable and access dt from Marble::getCameraTransform
gTimeDelta = F32(timeDelta) / 1000.0f;
#endif // MBU_FINISH_PAD_FIX

Platform::advanceTime(elapsedTime);
bool tickPass;
if (!gGamePaused)
Expand Down
24 changes: 24 additions & 0 deletions engine/source/game/marble/marble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1541,15 +1541,27 @@ void Marble::findRenderPos(F32 dt)

Point3F offset = mLastRenderPos - around;

#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel *= 1 - 0.05f * (60.0f * dt);
#else
*pLastRenderVel *= 0.949999988079071f;
#endif // MBU_FINISH_PAD_FIX

Point3F thing2 = forceEffect * 0.2000000029802322f;

#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel += thing2 * (60.0f * dt);
#else
*pLastRenderVel += thing2;
#endif // MBU_FINISH_PAD_FIX

F32 dist = offset.len();

#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel -= offset * 0.3499999940395355f * (60.0f * dt);
#else
*pLastRenderVel -= offset * 0.3499999940395355f;
#endif // MBU_FINISH_PAD_FIX

if (dist > 1.5f)
{
Expand All @@ -1558,7 +1570,11 @@ void Marble::findRenderPos(F32 dt)
F32 outforce = mDot(outward, *pLastRenderVel);
if (outforce > 0.0f)
{
#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel -= unk * outforce * 0.75f * (60.0f * dt);
#else
*pLastRenderVel -= unk * outforce * 0.75f;
#endif // MBU_FINISH_PAD_FIX

Point3F noodles = offset * outforce * 0.5f;
noodles = *pLastRenderVel - noodles;
Expand All @@ -1572,7 +1588,11 @@ void Marble::findRenderPos(F32 dt)
m_point3F_normalize(noodles);
}

#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel += noodles * outforce * 0.25f * (60.0f * dt);
#else
*pLastRenderVel += noodles * outforce * 0.25f;
#endif // MBU_FINISH_PAD_FIX
}
}

Expand Down Expand Up @@ -1612,7 +1632,11 @@ void Marble::findRenderPos(F32 dt)
Point3F newAround = normal * 1.5f;
newAround *= mDot(*pLastRenderVel, normal);

#ifdef MBU_FINISH_PAD_FIX
*pLastRenderVel -= newAround * (60.0f * dt);
#else
*pLastRenderVel -= newAround;
#endif // MBU_FINISH_PAD_FIX

} while (i < 4);

Expand Down
8 changes: 8 additions & 0 deletions engine/source/game/marble/marblecamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,17 @@ void Marble::getCameraTransform(F32* pos, MatrixF* mat)
startCam.z = padMat[10];

position += startCam;

#ifdef MBU_FINISH_PAD_FIX
extern F32 gTimeDelta;
F32 multOffset = 0.025f * (60.0f * gTimeDelta);
position *= multOffset;
position += mEffect.lastCamFocus * (1.0f - multOffset);
#else
position *= 0.02500000037252903;

position += mEffect.lastCamFocus * 0.9750000238418579;
#endif // MBU_FINISH_PAD_FIX
}

F64 verticalOffset = mRadius + 0.25;
Expand Down

0 comments on commit 04a09e2

Please sign in to comment.