From 8e3df5a38f3f65ad4e78ab28c22366870eeaa60f Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 10 Jul 2021 14:20:28 +1000 Subject: [PATCH] [client] main: dont push an invalid value into the timings buffers --- client/src/main.c | 18 ++++++++++++++---- client/src/main.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index a78ae3d8..2f692ec8 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -152,8 +152,13 @@ static int renderThread(void * unused) const uint64_t t = nanotime(); const uint64_t delta = t - g_state.lastRenderTime; g_state.lastRenderTime = t; - const float fdelta = (float)delta / 1000000.0f; - ringbuffer_push(g_state.renderTimings, &fdelta); + + if (g_state.lastRenderTimeValid) + { + const float fdelta = (float)delta / 1000000.0f; + ringbuffer_push(g_state.renderTimings, &fdelta); + } + g_state.lastRenderTimeValid = true; if (g_state.showFPS) { @@ -601,8 +606,13 @@ int main_frameThread(void * unused) const uint64_t t = nanotime(); const uint64_t delta = t - g_state.lastFrameTime; g_state.lastFrameTime = t; - const float fdelta = (float)delta / 1000000.0f; - ringbuffer_push(g_state.frameTimings, &fdelta); + + if (g_state.lastFrameTimeValid) + { + const float fdelta = (float)delta / 1000000.0f; + ringbuffer_push(g_state.frameTimings, &fdelta); + } + g_state.lastFrameTimeValid = true; atomic_fetch_add_explicit(&g_state.frameCount, 1, memory_order_relaxed); lgSignalEvent(e_frame); diff --git a/client/src/main.h b/client/src/main.h index 65781c2e..5748b81a 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -96,8 +96,10 @@ struct AppState bool formatValid; atomic_uint_least64_t frameTime; uint64_t lastFrameTime; + bool lastFrameTimeValid; uint64_t renderTime; uint64_t lastRenderTime; + bool lastRenderTimeValid; atomic_uint_least64_t frameCount; uint64_t renderCount; RingBuffer renderTimings;