From 60c12228c91563b2b4554b294a971db16d9731fd Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 23 Oct 2018 18:37:25 +0200 Subject: [PATCH] Correct average render / packet time calculations. We need to reset the avgrenderframetime and avgpacketframetime variables when we recalculate the average times spend rendering frame and / or processing package frames. Otherwise the result will be much too high, leading to lost frames down below. I wonder why nobody complained about this until now. While at it lower the security margin from 2% to just 1%. On the one hand we need a small security margin, because Quake II is not that precise and out average times spend may be too low. On the other hand the margin must not be too large, because the bigger the margin is the bigger is the risk of missing frames... Both 2% and 1% is very small, in fact often they don't even make a difference because of float -> int conversations. For example 16 * 0,02 = 0,32 -> cut to 0. But there are some extrem cases were it matters and my empirical testing showed that 1% is slighty better then 2%. At least on my system. An it's better to f*ck up the timing for a small number of frames than missing a frame. A broken timing is hard to recognize, a missed frame is much more annoying. --- src/common/frame.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/frame.c b/src/common/frame.c index 0466702f..e576faa8 100644 --- a/src/common/frame.c +++ b/src/common/frame.c @@ -532,12 +532,13 @@ Qcommon_Frame(int msec) scenes complexity. Take the last 60 pure render frames (frames that are only render frames and nothing else) into account and add a security - margin of 2%. */ + margin of 1%. */ if (last_was_renderframe && !last_was_packetframe) { int measuredframes = 0; static int renderframenum; + avgrenderframetime = 0; renderframetimes[renderframenum] = msec; for (int i = 0; i < 60; i++) @@ -550,7 +551,7 @@ Qcommon_Frame(int msec) } avgrenderframetime /= measuredframes; - avgrenderframetime += (avgrenderframetime * 0.02f); + avgrenderframetime += (avgrenderframetime * 0.01f); renderframenum++; @@ -567,12 +568,13 @@ Qcommon_Frame(int msec) speed and the network delay. Take the last 60 pure packet frames (frames that are only packet frames ans nothing else) into account and add a security margin - of 2%. */ + of 1%. */ if (last_was_packetframe && last_was_renderframe) { int measuredframes = 0; static int packetframenum; + avgpacketframetime = 0; packetframetimes[packetframenum] = msec; for (int i = 0; i < 60; i++) @@ -585,7 +587,7 @@ Qcommon_Frame(int msec) } avgpacketframetime /= measuredframes; - avgpacketframetime += (avgpacketframetime * 0.02f); + avgpacketframetime += (avgpacketframetime * 0.01f); packetframenum++;