ddnet/src/game/client/components/debughud.cpp

230 lines
9 KiB
C++
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#include <engine/graphics.h>
#include <engine/shared/config.h>
2010-05-29 07:25:38 +00:00
#include <engine/textrender.h>
2010-05-29 07:25:38 +00:00
#include <game/generated/client_data.h>
#include <game/generated/protocol.h>
2010-05-29 07:25:38 +00:00
#include <game/layers.h>
2010-05-29 07:25:38 +00:00
#include <game/client/animstate.h>
#include <game/client/gameclient.h>
2010-05-29 07:25:38 +00:00
#include <game/client/render.h>
2010-05-29 07:25:38 +00:00
//#include "controls.h"
//#include "camera.h"
#include "debughud.h"
2010-05-29 07:25:38 +00:00
void CDebugHud::RenderNetCorrections()
{
if(!g_Config.m_Debug || g_Config.m_DbgGraphs || !m_pClient->m_Snap.m_pLocalCharacter || !m_pClient->m_Snap.m_pLocalPrevCharacter)
return;
float Width = 300 * Graphics()->ScreenAspect();
Graphics()->MapScreen(0, 0, Width, 300);
/*float speed = distance(vec2(netobjects.local_prev_character->x, netobjects.local_prev_character->y),
vec2(netobjects.local_character->x, netobjects.local_character->y));*/
const float TicksPerSecond = 50.0f;
float Velspeed = length(vec2(m_pClient->m_Snap.m_pLocalCharacter->m_VelX / 256.0f, m_pClient->m_Snap.m_pLocalCharacter->m_VelY / 256.0f)) * TicksPerSecond;
float VelspeedX = m_pClient->m_Snap.m_pLocalCharacter->m_VelX / 256.0f * TicksPerSecond;
float VelspeedY = m_pClient->m_Snap.m_pLocalCharacter->m_VelY / 256.0f * TicksPerSecond;
float Ramp = VelocityRamp(Velspeed, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampStart, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampRange, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampCurvature);
const char *apStrings[] = {"velspeed:", "velspeed.x*ramp:", "velspeed.y:", "ramp:", "checkpoint:", "Pos", " x:", " y:", "angle:", "netobj corrections", " num:", " on:"};
const int Num = std::size(apStrings);
const float LineHeight = 6.0f;
const float Fontsize = 5.0f;
float x = Width - 100.0f, y = 50.0f;
for(int i = 0; i < Num; ++i)
TextRender()->Text(0, x, y + i * LineHeight, Fontsize, apStrings[i], -1.0f);
x = Width - 10.0f;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "%.2f Bps", Velspeed / 32);
float w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += LineHeight;
str_format(aBuf, sizeof(aBuf), "%.2f Bps", VelspeedX / 32 * Ramp);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += LineHeight;
str_format(aBuf, sizeof(aBuf), "%.2f Bps", VelspeedY / 32);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += LineHeight;
str_format(aBuf, sizeof(aBuf), "%.2f", Ramp);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
2020-08-15 23:51:35 +00:00
y += LineHeight;
const CCharacter *pCharacter = m_pClient->m_GameWorld.GetCharacterByID(m_pClient->m_Snap.m_LocalClientID);
if(pCharacter)
str_format(aBuf, sizeof(aBuf), "%d", pCharacter->m_TeleCheckpoint);
else
str_copy(aBuf, "-1", sizeof(aBuf));
2020-08-15 23:51:35 +00:00
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += 2 * LineHeight;
2022-03-21 06:10:44 +00:00
str_format(aBuf, sizeof(aBuf), "%.2f", m_pClient->m_Snap.m_pLocalCharacter->m_X / 32.0f);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += LineHeight;
2022-03-21 06:10:44 +00:00
str_format(aBuf, sizeof(aBuf), "%.2f", m_pClient->m_Snap.m_pLocalCharacter->m_Y / 32.0f);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
2017-04-24 19:05:36 +00:00
y += LineHeight;
str_format(aBuf, sizeof(aBuf), "%d", m_pClient->m_Snap.m_pLocalCharacter->m_Angle);
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += 2 * LineHeight;
str_format(aBuf, sizeof(aBuf), "%d", m_pClient->NetobjNumCorrections());
w = TextRender()->TextWidth(0, Fontsize, aBuf, -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, aBuf, -1.0f);
y += LineHeight;
w = TextRender()->TextWidth(0, Fontsize, m_pClient->NetobjCorrectedOn(), -1, -1.0f);
TextRender()->Text(0, x - w, y, Fontsize, m_pClient->NetobjCorrectedOn(), -1.0f);
}
2010-05-29 07:25:38 +00:00
void CDebugHud::RenderTuning()
{
// render tuning debugging
2010-05-29 07:25:38 +00:00
if(!g_Config.m_DbgTuning)
return;
2010-05-29 07:25:38 +00:00
CTuningParams StandardTuning;
Graphics()->MapScreen(0, 0, 300 * Graphics()->ScreenAspect(), 300);
float y = 27.0f;
2010-05-29 07:25:38 +00:00
int Count = 0;
2022-01-22 16:34:23 +00:00
for(int i = 0; i < CTuningParams::Num(); i++)
{
2010-05-29 07:25:38 +00:00
char aBuf[128];
float Current, Standard;
m_pClient->m_Tuning[g_Config.m_ClDummy].Get(i, &Current);
2010-05-29 07:25:38 +00:00
StandardTuning.Get(i, &Standard);
2010-05-29 07:25:38 +00:00
if(Standard == Current)
TextRender()->TextColor(1, 1, 1, 1.0f);
else
TextRender()->TextColor(1, 0.25f, 0.25f, 1.0f);
float w;
float x = 5.0f;
2010-05-29 07:25:38 +00:00
str_format(aBuf, sizeof(aBuf), "%.2f", Standard);
x += 20.0f;
w = TextRender()->TextWidth(0, 5, aBuf, -1, -1.0f);
TextRender()->Text(0x0, x - w, y + Count * 6, 5, aBuf, -1.0f);
2010-05-29 07:25:38 +00:00
str_format(aBuf, sizeof(aBuf), "%.2f", Current);
x += 20.0f;
w = TextRender()->TextWidth(0, 5, aBuf, -1, -1.0f);
TextRender()->Text(0x0, x - w, y + Count * 6, 5, aBuf, -1.0f);
x += 5.0f;
2022-01-22 16:34:23 +00:00
TextRender()->Text(0x0, x, y + Count * 6, 5, CTuningParams::ms_apNames[i], -1.0f);
2010-05-29 07:25:38 +00:00
Count++;
}
// Rander Velspeed.X*Ramp Graphs
Graphics()->MapScreen(0, 0, Graphics()->ScreenWidth(), Graphics()->ScreenHeight());
float GraphW = Graphics()->ScreenWidth() / 4.0f;
float GraphH = Graphics()->ScreenHeight() / 6.0f;
float sp = Graphics()->ScreenWidth() / 100.0f;
float GraphX = GraphW;
float GraphY = Graphics()->ScreenHeight() - GraphH - sp;
CTuningParams *ClinetTuning = &m_pClient->m_Tuning[g_Config.m_ClDummy];
const int StepSizeRampGraph = 270;
const int StepSizeZoomedInGraph = 14;
if(m_OldVelrampStart != ClinetTuning->m_VelrampStart || m_OldVelrampRange != ClinetTuning->m_VelrampRange || m_OldVelrampCurvature != ClinetTuning->m_VelrampCurvature)
{
m_OldVelrampStart = ClinetTuning->m_VelrampStart;
m_OldVelrampRange = ClinetTuning->m_VelrampRange;
m_OldVelrampCurvature = ClinetTuning->m_VelrampCurvature;
m_RampGraph.Init(0.0f, 0.0f);
m_SpeedTurningPoint = 0;
float pv = 1;
// CGraph must be fed with exactly 128 values.
for(int i = 0; i < 128; i++)
{
// This is a calculation of the speed values per second on the X axis, from 270 to 34560 in steps of 270
float Speed = (i + 1) * StepSizeRampGraph;
float Ramp = VelocityRamp(Speed, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampStart, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampRange, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampCurvature);
float RampedSpeed = Speed * Ramp;
if(RampedSpeed >= pv)
{
m_RampGraph.InsertAt(i, RampedSpeed / 32, 0, 1, 0);
m_SpeedTurningPoint = Speed;
}
else
{
m_RampGraph.InsertAt(i, RampedSpeed / 32, 1, 0, 0);
}
pv = RampedSpeed;
}
m_RampGraph.ScaleMin();
m_RampGraph.ScaleMax();
m_ZoomedInGraph.Init(0.0f, 0.0f);
pv = 1;
MiddleOfZoomedInGraph = m_SpeedTurningPoint;
for(int i = 0; i < 128; i++)
{
// This is a calculation of the speed values per second on the X axis, from (MiddleOfZoomedInGraph - 64 * StepSize) to (MiddleOfZoomedInGraph + 64 * StepSize)
float Speed = MiddleOfZoomedInGraph - 64 * StepSizeZoomedInGraph + i * StepSizeZoomedInGraph;
float Ramp = VelocityRamp(Speed, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampStart, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampRange, m_pClient->m_Tuning[g_Config.m_ClDummy].m_VelrampCurvature);
float RampedSpeed = Speed * Ramp;
if(RampedSpeed >= pv)
{
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, 0, 1, 0);
m_SpeedTurningPoint = Speed;
}
else
{
m_ZoomedInGraph.InsertAt(i, RampedSpeed / 32, 1, 0, 0);
}
if(i == 0)
{
m_ZoomedInGraph.m_Min = m_ZoomedInGraph.m_MinRange = RampedSpeed;
}
pv = RampedSpeed;
}
m_ZoomedInGraph.ScaleMin();
m_ZoomedInGraph.ScaleMax();
}
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Velspeed.X*Ramp in Bps (Velspeed %d to %d)", StepSizeRampGraph / 32, 128 * StepSizeRampGraph / 32);
m_RampGraph.Render(Graphics(), Client()->GetDebugFont(), GraphX, GraphY - GraphH - sp, GraphW, GraphH, aBuf);
str_format(aBuf, sizeof(aBuf), "Max Velspeed before it ramps off: %.2f Bps", m_SpeedTurningPoint / 32);
TextRender()->Text(0x0, GraphX, GraphY - sp - GraphH - 12, 12, aBuf, -1.0f);
str_format(aBuf, sizeof(aBuf), "Zoomed in on turning point (Velspeed %d to %d)", ((int)MiddleOfZoomedInGraph - 64 * StepSizeZoomedInGraph) / 32, ((int)MiddleOfZoomedInGraph + 64 * StepSizeZoomedInGraph) / 32);
m_ZoomedInGraph.Render(Graphics(), Client()->GetDebugFont(), GraphX, GraphY, GraphW, GraphH, aBuf);
TextRender()->TextColor(1, 1, 1, 1);
}
2020-11-03 07:03:24 +00:00
void CDebugHud::RenderHint()
{
if(!g_Config.m_Debug)
return;
float Width = 300 * Graphics()->ScreenAspect();
Graphics()->MapScreen(0, 0, Width, 300);
TextRender()->TextColor(1, 1, 1, 1);
TextRender()->Text(0x0, 5, 290, 5, Localize("Debug mode enabled. Press Ctrl+Shift+D to disable debug mode."), -1.0f);
}
2010-05-29 07:25:38 +00:00
void CDebugHud::OnRender()
{
2010-05-29 07:25:38 +00:00
RenderTuning();
RenderNetCorrections();
2020-11-03 07:03:24 +00:00
RenderHint();
}