Skip to content

Commit

Permalink
inventory: fix demo timer
Browse files Browse the repository at this point in the history
Resolves LostArtefacts#1368. This is an improvement to b276946 which didn't address
the underlying issue. It also offers a small refactor to boost the
readability.
  • Loading branch information
rr- committed Jul 11, 2024
1 parent a7db935 commit 9c6a569
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/game/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ static bool Clock_CheckElapsedUnit(
const double multiplier =
(bypass_turbo_cheat ? 1.0 : Clock_GetSpeedMultiplier()) / 1000.0;
const double frames = delta * multiplier * unit;
if (frames >= how_often || g_Config.rendering.fps != timer->prev_fps) {
if (g_Config.rendering.fps != timer->prev_fps) {
Clock_ResetTimer(timer);
return false;
}
if (frames >= how_often) {
Clock_ResetTimer(timer);
return true;
}
Expand Down
31 changes: 20 additions & 11 deletions src/game/phase/phase_inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static int32_t InvItem_GetFrames(
const INVENTORY_ITEM *inv_item, FRAME_INFO **out_frame1,
FRAME_INFO **out_frame2, int32_t *out_rate);
static void Inv_DrawItem(INVENTORY_ITEM *inv_item, int32_t frames);
static bool Inv_CheckDemoTimer(const IMOTION_INFO *motion);

static void Phase_Inventory_Start(void *arg);
static void Phase_Inventory_End(void);
Expand Down Expand Up @@ -550,6 +551,23 @@ static void Inv_DrawItem(INVENTORY_ITEM *const inv_item, const int32_t frames)
}
}

static bool Inv_CheckDemoTimer(const IMOTION_INFO *const motion)
{
if (!g_Config.enable_demo || !g_GameFlow.has_demo) {
return false;
}

if (g_InvMode != INV_TITLE_MODE || g_Input.any || g_InputDB.any
|| Console_IsOpened()) {
Clock_ResetTimer(&m_DemoTimer);
return false;
}

return motion->status == RNG_OPEN
&& Clock_CheckElapsedMilliseconds(
&m_DemoTimer, g_GameFlow.demo_delay * 1000.0);
}

static void Phase_Inventory_Start(void *arg)
{
Interpolation_Remember();
Expand Down Expand Up @@ -657,19 +675,10 @@ static GAMEFLOW_COMMAND Phase_Inventory_ControlFrame(void)
Inv_Ring_CalcAdders(ring, ROTATE_DURATION);

Input_Update();

// Do the demo inactivity check prior to postprocessing of the inputs.
if (g_InvMode != INV_TITLE_MODE || g_Input.any || g_InputDB.any
|| Console_IsOpened()) {
Clock_ResetTimer(&m_DemoTimer);
} else if (g_Config.enable_demo && motion->status == RNG_OPEN) {
if (g_GameFlow.has_demo
&& Clock_CheckElapsedMilliseconds(
&m_DemoTimer, g_GameFlow.demo_delay * 1000.0)) {
m_StartDemo = true;
}
if (Inv_CheckDemoTimer(motion)) {
m_StartDemo = true;
}

Shell_ProcessInput();
Game_ProcessInput();

Expand Down

0 comments on commit 9c6a569

Please sign in to comment.