Skip to content

Commit

Permalink
demo: do not rely on FPS
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Mar 29, 2024
1 parent d0ae12e commit 7587b5a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "game/phase/phase_picture.h"
#include "game/phase/phase_stats.h"
#include "game/room.h"
#include "global/const.h"
#include "global/vars.h"
#include "json/json_base.h"
#include "json/json_parse.h"
Expand Down Expand Up @@ -254,7 +253,7 @@ static bool GameFlow_LoadScriptMeta(struct json_object_s *obj)
LOG_ERROR("'demo_delay' must be a positive number");
return false;
}
g_GameFlow.demo_delay = tmp_d * LOGIC_FPS;
g_GameFlow.demo_delay = tmp_d;

g_GameFlow.force_game_modes =
GameFlow_ReadTristateBool(obj, "force_game_modes");
Expand Down
2 changes: 1 addition & 1 deletion src/game/gameflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef struct GAMEFLOW {
char *savegame_fmt_legacy;
char *savegame_fmt_bson;
int8_t has_demo;
int32_t demo_delay;
double demo_delay;
TRISTATE_BOOL force_game_modes;
TRISTATE_BOOL force_save_crystals;
GAMEFLOW_LEVEL *levels;
Expand Down
11 changes: 5 additions & 6 deletions src/game/phase/phase_inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static bool m_PlayedSpinin;
static bool m_PassportModeReady;
static int32_t m_StartLevel;
static bool m_StartDemo;
static int32_t m_NoInputCount;
static int32_t m_StartMS;
static TEXTSTRING *m_VersionText = NULL;
static int16_t m_InvNFrames = 2;
static int16_t m_CompassNeedle = 0;
Expand Down Expand Up @@ -196,7 +196,6 @@ static GAMEFLOW_OPTION Inv_Close(void)
}

if (m_StartDemo) {
m_NoInputCount = 0;
return GF_START_DEMO;
}

Expand Down Expand Up @@ -489,7 +488,6 @@ static void Phase_Inventory_Start(void *arg)
g_InvMode = inv_mode;

m_PassportModeReady = false;
m_NoInputCount = 0;
m_StartLevel = -1;
m_StartDemo = false;
m_InvNFrames = 2;
Expand Down Expand Up @@ -559,6 +557,7 @@ static GAMEFLOW_OPTION Phase_Inventory_Control(int32_t nframes)
return GF_PHASE_CONTINUE;
}

m_StartMS = Clock_GetMS();
if (!m_PlayedSpinin) {
Sound_Effect(SFX_MENU_SPININ, NULL, SPM_ALWAYS);
m_PlayedSpinin = true;
Expand All @@ -576,10 +575,10 @@ static GAMEFLOW_OPTION Phase_Inventory_Control(int32_t nframes)
Game_ProcessInput();

if (g_InvMode != INV_TITLE_MODE || g_Input.any || g_InputDB.any) {
m_NoInputCount = 0;
m_StartMS = Clock_GetMS();
} else if (g_Config.enable_demo && motion->status == RNG_OPEN) {
m_NoInputCount++;
if (g_GameFlow.has_demo && m_NoInputCount > g_GameFlow.demo_delay) {
if (g_GameFlow.has_demo
&& (Clock_GetMS() - m_StartMS) / 1000.0 > g_GameFlow.demo_delay) {
m_StartDemo = true;
}
}
Expand Down

0 comments on commit 7587b5a

Please sign in to comment.