diff --git a/Common/System/NativeApp.h b/Common/System/NativeApp.h index 265ad5b0a7..490d35c83d 100644 --- a/Common/System/NativeApp.h +++ b/Common/System/NativeApp.h @@ -49,21 +49,16 @@ void NativeSetRestarting(); // Retrieve current restarting flag. bool NativeIsRestarting(); -// Called ~sixty times a second, delivers the current input state. -// Main thread. -void NativeUpdate(); - -// Delivers touch events "instantly", without waiting for the next frame so that NativeUpdate can deliver. -// Useful for triggering audio events, saving a few ms. -// If you don't care about touch latency, just do a no-op implementation of this. -// time is not yet implemented. finger can be from 0 to 7, inclusive. +// Delivers touch/key/axis events "instantly", without waiting for the next frame so that NativeFrame can deliver. +// Some systems like UI will buffer these events internally but at least in gameplay we can get the minimum possible +// input latency - assuming your main loop is architected properly (NativeFrame called from a different thread than input event handling). void NativeTouch(const TouchInput &touch); bool NativeKey(const KeyInput &key); void NativeAxis(const AxisInput &axis); -// Called when it's time to render. If the device can keep up, this -// will also be called sixty times per second. Main thread. -void NativeRender(GraphicsContext *graphicsContext); +// Called when it's process a frame, including rendering. If the device can keep up, this +// will be called sixty times per second. Main thread. +void NativeFrame(GraphicsContext *graphicsContext); // This should render num_samples 44khz stereo samples. // Try not to make too many assumptions on the granularity diff --git a/Common/System/Request.h b/Common/System/Request.h index 420de22942..e6b3a10b37 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -29,7 +29,7 @@ public: void PostSystemSuccess(int requestId, const char *responseString, int responseValue = 0); void PostSystemFailure(int requestId); - // This must be called every frame from the beginning of NativeUpdate(). + // This must be called every frame from the beginning of NativeFrame(). // This will call the callback of any finished requests. void ProcessRequests(); diff --git a/Core/Core.cpp b/Core/Core.cpp index 5fce2079d0..854ecfb068 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -210,8 +210,7 @@ void UpdateRunLoop() { sleep_ms(16); return; } - NativeUpdate(); - NativeRender(graphicsContext); + NativeFrame(graphicsContext); } void KeepScreenAwake() { @@ -325,7 +324,7 @@ void Core_ProcessStepping() { } // Many platforms, like Android, do not call this function but handle things on their own. -// Instead they simply call NativeRender and NativeUpdate directly. +// Instead they simply call NativeFrame directly. bool Core_Run(GraphicsContext *ctx) { System_Notify(SystemNotification::DISASSEMBLY); while (true) { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index dbb551ec84..589b7f6fcd 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -151,6 +151,8 @@ #include +void HandleGlobalMessage(const std::string &msg, const std::string &value); + ScreenManager *g_screenManager; std::string config_filename; @@ -1047,14 +1049,43 @@ void RenderOverlays(UIContext *dc, void *userdata) { } } -void NativeRender(GraphicsContext *graphicsContext) { +void NativeFrame(GraphicsContext *graphicsContext) { + PROFILE_END_FRAME(); + + std::vector toProcess; + { + std::lock_guard lock(pendingMutex); + toProcess = std::move(pendingMessages); + pendingMessages.clear(); + } + + for (const auto &item : toProcess) { + HandleGlobalMessage(item.msg, item.value); + g_screenManager->sendMessage(item.msg.c_str(), item.value.c_str()); + } + + g_requestManager.ProcessRequests(); + + // it's ok to call this redundantly with DoFrame from EmuScreen + Achievements::Idle(); + + g_DownloadManager.Update(); + g_screenManager->update(); + + g_Discord.Update(); + g_BackgroundAudio.Play(); + + g_OSD.Update(); + + UI::SetSoundEnabled(g_Config.bUISound); + _dbg_assert_(graphicsContext != nullptr); _dbg_assert_(g_screenManager != nullptr); g_GameManager.Update(); if (GetUIState() != UISTATE_INGAME) { - // Note: We do this from NativeRender so that the graphics context is + // Note: We do this from NativeFrame so that the graphics context is // guaranteed valid, to be safe - g_gameInfoCache messes around with textures. g_BackgroundAudio.Update(); } @@ -1206,37 +1237,6 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { } } -void NativeUpdate() { - PROFILE_END_FRAME(); - - std::vector toProcess; - { - std::lock_guard lock(pendingMutex); - toProcess = std::move(pendingMessages); - pendingMessages.clear(); - } - - for (const auto &item : toProcess) { - HandleGlobalMessage(item.msg, item.value); - g_screenManager->sendMessage(item.msg.c_str(), item.value.c_str()); - } - - g_requestManager.ProcessRequests(); - - // it's ok to call this redundantly with DoFrame from EmuScreen - Achievements::Idle(); - - g_DownloadManager.Update(); - g_screenManager->update(); - - g_Discord.Update(); - g_BackgroundAudio.Play(); - - g_OSD.Update(); - - UI::SetSoundEnabled(g_Config.bUISound); -} - bool NativeIsAtTopLevel() { // This might need some synchronization? if (!g_screenManager) { diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 94d4091ffc..5bf8854a31 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -165,7 +165,6 @@ void PPSSPP_UWPMain::CreateWindowSizeDependentResources() { // Returns true if the frame was rendered and is ready to be displayed. bool PPSSPP_UWPMain::Render() { ctx_->GetDrawContext()->HandleEvent(Draw::Event::PRESENTED, 0, 0, nullptr, nullptr); - NativeUpdate(); static bool hasSetThreadName = false; if (!hasSetThreadName) { @@ -212,7 +211,7 @@ bool PPSSPP_UWPMain::Render() { context->RSSetViewports(1, &viewport); - NativeRender(ctx_.get()); + NativeFrame(ctx_.get()); return true; } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 61c737396c..54416a9ca4 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1121,8 +1121,7 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendRequestResult(JNIEn void LockedNativeUpdateRender() { std::lock_guard renderGuard(renderLock); - NativeUpdate(); - NativeRender(graphicsContext); + NativeFrame(graphicsContext); } void UpdateRunLoopAndroid(JNIEnv *env) { diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 1eb353f625..2c2b19cbb7 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -94,8 +94,7 @@ public: }; // Temporary hacks around annoying linking errors. -void NativeUpdate() { } -void NativeRender(GraphicsContext *graphicsContext) { } +void NativeFrame(GraphicsContext *graphicsContext) { } void NativeResized() { } std::string System_GetProperty(SystemProperty prop) { return ""; } diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 2bfa3dd63c..97fd315037 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -238,8 +238,7 @@ extern float g_safeInsetBottom; INFO_LOG(SYSTEM, "Emulation thread starting\n"); while (threadEnabled) { - NativeUpdate(); - NativeRender(graphicsContext); + NativeFrame(graphicsContext); } diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index cbb1609d65..4b762dee63 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1704,8 +1704,7 @@ void System_Notify(SystemNotification notification) { } bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; } void System_PostUIMessage(const std::string &message, const std::string ¶m) {} -void NativeUpdate() {} -void NativeRender(GraphicsContext *graphicsContext) {} +void NativeFrame(GraphicsContext *graphicsContext) {} void NativeResized() {} void System_Toast(const char *str) {} diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index 750b39ab57..4ad53fc65c 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -37,8 +37,7 @@ #include "Core/HLE/HLE.h" // Temporary hacks around annoying linking errors. Copied from Headless. -void NativeUpdate() { } -void NativeRender(GraphicsContext *graphicsContext) { } +void NativeFrame(GraphicsContext *graphicsContext) { } void NativeResized() { } bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }