Skip to content

Commit

Permalink
Revert "Fixed client crash caused by destroying markers during hit/le…
Browse files Browse the repository at this point in the history
…ave events"

This reverts commit 984ea46.
  • Loading branch information
ccw808 committed Mar 30, 2018
1 parent 89f742d commit 30f8fa9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 60 deletions.
19 changes: 17 additions & 2 deletions Client/mods/deathmatch/logic/CClientMarkerManager.cpp
Expand Up @@ -10,6 +10,8 @@

#include "StdInc.h"

using std::list;

CClientMarkerManager::CClientMarkerManager(CClientManager* pManager)
{
// Init
Expand All @@ -35,6 +37,21 @@ CClientMarker* CClientMarkerManager::Get(ElementID ID)
return NULL;
}

bool CClientMarkerManager::Exists(CClientMarker* pMarker)
{
return m_Markers.contains(pMarker);
}

void CClientMarkerManager::Delete(int ID)
{
// Grab it and eventually delete it
CClientMarker* pMarker = Get(ID);
if (pMarker)
{
delete pMarker;
}
}

void CClientMarkerManager::DeleteAll(void)
{
// Delete each checkpoint
Expand All @@ -53,12 +70,10 @@ void CClientMarkerManager::DeleteAll(void)

void CClientMarkerManager::DoPulse(void)
{
m_Markers.SuspendModifyOperations();
// Pulse all our markers
CFastList<CClientMarker*>::const_iterator iter = m_Markers.begin();
for (; iter != m_Markers.end(); iter++)
{
(*iter)->DoPulse();
}
m_Markers.ResumeModifyOperations();
}
10 changes: 9 additions & 1 deletion Client/mods/deathmatch/logic/CClientMarkerManager.h
Expand Up @@ -23,12 +23,20 @@ class CClientMarkerManager
public:
unsigned int Count(void) { return static_cast<unsigned int>(m_Markers.size()); };
static CClientMarker* Get(ElementID ID);
void DeleteAll(void);
bool Exists(CClientMarker* pMarker);

void Delete(int ID);
void DeleteAll(void);

CFastList<CClientMarker*>::const_iterator IterBegin(void) { return m_Markers.begin(); };
CFastList<CClientMarker*>::const_iterator IterEnd(void) { return m_Markers.end(); };

private:
CClientMarkerManager(class CClientManager* pManager);
~CClientMarkerManager(void);

void DoPulse(void);

void AddToList(CClientMarker* pCheckpoint) { m_Markers.push_back(pCheckpoint); };
void RemoveFromList(CClientMarker* pCheckpoint)
{
Expand Down
58 changes: 1 addition & 57 deletions Shared/sdk/CFastList.h
Expand Up @@ -36,27 +36,14 @@ class CFastList
typedef typename std::map<uint, T> MapType;
typedef typename std::pair<uint, T> MapTypePair;
typedef typename std::map<T, uint> InfoType;
enum class EOperation
{
PushBack,
PushFront,
Remove,
};
struct SSuspendedOperation
{
EOperation operation;
T item;
};

uint uiRevision; // Incremented every time the ordered map changes
uint uiNextFrontIndex; // Next (decrementing) index to use as a map key for items added to the front
uint uiNextBackIndex; // Next (incrementing) index to use as a map key for items added to the back
MapType orderedMap; // Ordered map of items
InfoType infoMap; // info for each item
bool m_bSuspendingModifyOperations;
std::vector<SSuspendedOperation> m_SuspendedOperationList;

CFastList(void) : uiRevision(1), uiNextFrontIndex(UINT_MAX / 2 - 1), uiNextBackIndex(UINT_MAX / 2), m_bSuspendingModifyOperations(false)
CFastList(void) : uiRevision(1), uiNextFrontIndex(UINT_MAX / 2 - 1), uiNextBackIndex(UINT_MAX / 2)
{
#ifdef MTA_DEBUG
// T must be a pointer
Expand All @@ -69,18 +56,12 @@ class CFastList

void pop_front(void)
{
dassert(!m_bSuspendingModifyOperations);
T item = front();
remove(item);
}

void push_front(const T& item)
{
if (m_bSuspendingModifyOperations)
{
m_SuspendedOperationList.push_back({EOperation::PushFront, item});
return;
}
// Check if indexing will wrap (and so destroy map order)
if (uiNextFrontIndex < 5000)
Reindex();
Expand All @@ -94,11 +75,6 @@ class CFastList

void push_back(const T& item)
{
if (m_bSuspendingModifyOperations)
{
m_SuspendedOperationList.push_back({EOperation::PushBack, item});
return;
}
// Check if indexing will wrap (and so destroy map order)
if (uiNextBackIndex > UINT_MAX - 5000)
Reindex();
Expand All @@ -118,7 +94,6 @@ class CFastList

void clear(void)
{
dassert(!m_bSuspendingModifyOperations);
orderedMap.clear();
uiRevision++;
infoMap.clear();
Expand All @@ -128,11 +103,6 @@ class CFastList

void remove(const T& item)
{
if (m_bSuspendingModifyOperations)
{
m_SuspendedOperationList.push_back({EOperation::Remove, item});
return;
}
if (uint uiIndex = GetItemIndex(item))
{
typename MapType::iterator it = orderedMap.find(uiIndex);
Expand All @@ -146,32 +116,6 @@ class CFastList

uint GetRevision(void) const { return uiRevision; }

// Queue remove/push_back/push_front operations until ResumeModifyOperations is called
void SuspendModifyOperations(void)
{
dassert(!m_bSuspendingModifyOperations);
m_bSuspendingModifyOperations = true;
}

// Replay queued operations
void ResumeModifyOperations(void)
{
dassert(m_bSuspendingModifyOperations);
m_bSuspendingModifyOperations = false;
for (const auto& suspendedOperation : m_SuspendedOperationList)
{
if (suspendedOperation.operation == EOperation::PushBack)
push_back(suspendedOperation.item);
else
if (suspendedOperation.operation == EOperation::PushFront)
push_front(suspendedOperation.item);
else
if (suspendedOperation.operation == EOperation::Remove)
remove(suspendedOperation.item);
}
m_SuspendedOperationList.clear();
}

protected:
// Reset indexing
void Reindex(void)
Expand Down

0 comments on commit 30f8fa9

Please sign in to comment.