diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index fbb94dc62..a6bc5451e 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -116,14 +116,14 @@ CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoi g_GameState->GameOptions().EnsureSettings(); } -void CGameArchitectureSupport::UpdateTicks() { +void CGameArchitectureSupport::UpdateTicks(float dt) { x4_archQueue.Push(MakeMsg::CreateFrameBegin(EArchMsgTarget::Game, x78_gameFrameCount)); - x4_archQueue.Push(MakeMsg::CreateTimerTick(EArchMsgTarget::Game, 1.f / 60.f)); + x4_archQueue.Push(MakeMsg::CreateTimerTick(EArchMsgTarget::Game, dt)); } -void CGameArchitectureSupport::Update() { +void CGameArchitectureSupport::Update(float dt) { g_GameState->GetWorldTransitionManager()->TouchModels(); - x30_inputGenerator.Update(1 / 60.f, x4_archQueue); + x30_inputGenerator.Update(dt, x4_archQueue); x4_archQueue.Push(MakeMsg::CreateFrameEnd(EArchMsgTarget::Game, x78_gameFrameCount)); x58_ioWinManager.PumpMessages(x4_archQueue); } @@ -817,13 +817,25 @@ bool CMain::Proc() { m_loadedPersistentResources = true; } + float dt = 1 / 60.f; +#if MP1_VARIABLE_DELTA_TIME + auto now = delta_clock::now(); + if (m_firstFrame) { + m_firstFrame = false; + } else { + using delta_duration = std::chrono::duration>; + dt = std::min(std::chrono::duration_cast(now - m_prevFrameTime).count(), dt); + } + m_prevFrameTime = now; +#endif + m_console->proc(); if (!m_console->isOpen()) { CGBASupport::GlobalPoll(); - x164_archSupport->UpdateTicks(); - x164_archSupport->Update(); - CSfxManager::Update(1.f / 60.f); - CStreamAudioManager::Update(1.f / 60.f); + x164_archSupport->UpdateTicks(dt); + x164_archSupport->Update(dt); + CSfxManager::Update(dt); + CStreamAudioManager::Update(dt); } if (x164_archSupport->GetIOWinManager().IsEmpty() || CheckReset()) { diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index bfcb8b5d0..397031000 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -1,6 +1,11 @@ #pragma once +#ifndef MP1_USE_BOO #define MP1_USE_BOO 0 +#endif +#ifndef MP1_VARIABLE_DELTA_TIME +#define MP1_VARIABLE_DELTA_TIME 0 +#endif #include "IMain.hpp" #include "CTweaks.hpp" @@ -108,7 +113,6 @@ public: CScriptMazeNode::LoadMazeSeeds(); } - void ResetGameState() { x134_gameState = std::make_unique(); g_GameState = x134_gameState.get(); @@ -174,8 +178,8 @@ public: void PreloadAudio(); bool LoadAudio(); void UnloadAudio(); - void UpdateTicks(); - void Update(); + void UpdateTicks(float dt); + void Update(float dt); void Draw(); bool isRectDirty() const { return m_rectIsDirty; } @@ -251,6 +255,12 @@ private: bool m_loadedPersistentResources = false; bool m_doQuit = false; +#if MP1_VARIABLE_DELTA_TIME + bool m_firstFrame = true; + using delta_clock = std::chrono::high_resolution_clock; + std::chrono::time_point m_prevFrameTime; +#endif + void InitializeSubsystems(); static void InitializeDiscord(); static void ShutdownDiscord();