[Scummvm-git-logs] scummvm master -> 842a52fd42c23d0290af768bf2593634008467ba
spleen1981
noreply at scummvm.org
Sun May 7 13:25:42 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
842a52fd42 LIBRETRO: fix delayMillis regular method
Commit: 842a52fd42c23d0290af768bf2593634008467ba
https://github.com/scummvm/scummvm/commit/842a52fd42c23d0290af768bf2593634008467ba
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-05-07T15:25:11+02:00
Commit Message:
LIBRETRO: fix delayMillis regular method
Changed paths:
backends/platform/libretro/src/libretro-os.cpp
diff --git a/backends/platform/libretro/src/libretro-os.cpp b/backends/platform/libretro/src/libretro-os.cpp
index c8d38d96221..dc9a720975b 100644
--- a/backends/platform/libretro/src/libretro-os.cpp
+++ b/backends/platform/libretro/src/libretro-os.cpp
@@ -678,27 +678,35 @@ public:
virtual void delayMillis(uint msecs) {
uint32 start_time = getMillis();
+ uint32 elapsed_time = 0;
+
_threadSwitchCaller = THREAD_SWITCH_DELAY;
- uint32 elapsed_time = 0;
- uint32 time_remaining = msecs;
- while (time_remaining > 0) {
- /* if remaining delay is lower than last amount of time spent on main thread, burn it in emu thread
- to improve accuracy */
- if (time_remaining >= ((LibretroTimerManager *)_timerManager)->spentOnMainThread()) {
- /* If timing inaccuracies is enabled, when remaining delay would take us past the next
- thread switch time, we switch immediately in order to burn as much as possible delay time in the main RetroArch
- thread as soon as possible. */
- if (timing_inaccuracies_is_enabled() && time_remaining >= ((LibretroTimerManager *)_timerManager)->timeToNextSwitch())
+ if (timing_inaccuracies_is_enabled()) {
+ while (elapsed_time < msecs) {
+ /* When remaining delay would take us past the next thread switch time, we switch immediately
+ in order to burn as much as possible delay time in the main RetroArch thread as soon as possible. */
+ if (msecs - elapsed_time >= ((LibretroTimerManager *)_timerManager)->timeToNextSwitch())
((LibretroTimerManager *)_timerManager)->switchThread();
else
- ((LibretroTimerManager *)_timerManager)->checkThread();
- } else
- usleep(1000);
+ usleep(1000);
- elapsed_time = getMillis() - start_time;
- time_remaining = time_remaining > elapsed_time ? time_remaining - elapsed_time : 0;
+ /* Actual delay provided will be lower than requested: elapsed time is calculated cumulatively.
+ i.e. the higher the requested delay, the higher the actual delay reduction */
+ elapsed_time += getMillis() - start_time;
+ }
+ } else {
+ while (elapsed_time < msecs) {
+ /* if remaining delay is lower than last amount of time spent on main thread, burn it in emu thread
+ to avoid exceeding requested delay */
+ if (msecs - elapsed_time >= ((LibretroTimerManager *)_timerManager)->spentOnMainThread() && !((LibretroTimerManager *)_timerManager)->timeToNextSwitch())
+ ((LibretroTimerManager *)_timerManager)->switchThread();
+ else
+ usleep(1000);
+ elapsed_time = getMillis() - start_time;
+ }
}
+
((LibretroTimerManager *)_timerManager)->handler();
}
More information about the Scummvm-git-logs
mailing list