less calls to clock::now()

This commit is contained in:
Jakob Hördt 2024-08-04 15:00:16 +02:00
parent baf1a05e0a
commit 5f7c070f78

View file

@ -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