Reduce input lag by one frame by reading the controller at the correct place

This commit is contained in:
Emil Lenngren 2022-04-29 22:17:07 +02:00 committed by Kenix3
parent 5b52e7e570
commit 589557be9c
6 changed files with 12 additions and 1 deletions

View File

@ -275,8 +275,11 @@ namespace Ship {
WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp); WmApi->set_keyboard_callbacks(Window::KeyDown, Window::KeyUp, Window::AllKeysUp);
} }
void Window::RunCommands(Gfx* Commands) { void Window::StartFrame() {
gfx_start_frame(); gfx_start_frame();
}
void Window::RunCommands(Gfx* Commands) {
gfx_run(Commands); gfx_run(Commands);
gfx_end_frame(); gfx_end_frame();
} }

View File

@ -18,6 +18,7 @@ namespace Ship {
~Window(); ~Window();
void MainLoop(void (*MainFunction)(void)); void MainLoop(void (*MainFunction)(void));
void Init(); void Init();
void StartFrame();
void RunCommands(Gfx* Commands); void RunCommands(Gfx* Commands);
void SetFrameDivisor(int divisor); void SetFrameDivisor(int divisor);
void GetPixelDepthPrepare(float x, float y); void GetPixelDepthPrepare(float x, float y);

View File

@ -5,6 +5,7 @@
extern "C" { extern "C" {
void InitOTR(); void InitOTR();
void Graph_ProcessFrame(void (*run_one_game_iter)(void)); void Graph_ProcessFrame(void (*run_one_game_iter)(void));
void Graph_StartFrame();
void Graph_ProcessGfxCommands(Gfx* commands); void Graph_ProcessGfxCommands(Gfx* commands);
void OTRLogString(const char* src); void OTRLogString(const char* src);
void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)); void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char));

View File

@ -92,6 +92,10 @@ extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) {
OTRGlobals::Instance->context->GetWindow()->MainLoop(run_one_game_iter); OTRGlobals::Instance->context->GetWindow()->MainLoop(run_one_game_iter);
} }
extern "C" void Graph_StartFrame() {
OTRGlobals::Instance->context->GetWindow()->StartFrame();
}
// C->C++ Bridge // C->C++ Bridge
extern "C" void Graph_ProcessGfxCommands(Gfx* commands) { extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
OTRGlobals::Instance->context->GetWindow()->SetFrameDivisor(R_UPDATE_RATE); OTRGlobals::Instance->context->GetWindow()->SetFrameDivisor(R_UPDATE_RATE);

View File

@ -21,6 +21,7 @@ private:
#ifndef __cplusplus #ifndef __cplusplus
void InitOTR(); void InitOTR();
void Graph_ProcessFrame(void (*run_one_game_iter)(void)); void Graph_ProcessFrame(void (*run_one_game_iter)(void));
void Graph_StartFrame();
void Graph_ProcessGfxCommands(Gfx* commands); void Graph_ProcessGfxCommands(Gfx* commands);
void OTRLogString(const char* src); void OTRLogString(const char* src);
void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)); void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char));

View File

@ -472,6 +472,7 @@ static void RunFrame()
uint64_t ticksA, ticksB; uint64_t ticksA, ticksB;
ticksA = GetPerfCounter(); ticksA = GetPerfCounter();
Graph_StartFrame();
PadMgr_ThreadEntry(&gPadMgr); PadMgr_ThreadEntry(&gPadMgr);