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>
2020-09-26 19:41:58 +00:00
# include <engine/shared/config.h>
2010-05-29 07:25:38 +00:00
# include <engine/textrender.h>
2008-08-27 15:48:50 +00:00
2020-09-26 19:41:58 +00:00
# include <game/generated/protocol.h>
2008-08-27 15:48:50 +00:00
2020-09-26 19:41:58 +00:00
# include <game/client/gameclient.h>
2022-05-29 16:33:38 +00:00
# include <game/client/prediction/entities/character.h>
# include <game/localization.h>
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
# include "debughud.h"
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
void CDebugHud : : RenderNetCorrections ( )
2008-08-27 15:48:50 +00:00
{
2010-09-12 10:55:37 +00:00
if ( ! g_Config . m_Debug | | g_Config . m_DbgGraphs | | ! m_pClient - > m_Snap . m_pLocalCharacter | | ! m_pClient - > m_Snap . m_pLocalPrevCharacter )
2008-08-27 15:48:50 +00:00
return ;
2023-08-05 21:18:08 +00:00
const float Height = 300.0f ;
const float Width = Height * Graphics ( ) - > ScreenAspect ( ) ;
Graphics ( ) - > MapScreen ( 0.0f , 0.0f , Width , Height ) ;
const float Velspeed = length ( vec2 ( m_pClient - > m_Snap . m_pLocalCharacter - > m_VelX / 256.0f , m_pClient - > m_Snap . m_pLocalCharacter - > m_VelY / 256.0f ) ) * Client ( ) - > GameTickSpeed ( ) ;
const float VelspeedX = m_pClient - > m_Snap . m_pLocalCharacter - > m_VelX / 256.0f * Client ( ) - > GameTickSpeed ( ) ;
const float VelspeedY = m_pClient - > m_Snap . m_pLocalCharacter - > m_VelY / 256.0f * Client ( ) - > GameTickSpeed ( ) ;
const float Ramp = VelocityRamp ( Velspeed , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampStart , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampRange , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampCurvature ) ;
const CCharacter * pCharacter = m_pClient - > m_GameWorld . GetCharacterByID ( m_pClient - > m_Snap . m_LocalClientID ) ;
2011-04-13 18:37:12 +00:00
2023-08-05 21:18:08 +00:00
const float FontSize = 5.0f ;
const float LineHeight = FontSize + 1.0f ;
2011-04-13 18:37:12 +00:00
2023-08-05 21:18:08 +00:00
float y = 50.0f ;
char aBuf [ 128 ] ;
const auto & & RenderRow = [ & ] ( const char * pLabel , const char * pValue ) {
TextRender ( ) - > Text ( Width - 100.0f , y , FontSize , pLabel ) ;
TextRender ( ) - > Text ( Width - 10.0f - TextRender ( ) - > TextWidth ( FontSize , pValue ) , y , FontSize , pValue ) ;
y + = LineHeight ;
} ;
2010-08-13 01:07:51 +00:00
2023-08-05 21:18:08 +00:00
TextRender ( ) - > TextColor ( TextRender ( ) - > DefaultTextColor ( ) ) ;
2010-08-13 01:07:51 +00:00
2022-06-15 08:52:29 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.0f Bps " , Velspeed / 32 ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Velspeed: " , aBuf ) ;
2022-06-15 08:52:29 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.0f Bps " , VelspeedX / 32 * Ramp ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Velspeed.x * Ramp: " , aBuf ) ;
2022-06-15 08:52:29 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.0f Bps " , VelspeedY / 32 ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Velspeed.y: " , aBuf ) ;
2010-08-13 01:07:51 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.2f " , Ramp ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Ramp: " , aBuf ) ;
str_format ( aBuf , sizeof ( aBuf ) , " %d " , pCharacter = = nullptr ? - 1 : pCharacter - > m_TeleCheckpoint ) ;
RenderRow ( " Checkpoint: " , aBuf ) ;
str_format ( aBuf , sizeof ( aBuf ) , " %d " , pCharacter = = nullptr ? - 1 : pCharacter - > m_TuneZone ) ;
RenderRow ( " Tune zone: " , aBuf ) ;
2022-03-21 06:10:44 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.2f " , m_pClient - > m_Snap . m_pLocalCharacter - > m_X / 32.0f ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Pos.x: " , aBuf ) ;
2022-03-21 06:10:44 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.2f " , m_pClient - > m_Snap . m_pLocalCharacter - > m_Y / 32.0f ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Pos.y: " , aBuf ) ;
2017-04-24 19:05:36 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d " , m_pClient - > m_Snap . m_pLocalCharacter - > m_Angle ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Angle: " , aBuf ) ;
2010-08-13 01:07:51 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %d " , m_pClient - > NetobjNumCorrections ( ) ) ;
2023-08-05 21:18:08 +00:00
RenderRow ( " Netobj corrections " , aBuf ) ;
RenderRow ( " on: " , m_pClient - > NetobjCorrectedOn ( ) ) ;
2008-08-27 15:48:50 +00:00
}
2010-05-29 07:25:38 +00:00
void CDebugHud : : RenderTuning ( )
2008-08-27 15:48:50 +00:00
{
// render tuning debugging
2010-05-29 07:25:38 +00:00
if ( ! g_Config . m_DbgTuning )
2008-08-27 15:48:50 +00:00
return ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
CTuningParams StandardTuning ;
2011-04-13 18:37:12 +00:00
2020-09-26 19:41:58 +00:00
Graphics ( ) - > MapScreen ( 0 , 0 , 300 * Graphics ( ) - > ScreenAspect ( ) , 300 ) ;
2011-04-13 18:37:12 +00:00
2014-04-18 12:37:40 +00:00
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 + + )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
char aBuf [ 128 ] ;
float Current , Standard ;
2022-06-30 22:36:32 +00:00
m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . Get ( i , & Current ) ;
2010-05-29 07:25:38 +00:00
StandardTuning . Get ( i , & Standard ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
if ( Standard = = Current )
2020-09-26 19:41:58 +00:00
TextRender ( ) - > TextColor ( 1 , 1 , 1 , 1.0f ) ;
2008-08-27 15:48:50 +00:00
else
2020-09-26 19:41:58 +00:00
TextRender ( ) - > TextColor ( 1 , 0.25f , 0.25f , 1.0f ) ;
2008-08-27 15:48:50 +00:00
float w ;
float x = 5.0f ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.2f " , Standard ) ;
2008-08-27 15:48:50 +00:00
x + = 20.0f ;
2023-02-17 17:13:20 +00:00
w = TextRender ( ) - > TextWidth ( 5 , aBuf , - 1 , - 1.0f ) ;
TextRender ( ) - > Text ( x - w , y + Count * 6 , 5 , aBuf , - 1.0f ) ;
2008-08-27 15:48:50 +00:00
2010-05-29 07:25:38 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " %.2f " , Current ) ;
2008-08-27 15:48:50 +00:00
x + = 20.0f ;
2023-02-17 17:13:20 +00:00
w = TextRender ( ) - > TextWidth ( 5 , aBuf , - 1 , - 1.0f ) ;
TextRender ( ) - > Text ( x - w , y + Count * 6 , 5 , aBuf , - 1.0f ) ;
2008-08-27 15:48:50 +00:00
x + = 5.0f ;
2023-02-17 17:13:20 +00:00
TextRender ( ) - > Text ( x , y + Count * 6 , 5 , CTuningParams : : Name ( i ) , - 1.0f ) ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
Count + + ;
2008-08-27 15:48:50 +00:00
}
2011-04-13 18:37:12 +00:00
2022-04-14 12:07:01 +00:00
// Rander Velspeed.X*Ramp Graphs
2022-04-14 11:31:00 +00:00
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 ;
2022-06-30 22:36:32 +00:00
CTuningParams * pClientTuning = & m_pClient - > m_aTuning [ g_Config . m_ClDummy ] ;
2022-04-14 11:31:00 +00:00
const int StepSizeRampGraph = 270 ;
const int StepSizeZoomedInGraph = 14 ;
2022-06-30 22:36:32 +00:00
if ( m_OldVelrampStart ! = pClientTuning - > m_VelrampStart | | m_OldVelrampRange ! = pClientTuning - > m_VelrampRange | | m_OldVelrampCurvature ! = pClientTuning - > m_VelrampCurvature )
2008-08-27 15:48:50 +00:00
{
2022-06-30 22:36:32 +00:00
m_OldVelrampStart = pClientTuning - > m_VelrampStart ;
m_OldVelrampRange = pClientTuning - > m_VelrampRange ;
m_OldVelrampCurvature = pClientTuning - > m_VelrampCurvature ;
2022-04-14 11:31:00 +00:00
m_RampGraph . Init ( 0.0f , 0.0f ) ;
m_SpeedTurningPoint = 0 ;
float pv = 1 ;
2022-08-12 12:01:46 +00:00
for ( size_t i = 0 ; i < CGraph : : MAX_VALUES ; i + + )
2022-04-14 11:31:00 +00:00
{
// 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 ;
2022-06-30 22:36:32 +00:00
float Ramp = VelocityRamp ( Speed , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampStart , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampRange , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampCurvature ) ;
2022-04-14 11:31:00 +00:00
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 ;
}
2022-08-12 11:58:07 +00:00
m_RampGraph . Scale ( ) ;
2022-04-14 11:31:00 +00:00
m_ZoomedInGraph . Init ( 0.0f , 0.0f ) ;
pv = 1 ;
MiddleOfZoomedInGraph = m_SpeedTurningPoint ;
2022-08-12 12:01:46 +00:00
for ( size_t i = 0 ; i < CGraph : : MAX_VALUES ; i + + )
2022-04-14 11:31:00 +00:00
{
// 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 ;
2022-06-30 22:36:32 +00:00
float Ramp = VelocityRamp ( Speed , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampStart , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampRange , m_pClient - > m_aTuning [ g_Config . m_ClDummy ] . m_VelrampCurvature ) ;
2022-04-14 11:31:00 +00:00
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 )
{
2022-08-12 12:23:50 +00:00
m_ZoomedInGraph . SetMin ( RampedSpeed ) ;
2022-04-14 11:31:00 +00:00
}
pv = RampedSpeed ;
}
2022-08-12 11:58:07 +00:00
m_ZoomedInGraph . Scale ( ) ;
2008-08-27 15:48:50 +00:00
}
2022-04-14 11:31:00 +00:00
char aBuf [ 128 ] ;
str_format ( aBuf , sizeof ( aBuf ) , " Velspeed.X*Ramp in Bps (Velspeed %d to %d) " , StepSizeRampGraph / 32 , 128 * StepSizeRampGraph / 32 ) ;
2023-08-05 21:26:11 +00:00
m_RampGraph . Render ( Graphics ( ) , TextRender ( ) , GraphX , GraphY - GraphH - sp , GraphW , GraphH , aBuf ) ;
2022-04-14 11:31:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " Max Velspeed before it ramps off: %.2f Bps " , m_SpeedTurningPoint / 32 ) ;
2023-02-17 17:13:20 +00:00
TextRender ( ) - > Text ( GraphX , GraphY - sp - GraphH - 12 , 12 , aBuf , - 1.0f ) ;
2022-04-14 11:31:00 +00:00
str_format ( aBuf , sizeof ( aBuf ) , " Zoomed in on turning point (Velspeed %d to %d) " , ( ( int ) MiddleOfZoomedInGraph - 64 * StepSizeZoomedInGraph ) / 32 , ( ( int ) MiddleOfZoomedInGraph + 64 * StepSizeZoomedInGraph ) / 32 ) ;
2023-08-05 21:26:11 +00:00
m_ZoomedInGraph . Render ( Graphics ( ) , TextRender ( ) , GraphX , GraphY , GraphW , GraphH , aBuf ) ;
2020-09-26 19:41:58 +00:00
TextRender ( ) - > TextColor ( 1 , 1 , 1 , 1 ) ;
2008-08-27 15:48:50 +00:00
}
2020-11-03 07:03:24 +00:00
void CDebugHud : : RenderHint ( )
{
if ( ! g_Config . m_Debug )
return ;
2023-08-02 20:14:39 +00:00
const float Height = 300.0f ;
const float Width = Height * Graphics ( ) - > ScreenAspect ( ) ;
Graphics ( ) - > MapScreen ( 0.0f , 0.0f , Width , Height ) ;
const float FontSize = 5.0f ;
const float Spacing = 5.0f ;
TextRender ( ) - > TextColor ( TextRender ( ) - > DefaultTextColor ( ) ) ;
TextRender ( ) - > Text ( Spacing , Height - FontSize - Spacing , FontSize , Localize ( " Debug mode enabled. Press Ctrl+Shift+D to disable debug mode. " ) ) ;
2020-11-03 07:03:24 +00:00
}
2010-05-29 07:25:38 +00:00
void CDebugHud : : OnRender ( )
2008-08-27 15:48:50 +00:00
{
2010-05-29 07:25:38 +00:00
RenderTuning ( ) ;
RenderNetCorrections ( ) ;
2020-11-03 07:03:24 +00:00
RenderHint ( ) ;
2008-08-27 15:48:50 +00:00
}