mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-10 21:00:55 -04:00
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:
+3
-5
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user