mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
'con_notify' improvements
* Fade notify text by a fixed amount regardless of the frame times. * Implement Valve's 'lerping' animation for text when entries fade away and expire. * Don't run/push/remove anything if 'con_drawnotify' is disabled.
This commit is contained in:
parent
83b3feb9db
commit
1b754fd0b9
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <engine/server/server.h>
|
||||
#endif
|
||||
#include <rtech/rtech_utils.h>
|
||||
#include <engine/sys_engine.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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<std::mutex> 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<std::mutex> 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<float>(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<int>(ptc);
|
||||
int x = cl_consoleoverlay_offset_x->GetInt();
|
||||
int y = cl_consoleoverlay_offset_y->GetInt() + (m_nFontHeight * static_cast<int>(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<int>(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<std::mutex> 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())
|
||||
{
|
||||
|
@ -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<LogMsg_t> m_vLogs;
|
||||
int m_nFontHeight;
|
||||
vector<CNotifyText> m_vNotifyText;
|
||||
int m_nFontHeight; // Hardcoded to 16 in this engine.
|
||||
|
||||
mutable std::mutex m_Mutex;
|
||||
|
||||
public:
|
||||
char m_pszCon_NPrintf_Buf[4096]{};
|
||||
|
Loading…
x
Reference in New Issue
Block a user