Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8a11b3c
mbedTLS fix for cURL 8.8.0
Lpsd May 24, 2024
181bf0f
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd May 24, 2024
6728cbe
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd May 25, 2024
0b989ac
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd May 26, 2024
9c19509
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Jun 2, 2024
75c36ed
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Jun 19, 2024
96dd1ee
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 2, 2024
f9eaf3f
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 8, 2024
54bd11b
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 10, 2024
ddee2d0
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 19, 2024
288b8db
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 21, 2024
b30a4a2
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Oct 22, 2024
27b9eae
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Dec 17, 2024
3731d81
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Jan 14, 2025
b50a68c
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Jan 22, 2025
58ae23f
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Feb 19, 2025
20f1d27
Allow display manager to cleanup expired instances
Lpsd Feb 20, 2025
90bc1dd
Adjust expiration (only after svg destroyed)
Lpsd Feb 20, 2025
f3645b8
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Mar 4, 2025
489eb7b
Merge branch 'master' into svg-ptr-fix
Lpsd Mar 4, 2025
df9d47d
Use shared_ptr
Lpsd Mar 5, 2025
e62d9f4
Merge branch 'master' of https://github.com/multitheftauto/mtasa-blue
Lpsd Mar 14, 2025
812ec31
Merge branch 'master' into svg-ptr-fix
Lpsd Mar 14, 2025
e95ca0e
Implement shared_ptr and weak_ptr references for CClientDisplay(Manager)
Lpsd Mar 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions Client/mods/deathmatch/logic/CClientDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@

#include <StdInc.h>

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;
}
}
16 changes: 6 additions & 10 deletions Client/mods/deathmatch/logic/CClientDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand All @@ -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;
Expand Down
85 changes: 30 additions & 55 deletions Client/mods/deathmatch/logic/CClientDisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CClientDisplay> CClientDisplayManager::Get(unsigned long ulID)
{
// Find the display with the given id
list<CClientDisplay*>::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;
Expand All @@ -49,57 +43,38 @@ void CClientDisplayManager::DrawText2D(const char* szCaption, const CVector& vec
static_cast<int>(fResHeight), rgbaColor, szCaption, fScale, fScale, 0);
}

void CClientDisplayManager::AddToList(CClientDisplay* pDisplay)
void CClientDisplayManager::AddToList(const std::shared_ptr<CClientDisplay>& 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<CClientDisplay*>::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<CClientDisplay>& 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<CClientVectorGraphicDisplay> CClientDisplayManager::CreateVectorGraphicDisplay(CClientVectorGraphic* svg)
{
// Render all our displays
m_bCanRemoveFromList = false;
list<CClientDisplay*>::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<CClientVectorGraphicDisplay>(svg);
AddToList(display);
return display;
}

m_bCanRemoveFromList = true;
std::shared_ptr<CClientTextDisplay> CClientDisplayManager::CreateTextDisplay(int ID)
{
auto display = std::make_shared<CClientTextDisplay>(ID);
AddToList(display);
return display;
}
23 changes: 13 additions & 10 deletions Client/mods/deathmatch/logic/CClientDisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@ class CClientDisplayManager;
#pragma once

#include "CClientManager.h"
#include <list>

class CClientDisplay;
#include "CClientDisplay.h"
#include "CClientVectorGraphicDisplay.h"
#include "CClientTextDisplay.h"

#include <list>

class CClientDisplayManager
{
friend class CClientManager;
friend class CClientDisplay;

public:
CClientDisplayManager();
~CClientDisplayManager();
CClientDisplayManager() = default;
~CClientDisplayManager() = default;

void DoPulse();

unsigned int Count() { return static_cast<unsigned int>(m_List.size()); };
CClientDisplay* Get(unsigned long ulID);
std::shared_ptr<CClientDisplay> 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<CClientDisplay>& display);

void AddToList(CClientDisplay* pDisplay);
void RemoveFromList(CClientDisplay* pDisplay);
std::shared_ptr<CClientVectorGraphicDisplay> CreateVectorGraphicDisplay(CClientVectorGraphic* svg);
std::shared_ptr<CClientTextDisplay> CreateTextDisplay(int ID = 0xFFFFFFFF);

std::list<CClientDisplay*> m_List;
bool m_bCanRemoveFromList;
std::list<std::weak_ptr<CClientDisplay>> m_List;
};

6 changes: 1 addition & 5 deletions Client/mods/deathmatch/logic/CClientTextDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ 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;
m_ulFormat = 0;
m_bVisible = true;
}

CClientTextDisplay::~CClientTextDisplay()
{
}

void CClientTextDisplay::SetCaption(const char* szCaption)
{
if (szCaption)
Expand Down
16 changes: 7 additions & 9 deletions Client/mods/deathmatch/logic/CClientTextDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ class CClientTextDisplay;
#include "CClientDisplayManager.h"
#include <gui/CGUI.h>

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; }

Expand All @@ -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;
};
10 changes: 6 additions & 4 deletions Client/mods/deathmatch/logic/CClientVectorGraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ CClientVectorGraphic::CClientVectorGraphic(CClientManager* pManager, ElementID I
SetTypeName("svg");

m_pManager = pManager;

m_pVectorGraphicDisplay = std::make_unique<CClientVectorGraphicDisplay>(m_pManager->GetDisplayManager(), this);
m_pVectorGraphicDisplay = m_pManager->GetDisplayManager()->CreateVectorGraphicDisplay(this);

// Generate the default XML document
SString defaultXmlString = SString("<svg viewBox='0 0 %u %u'></svg>", pVectorGraphicItem->m_uiSizeX, pVectorGraphicItem->m_uiSizeY);
Expand Down Expand Up @@ -46,7 +45,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)
Expand Down Expand Up @@ -80,11 +79,14 @@ bool CClientVectorGraphic::RemoveUpdateCallback()

void CClientVectorGraphic::OnUpdate()
{
if (!m_pVectorGraphicDisplay)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this situation possible?

return;

m_pVectorGraphicDisplay->UpdateTexture();

if (std::holds_alternative<CLuaFunctionRef>(m_updateCallbackRef))
{
auto func = std::get<CLuaFunctionRef>(m_updateCallbackRef);
auto& func = std::get<CLuaFunctionRef>(m_updateCallbackRef);
auto state = func.GetLuaVM();

if (VERIFY_FUNCTION(func) && state != NULL)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientVectorGraphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CClientVectorGraphic final : public CClientTexture
std::unique_ptr<SXMLString> m_pXMLString = nullptr;
CXMLNode* m_pXMLDocument = nullptr;

std::unique_ptr<CClientVectorGraphicDisplay> m_pVectorGraphicDisplay;
std::shared_ptr<CClientVectorGraphicDisplay> m_pVectorGraphicDisplay;

std::variant<CLuaFunctionRef, bool> m_updateCallbackRef = false;

Expand Down
9 changes: 6 additions & 3 deletions Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions Client/mods/deathmatch/logic/CClientVectorGraphicDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -38,7 +38,6 @@ class CClientVectorGraphicDisplay final : public CClientDisplay
private:
void UnpremultiplyBitmap(lunasvg::Bitmap& bitmap);

private:
CClientVectorGraphic* m_pVectorGraphic;

bool m_bIsCleared;
Expand Down
Loading
Loading