Add MP1_VARIABLE_DELTA_TIME option (for high refresh rates; buggy)

This commit is contained in:
Luke Street 2020-02-24 21:42:55 -05:00
parent 051a547c42
commit ae591d4817
2 changed files with 33 additions and 11 deletions

View File

@ -116,14 +116,14 @@ CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoi
g_GameState->GameOptions().EnsureSettings(); 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::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(); 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)); x4_archQueue.Push(MakeMsg::CreateFrameEnd(EArchMsgTarget::Game, x78_gameFrameCount));
x58_ioWinManager.PumpMessages(x4_archQueue); x58_ioWinManager.PumpMessages(x4_archQueue);
} }
@ -817,13 +817,25 @@ bool CMain::Proc() {
m_loadedPersistentResources = true; 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<float, std::ratio<1>>;
dt = std::min(std::chrono::duration_cast<delta_duration>(now - m_prevFrameTime).count(), dt);
}
m_prevFrameTime = now;
#endif
m_console->proc(); m_console->proc();
if (!m_console->isOpen()) { if (!m_console->isOpen()) {
CGBASupport::GlobalPoll(); CGBASupport::GlobalPoll();
x164_archSupport->UpdateTicks(); x164_archSupport->UpdateTicks(dt);
x164_archSupport->Update(); x164_archSupport->Update(dt);
CSfxManager::Update(1.f / 60.f); CSfxManager::Update(dt);
CStreamAudioManager::Update(1.f / 60.f); CStreamAudioManager::Update(dt);
} }
if (x164_archSupport->GetIOWinManager().IsEmpty() || CheckReset()) { if (x164_archSupport->GetIOWinManager().IsEmpty() || CheckReset()) {

View File

@ -1,6 +1,11 @@
#pragma once #pragma once
#ifndef MP1_USE_BOO
#define MP1_USE_BOO 0 #define MP1_USE_BOO 0
#endif
#ifndef MP1_VARIABLE_DELTA_TIME
#define MP1_VARIABLE_DELTA_TIME 0
#endif
#include "IMain.hpp" #include "IMain.hpp"
#include "CTweaks.hpp" #include "CTweaks.hpp"
@ -108,7 +113,6 @@ public:
CScriptMazeNode::LoadMazeSeeds(); CScriptMazeNode::LoadMazeSeeds();
} }
void ResetGameState() { void ResetGameState() {
x134_gameState = std::make_unique<CGameState>(); x134_gameState = std::make_unique<CGameState>();
g_GameState = x134_gameState.get(); g_GameState = x134_gameState.get();
@ -174,8 +178,8 @@ public:
void PreloadAudio(); void PreloadAudio();
bool LoadAudio(); bool LoadAudio();
void UnloadAudio(); void UnloadAudio();
void UpdateTicks(); void UpdateTicks(float dt);
void Update(); void Update(float dt);
void Draw(); void Draw();
bool isRectDirty() const { return m_rectIsDirty; } bool isRectDirty() const { return m_rectIsDirty; }
@ -251,6 +255,12 @@ private:
bool m_loadedPersistentResources = false; bool m_loadedPersistentResources = false;
bool m_doQuit = 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<delta_clock> m_prevFrameTime;
#endif
void InitializeSubsystems(); void InitializeSubsystems();
static void InitializeDiscord(); static void InitializeDiscord();
static void ShutdownDiscord(); static void ShutdownDiscord();