less calls to clock::now()
This commit is contained in:
parent
baf1a05e0a
commit
5f7c070f78
1 changed files with 11 additions and 16 deletions
27
main.cpp
27
main.cpp
|
@ -109,17 +109,22 @@ int main() {
|
||||||
}
|
}
|
||||||
SDL_UnlockSurface(window_surface);
|
SDL_UnlockSurface(window_surface);
|
||||||
|
|
||||||
|
|
||||||
const auto start_time = clock::now();
|
const auto start_time = clock::now();
|
||||||
auto next_poll_events_time = start_time;
|
auto next_poll_events_time = start_time;
|
||||||
auto frame_start = start_time;
|
auto frame_start = start_time;
|
||||||
clock::duration frame_time;
|
clock::duration frame_time;
|
||||||
for (bool continu = true; continu;) {
|
for (bool continu = true; continu;) {
|
||||||
{
|
// measure frame_time
|
||||||
// measure frame_time
|
const auto now = clock::now();
|
||||||
auto now = clock::now();
|
frame_time = now - frame_start;
|
||||||
frame_time = now - frame_start;
|
frame_start = now;
|
||||||
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);
|
SDL_LockSurface(window_surface);
|
||||||
|
@ -134,17 +139,7 @@ int main() {
|
||||||
)[pos.x + pos.y * window_surface->w] = walk_color;
|
)[pos.x + pos.y * window_surface->w] = walk_color;
|
||||||
}
|
}
|
||||||
SDL_UnlockSurface(window_surface);
|
SDL_UnlockSurface(window_surface);
|
||||||
|
|
||||||
SDL_UpdateWindowSurface(window);
|
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
|
// leaking memory, nothing I can do
|
||||||
|
|
Loading…
Reference in a new issue