Skip to content

Commit 4b20544

Browse files
committed
Fixed #9859 (100% CPU usage after some messages in /debugscript)
1 parent 0df3fb2 commit 4b20544

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

Client/core/CChat.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void CChat::LoadCVars(void)
145145
//
146146
// Draw
147147
//
148-
void CChat::Draw(bool bUseCacheTexture)
148+
void CChat::Draw(bool bUseCacheTexture, bool bAllowOutline)
149149
{
150150
// Are we visible?
151151
if (!m_bVisible)
@@ -159,9 +159,12 @@ void CChat::Draw(bool bUseCacheTexture)
159159
UpdateGUI();
160160
}
161161

162+
bool bUsingOutline = m_bTextBlackOutline && bAllowOutline && bUseCacheTexture;
163+
DrawInputLine(bUsingOutline);
164+
162165
// Get drawList for the chat box text
163166
SDrawList drawList;
164-
GetDrawList(drawList);
167+
GetDrawList(drawList, bUsingOutline);
165168

166169
// Calc some size info
167170
CVector2D chatTopLeft(drawList.renderBounds.fX1, drawList.renderBounds.fY1);
@@ -212,6 +215,7 @@ void CChat::Draw(bool bUseCacheTexture)
212215
// If we can't get a rendertarget for some reason, just render the text directly to the screen
213216
if (!m_pCacheTexture)
214217
{
218+
drawList.bOutline = false; // Outline too slow without cache texture
215219
DrawDrawList(drawList, chatTopLeft);
216220
return;
217221
}
@@ -270,15 +274,14 @@ void CChat::DrawDrawList(const SDrawList& drawList, const CVector2D& topLeftOffs
270274
//
271275
// Get list of text lines to draw
272276
//
273-
void CChat::GetDrawList(SDrawList& outDrawList)
277+
void CChat::GetDrawList(SDrawList& outDrawList, bool bUsingOutline)
274278
{
275279
float fLineDifference = CChat::GetFontHeight(m_vecScale.fY);
276280
CVector2D vecPosition(m_vecBackgroundPosition.fX + (5.0f * m_vecScale.fX), m_vecBackgroundPosition.fY + m_vecBackgroundSize.fY - (fLineDifference * 1.25f));
277281
float fMaxLineWidth = m_vecBackgroundSize.fX - (10.0f * m_vecScale.fX);
278282
unsigned long ulTime = GetTickCount32();
279283
float fRcpChatLineFadeOut = 1.0f / m_ulChatLineFadeOut;
280-
bool bShadow = (m_Color.A * m_fBackgroundAlpha == 0.f) && !m_bTextBlackOutline;
281-
bool bInputShadow = (m_InputColor.A * m_fInputBackgroundAlpha == 0.f) && !m_bTextBlackOutline;
284+
bool bShadow = (m_Color.A * m_fBackgroundAlpha == 0.f) && !bUsingOutline;
282285

283286
if (m_Color.A * m_fBackgroundAlpha > 0.f)
284287
{
@@ -304,7 +307,7 @@ void CChat::GetDrawList(SDrawList& outDrawList)
304307

305308
outDrawList.renderBounds = RenderBounds;
306309
outDrawList.bShadow = bShadow;
307-
outDrawList.bOutline = m_bTextBlackOutline;
310+
outDrawList.bOutline = bUsingOutline;
308311

309312
// Smooth scroll
310313
int iLineScroll;
@@ -351,7 +354,13 @@ void CChat::GetDrawList(SDrawList& outDrawList)
351354
if (uiLine == m_uiMostRecentLine) // Went through all lines?
352355
break;
353356
}
357+
}
354358

359+
//
360+
// CChat::DrawInputLine
361+
//
362+
void CChat::DrawInputLine(bool bUsingOutline)
363+
{
355364
if (m_InputColor.A * m_fInputBackgroundAlpha > 0.f)
356365
{
357366
if (m_pInput)
@@ -366,8 +375,10 @@ void CChat::GetDrawList(SDrawList& outDrawList)
366375

367376
if (m_bInputVisible)
368377
{
378+
float fLineDifference = CChat::GetFontHeight(m_vecScale.fY);
379+
bool bInputShadow = (m_InputColor.A * m_fInputBackgroundAlpha == 0.f) && !bUsingOutline;
369380
CVector2D vecPosition(m_vecInputPosition.fX + (5.0f * m_vecScale.fX), m_vecInputPosition.fY + (fLineDifference * 0.125f));
370-
m_InputLine.Draw(vecPosition, 255, bInputShadow, m_bTextBlackOutline);
381+
m_InputLine.Draw(vecPosition, 255, bInputShadow, bUsingOutline);
371382
}
372383
}
373384

Client/core/CChat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class CChat
157157
CChat(CGUI* pManager, const CVector2D& vecPosition);
158158
~CChat(void);
159159

160-
virtual void Draw(bool bUseCacheTexture);
160+
virtual void Draw(bool bUseCacheTexture, bool bAllowOutline);
161161
virtual void Output(const char* szText, bool bColorCoded = true);
162162
void Clear(void);
163163
void ClearInput(void);
@@ -202,7 +202,8 @@ class CChat
202202
void UpdatePosition(void);
203203
void UpdateSmoothScroll(float* pfPixelScroll, int* piLineScroll);
204204
void DrawDrawList(const SDrawList& drawList, const CVector2D& topLeftOffset = CVector2D(0, 0));
205-
void GetDrawList(SDrawList& outDrawList);
205+
void GetDrawList(SDrawList& outDrawList, bool bUsingOutline);
206+
void DrawInputLine(bool bUsingOutline);
206207

207208
CChatLine m_Lines[CHAT_MAX_LINES]; // Circular buffer
208209
int m_iScrollState; // 1 up, 0 stop, -1 down

Client/core/CDebugView.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ CDebugView::CDebugView(CGUI* pManager, const CVector2D& vecPosition) : CChat()
7676
UpdateGUI();
7777
}
7878

79-
void CDebugView::Draw(bool bUseCacheTexture)
79+
void CDebugView::Draw(bool bUseCacheTexture, bool bAllowOutline)
8080
{
8181
// Are we visible?
8282
if (!m_bVisible)
@@ -91,9 +91,11 @@ void CDebugView::Draw(bool bUseCacheTexture)
9191
CVector2D vecResolution = m_pManager->GetResolution();
9292
float height = m_uiNumLines * GetFontHeight(1) * m_vecScale.fY;
9393
m_vecBackgroundPosition = vecPosition * vecResolution - CVector2D(0, height);
94+
m_vecBackgroundPosition.fX = Round(m_vecBackgroundPosition.fX);
95+
m_vecBackgroundPosition.fY = Round(m_vecBackgroundPosition.fY);
9496
m_pBackground->SetPosition(m_vecBackgroundPosition);
9597

96-
CChat::Draw(bUseCacheTexture);
98+
CChat::Draw(bUseCacheTexture, bAllowOutline);
9799
g_pChat = pChat;
98100
}
99101

Client/core/CDebugView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CDebugView : public CChat
2424
public:
2525
CDebugView(CGUI* pManager, const CVector2D& vecPosition);
2626

27-
void Draw(bool bUseCacheTexture);
27+
void Draw(bool bUseCacheTexture, bool bAllowOutline);
2828
void Output(const char* szText, bool bColorCoded);
2929

3030
protected:

Client/core/CGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ void CLocalGUI::Draw(void)
299299
UpdateCursor();
300300

301301
// Draw the chat
302-
m_pChat->Draw(true);
302+
m_pChat->Draw(true, true);
303303
// Draw the debugger
304-
m_pDebugView->Draw(false);
304+
m_pDebugView->Draw(true, false);
305305

306306
// If we're not at the loadingscreen
307307
static bool bDelayedFrame = false;

0 commit comments

Comments
 (0)