From 589557be9c912668f5b04519cfe5a6a89c75e70a Mon Sep 17 00:00:00 2001 From: Emil Lenngren Date: Fri, 29 Apr 2022 22:17:07 +0200 Subject: [PATCH] Reduce input lag by one frame by reading the controller at the correct place --- libultraship/libultraship/Window.cpp | 5 ++++- libultraship/libultraship/Window.h | 1 + soh/soh/GbiWrap.cpp | 1 + soh/soh/OTRGlobals.cpp | 4 ++++ soh/soh/OTRGlobals.h | 1 + soh/src/code/graph.c | 1 + 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/Window.cpp b/libultraship/libultraship/Window.cpp index 2b57c547e..0feb7229f 100644 --- a/libultraship/libultraship/Window.cpp +++ b/libultraship/libultraship/Window.cpp @@ -275,8 +275,11 @@ namespace Ship { WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp); } - void Window::RunCommands(Gfx* Commands) { + void Window::StartFrame() { gfx_start_frame(); + } + + void Window::RunCommands(Gfx* Commands) { gfx_run(Commands); gfx_end_frame(); } diff --git a/libultraship/libultraship/Window.h b/libultraship/libultraship/Window.h index 0d12211b0..b075e496f 100644 --- a/libultraship/libultraship/Window.h +++ b/libultraship/libultraship/Window.h @@ -18,6 +18,7 @@ namespace Ship { ~Window(); void MainLoop(void (*MainFunction)(void)); void Init(); + void StartFrame(); void RunCommands(Gfx* Commands); void SetFrameDivisor(int divisor); void GetPixelDepthPrepare(float x, float y); diff --git a/soh/soh/GbiWrap.cpp b/soh/soh/GbiWrap.cpp index c7f69f1a9..9f71f1717 100644 --- a/soh/soh/GbiWrap.cpp +++ b/soh/soh/GbiWrap.cpp @@ -5,6 +5,7 @@ extern "C" { void InitOTR(); void Graph_ProcessFrame(void (*run_one_game_iter)(void)); +void Graph_StartFrame(); void Graph_ProcessGfxCommands(Gfx* commands); void OTRLogString(const char* src); void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 69917e8ac..d2bc941cf 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -92,6 +92,10 @@ extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) { OTRGlobals::Instance->context->GetWindow()->MainLoop(run_one_game_iter); } +extern "C" void Graph_StartFrame() { + OTRGlobals::Instance->context->GetWindow()->StartFrame(); +} + // C->C++ Bridge extern "C" void Graph_ProcessGfxCommands(Gfx* commands) { OTRGlobals::Instance->context->GetWindow()->SetFrameDivisor(R_UPDATE_RATE); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index dfb235712..7ce08649a 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -21,6 +21,7 @@ private: #ifndef __cplusplus void InitOTR(); void Graph_ProcessFrame(void (*run_one_game_iter)(void)); +void Graph_StartFrame(); void Graph_ProcessGfxCommands(Gfx* commands); void OTRLogString(const char* src); void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)); diff --git a/soh/src/code/graph.c b/soh/src/code/graph.c index 10293fa5f..5d0495961 100644 --- a/soh/src/code/graph.c +++ b/soh/src/code/graph.c @@ -472,6 +472,7 @@ static void RunFrame() uint64_t ticksA, ticksB; ticksA = GetPerfCounter(); + Graph_StartFrame(); PadMgr_ThreadEntry(&gPadMgr);