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)
|
if (g_bSdkInitialized && logLevel >= LogLevel_t::LEVEL_NOTIFY)
|
||||||
{
|
{
|
||||||
// Draw to mini console.
|
// Draw to mini console.
|
||||||
g_TextOverlay.AddLog(overlayContext, message.c_str());
|
g_TextOverlay.AddLog(overlayContext, message.c_str(), (ssize_t)message.length());
|
||||||
}
|
}
|
||||||
#endif // !DEDICATED
|
#endif // !DEDICATED
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ void CTextOverlay::Update(void)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: add a log to the vector.
|
// 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);
|
Assert(pszText);
|
||||||
|
|
||||||
@ -121,7 +121,11 @@ void CTextOverlay::AddLog(const eDLL_T context, const char* pszText)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AUTO_LOCK(m_Mutex);
|
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 &&
|
while (m_NotifyLines.Count() > 0 &&
|
||||||
(m_NotifyLines.Count() > con_notifylines.GetInt()))
|
(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++)
|
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);
|
Color c = GetLogColorForType(notify.m_Type);
|
||||||
|
|
||||||
const float flTimeleft = notify.m_flLifeRemaining;
|
const float flTimeleft = notify.m_flLifeRemaining;
|
||||||
@ -214,10 +218,10 @@ void CTextOverlay::ShouldDraw(const float flFrameTime)
|
|||||||
|
|
||||||
FOR_EACH_VEC_BACK(m_NotifyLines, i)
|
FOR_EACH_VEC_BACK(m_NotifyLines, i)
|
||||||
{
|
{
|
||||||
CTextNotify* pNotify = &m_NotifyLines[i];
|
TextNotify_s& notify = m_NotifyLines[i];
|
||||||
pNotify->m_flLifeRemaining -= flFrameTime;
|
notify.m_flLifeRemaining -= flFrameTime;
|
||||||
|
|
||||||
if (pNotify->m_flLifeRemaining <= 0.0f)
|
if (notify.m_flLifeRemaining <= 0.0f)
|
||||||
{
|
{
|
||||||
m_NotifyLines.Remove(i);
|
m_NotifyLines.Remove(i);
|
||||||
continue;
|
continue;
|
||||||
|
@ -2,21 +2,23 @@
|
|||||||
#include "core/stdafx.h"
|
#include "core/stdafx.h"
|
||||||
#include "mathlib/color.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
|
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:
|
public:
|
||||||
CTextOverlay()
|
CTextOverlay()
|
||||||
{
|
{
|
||||||
@ -26,7 +28,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update(void);
|
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 DrawNotify(void);
|
||||||
void DrawFormat(const int x, const int y, const Color c, const char* pszFormat, ...) const;
|
void DrawFormat(const int x, const int y, const Color c, const char* pszFormat, ...) const;
|
||||||
void ShouldDraw(const float flFrameTime);
|
void ShouldDraw(const float flFrameTime);
|
||||||
@ -38,7 +40,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Color GetLogColorForType(const eDLL_T type) const;
|
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.
|
int m_nFontHeight; // Hardcoded to 16 in this engine.
|
||||||
|
|
||||||
mutable CThreadFastMutex m_Mutex;
|
mutable CThreadFastMutex m_Mutex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user