From 5f7c070f78b8275992771162927bce5adfa1dda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20H=C3=B6rdt?= <6329417-neop_@users.noreply.gitlab.com> Date: Sun, 4 Aug 2024 15:00:16 +0200 Subject: [PATCH] less calls to clock::now() --- main.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index ba45d45..a23c96c 100644 --- a/main.cpp +++ b/main.cpp @@ -109,17 +109,22 @@ int main() { } SDL_UnlockSurface(window_surface); - const auto start_time = clock::now(); auto next_poll_events_time = start_time; auto frame_start = start_time; clock::duration frame_time; for (bool continu = true; continu;) { - { - // measure frame_time - auto now = clock::now(); - frame_time = now - frame_start; - frame_start = now; + // measure frame_time + const auto now = clock::now(); + frame_time = now - frame_start; + frame_start = now; + + if (now >= next_poll_events_time) { + next_poll_events_time = now + std::chrono::milliseconds{200}; + poll_events(continu); + std::println( + "last frame_time={} batchsize={}", frame_time, batchsize + ); } SDL_LockSurface(window_surface); @@ -134,17 +139,7 @@ int main() { )[pos.x + pos.y * window_surface->w] = walk_color; } SDL_UnlockSurface(window_surface); - SDL_UpdateWindowSurface(window); - - const auto now = clock::now(); - if (now >= next_poll_events_time) { - next_poll_events_time = now + std::chrono::milliseconds{200}; - poll_events(continu); - std::println( - "last frame_time={} batchsize={}", frame_time, batchsize - ); - } } // leaking memory, nothing I can do