mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
VGui: use cached string lengths for notify logs
Don't recalculate the string length when displaying it on the VGui console.
This commit is contained in:
parent
26ec02f302
commit
1331c3c67b
@ -352,7 +352,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
|
||||
if (g_bSdkInitialized && logLevel >= LogLevel_t::LEVEL_NOTIFY)
|
||||
{
|
||||
// Draw to mini console.
|
||||
g_TextOverlay.AddLog(overlayContext, message.c_str());
|
||||
g_TextOverlay.AddLog(overlayContext, message.c_str(), (ssize_t)message.length());
|
||||
}
|
||||
#endif // !DEDICATED
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void CTextOverlay::Update(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: add a log to the vector.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CTextOverlay::AddLog(const eDLL_T context, const char* pszText)
|
||||
void CTextOverlay::AddLog(const eDLL_T context, const char* pszText, const ssize_t textLen)
|
||||
{
|
||||
Assert(pszText);
|
||||
|
||||
@ -121,7 +121,11 @@ void CTextOverlay::AddLog(const eDLL_T context, const char* pszText)
|
||||
}
|
||||
|
||||
AUTO_LOCK(m_Mutex);
|
||||
m_NotifyLines.AddToTail(CTextNotify{ context, con_notifytime.GetFloat() , pszText });
|
||||
|
||||
const int newLine = m_NotifyLines.AddToTail();
|
||||
TextNotify_s& notify = m_NotifyLines[newLine];
|
||||
|
||||
notify.Init(context, con_notifytime.GetFloat(), pszText, textLen);
|
||||
|
||||
while (m_NotifyLines.Count() > 0 &&
|
||||
(m_NotifyLines.Count() > con_notifylines.GetInt()))
|
||||
@ -145,7 +149,7 @@ void CTextOverlay::DrawNotify(void)
|
||||
|
||||
for (int i = 0, j = m_NotifyLines.Count(); i < j; i++)
|
||||
{
|
||||
const CTextNotify& notify = m_NotifyLines[i];
|
||||
const TextNotify_s& notify = m_NotifyLines[i];
|
||||
Color c = GetLogColorForType(notify.m_Type);
|
||||
|
||||
const float flTimeleft = notify.m_flLifeRemaining;
|
||||
@ -214,10 +218,10 @@ void CTextOverlay::ShouldDraw(const float flFrameTime)
|
||||
|
||||
FOR_EACH_VEC_BACK(m_NotifyLines, i)
|
||||
{
|
||||
CTextNotify* pNotify = &m_NotifyLines[i];
|
||||
pNotify->m_flLifeRemaining -= flFrameTime;
|
||||
TextNotify_s& notify = m_NotifyLines[i];
|
||||
notify.m_flLifeRemaining -= flFrameTime;
|
||||
|
||||
if (pNotify->m_flLifeRemaining <= 0.0f)
|
||||
if (notify.m_flLifeRemaining <= 0.0f)
|
||||
{
|
||||
m_NotifyLines.Remove(i);
|
||||
continue;
|
||||
|
@ -2,21 +2,23 @@
|
||||
#include "core/stdafx.h"
|
||||
#include "mathlib/color.h"
|
||||
|
||||
struct CTextNotify
|
||||
{
|
||||
CTextNotify(const eDLL_T type, const float flTime, const char* pszText)
|
||||
{
|
||||
this->m_Text = pszText;
|
||||
this->m_flLifeRemaining = flTime;
|
||||
this->m_Type = type;
|
||||
}
|
||||
eDLL_T m_Type;
|
||||
float m_flLifeRemaining;
|
||||
CUtlString m_Text;
|
||||
};
|
||||
|
||||
class CTextOverlay
|
||||
{
|
||||
private:
|
||||
struct TextNotify_s
|
||||
{
|
||||
void Init(const eDLL_T type, const float flTime, const char* pszText, const ssize_t textLen)
|
||||
{
|
||||
this->m_Type = type;
|
||||
this->m_flLifeRemaining = flTime;
|
||||
this->m_Text.SetDirect(pszText, textLen);
|
||||
}
|
||||
|
||||
eDLL_T m_Type;
|
||||
float m_flLifeRemaining;
|
||||
CUtlString m_Text;
|
||||
};
|
||||
|
||||
public:
|
||||
CTextOverlay()
|
||||
{
|
||||
@ -26,7 +28,7 @@ public:
|
||||
}
|
||||
|
||||
void Update(void);
|
||||
void AddLog(const eDLL_T context, const char* pszText);
|
||||
void AddLog(const eDLL_T context, const char* pszText, const ssize_t textLen);
|
||||
void DrawNotify(void);
|
||||
void DrawFormat(const int x, const int y, const Color c, const char* pszFormat, ...) const;
|
||||
void ShouldDraw(const float flFrameTime);
|
||||
@ -38,7 +40,7 @@ public:
|
||||
|
||||
private:
|
||||
Color GetLogColorForType(const eDLL_T type) const;
|
||||
CUtlVector<CTextNotify> m_NotifyLines;
|
||||
CUtlVector<TextNotify_s> m_NotifyLines;
|
||||
int m_nFontHeight; // Hardcoded to 16 in this engine.
|
||||
|
||||
mutable CThreadFastMutex m_Mutex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user