dirkwhoffmann / vAmiga

vAmiga is a user-friendly Amiga 500, 1000, 2000 emulator for macOS
https://dirkwhoffmann.github.io/vAmiga
Other
293 stars 24 forks source link

Improved thread synchronization #779

Closed dirkwhoffmann closed 1 year ago

dirkwhoffmann commented 1 year ago
dirkwhoffmann commented 1 year ago

vAmiga got a new thread synchronization mode called Adaptive.

From Thread.h:

 * The Thread class is also responsible for timing synchronization. I.e., it
 * has to ensure that the proper amount of frames are executed per second.
 * Three different synchronization modes are supported:
 *
 * - Periodic:
 *
 *   In periodic mode the thread puts itself to sleep and utilizes a timer to
 *   schedule a wakeup call. In this mode, no further action has to be taken
 *   by the GUI. This method was the default mode used by vAmiga up to version
 *   2.3.
 *
 * - Pulsed:
 *
 *   In pulsed mode, the thread waits for an external wake-up signal that has
 *   to be sent by the GUI. When the wake-up signal is received, a single frame
 *   is computed. vAmiga uses this mode to implement VSYNC.
 *
 * - Adaptive:
 *
 *  In adaptive mode, the thread waits for an external wake-up signal just as
 *  it does in pulsed mode. When the wake-up signal comes in, the thread
 *  computes the number of missing frames based on the current time and the time
 *  the thread had been lauchen. Then it executes all missing frames or
 *  resynchronizes if the number of missing frames is way off.

Adaptive mode should reduce jitter, because it establishes some synchronization between the emulator thread and the drawing loop. To achieve best results, the GUI should issue a wakeUp() call right after it has grabbed the most recent texture from the emulator.

Next step: Port code over to vAmiga.net.

dirkwhoffmann commented 1 year ago

Part of v2.4b1.