From 14fcaf1d7ee6bf91535b2f71a0325edf4bf7bd69 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 5 Jan 2024 15:14:58 +0100 Subject: [PATCH] why is windows so bad --- src/main.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3375f82..d973ebc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,26 +139,40 @@ int main(int argc, char** argv) { //); +#if 1 if (render || tick) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms + // why is windows like this + //std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms + SDL_Delay(1); // yield for 1ms } else { -#if 0 + #if 0 // pretty hacky and spins if close to next update // if next loop >= 1ms away, wait 1ms if (time_delta_tick+0.001f < screen->nextTick() && time_delta_render+0.001f < screen->nextRender()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms } -#else + #else // dynamic sleep, sleeps the reminder till next update - std::this_thread::sleep_for(std::chrono::duration( + //std::this_thread::sleep_for(std::chrono::duration( + //std::min( + //screen->nextTick() - time_delta_tick, + //screen->nextRender() - time_delta_render + //) + //)); + SDL_Delay(uint32_t( std::min( screen->nextTick() - time_delta_tick, screen->nextRender() - time_delta_render - ) + ) * 1000.f )); -#endif + #endif } +#else + // why is windows like this + //std::this_thread::sleep_for(std::chrono::milliseconds(1)); // yield for 1ms + SDL_Delay(1); // yield for 1ms +#endif } return 0;