MCPcopy Create free account
hub / github.com/ddnet/ddnet / Scale

Method Scale

src/engine/client/graph.cpp:38–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void CGraph::Scale(int64_t WantedTotalTime)
39{
40 // Scale X axis for wanted total time
41 if(m_Entries.First() != nullptr)
42 {
43 const int64_t EndTime = m_Entries.Last()->m_Time;
44 bool ScaleTotalTime = false;
45 m_pFirstScaled = nullptr;
46
47 if(m_Entries.First()->m_Time >= EndTime - WantedTotalTime)
48 {
49 m_pFirstScaled = m_Entries.First();
50 }
51 else
52 {
53 m_pFirstScaled = m_Entries.Last();
54 while(m_pFirstScaled)
55 {
56 CEntry *pPrev = m_Entries.Prev(m_pFirstScaled);
57 if(pPrev == nullptr)
58 break;
59 if(pPrev->m_Time < EndTime - WantedTotalTime)
60 {
61 // Scale based on actual total time instead of based on wanted total time,
62 // to avoid flickering last segment due to rounding errors.
63 ScaleTotalTime = true;
64 break;
65 }
66 m_pFirstScaled = pPrev;
67 }
68 }
69
70 m_RenderedTotalTime = ScaleTotalTime ? (EndTime - m_pFirstScaled->m_Time) : WantedTotalTime;
71
72 // Ensure that color is applied to first line segment
73 if(m_pFirstScaled)
74 {
75 m_pFirstScaled->m_ApplyColor = true;
76 CEntry *pNext = m_Entries.Next(m_pFirstScaled);
77 if(pNext != nullptr)
78 {
79 pNext->m_ApplyColor = true;
80 }
81 }
82 }
83 else
84 {
85 m_pFirstScaled = nullptr;
86 m_RenderedTotalTime = 0;
87 }
88
89 // Scale Y axis
90 m_Average = 0.0f;
91 size_t NumValues = 0;
92 m_MinAxis = m_MinRange;
93 m_MaxAxis = m_MaxRange;
94 m_MinValue = std::numeric_limits<float>::max();
95 m_MaxValue = std::numeric_limits<float>::min();

Callers 2

RenderTuningMethod · 0.80
RenderGraphsMethod · 0.80

Calls 4

FirstMethod · 0.45
LastMethod · 0.45
PrevMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected