From 8a11b3ce0b5610845a37487acbb5c5713598a9f7 Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Fri, 24 May 2024 10:35:23 +0100 Subject: [PATCH 1/5] mbedTLS fix for cURL 8.8.0 https://github.com/curl/curl/issues/13748 --- vendor/curl/lib/config-linux.h | 2 +- vendor/curl/lib/config-macos.h | 2 +- vendor/curl/lib/vtls/mbedtls.c | 21 +++++++++++++-------- vendor/curl/premake5.lua | 3 +++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/vendor/curl/lib/config-linux.h b/vendor/curl/lib/config-linux.h index 02a1306ed00..b0084d92dd5 100644 --- a/vendor/curl/lib/config-linux.h +++ b/vendor/curl/lib/config-linux.h @@ -869,7 +869,7 @@ /* #undef USE_MANUAL */ /* if mbedTLS is enabled */ -/* #undef USE_MBEDTLS */ +#define USE_MBEDTLS 1 /* if msh3 is in use */ /* #undef USE_MSH3 */ diff --git a/vendor/curl/lib/config-macos.h b/vendor/curl/lib/config-macos.h index bf5733fccac..c46b5ec014d 100644 --- a/vendor/curl/lib/config-macos.h +++ b/vendor/curl/lib/config-macos.h @@ -869,7 +869,7 @@ /* #undef USE_MANUAL */ /* if mbedTLS is enabled */ -/* #undef USE_MBEDTLS */ +#define USE_MBEDTLS 1 /* if msh3 is in use */ /* #undef USE_MSH3 */ diff --git a/vendor/curl/lib/vtls/mbedtls.c b/vendor/curl/lib/vtls/mbedtls.c index ec0b10dd9a9..1197d2956de 100644 --- a/vendor/curl/lib/vtls/mbedtls.c +++ b/vendor/curl/lib/vtls/mbedtls.c @@ -902,8 +902,6 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) (struct mbed_ssl_backend_data *)connssl->backend; struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf); const mbedtls_x509_crt *peercert; - char cipher_str[64]; - uint16_t cipher_id; #ifndef CURL_DISABLE_PROXY const char * const pinnedpubkey = Curl_ssl_cf_is_proxy(cf)? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]: @@ -932,11 +930,18 @@ mbed_connect_step2(struct Curl_cfilter *cf, struct Curl_easy *data) return CURLE_SSL_CONNECT_ERROR; } - cipher_id = (uint16_t) - mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); - mbed_cipher_suite_get_str(cipher_id, cipher_str, sizeof(cipher_str), true); - infof(data, "mbedTLS: Handshake complete, cipher is %s", cipher_str); - +#if MBEDTLS_VERSION_NUMBER >= 0x03020000 + { + char cipher_str[64]; + uint16_t cipher_id; + cipher_id = (uint16_t) + mbedtls_ssl_get_ciphersuite_id_from_ssl(&backend->ssl); + mbed_cipher_suite_get_str(cipher_id, cipher_str, sizeof(cipher_str), true); + infof(data, "mbedTLS: Handshake complete, cipher is %s", cipher_str); + } +#else + infof(data, "mbedTLS: Handshake complete"); +#endif ret = mbedtls_ssl_get_verify_result(&backend->ssl); if(!conn_config->verifyhost) @@ -1506,4 +1511,4 @@ const struct Curl_ssl Curl_ssl_mbedtls = { mbed_send, /* send data to encrypt */ }; -#endif /* USE_MBEDTLS */ +#endif /* USE_MBEDTLS */ \ No newline at end of file diff --git a/vendor/curl/premake5.lua b/vendor/curl/premake5.lua index d86088f267c..b3ac6a517f7 100644 --- a/vendor/curl/premake5.lua +++ b/vendor/curl/premake5.lua @@ -32,6 +32,9 @@ project "curl" defines { "USE_SCHANNEL", "USE_WINDOWS_SSPI", "USE_WIN32_IDN" } links { "crypt32", "Normaliz" } + filter { "system:not windows" } + defines { "USE_MBEDTLS" } + filter { "system:linux or bsd or macosx" } defines { "CURL_HIDDEN_SYMBOLS" } From 20f1d270a619f037a3a1add7cee70b86dc088b6f Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Thu, 20 Feb 2025 00:29:48 +0000 Subject: [PATCH 2/5] Allow display manager to cleanup expired instances --- Client/mods/deathmatch/logic/CClientVectorGraphic.cpp | 2 +- Client/mods/deathmatch/logic/CClientVectorGraphic.h | 4 ++-- Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp index bb2f078b1a3..744a8780c13 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp @@ -18,7 +18,7 @@ CClientVectorGraphic::CClientVectorGraphic(CClientManager* pManager, ElementID I m_pManager = pManager; - m_pVectorGraphicDisplay = std::make_unique(m_pManager->GetDisplayManager(), this); + m_pVectorGraphicDisplay = new CClientVectorGraphicDisplay(m_pManager->GetDisplayManager(), this); // Generate the default XML document SString defaultXmlString = SString("", pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY); diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphic.h b/Client/mods/deathmatch/logic/CClientVectorGraphic.h index d1d0493a7f2..a28f7a610ca 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphic.h +++ b/Client/mods/deathmatch/logic/CClientVectorGraphic.h @@ -36,7 +36,7 @@ class CClientVectorGraphic final : public CClientTexture lunasvg::Document* GetSVGDocument() const { return m_pSVGDocument.get(); } CXMLNode* GetXMLDocument() const { return m_pXMLDocument; } - CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay.get(); } + CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay; } bool IsDisplayCleared() const { return m_pVectorGraphicDisplay->IsCleared(); } bool IsDestroyed() const { return m_bIsDestroyed; } @@ -57,7 +57,7 @@ class CClientVectorGraphic final : public CClientTexture std::unique_ptr m_pXMLString = nullptr; CXMLNode* m_pXMLDocument = nullptr; - std::unique_ptr m_pVectorGraphicDisplay; + CClientVectorGraphicDisplay* m_pVectorGraphicDisplay; std::variant m_updateCallbackRef = false; diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp index 9e174d18783..26df12c988c 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp @@ -42,6 +42,10 @@ void CClientVectorGraphicDisplay::Render() { m_pVectorGraphic->OnUpdate(); } + + // if we don't update the SVG, or vector graphic is deleted, after 60 seconds the display manager will destroy it + // see CClientDisplayManager::DoPulse + SetTimeTillExpiration(60 * 1000); } void CClientVectorGraphicDisplay::UnpremultiplyBitmap(Bitmap& bitmap) From 90bc1ddf3506b1829149db4e422c0f48fe7b7a4d Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Thu, 20 Feb 2025 00:52:46 +0000 Subject: [PATCH 3/5] Adjust expiration (only after svg destroyed) --- .../deathmatch/logic/CClientVectorGraphicDisplay.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp index 26df12c988c..a29c2decd63 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp @@ -25,8 +25,11 @@ CClientVectorGraphicDisplay::CClientVectorGraphicDisplay(CClientDisplayManager* void CClientVectorGraphicDisplay::Render() { + // When the underlying vector graphic is deleted, this display will be destroyed automatically by the manager. + // CClientVectorGraphicDisplay::Render should be called as long as the display manager is still alive. + // see CClientDisplayManager::DoPulse if (!m_pVectorGraphic || m_pVectorGraphic->IsDestroyed()) - return; + return SetTimeTillExpiration(1); if (!m_bVisible) { @@ -42,10 +45,6 @@ void CClientVectorGraphicDisplay::Render() { m_pVectorGraphic->OnUpdate(); } - - // if we don't update the SVG, or vector graphic is deleted, after 60 seconds the display manager will destroy it - // see CClientDisplayManager::DoPulse - SetTimeTillExpiration(60 * 1000); } void CClientVectorGraphicDisplay::UnpremultiplyBitmap(Bitmap& bitmap) From df9d47d6d3359c8321db6fe4423a1ae0374af940 Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Wed, 5 Mar 2025 00:43:07 +0000 Subject: [PATCH 4/5] Use shared_ptr --- Client/mods/deathmatch/logic/CClientVectorGraphic.cpp | 7 +++++-- Client/mods/deathmatch/logic/CClientVectorGraphic.h | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp index 744a8780c13..cce8a76b668 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp @@ -18,7 +18,7 @@ CClientVectorGraphic::CClientVectorGraphic(CClientManager* pManager, ElementID I m_pManager = pManager; - m_pVectorGraphicDisplay = new CClientVectorGraphicDisplay(m_pManager->GetDisplayManager(), this); + m_pVectorGraphicDisplay = std::make_shared(m_pManager->GetDisplayManager(), this); // Generate the default XML document SString defaultXmlString = SString("", pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY); @@ -46,7 +46,7 @@ bool CClientVectorGraphic::LoadFromString(std::string strData) bool CClientVectorGraphic::SetDocument(CXMLNode* node) { - if (!node || !node->IsValid()) + if (!m_pVectorGraphicDisplay || !node || !node->IsValid()) return false; if (m_pXMLString && m_pXMLString->node != node) @@ -80,6 +80,9 @@ bool CClientVectorGraphic::RemoveUpdateCallback() void CClientVectorGraphic::OnUpdate() { + if (!m_pVectorGraphicDisplay) + return; + m_pVectorGraphicDisplay->UpdateTexture(); if (std::holds_alternative(m_updateCallbackRef)) diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphic.h b/Client/mods/deathmatch/logic/CClientVectorGraphic.h index a28f7a610ca..274191d39f1 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphic.h +++ b/Client/mods/deathmatch/logic/CClientVectorGraphic.h @@ -36,7 +36,7 @@ class CClientVectorGraphic final : public CClientTexture lunasvg::Document* GetSVGDocument() const { return m_pSVGDocument.get(); } CXMLNode* GetXMLDocument() const { return m_pXMLDocument; } - CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay; } + CClientVectorGraphicDisplay* GetDisplay() const { return m_pVectorGraphicDisplay.get(); } bool IsDisplayCleared() const { return m_pVectorGraphicDisplay->IsCleared(); } bool IsDestroyed() const { return m_bIsDestroyed; } @@ -57,7 +57,7 @@ class CClientVectorGraphic final : public CClientTexture std::unique_ptr m_pXMLString = nullptr; CXMLNode* m_pXMLDocument = nullptr; - CClientVectorGraphicDisplay* m_pVectorGraphicDisplay; + std::shared_ptr m_pVectorGraphicDisplay; std::variant m_updateCallbackRef = false; From e95ca0e66d0d4d025f2bb263b29c5e8d570f836c Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Sat, 15 Mar 2025 00:46:59 +0000 Subject: [PATCH 5/5] Implement shared_ptr and weak_ptr references for CClientDisplay(Manager) --- .../mods/deathmatch/logic/CClientDisplay.cpp | 13 +-- Client/mods/deathmatch/logic/CClientDisplay.h | 16 ++-- .../logic/CClientDisplayManager.cpp | 85 +++++++------------ .../deathmatch/logic/CClientDisplayManager.h | 23 ++--- .../deathmatch/logic/CClientTextDisplay.cpp | 6 +- .../deathmatch/logic/CClientTextDisplay.h | 16 ++-- .../deathmatch/logic/CClientVectorGraphic.cpp | 5 +- .../logic/CClientVectorGraphicDisplay.cpp | 4 +- .../logic/CClientVectorGraphicDisplay.h | 3 +- .../mods/deathmatch/logic/CPacketHandler.cpp | 31 ++++--- Client/mods/deathmatch/logic/CPacketHandler.h | 3 + Client/mods/deathmatch/logic/CPlayerMap.cpp | 5 +- Client/mods/deathmatch/logic/CPlayerMap.h | 2 +- 13 files changed, 87 insertions(+), 125 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientDisplay.cpp b/Client/mods/deathmatch/logic/CClientDisplay.cpp index 1709a4eb364..b6df06f697a 100644 --- a/Client/mods/deathmatch/logic/CClientDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientDisplay.cpp @@ -10,25 +10,16 @@ #include -CClientDisplay::CClientDisplay(CClientDisplayManager* pDisplayManager, unsigned long ulID) +CClientDisplay::CClientDisplay(unsigned long ulID) { - m_pDisplayManager = pDisplayManager; m_ulID = ulID; m_ulExpirationTime = 0; m_bVisible = true; m_Color = SColorRGBA(255, 255, 255, 255); - - m_pDisplayManager->AddToList(this); -} - -CClientDisplay::~CClientDisplay() -{ - // Remove us from the manager - m_pDisplayManager->RemoveFromList(this); } void CClientDisplay::SetColorAlpha(unsigned char ucAlpha) { m_Color.A = ucAlpha; -} \ No newline at end of file +} diff --git a/Client/mods/deathmatch/logic/CClientDisplay.h b/Client/mods/deathmatch/logic/CClientDisplay.h index 291180c3c55..8fe714d68ee 100644 --- a/Client/mods/deathmatch/logic/CClientDisplay.h +++ b/Client/mods/deathmatch/logic/CClientDisplay.h @@ -22,18 +22,16 @@ enum eDisplayType class CClientDisplay { - friend class CClientDisplayManager; - public: - CClientDisplay(class CClientDisplayManager* pDisplayManager, unsigned long ulID); - virtual ~CClientDisplay(); + CClientDisplay(unsigned long ulID); + virtual ~CClientDisplay() = default; - unsigned long GetID() { return m_ulID; } + unsigned long GetID() const { return m_ulID; } virtual eDisplayType GetType() = 0; - unsigned long GetExpirationTime() { return m_ulExpirationTime; }; + unsigned long GetExpirationTime() const { return m_ulExpirationTime; }; void SetExpirationTime(unsigned long ulTime) { m_ulExpirationTime = ulTime; }; - unsigned long GetTimeTillExpiration() { return m_ulExpirationTime - CClientTime::GetTime(); }; + unsigned long GetTimeTillExpiration() const { return m_ulExpirationTime - CClientTime::GetTime(); }; void SetTimeTillExpiration(unsigned long ulMs) { m_ulExpirationTime = CClientTime::GetTime() + ulMs; }; virtual const CVector& GetPosition() { return m_vecPosition; }; @@ -49,9 +47,7 @@ class CClientDisplay virtual void Render() = 0; protected: - bool IsExpired() { return (m_ulExpirationTime != 0 && (CClientTime::GetTime() > m_ulExpirationTime)); }; - - CClientDisplayManager* m_pDisplayManager; + bool IsExpired() const { return (m_ulExpirationTime != 0 && (CClientTime::GetTime() > m_ulExpirationTime)); }; unsigned long m_ulID; unsigned long m_ulExpirationTime; diff --git a/Client/mods/deathmatch/logic/CClientDisplayManager.cpp b/Client/mods/deathmatch/logic/CClientDisplayManager.cpp index 5eafeea8cc9..651b1d2efa1 100644 --- a/Client/mods/deathmatch/logic/CClientDisplayManager.cpp +++ b/Client/mods/deathmatch/logic/CClientDisplayManager.cpp @@ -12,27 +12,21 @@ using std::list; -CClientDisplayManager::CClientDisplayManager() -{ - // Init - m_bCanRemoveFromList = true; -} - -CClientDisplayManager::~CClientDisplayManager() -{ - RemoveAll(); -} - -CClientDisplay* CClientDisplayManager::Get(unsigned long ulID) +std::shared_ptr CClientDisplayManager::Get(unsigned long ulID) { // Find the display with the given id - list::const_iterator iter = m_List.begin(); - for (; iter != m_List.end(); iter++) + auto iter = m_List.begin(); + + for (; iter != m_List.end(); iter++) // Iterate weak_ptr list { - if ((*iter)->GetID() == ulID) + if (const auto& display = (*iter).lock()) // Make sure the shared_ptr still exists { - return *iter; + if (display->GetID() == ulID) + { + return display; + } } + } return NULL; @@ -49,57 +43,38 @@ void CClientDisplayManager::DrawText2D(const char* szCaption, const CVector& vec static_cast(fResHeight), rgbaColor, szCaption, fScale, fScale, 0); } -void CClientDisplayManager::AddToList(CClientDisplay* pDisplay) +void CClientDisplayManager::AddToList(const std::shared_ptr& display) { - m_List.push_back(pDisplay); + m_List.push_back(display); } -void CClientDisplayManager::RemoveAll() +void CClientDisplayManager::DoPulse() { - // Delete all the items in the list - m_bCanRemoveFromList = false; - list::iterator iter = m_List.begin(); - for (; iter != m_List.end(); iter++) - { - delete *iter; - } + // Render all our displays + auto iter = m_List.begin(); - // Clear the list - m_List.clear(); - m_bCanRemoveFromList = true; -} + // Clean up expired weak_ptr + m_List.remove_if([](const std::weak_ptr& wp) { return wp.expired(); }); -void CClientDisplayManager::RemoveFromList(CClientDisplay* pDisplay) -{ - if (m_bCanRemoveFromList) + for (; iter != m_List.end(); iter++) // Iterate weak_ptr list { - if (!m_List.empty()) + if (const auto& display = (*iter).lock()) // Make sure the shared_ptr still exists { - m_List.remove(pDisplay); + display->Render(); } } } -void CClientDisplayManager::DoPulse() +std::shared_ptr CClientDisplayManager::CreateVectorGraphicDisplay(CClientVectorGraphic* svg) { - // Render all our displays - m_bCanRemoveFromList = false; - list::iterator iter = m_List.begin(); - while (iter != m_List.end()) - { - CClientDisplay* pObject = *iter; - if (pObject->IsExpired()) - { - // Delete it and remove it from the list - delete pObject; - iter = m_List.erase(iter); - } - else - { - ++iter; - pObject->Render(); - } - } + auto display = std::make_shared(svg); + AddToList(display); + return display; +} - m_bCanRemoveFromList = true; +std::shared_ptr CClientDisplayManager::CreateTextDisplay(int ID) +{ + auto display = std::make_shared(ID); + AddToList(display); + return display; } diff --git a/Client/mods/deathmatch/logic/CClientDisplayManager.h b/Client/mods/deathmatch/logic/CClientDisplayManager.h index f4fcffdfd5a..eac7e290842 100644 --- a/Client/mods/deathmatch/logic/CClientDisplayManager.h +++ b/Client/mods/deathmatch/logic/CClientDisplayManager.h @@ -13,9 +13,12 @@ class CClientDisplayManager; #pragma once #include "CClientManager.h" -#include -class CClientDisplay; +#include "CClientDisplay.h" +#include "CClientVectorGraphicDisplay.h" +#include "CClientTextDisplay.h" + +#include class CClientDisplayManager { @@ -23,21 +26,21 @@ class CClientDisplayManager friend class CClientDisplay; public: - CClientDisplayManager(); - ~CClientDisplayManager(); + CClientDisplayManager() = default; + ~CClientDisplayManager() = default; void DoPulse(); unsigned int Count() { return static_cast(m_List.size()); }; - CClientDisplay* Get(unsigned long ulID); + std::shared_ptr Get(unsigned long ulID); void DrawText2D(const char* szCaption, const CVector& vecPosition, float fScale = 1.0f, RGBA rgbaColor = 0xFFFFFFFF); - void RemoveAll(); + void AddToList(const std::shared_ptr& display); - void AddToList(CClientDisplay* pDisplay); - void RemoveFromList(CClientDisplay* pDisplay); + std::shared_ptr CreateVectorGraphicDisplay(CClientVectorGraphic* svg); + std::shared_ptr CreateTextDisplay(int ID = 0xFFFFFFFF); - std::list m_List; - bool m_bCanRemoveFromList; + std::list> m_List; }; + diff --git a/Client/mods/deathmatch/logic/CClientTextDisplay.cpp b/Client/mods/deathmatch/logic/CClientTextDisplay.cpp index 8b7962f5b0e..5ebc9a692ed 100644 --- a/Client/mods/deathmatch/logic/CClientTextDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientTextDisplay.cpp @@ -14,7 +14,7 @@ using std::list; float CClientTextDisplay::m_fGlobalScale = 1.0f; -CClientTextDisplay::CClientTextDisplay(CClientDisplayManager* pDisplayManager, int ID) : CClientDisplay(pDisplayManager, ID) +CClientTextDisplay::CClientTextDisplay(int ID) : CClientDisplay(ID) { // Init m_fScale = 1; @@ -22,10 +22,6 @@ CClientTextDisplay::CClientTextDisplay(CClientDisplayManager* pDisplayManager, i m_bVisible = true; } -CClientTextDisplay::~CClientTextDisplay() -{ -} - void CClientTextDisplay::SetCaption(const char* szCaption) { if (szCaption) diff --git a/Client/mods/deathmatch/logic/CClientTextDisplay.h b/Client/mods/deathmatch/logic/CClientTextDisplay.h index 74e0cd382ad..299c3f6c5e3 100644 --- a/Client/mods/deathmatch/logic/CClientTextDisplay.h +++ b/Client/mods/deathmatch/logic/CClientTextDisplay.h @@ -16,13 +16,11 @@ class CClientTextDisplay; #include "CClientDisplayManager.h" #include -class CClientTextDisplay : public CClientDisplay +class CClientTextDisplay final : public CClientDisplay { - friend class CClientDisplayManager; - public: - CClientTextDisplay(CClientDisplayManager* pDisplayManager, int ID = 0xFFFFFFFF); - ~CClientTextDisplay(); + CClientTextDisplay(int ID = 0xFFFFFFFF); + ~CClientTextDisplay() = default; eDisplayType GetType() { return DISPLAY_TEXT; } @@ -34,24 +32,24 @@ class CClientTextDisplay : public CClientDisplay void SetColorAlpha(unsigned char ucAlpha); void SetShadowAlpha(unsigned char ucShadowAlpha); - float GetScale() { return m_fScale; }; + float GetScale() const { return m_fScale; }; void SetScale(float fScale); - unsigned long GetFormat() { return m_ulFormat; }; + unsigned long GetFormat() const { return m_ulFormat; }; void SetFormat(unsigned long ulFormat); void SetVisible(bool bVisible); void Render(); - static void SetGlobalScale(float fScale) { m_fGlobalScale = fScale; } + static void SetGlobalScale(float fScale) { m_fGlobalScale = fScale; }; private: SString m_strCaption; float m_fScale; unsigned long m_ulFormat; - unsigned char m_ucShadowAlpha; + unsigned char m_ucShadowAlpha{}; static float m_fGlobalScale; }; diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp index cce8a76b668..f2435adf810 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphic.cpp @@ -17,8 +17,7 @@ CClientVectorGraphic::CClientVectorGraphic(CClientManager* pManager, ElementID I SetTypeName("svg"); m_pManager = pManager; - - m_pVectorGraphicDisplay = std::make_shared(m_pManager->GetDisplayManager(), this); + m_pVectorGraphicDisplay = m_pManager->GetDisplayManager()->CreateVectorGraphicDisplay(this); // Generate the default XML document SString defaultXmlString = SString("", pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY); @@ -87,7 +86,7 @@ void CClientVectorGraphic::OnUpdate() if (std::holds_alternative(m_updateCallbackRef)) { - auto func = std::get(m_updateCallbackRef); + auto& func = std::get(m_updateCallbackRef); auto state = func.GetLuaVM(); if (VERIFY_FUNCTION(func) && state != NULL) diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp index 9683c7d075b..ba495968c62 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp @@ -13,8 +13,8 @@ using namespace lunasvg; -CClientVectorGraphicDisplay::CClientVectorGraphicDisplay(CClientDisplayManager* pDisplayManager, CClientVectorGraphic* pVectorGraphic, int ID) - : CClientDisplay(pDisplayManager, ID) +CClientVectorGraphicDisplay::CClientVectorGraphicDisplay(CClientVectorGraphic* pVectorGraphic, int ID) + : CClientDisplay(ID) { m_pVectorGraphic = pVectorGraphic; m_bVisible = true; diff --git a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.h b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.h index 40da0d46f27..dbff889da76 100644 --- a/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.h +++ b/Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.h @@ -20,7 +20,7 @@ class CClientVectorGraphicDisplay final : public CClientDisplay friend class CClientDisplayManager; public: - CClientVectorGraphicDisplay(CClientDisplayManager* pDisplayManager, CClientVectorGraphic* pVectorGraphic, int ID = DISPLAY_VECTORGRAPHIC); + CClientVectorGraphicDisplay(CClientVectorGraphic* pVectorGraphic, int ID = DISPLAY_VECTORGRAPHIC); ~CClientVectorGraphicDisplay() = default; eDisplayType GetType() { return DISPLAY_VECTORGRAPHIC; } @@ -38,7 +38,6 @@ class CClientVectorGraphicDisplay final : public CClientDisplay private: void UnpremultiplyBitmap(lunasvg::Bitmap& bitmap); -private: CClientVectorGraphic* m_pVectorGraphic; bool m_bIsCleared; diff --git a/Client/mods/deathmatch/logic/CPacketHandler.cpp b/Client/mods/deathmatch/logic/CPacketHandler.cpp index 094812d816b..ad5d7cfb4e4 100644 --- a/Client/mods/deathmatch/logic/CPacketHandler.cpp +++ b/Client/mods/deathmatch/logic/CPacketHandler.cpp @@ -4496,10 +4496,11 @@ void CPacketHandler::Packet_TextItem(NetBitStreamInterface& bitStream) if (bDelete) { // Grab it and delete it - CClientDisplay* pDisplay = g_pClientGame->m_pDisplayManager->Get(ulID); + std::shared_ptr pDisplay = g_pClientGame->m_pDisplayManager->Get(ulID); + if (pDisplay) { - delete pDisplay; + m_displayTextList.remove(std::static_pointer_cast(pDisplay)); } } else @@ -4535,26 +4536,28 @@ void CPacketHandler::Packet_TextItem(NetBitStreamInterface& bitStream) } // Does the text not already exist? Create it - CClientTextDisplay* pTextDisplay = NULL; - CClientDisplay* pDisplay = g_pClientGame->m_pDisplayManager->Get(ulID); - if (pDisplay && pDisplay->GetType() == DISPLAY_TEXT) + std::shared_ptr textDisplay = nullptr; + std::shared_ptr display = g_pClientGame->m_pDisplayManager->Get(ulID); + + if (display && display->GetType() == DISPLAY_TEXT) { - pTextDisplay = static_cast(pDisplay); + textDisplay = std::static_pointer_cast(display); } - if (!pTextDisplay) + if (!textDisplay) { // Create it - pTextDisplay = new CClientTextDisplay(g_pClientGame->m_pDisplayManager, ulID); + textDisplay = g_pClientGame->m_pDisplayManager->CreateTextDisplay(ulID); + m_displayTextList.push_back(textDisplay); } // Set the text properties - pTextDisplay->SetCaption(szText); - pTextDisplay->SetPosition(CVector(fX, fY, 0)); - pTextDisplay->SetColor(color); - pTextDisplay->SetScale(fScale); - pTextDisplay->SetFormat((unsigned long)ucFormat); - pTextDisplay->SetShadowAlpha(ucShadowAlpha); + textDisplay->SetCaption(szText); + textDisplay->SetPosition(CVector(fX, fY, 0)); + textDisplay->SetColor(color); + textDisplay->SetScale(fScale); + textDisplay->SetFormat((unsigned long)ucFormat); + textDisplay->SetShadowAlpha(ucShadowAlpha); delete[] szText; } diff --git a/Client/mods/deathmatch/logic/CPacketHandler.h b/Client/mods/deathmatch/logic/CPacketHandler.h index 9a50b246156..8a370774b58 100644 --- a/Client/mods/deathmatch/logic/CPacketHandler.h +++ b/Client/mods/deathmatch/logic/CPacketHandler.h @@ -16,6 +16,7 @@ class CClientEntity; class CCustomData; +class CClientTextDisplay; class CPacketHandler { @@ -112,4 +113,6 @@ class CPacketHandler std::vector m_EntityAddReadOffsetStore; NetBitStreamInterface* m_pEntityAddBitStream; uint m_uiEntityAddNumEntities; + + std::list> m_displayTextList; }; diff --git a/Client/mods/deathmatch/logic/CPlayerMap.cpp b/Client/mods/deathmatch/logic/CPlayerMap.cpp index de1529972a5..332ef0282ed 100644 --- a/Client/mods/deathmatch/logic/CPlayerMap.cpp +++ b/Client/mods/deathmatch/logic/CPlayerMap.cpp @@ -87,7 +87,7 @@ CPlayerMap::CPlayerMap(CClientManager* pManager) for (uint i = 0; i < NUMELMS(messageList); i++) { - CClientTextDisplay* pTextDisplay = new CClientTextDisplay(m_pManager->GetDisplayManager()); + auto pTextDisplay = m_pManager->GetDisplayManager()->CreateTextDisplay(); pTextDisplay->SetCaption(messageList[i].strMessage); pTextDisplay->SetColor(messageList[i].color); pTextDisplay->SetPosition(CVector(0.50f, messageList[i].fPosY, 0)); @@ -112,8 +112,7 @@ CPlayerMap::~CPlayerMap() for (uint i = 0; i < m_markerTextureList.size(); i++) SAFE_RELEASE(m_markerTextureList[i]); m_markerTextureList.clear(); - - // Don't need to delete the help texts as those are destroyed by the display manager + m_HelpTextList.clear(); } void CPlayerMap::CreateOrUpdateMapTexture() diff --git a/Client/mods/deathmatch/logic/CPlayerMap.h b/Client/mods/deathmatch/logic/CPlayerMap.h index 0d6edebb6f2..04022ce3ce6 100644 --- a/Client/mods/deathmatch/logic/CPlayerMap.h +++ b/Client/mods/deathmatch/logic/CPlayerMap.h @@ -116,7 +116,7 @@ class CPlayerMap unsigned long m_ulUpdateTime; - std::vector m_HelpTextList; + std::vector> m_HelpTextList; bool m_bHideHelpText; bool m_bHudVisible;