diff --git a/r5dev/engine/host.cpp b/r5dev/engine/host.cpp index 230fdc6e..84e597d1 100644 --- a/r5dev/engine/host.cpp +++ b/r5dev/engine/host.cpp @@ -8,6 +8,9 @@ #include "core/stdafx.h" #include "tier0/frametask.h" #include "engine/host.h" +#ifndef DEDICATED +#include "vgui/vgui_debugpanel.h" +#endif // !DEDICATED /* ================== @@ -18,7 +21,7 @@ Runs all active servers */ void _Host_RunFrame(void* unused, float time) { - for (const auto& task : g_FrameTasks) + for (IFrameTask* const& task : g_FrameTasks) { task->RunFrame(); } @@ -28,6 +31,10 @@ void _Host_RunFrame(void* unused, float time) return task->IsFinished(); }), g_FrameTasks.end()); +#ifndef DEDICATED + g_pLogSystem.ShouldDraw(time); +#endif // !DEDICATED + return v_Host_RunFrame(unused, time); } diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index c4a68c9a..8ab15659 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -122,13 +122,16 @@ void ConVar::Init(void) const #ifndef DEDICATED cl_rcon_request_sendlogs = ConVar::Create("cl_rcon_request_sendlogs", "1" , FCVAR_RELEASE, "Request the rcon server to send console logs on connect.", false, 0.f, false, 0.f, nullptr, nullptr); - cl_drawconsoleoverlay = ConVar::Create("cl_drawconsoleoverlay" , "0" , FCVAR_DEVELOPMENTONLY, "Draws the RUI console overlay at the top of the screen.", false, 0.f, false, 0.f, nullptr, nullptr); + con_drawnotify = ConVar::Create("con_drawnotify" , "0" , FCVAR_DEVELOPMENTONLY, "Draws the RUI console overlay at the top of the screen.", false, 0.f, false, 0.f, nullptr, nullptr); cl_consoleoverlay_lines = ConVar::Create("cl_consoleoverlay_lines" , "3" , FCVAR_DEVELOPMENTONLY, "Number of lines of console output to draw.", true, 1.f, false, 0.f, nullptr, nullptr); cl_consoleoverlay_invert_rect_x = ConVar::Create("cl_consoleoverlay_invert_rect_x", "0" , FCVAR_DEVELOPMENTONLY, "Inverts the X rect for RUI console overlay.", false, 0.f, false, 0.f, nullptr, nullptr); cl_consoleoverlay_invert_rect_y = ConVar::Create("cl_consoleoverlay_invert_rect_y", "0" , FCVAR_DEVELOPMENTONLY, "Inverts the Y rect for RUI console overlay.", false, 0.f, false, 0.f, nullptr, nullptr); cl_consoleoverlay_offset_x = ConVar::Create("cl_consoleoverlay_offset_x" , "10", FCVAR_DEVELOPMENTONLY, "X offset for RUI console overlay.", false, 1.f, false, 50.f, nullptr, nullptr); cl_consoleoverlay_offset_y = ConVar::Create("cl_consoleoverlay_offset_y" , "10", FCVAR_DEVELOPMENTONLY, "Y offset for RUI console overlay.", false, 1.f, false, 50.f, nullptr, nullptr); + + con_notifytime = ConVar::Create("con_notifytime", "6", FCVAR_DEVELOPMENTONLY | FCVAR_MATERIAL_SYSTEM_THREAD, "How long to display recent console text to the upper part of the game window.", false, 1.f, false, 50.f, nullptr, nullptr); + cl_conoverlay_script_server_clr = ConVar::Create("cl_conoverlay_script_server_clr", "130 120 245 255", FCVAR_DEVELOPMENTONLY, "Script SERVER VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); cl_conoverlay_script_client_clr = ConVar::Create("cl_conoverlay_script_client_clr", "117 116 139 255", FCVAR_DEVELOPMENTONLY, "Script CLIENT VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); cl_conoverlay_script_ui_clr = ConVar::Create("cl_conoverlay_script_ui_clr" , "200 110 110 255", FCVAR_DEVELOPMENTONLY, "Script UI VM RUI console overlay log color.", false, 1.f, false, 50.f, nullptr, nullptr); diff --git a/r5dev/tier1/cvar.cpp b/r5dev/tier1/cvar.cpp index ba77993c..bdc40870 100644 --- a/r5dev/tier1/cvar.cpp +++ b/r5dev/tier1/cvar.cpp @@ -88,13 +88,15 @@ ConVar* bhit_abs_origin = nullptr; #ifndef DEDICATED ConVar* cl_rcon_request_sendlogs = nullptr; -ConVar* cl_drawconsoleoverlay = nullptr; +ConVar* con_drawnotify = nullptr; ConVar* cl_consoleoverlay_lines = nullptr; ConVar* cl_consoleoverlay_invert_rect_x = nullptr; ConVar* cl_consoleoverlay_invert_rect_y = nullptr; ConVar* cl_consoleoverlay_offset_x = nullptr; ConVar* cl_consoleoverlay_offset_y = nullptr; +ConVar* con_notifytime = nullptr; + ConVar* cl_conoverlay_script_server_clr = nullptr; ConVar* cl_conoverlay_script_client_clr = nullptr; ConVar* cl_conoverlay_script_ui_clr = nullptr; diff --git a/r5dev/tier1/cvar.h b/r5dev/tier1/cvar.h index 03864f14..a6f42923 100644 --- a/r5dev/tier1/cvar.h +++ b/r5dev/tier1/cvar.h @@ -83,13 +83,15 @@ extern ConVar* bhit_abs_origin; #ifndef DEDICATED extern ConVar* cl_rcon_request_sendlogs; -extern ConVar* cl_drawconsoleoverlay; +extern ConVar* con_drawnotify; extern ConVar* cl_consoleoverlay_lines; extern ConVar* cl_consoleoverlay_invert_rect_x; extern ConVar* cl_consoleoverlay_invert_rect_y; extern ConVar* cl_consoleoverlay_offset_x; extern ConVar* cl_consoleoverlay_offset_y; +extern ConVar* con_notifytime; + extern ConVar* cl_conoverlay_script_server_clr; extern ConVar* cl_conoverlay_script_client_clr; extern ConVar* cl_conoverlay_script_ui_clr; diff --git a/r5dev/vgui/vgui_debugpanel.cpp b/r5dev/vgui/vgui_debugpanel.cpp index 1639e264..7bead9ce 100644 --- a/r5dev/vgui/vgui_debugpanel.cpp +++ b/r5dev/vgui/vgui_debugpanel.cpp @@ -22,6 +22,7 @@ #include #endif #include +#include //----------------------------------------------------------------------------- // Purpose: proceed a log update @@ -32,9 +33,9 @@ void CLogSystem::Update(void) { return; } - if (cl_drawconsoleoverlay->GetBool()) + if (con_drawnotify->GetBool()) { - DrawLog(); + DrawNotify(); } if (cl_showsimstats->GetBool()) { @@ -63,57 +64,109 @@ void CLogSystem::Update(void) //----------------------------------------------------------------------------- void CLogSystem::AddLog(const EGlobalContext_t context, const string& svText) { - if (svText.length() > 0) + if (con_drawnotify->GetBool()) { - m_vLogs.push_back(LogMsg_t{ svText, 1024, context }); + if (svText.length() > 0) + { + std::lock_guard l(m_Mutex); + m_vNotifyText.push_back(CNotifyText{ context, con_notifytime->GetFloat() , svText }); + + while (m_vNotifyText.size() > 0 && + (m_vNotifyText.size() >= cl_consoleoverlay_lines->GetInt())) + { + m_vNotifyText.erase(m_vNotifyText.begin()); + } + } } } //----------------------------------------------------------------------------- -// Purpose: draw log on screen. +// Purpose: draw notify logs on screen. //----------------------------------------------------------------------------- -void CLogSystem::DrawLog(void) +void CLogSystem::DrawNotify(void) { - if (!m_vLogs.empty()) + int x; + int y; + if (cl_consoleoverlay_invert_rect_x->GetBool()) { - for (size_t i = 0; i < m_vLogs.size(); ++i) + x = g_nWindowWidth - cl_consoleoverlay_offset_x->GetInt(); + } + else + { + x = cl_consoleoverlay_offset_x->GetInt(); + } + if (cl_consoleoverlay_invert_rect_y->GetBool()) + { + y = g_nWindowHeight - cl_consoleoverlay_offset_y->GetInt(); + } + else + { + y = cl_consoleoverlay_offset_y->GetInt(); + } + + std::lock_guard l(m_Mutex); + for (int i = 0, j = m_vNotifyText.size(); i < j; i++) + { + CNotifyText* pNotify = &m_vNotifyText[i]; + Color c = GetLogColorForType(m_vNotifyText[i].m_type); + + float flTimeleft = pNotify->m_flLifeRemaining; + + if (flTimeleft < .5f) { - if (m_vLogs[i].m_nTicks >= 0) + float f = clamp(flTimeleft, 0.0f, .5f) / .5f; + c[3] = (int)(f * 255.0f); + + if (i == 0 && f < 0.2f) { - if (i < cl_consoleoverlay_lines->GetSizeT()) - { - float fadepct = fminf(static_cast(m_vLogs[i].m_nTicks) / 255.f, 4.f); // TODO [ AMOS ]: register a ConVar for this! - float ptc = ceilf(fadepct * 100.f); - int alpha = static_cast(ptc); - int x = cl_consoleoverlay_offset_x->GetInt(); - int y = cl_consoleoverlay_offset_y->GetInt() + (m_nFontHeight * static_cast(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 * static_cast(i); - } - - CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, x, y, c.r(), c.g(), c.b(), alpha, m_vLogs[i].m_svMessage.c_str()); - } - else - { - m_vLogs.erase(m_vLogs.begin()); - continue; - } - - m_vLogs[i].m_nTicks--; - } - else - { - m_vLogs.erase(m_vLogs.begin() + i); + y -= m_nFontHeight * (1.0f - f / 0.2f); } } + else + { + c[3] = 255; + } + CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, x, y, c.r(), c.g(), c.b(), c.a(), m_vNotifyText[i].m_svMessage.c_str()); + + if (IsX360()) + { + // For some reason the fontTall value on 360 is about twice as high as it should be + y += 12; + } + else + { + y += m_nFontHeight; + } + } +} + +//----------------------------------------------------------------------------- +// Purpose: checks if the notify text is expired +// Input : flFrameTime - +//----------------------------------------------------------------------------- +void CLogSystem::ShouldDraw(const float flFrameTime) +{ + if (con_drawnotify->GetBool()) + { + std::lock_guard l(m_Mutex); + + int i; + int c = m_vNotifyText.size(); + for (i = c - 1; i >= 0; i--) + { + CNotifyText* notify = &m_vNotifyText[i]; + notify->m_flLifeRemaining -= flFrameTime; + + if (notify->m_flLifeRemaining <= 0.0f) + { + m_vNotifyText.erase(m_vNotifyText.begin() + i); + continue; + } + } + } + else if (!m_vNotifyText.empty()) + { + m_vNotifyText.clear(); } } @@ -124,7 +177,7 @@ 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 }; + const static Color c = { 255, 255, 255, 255 }; if (cl_hoststats_invert_rect_x->GetBool()) { diff --git a/r5dev/vgui/vgui_debugpanel.h b/r5dev/vgui/vgui_debugpanel.h index 57f5dab6..5e002291 100644 --- a/r5dev/vgui/vgui_debugpanel.h +++ b/r5dev/vgui/vgui_debugpanel.h @@ -2,17 +2,17 @@ #include "core/stdafx.h" #include "mathlib/color.h" -struct LogMsg_t +struct CNotifyText { - LogMsg_t(const string svMessage, const int nTicks, const EGlobalContext_t type) + CNotifyText(const EGlobalContext_t type, const float nTime, const string& svMessage) { - this->m_svMessage = svMessage; - this->m_nTicks = nTicks; - this->m_type = type; + this->m_svMessage = svMessage; + this->m_flLifeRemaining = nTime; + this->m_type = type; } - string m_svMessage = ""; - int m_nTicks = 1024; - EGlobalContext_t m_type = EGlobalContext_t::NONE; + EGlobalContext_t m_type = EGlobalContext_t::NONE; + float m_flLifeRemaining = 0.0f; + string m_svMessage = ""; }; class CLogSystem @@ -27,6 +27,8 @@ public: void Update(void); void AddLog(const EGlobalContext_t context, const string& svText); void DrawLog(void); + void DrawNotify(); + void ShouldDraw(const float flFrameTime); void DrawHostStats(void) const; void DrawSimStats(void) const; void DrawGPUStats(void) const; @@ -35,8 +37,10 @@ public: private: Color GetLogColorForType(const EGlobalContext_t type) const; - vector m_vLogs; - int m_nFontHeight; + vector m_vNotifyText; + int m_nFontHeight; // Hardcoded to 16 in this engine. + + mutable std::mutex m_Mutex; public: char m_pszCon_NPrintf_Buf[4096]{};