2022-02-19 02:31:16 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Implements the debug panels.
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
#include <core/stdafx.h>
|
2022-04-09 16:16:40 +02:00
|
|
|
#include <tier1/cvar.h>
|
2022-02-28 01:01:40 +01:00
|
|
|
#include <windows/id3dx.h>
|
|
|
|
#include <vpc/keyvalues.h>
|
2022-02-19 02:31:16 +01:00
|
|
|
#include <mathlib/color.h>
|
|
|
|
#include <vgui/vgui_debugpanel.h>
|
|
|
|
#include <vguimatsurface/MatSystemSurface.h>
|
2022-03-26 01:18:48 +01:00
|
|
|
#include <materialsystem/cmaterialsystem.h>
|
2022-02-19 02:31:16 +01:00
|
|
|
#include <engine/debugoverlay.h>
|
2022-05-20 11:52:19 +02:00
|
|
|
#include <engine/client/clientstate.h>
|
|
|
|
#include <engine/server/server.h>
|
2022-07-01 22:33:48 +01:00
|
|
|
#include <materialsystem/cmaterialglue.h>
|
2021-12-25 22:36:38 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-17 18:00:29 +01:00
|
|
|
void CLogSystem::Update(void)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-01-08 02:05:33 +01:00
|
|
|
if (!g_pMatSystemSurface)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-01-09 16:14:17 +01:00
|
|
|
if (cl_drawconsoleoverlay->GetBool())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-01-08 02:05:33 +01:00
|
|
|
DrawLog();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-01-09 16:14:17 +01:00
|
|
|
if (cl_showsimstats->GetBool())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-01-08 02:05:33 +01:00
|
|
|
DrawSimStats();
|
|
|
|
}
|
2022-01-09 16:14:17 +01:00
|
|
|
if (cl_showgpustats->GetBool())
|
2022-01-08 02:05:33 +01:00
|
|
|
{
|
|
|
|
DrawGPUStats();
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-02-28 01:01:40 +01:00
|
|
|
if (cl_showhoststats->GetBool())
|
|
|
|
{
|
|
|
|
DrawHostStats();
|
|
|
|
}
|
2022-07-01 22:33:48 +01:00
|
|
|
if (cl_showmaterialinfo->GetBool())
|
|
|
|
{
|
|
|
|
DrawCrosshairMaterial();
|
|
|
|
}
|
2022-01-08 02:05:33 +01:00
|
|
|
}
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-01-08 02:05:33 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-06-12 17:41:26 +02:00
|
|
|
void CLogSystem::AddLog(LogType_t type, string svMessage)
|
2022-01-08 02:05:33 +01:00
|
|
|
{
|
2022-02-17 18:00:29 +01:00
|
|
|
if (svMessage.length() > 0)
|
2022-01-08 02:05:33 +01:00
|
|
|
{
|
2022-02-19 02:31:16 +01:00
|
|
|
m_vLogs.push_back(LogMsg_t{ svMessage, 1024, type });
|
2022-01-08 02:05:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-17 18:00:29 +01:00
|
|
|
void CLogSystem::DrawLog(void)
|
2022-01-08 02:05:33 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
if (!m_vLogs.empty())
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
for (size_t i = 0; i < m_vLogs.size(); ++i)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
if (m_vLogs[i].m_nTicks >= 0)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
if (i < cl_consoleoverlay_lines->GetSizeT())
|
2022-02-28 01:01:40 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
float fadepct = fminf(static_cast<float>(m_vLogs[i].m_nTicks) / 255.f, 4.f); // TODO [ AMOS ]: register a ConVar for this!
|
|
|
|
float ptc = static_cast<int>(ceilf(fadepct * 100.f));
|
|
|
|
int alpha = static_cast<int>(ptc);
|
|
|
|
int x = cl_consoleoverlay_offset_x->GetInt();
|
|
|
|
int y = cl_consoleoverlay_offset_y->GetInt() + (m_nFontHeight * i);
|
|
|
|
Color c = GetLogColorForType(m_vLogs[i].m_type);
|
|
|
|
|
|
|
|
if (cl_consoleoverlay_invert_rect_x->GetBool())
|
|
|
|
{
|
|
|
|
x = g_nWindowWidth - cl_consoleoverlay_offset_x->GetInt();
|
|
|
|
}
|
|
|
|
if (cl_consoleoverlay_invert_rect_y->GetBool())
|
|
|
|
{
|
|
|
|
y = g_nWindowHeight - cl_consoleoverlay_offset_y->GetInt();
|
|
|
|
y += m_nFontHeight * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, x, y, c.r(), c.g(), c.b(), alpha, m_vLogs[i].m_svMessage.c_str());
|
2022-02-28 01:01:40 +01:00
|
|
|
}
|
2022-06-09 13:30:21 +02:00
|
|
|
else
|
2022-02-28 01:01:40 +01:00
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
m_vLogs.erase(m_vLogs.begin());
|
|
|
|
continue;
|
2022-02-28 01:01:40 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 13:30:21 +02:00
|
|
|
m_vLogs[i].m_nTicks--;
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-09 13:30:21 +02:00
|
|
|
m_vLogs.erase(m_vLogs.begin() + i);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 01:01:40 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CLogSystem::DrawHostStats(void) const
|
|
|
|
{
|
|
|
|
int nWidth = cl_hoststats_offset_x->GetInt();
|
|
|
|
int nHeight = cl_hoststats_offset_y->GetInt();
|
|
|
|
static Color c = { 255, 255, 255, 255 };
|
|
|
|
|
|
|
|
if (cl_hoststats_invert_rect_x->GetBool())
|
|
|
|
{
|
|
|
|
nWidth = g_nWindowWidth - nWidth;
|
|
|
|
}
|
|
|
|
if (cl_hoststats_invert_rect_y->GetBool())
|
|
|
|
{
|
|
|
|
nHeight = g_nWindowHeight - nHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), (char*)m_pszCon_NPrintf_Buf);
|
|
|
|
}
|
|
|
|
|
2022-01-08 02:05:33 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-17 18:00:29 +01:00
|
|
|
void CLogSystem::DrawSimStats(void) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-02-28 01:01:40 +01:00
|
|
|
int nWidth = cl_simstats_offset_x->GetInt();
|
|
|
|
int nHeight = cl_simstats_offset_y->GetInt();
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
static Color c = { 255, 255, 255, 255 };
|
2022-01-08 02:05:33 +01:00
|
|
|
static const char* szLogbuf[4096]{};
|
2022-01-09 16:14:17 +01:00
|
|
|
snprintf((char*)szLogbuf, 4096, "Server Frame: (%d) Client Frame: (%d) Render Frame: (%d)\n",
|
2022-05-20 20:14:39 +02:00
|
|
|
g_pServer->GetTick(), g_pClientState->GetClientTickCount(), *render_tickcount);
|
2022-01-08 02:05:33 +01:00
|
|
|
|
2022-02-28 01:01:40 +01:00
|
|
|
if (cl_simstats_invert_rect_x->GetBool())
|
|
|
|
{
|
|
|
|
nWidth = g_nWindowWidth - nWidth;
|
|
|
|
}
|
|
|
|
if (cl_simstats_invert_rect_y->GetBool())
|
|
|
|
{
|
|
|
|
nHeight = g_nWindowHeight - nHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), (char*)szLogbuf);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-08 02:05:33 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-17 18:00:29 +01:00
|
|
|
void CLogSystem::DrawGPUStats(void) const
|
2022-01-08 02:05:33 +01:00
|
|
|
{
|
2022-02-28 01:01:40 +01:00
|
|
|
int nWidth = cl_gpustats_offset_x->GetInt();
|
|
|
|
int nHeight = cl_gpustats_offset_y->GetInt();
|
|
|
|
|
2022-01-12 02:53:07 +01:00
|
|
|
static Color c = { 255, 255, 255, 255 };
|
2022-01-08 02:05:33 +01:00
|
|
|
static const char* szLogbuf[4096]{};
|
|
|
|
snprintf((char*)szLogbuf, 4096, "%8d/%8d/%8dkiB unusable/unfree/total GPU Streaming Texture memory\n",
|
|
|
|
*unusable_streaming_tex_memory / 1024, *unfree_streaming_tex_memory / 1024, *unusable_streaming_tex_memory / 1024);
|
|
|
|
|
2022-02-28 01:01:40 +01:00
|
|
|
if (cl_gpustats_invert_rect_x->GetBool())
|
|
|
|
{
|
|
|
|
nWidth = g_nWindowWidth - nWidth;
|
|
|
|
}
|
|
|
|
if (cl_gpustats_invert_rect_y->GetBool())
|
|
|
|
{
|
|
|
|
nHeight = g_nWindowHeight - nHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, nWidth, nHeight, c.r(), c.g(), c.b(), c.a(), (char*)szLogbuf);
|
2022-01-08 02:05:33 +01:00
|
|
|
}
|
|
|
|
|
2022-07-01 22:33:48 +01:00
|
|
|
void CLogSystem::DrawCrosshairMaterial(void) const
|
|
|
|
{
|
|
|
|
CMaterialGlue* material = GetMaterialAtCrossHair();
|
|
|
|
if (material)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static Color c = { 255, 255, 255, 255 };
|
|
|
|
static const char* szLogbuf[4096]{};
|
|
|
|
snprintf((char*)szLogbuf, 4096, "name: %s\nguid: %llx\ndimensions: %d x %d\nsurface: %s/%s\nsig: %i",
|
|
|
|
material->m_pszName,
|
|
|
|
material->m_GUID,
|
|
|
|
material->m_iWidth, material->m_iHeight,
|
|
|
|
material->m_pszSurfaceName1, material->m_pszSurfaceName2,
|
|
|
|
material->m_UnknownSignature);
|
|
|
|
|
|
|
|
CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, 0x13, m_nFontHeight, cl_materialinfo_offset_x->GetInt(), cl_materialinfo_offset_y->GetInt(), c.r(), c.g(), c.b(), c.a(), (char*)szLogbuf);
|
|
|
|
}
|
|
|
|
|
2022-01-08 02:05:33 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose:
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-02-19 02:31:16 +01:00
|
|
|
Color CLogSystem::GetLogColorForType(LogType_t type) const
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2022-01-12 02:53:07 +01:00
|
|
|
case LogType_t::SCRIPT_SERVER:
|
2022-02-17 18:00:29 +01:00
|
|
|
return { cl_conoverlay_script_server_clr->GetColor() };
|
2022-01-12 02:53:07 +01:00
|
|
|
case LogType_t::SCRIPT_CLIENT:
|
2022-02-17 18:00:29 +01:00
|
|
|
return { cl_conoverlay_script_client_clr->GetColor() };
|
2022-01-12 02:53:07 +01:00
|
|
|
case LogType_t::SCRIPT_UI:
|
2022-02-17 18:00:29 +01:00
|
|
|
return { cl_conoverlay_script_ui_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_SERVER:
|
|
|
|
return { cl_conoverlay_native_server_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_CLIENT:
|
|
|
|
return { cl_conoverlay_native_client_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_UI:
|
|
|
|
return { cl_conoverlay_native_ui_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_ENGINE:
|
|
|
|
return { cl_conoverlay_native_engine_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_FS:
|
|
|
|
return { cl_conoverlay_native_fs_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_RTECH:
|
|
|
|
return { cl_conoverlay_native_rtech_clr->GetColor() };
|
|
|
|
case LogType_t::NATIVE_MS:
|
2022-02-18 14:17:14 +01:00
|
|
|
return { cl_conoverlay_native_ms_clr->GetColor() };
|
2022-02-17 18:00:29 +01:00
|
|
|
case LogType_t::NETCON_S:
|
|
|
|
return { cl_conoverlay_netcon_clr->GetColor() };
|
|
|
|
case LogType_t::WARNING_C:
|
|
|
|
return { cl_conoverlay_warning_clr->GetColor() };
|
|
|
|
case LogType_t::ERROR_C:
|
|
|
|
return { cl_conoverlay_error_clr->GetColor() };
|
2022-01-12 02:53:07 +01:00
|
|
|
default:
|
2022-02-17 18:00:29 +01:00
|
|
|
return { cl_conoverlay_native_engine_clr->GetColor() };
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
CLogSystem g_pLogSystem;
|