From 1d5f98db32ca148b2704d96e72b13de09acb1be9 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 7 Dec 2017 16:10:00 +1100 Subject: [PATCH] [client] adjusted presentation time to be more accurate --- client/main.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/client/main.c b/client/main.c index c424a772..e4e66511 100644 --- a/client/main.c +++ b/client/main.c @@ -161,19 +161,17 @@ inline uint64_t microtime() uint64_t detectPresentTime() { - // warm up first as the GPU driver may have multiple buffers - for(int i = 0; i < 10; ++i) - SDL_RenderPresent(state.renderer); - - // time 10 iterations and compute the average - const uint64_t start = microtime(); - for(int i = 0; i < 10; ++i) - SDL_RenderPresent(state.renderer); - const uint64_t t = (microtime() - start) / 10; - - // ensure all buffers are flushed glFinish(); + // time 20 iterations and compute the average + const uint64_t start = microtime(); + for(int i = 0; i < 20; ++i) + { + SDL_RenderPresent(state.renderer); + glFinish(); + } + const uint64_t t = (microtime() - start) / 20; + DEBUG_INFO("detected: %lu (%f Hz)", t, 1000000.0f / t); return t; }