Skip to content

Commit

Permalink
tr2/inventory: fix fast spinout animation
Browse files Browse the repository at this point in the history
Resolves #1704.

This was especially evident with FMVs that don't depend on the clock -
m_LastCounter held old time data, making the game try to make up for the
perceived large difference, and skip ahead by many frames at once.
  • Loading branch information
rr- committed Nov 5, 2024
1 parent 6c36549 commit 5699694
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- fixed harpoon bolts damaging inactive enemies (#1804)
- fixed enemies that are run over by the skidoo not being counted in the statistics (#1772)
- fixed sound settings resuming the music (#1707)
- fixed the inventory ring spinout animation sometimes running too fast (#1704)

## [0.5](https://github.com/LostArtefacts/TRX/compare/afaf12a...tr2-0.5) - 2024-10-08
- added `/sfx` command
Expand Down
9 changes: 7 additions & 2 deletions src/libtrx/game/clock/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ double Clock_GetHighPrecisionCounter(void)
/ (double)m_Frequency;
}

int32_t Clock_SyncTicks(void)
void Clock_SyncTick(void)
{
m_LastCounter = SDL_GetPerformanceCounter();
}

int32_t Clock_WaitTick(void)
{
const Uint64 counter = SDL_GetPerformanceCounter();

Expand All @@ -73,7 +78,7 @@ int32_t Clock_SyncTicks(void)
elapsed_frames = 1;
}

m_LastCounter = SDL_GetPerformanceCounter();
Clock_SyncTick();

return elapsed_frames;
}
3 changes: 2 additions & 1 deletion src/libtrx/include/libtrx/game/clock/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

void Clock_Init(void);

int32_t Clock_SyncTicks(void);
void Clock_SyncTick(void);
int32_t Clock_WaitTick(void);

size_t Clock_GetDateTime(char *buffer, size_t size);

Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Input_Update(); \
Output_EndScene(); \
Output_AnimateFades(); \
Clock_SyncTicks(); \
Clock_WaitTick(); \
} while (g_Input.key);

void Game_ProcessInput(void)
Expand Down
6 changes: 3 additions & 3 deletions src/tr1/game/phase/phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void M_SetUnconditionally(const PHASE phase, const void *args)
// set it at the end, so that the start callbacks can retrieve the old phase
m_Phase = phase;

Clock_SyncTicks();
Clock_WaitTick();
}

PHASE Phase_Get(void)
Expand All @@ -134,13 +134,13 @@ static int32_t M_Wait(void)
if (m_Phaser && m_Phaser->wait) {
return m_Phaser->wait();
} else {
return Clock_SyncTicks();
return Clock_WaitTick();
}
}

GAMEFLOW_COMMAND Phase_Run(void)
{
int32_t nframes = Clock_SyncTicks();
int32_t nframes = Clock_WaitTick();
PHASE_CONTROL control = { .end = false };

m_Running = true;
Expand Down
4 changes: 2 additions & 2 deletions src/tr2/decomp/decomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,7 @@ void __cdecl S_Wait(int32_t frames, const BOOL input_check)
if (!g_Input.any) {
break;
}
frames -= Clock_SyncTicks() * TICKS_PER_FRAME;
frames -= Clock_WaitTick() * TICKS_PER_FRAME;

if (g_IsGameToExit) {
break;
Expand Down Expand Up @@ -2910,7 +2910,7 @@ void __cdecl DisplayCredits(void)

DWORD __cdecl S_DumpScreen(void)
{
const int32_t passed = Clock_SyncTicks();
const int32_t passed = Clock_WaitTick();
ScreenPartialDump();
return passed;
}
2 changes: 2 additions & 0 deletions src/tr2/game/inventory/common.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "game/inventory/common.h"

#include "decomp/decomp.h"
#include "game/clock.h"
#include "game/console/common.h"
#include "game/demo.h"
#include "game/game.h"
Expand Down Expand Up @@ -185,6 +186,7 @@ void __cdecl Inv_Construct(void)

int32_t __cdecl Inv_Display(int32_t inventory_mode)
{
Clock_SyncTick();
Stats_StartTimer();
RING_INFO ring = { 0 };
IMOTION_INFO imo = { 0 };
Expand Down

0 comments on commit 5699694

Please sign in to comment.