Skip to content

Commit c5628c8

Browse files
committed
Revert "Improve addEvent when sharing events over multiple resources (#2333)"
This reverts commit f3811cb.
1 parent 39f3d39 commit c5628c8

File tree

4 files changed

+36
-64
lines changed

4 files changed

+36
-64
lines changed

Client/mods/deathmatch/logic/CEvents.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,16 @@ bool CEvents::AddEvent(const char* szName, const char* szArguments, CLuaMain* pL
2828
assert(szName);
2929
assert(szArguments);
3030

31-
// Get the event if it already exists
32-
SEvent* pEvent = Get(szName);
31+
// If it already exists, return
32+
if (Get(szName))
33+
return false;
3334

34-
if (pEvent)
35-
{
36-
// If bAllowRemoteTrigger has been altered, return
37-
if (pEvent->bAllowRemoteTrigger != bAllowRemoteTrigger)
38-
return false;
39-
40-
// Add pLuaMain to the vector, in case it's not already there
41-
if (!ListContains(pEvent->pLuaMainVector, pLuaMain))
42-
pEvent->pLuaMainVector.push_back(pLuaMain);
43-
}
44-
else
45-
{
46-
// Create and add the event
47-
pEvent = new SEvent;
48-
pEvent->strName = szName;
49-
pEvent->strArguments = szArguments;
50-
pEvent->pLuaMainVector.push_back(pLuaMain);
51-
pEvent->bAllowRemoteTrigger = bAllowRemoteTrigger;
52-
}
35+
// Create and add the event
36+
SEvent* pEvent = new SEvent;
37+
pEvent->strName = szName;
38+
pEvent->strArguments = szArguments;
39+
pEvent->pLuaMain = pLuaMain;
40+
pEvent->bAllowRemoteTrigger = bAllowRemoteTrigger;
5341

5442
m_EventHashMap[szName] = pEvent;
5543

@@ -92,19 +80,17 @@ void CEvents::RemoveAllEvents(class CLuaMain* pMain)
9280
while (iter != m_EventHashMap.end())
9381
{
9482
SEvent* pEvent = (*iter).second;
95-
ListRemoveFirst(pEvent->pLuaMainVector, pMain);
96-
97-
// If no pMain is left, delete it null it and set the bool
98-
if (pEvent->pLuaMainVector.empty())
83+
// If they match, delete it null it and set the bool
84+
if (pEvent != NULL && pEvent->pLuaMain == pMain)
9985
{
10086
// Delete the object
10187
delete pEvent;
10288

10389
// Remove from list
104-
m_EventHashMap.erase(iter);
90+
m_EventHashMap.erase(iter++);
10591
}
106-
107-
++iter;
92+
else
93+
++iter;
10894
}
10995
}
11096

Client/mods/deathmatch/logic/CEvents.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
struct SEvent
1818
{
19-
std::vector<class CLuaMain*> pLuaMainVector;
20-
std::string strName;
21-
std::string strArguments;
22-
bool bAllowRemoteTrigger;
19+
class CLuaMain* pLuaMain;
20+
std::string strName;
21+
std::string strArguments;
22+
bool bAllowRemoteTrigger;
2323
};
2424

2525
class CEvents

Server/mods/deathmatch/logic/CEvents.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,16 @@ bool CEvents::AddEvent(const char* szName, const char* szArguments, CLuaMain* pL
2222
assert(szName);
2323
assert(szArguments);
2424

25-
// Get the event if it already exists
26-
SEvent* pEvent = Get(szName);
25+
// If it already exists, return
26+
if (Get(szName))
27+
return false;
2728

28-
if (pEvent)
29-
{
30-
// If bAllowRemoteTrigger has been altered, return
31-
if (pEvent->bAllowRemoteTrigger != bAllowRemoteTrigger)
32-
return false;
33-
34-
// Add pLuaMain to the vector, in case it's not already there
35-
if (!ListContains(pEvent->pLuaMainVector, pLuaMain))
36-
pEvent->pLuaMainVector.push_back(pLuaMain);
37-
}
38-
else
39-
{
40-
// Create and add the event
41-
pEvent = new SEvent;
42-
pEvent->strName = szName;
43-
pEvent->strArguments = szArguments;
44-
pEvent->pLuaMainVector.push_back(pLuaMain);
45-
pEvent->bAllowRemoteTrigger = bAllowRemoteTrigger;
46-
}
29+
// Create and add the event
30+
SEvent* pEvent = new SEvent;
31+
pEvent->strName = szName;
32+
pEvent->strArguments = szArguments;
33+
pEvent->pLuaMain = pLuaMain;
34+
pEvent->bAllowRemoteTrigger = bAllowRemoteTrigger;
4735

4836
m_EventHashMap[szName] = pEvent;
4937

@@ -80,19 +68,17 @@ void CEvents::RemoveAllEvents(class CLuaMain* pMain)
8068
while (iter != m_EventHashMap.end())
8169
{
8270
SEvent* pEvent = (*iter).second;
83-
ListRemoveFirst(pEvent->pLuaMainVector, pMain);
84-
85-
// If no pMain is left, delete it null it and set the bool
86-
if (pEvent->pLuaMainVector.empty())
71+
// If they match, delete it null it and set the bool
72+
if (pEvent->pLuaMain == pMain)
8773
{
8874
// Delete the object
8975
delete pEvent;
9076

9177
// Remove from list
92-
m_EventHashMap.erase(iter);
78+
m_EventHashMap.erase(iter++);
9379
}
94-
95-
++iter;
80+
else
81+
++iter;
9682
}
9783
}
9884

Server/mods/deathmatch/logic/CEvents.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
struct SEvent
1919
{
20-
std::vector<class CLuaMain*> pLuaMainVector;
21-
std::string strName;
22-
std::string strArguments;
23-
bool bAllowRemoteTrigger;
20+
class CLuaMain* pLuaMain;
21+
std::string strName;
22+
std::string strArguments;
23+
bool bAllowRemoteTrigger;
2424
};
2525

2626
class CEvents

0 commit comments

Comments
 (0)