mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Use ColorRGBA
for CGraph
entry color
This commit is contained in:
parent
912355f9ec
commit
dc7fa1fbb2
|
@ -3017,7 +3017,7 @@ void CClient::Run()
|
|||
{
|
||||
// update frametime
|
||||
m_RenderFrameTime = (Now - m_LastRenderTime) / (float)time_freq();
|
||||
m_FpsGraph.Add(1.0f / m_RenderFrameTime, 1, 1, 1);
|
||||
m_FpsGraph.Add(1.0f / m_RenderFrameTime);
|
||||
|
||||
if(m_BenchmarkFile)
|
||||
{
|
||||
|
|
|
@ -27,28 +27,26 @@ void CGraph::Scale()
|
|||
{
|
||||
m_Min = m_MinRange;
|
||||
m_Max = m_MaxRange;
|
||||
for(auto Value : m_aValues)
|
||||
for(auto &Entry : m_aEntries)
|
||||
{
|
||||
if(Value > m_Max)
|
||||
m_Max = Value;
|
||||
else if(Value < m_Min)
|
||||
m_Min = Value;
|
||||
if(Entry.m_Value > m_Max)
|
||||
m_Max = Entry.m_Value;
|
||||
else if(Entry.m_Value < m_Min)
|
||||
m_Min = Entry.m_Value;
|
||||
}
|
||||
}
|
||||
|
||||
void CGraph::Add(float v, float r, float g, float b)
|
||||
void CGraph::Add(float Value, ColorRGBA Color)
|
||||
{
|
||||
m_Index = (m_Index + 1) % MAX_VALUES;
|
||||
InsertAt(m_Index, v, r, g, b);
|
||||
InsertAt(m_Index, Value, Color);
|
||||
}
|
||||
|
||||
void CGraph::InsertAt(size_t Index, float v, float r, float g, float b)
|
||||
void CGraph::InsertAt(size_t Index, float Value, ColorRGBA Color)
|
||||
{
|
||||
dbg_assert(Index < MAX_VALUES, "Index out of bounds");
|
||||
m_aValues[Index] = v;
|
||||
m_aColors[Index][0] = r;
|
||||
m_aColors[Index][1] = g;
|
||||
m_aColors[Index][2] = b;
|
||||
m_aEntries[Index].m_Value = Value;
|
||||
m_aEntries[Index].m_Color = Color;
|
||||
}
|
||||
|
||||
void CGraph::Render(IGraphics *pGraphics, ITextRender *pTextRender, float x, float y, float w, float h, const char *pDescription)
|
||||
|
@ -77,12 +75,12 @@ void CGraph::Render(IGraphics *pGraphics, ITextRender *pTextRender, float x, flo
|
|||
int i0 = (m_Index + i - 1) % MAX_VALUES;
|
||||
int i1 = (m_Index + i) % MAX_VALUES;
|
||||
|
||||
float v0 = (m_aValues[i0] - m_Min) / (m_Max - m_Min);
|
||||
float v1 = (m_aValues[i1] - m_Min) / (m_Max - m_Min);
|
||||
float v0 = (m_aEntries[i0].m_Value - m_Min) / (m_Max - m_Min);
|
||||
float v1 = (m_aEntries[i1].m_Value - m_Min) / (m_Max - m_Min);
|
||||
|
||||
IGraphics::CColorVertex aColorVertices[2] = {
|
||||
IGraphics::CColorVertex(0, m_aColors[i0][0], m_aColors[i0][1], m_aColors[i0][2], 0.75f),
|
||||
IGraphics::CColorVertex(1, m_aColors[i1][0], m_aColors[i1][1], m_aColors[i1][2], 0.75f)};
|
||||
IGraphics::CColorVertex(0, m_aEntries[i0].m_Color.r, m_aEntries[i0].m_Color.g, m_aEntries[i0].m_Color.b, m_aEntries[i0].m_Color.a),
|
||||
IGraphics::CColorVertex(1, m_aEntries[i1].m_Color.r, m_aEntries[i1].m_Color.g, m_aEntries[i1].m_Color.b, m_aEntries[i1].m_Color.a)};
|
||||
pGraphics->SetColorVertex(aColorVertices, std::size(aColorVertices));
|
||||
IGraphics::CLineItem LineItem2(x + a0 * w, y + h - v0 * h, x + a1 * w, y + h - v1 * h);
|
||||
pGraphics->LinesDraw(&LineItem2, 1);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#ifndef ENGINE_CLIENT_GRAPH_H
|
||||
#define ENGINE_CLIENT_GRAPH_H
|
||||
|
||||
#include <base/color.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class IGraphics;
|
||||
|
@ -18,10 +20,14 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
struct SEntry
|
||||
{
|
||||
float m_Value;
|
||||
ColorRGBA m_Color;
|
||||
};
|
||||
float m_Min, m_Max;
|
||||
float m_MinRange, m_MaxRange;
|
||||
float m_aValues[MAX_VALUES];
|
||||
float m_aColors[MAX_VALUES][3];
|
||||
SEntry m_aEntries[MAX_VALUES];
|
||||
size_t m_Index;
|
||||
|
||||
public:
|
||||
|
@ -30,8 +36,8 @@ public:
|
|||
void SetMax(float Max);
|
||||
|
||||
void Scale();
|
||||
void Add(float v, float r, float g, float b);
|
||||
void InsertAt(size_t Index, float v, float r, float g, float b);
|
||||
void Add(float Value, ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f));
|
||||
void InsertAt(size_t Index, float Value, ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f));
|
||||
void Render(IGraphics *pGraphics, ITextRender *pTextRender, float x, float y, float w, float h, const char *pDescription);
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ int64_t CSmoothTime::Get(int64_t Now)
|
|||
|
||||
int64_t r = c + (int64_t)((t - c) * a);
|
||||
|
||||
m_Graph.Add(a + 0.5f, 1, 1, 1);
|
||||
m_Graph.Add(a + 0.5f);
|
||||
|
||||
return r + GetMargin(Now);
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ void CSmoothTime::Update(CGraph *pGraph, int64_t Target, int TimeLeft, int Adjus
|
|||
{
|
||||
// ignore this ping spike
|
||||
UpdateTimer = 0;
|
||||
pGraph->Add(TimeLeft, 1, 1, 0);
|
||||
pGraph->Add(TimeLeft, ColorRGBA(1.0f, 1.0f, 0.0f, 0.75f));
|
||||
}
|
||||
else
|
||||
{
|
||||
pGraph->Add(TimeLeft, 1, 0, 0);
|
||||
pGraph->Add(TimeLeft, ColorRGBA(1.0f, 0.0f, 0.0f, 0.75f));
|
||||
if(m_aAdjustSpeed[AdjustDirection] < 30.0f)
|
||||
m_aAdjustSpeed[AdjustDirection] *= 2.0f;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ void CSmoothTime::Update(CGraph *pGraph, int64_t Target, int TimeLeft, int Adjus
|
|||
if(m_SpikeCounter)
|
||||
m_SpikeCounter--;
|
||||
|
||||
pGraph->Add(TimeLeft, 0, 1, 0);
|
||||
pGraph->Add(TimeLeft, ColorRGBA(0.0f, 1.0f, 0.0f, 0.75f));
|
||||
|
||||
m_aAdjustSpeed[AdjustDirection] *= 0.95f;
|
||||
if(m_aAdjustSpeed[AdjustDirection] < 2.0f)
|
||||
|
|
|
@ -187,12 +187,12 @@ void CDebugHud::RenderTuning()
|
|||
const float RampedSpeed = Speed * Ramp;
|
||||
if(RampedSpeed >= PreviousRampedSpeed)
|
||||
{
|
||||
m_RampGraph.InsertAt(i, RampedSpeed / 32, 0, 1, 0);
|
||||
m_RampGraph.InsertAt(i, RampedSpeed / 32, ColorRGBA(0.0f, 1.0f, 0.0f, 0.75f));
|
||||
m_SpeedTurningPoint = Speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_RampGraph.InsertAt(i, RampedSpeed / 32, 1, 0, 0);
|
||||
m_RampGraph.InsertAt(i, RampedSpeed / 32, ColorRGBA(1.0f, 0.0f, 0.0f, 0.75f));
|
||||
}
|
||||
PreviousRampedSpeed = RampedSpeed;
|
||||
}
|
||||
|
@ -209,12 +209,12 @@ void CDebugHud::RenderTuning()
|
|||
const float RampedSpeed = Speed * Ramp;
|
||||
if(RampedSpeed >= PreviousRampedSpeed)
|
||||
{
|
||||
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, 0, 1, 0);
|
||||
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, ColorRGBA(0.0f, 1.0f, 0.0f, 0.75f));
|
||||
m_SpeedTurningPoint = Speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, 1, 0, 0);
|
||||
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, ColorRGBA(1.0f, 0.0f, 0.0f, 0.75f));
|
||||
}
|
||||
if(i == 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue