From 8e0a935d5cd97d7b9ba5dd985a383d179e1813d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 12 Aug 2022 13:58:07 +0200 Subject: [PATCH] Combine `CGraph::ScaleMin` and `ScaleMax` into `Scale` As the methods are always called at the same time, they can be combined. This also improves the performance, as the array only needs to be iterated once. --- src/engine/client/client.cpp | 32 ++++++++----------------- src/engine/client/client.h | 4 +--- src/game/client/components/debughud.cpp | 6 ++--- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 823005dcd..f57dab612 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -89,25 +89,16 @@ void CGraph::Init(float Min, float Max) m_Index = 0; } -void CGraph::ScaleMax() +void CGraph::Scale() { - int i = 0; - m_Max = m_MaxRange; - for(i = 0; i < MAX_VALUES; i++) - { - if(m_aValues[i] > m_Max) - m_Max = m_aValues[i]; - } -} - -void CGraph::ScaleMin() -{ - int i = 0; m_Min = m_MinRange; - for(i = 0; i < MAX_VALUES; i++) + m_Max = m_MaxRange; + for(auto Value : m_aValues) { - if(m_aValues[i] < m_Min) - m_Min = m_aValues[i]; + if(Value > m_Max) + m_Max = Value; + else if(Value < m_Min) + m_Min = Value; } } @@ -1143,14 +1134,11 @@ void CClient::DebugRender() float sp = Graphics()->ScreenWidth() / 100.0f; float x = Graphics()->ScreenWidth() - w - sp; - m_FpsGraph.ScaleMax(); - m_FpsGraph.ScaleMin(); + m_FpsGraph.Scale(); m_FpsGraph.Render(Graphics(), m_DebugFont, x, sp * 5, w, h, "FPS"); - m_InputtimeMarginGraph.ScaleMin(); - m_InputtimeMarginGraph.ScaleMax(); + m_InputtimeMarginGraph.Scale(); m_InputtimeMarginGraph.Render(Graphics(), m_DebugFont, x, sp * 5 + h + sp, w, h, "Prediction Margin"); - m_GametimeMarginGraph.ScaleMin(); - m_GametimeMarginGraph.ScaleMax(); + m_GametimeMarginGraph.Scale(); m_GametimeMarginGraph.Render(Graphics(), m_DebugFont, x, sp * 5 + h + sp + h + sp, w, h, "Gametime Margin"); } } diff --git a/src/engine/client/client.h b/src/engine/client/client.h index e808389e0..fe8fb8077 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -56,9 +56,7 @@ public: void Init(float Min, float Max); - void ScaleMax(); - void ScaleMin(); - + void Scale(); void Add(float v, float r, float g, float b); bool InsertAt(int i, float v, float r, float g, float b); void Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription); diff --git a/src/game/client/components/debughud.cpp b/src/game/client/components/debughud.cpp index 2d4cb8d39..e5ad458d2 100644 --- a/src/game/client/components/debughud.cpp +++ b/src/game/client/components/debughud.cpp @@ -162,8 +162,7 @@ void CDebugHud::RenderTuning() } pv = RampedSpeed; } - m_RampGraph.ScaleMin(); - m_RampGraph.ScaleMax(); + m_RampGraph.Scale(); m_ZoomedInGraph.Init(0.0f, 0.0f); pv = 1; @@ -189,8 +188,7 @@ void CDebugHud::RenderTuning() } pv = RampedSpeed; } - m_ZoomedInGraph.ScaleMin(); - m_ZoomedInGraph.ScaleMax(); + m_ZoomedInGraph.Scale(); } char aBuf[128]; str_format(aBuf, sizeof(aBuf), "Velspeed.X*Ramp in Bps (Velspeed %d to %d)", StepSizeRampGraph / 32, 128 * StepSizeRampGraph / 32);