Use Limiter class in waitForTick (#330)

This uses the existing `Limiter` class (stolen from Metaforce) in `JFWDisplay::waitForTick`.
The limiter also now uses `SDL_DelayPrecise` internally on non-Windows platforms.
On Windows, the existing `NanoSleep` logic is untouched, as it appears to provide a
more stable framerate for the folks testing it on Windows than `SDL_DelayPrecise` does.
On Linux, however, `SDL_DelayPrecise` is plenty accurate.
This commit is contained in:
Luke Street
2026-04-11 17:50:52 -06:00
committed by GitHub
parent b628a1beb6
commit aafd50cd09
4 changed files with 46 additions and 33 deletions
+3 -5
View File
@@ -15,12 +15,10 @@
#include <Windows.h>
#include <shellapi.h>
#include <intrin.h>
#else
#include "SDL3/SDL_timer.h"
#endif
#include "dusk/logging.h"
constexpr auto DUSK_FRAME_PERIOD = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(1001.0 / 30000.0));
class Limiter {
using delta_clock = std::chrono::high_resolution_clock;
using duration_t = std::chrono::nanoseconds;
@@ -101,7 +99,7 @@ private:
} while (current.QuadPart - start.QuadPart < ticksToWait);
}
#else
void NanoSleep(const duration_t duration) { std::this_thread::sleep_for(duration); }
void NanoSleep(const duration_t duration) { SDL_DelayPrecise(duration.count()); }
#endif
};