Skip to content

Commit 556de1e

Browse files
committed
Fixed listeners
- Fixed listener manager "ServerActivate"
1 parent 2d68742 commit 556de1e

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

src/core/addons/sp_addon.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ void CAddonManager::LevelInit( char const *pMapName )
8989
//---------------------------------------------------------------------------------
9090
// Calls server activate listeners.
9191
//---------------------------------------------------------------------------------
92-
// TODO: will not work if this is really a list
9392
void CAddonManager::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
9493
{
95-
CALL_LISTENERS(ServerActivate, pEdictList, edictCount, clientMax);
94+
list edicts;
95+
for(int i=0; i < edictCount; i++)
96+
edicts.append(pEdictList[i]);
97+
98+
CALL_LISTENERS(ServerActivate, edicts, edictCount, clientMax);
9699
}
97100

98101
//---------------------------------------------------------------------------------

src/core/modules/listeners/listenermanager.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
//-----------------------------------------------------------------------------
1313
// Macros
1414
//-----------------------------------------------------------------------------
15-
// This creates a static manager (only visible in file that uses this macro)
16-
// and an inline function that returns a pointer to the manager. That way we
17-
// avoid multiple definitions
15+
// This creates a static manager and an inline function that returns a pointer
16+
// to the manager. Must be used in a *.cpp file!
1817
#define DEFINE_MANAGER_ACCESSOR(name) \
1918
static CListenerManager s_##name; \
2019
inline CListenerManager* Get##name##ListenerManager() \
2120
{ return &s_##name; }
2221

2322
// Calls all listeners of the given manager
24-
#define CALL_LISTENERS(manager, ...) \
25-
for(int i = 0; i < s_##manager.m_vecCallables.Count(); i++) \
23+
#define CALL_LISTENERS(name, ...) \
24+
extern CListenerManager* Get##name##ListenerManager(); \
25+
for(int i = 0; i < Get##name##ListenerManager()->m_vecCallables.Count(); i++) \
2626
{ \
2727
BEGIN_BOOST_PY() \
28-
CALL_PY_FUNC(s_##manager.m_vecCallables[i].ptr(), ##__VA_ARGS__); \
29-
END_BOOST_PY_NORET() \
28+
CALL_PY_FUNC(Get##name##ListenerManager()->m_vecCallables[i].ptr(), ##__VA_ARGS__); \
29+
END_BOOST_PY_NORET() \
3030
}
3131

3232

@@ -43,20 +43,4 @@ class CListenerManager
4343
CUtlVector<object> m_vecCallables;
4444
};
4545

46-
// Create manager accessor functions
47-
DEFINE_MANAGER_ACCESSOR(ClientActive)
48-
DEFINE_MANAGER_ACCESSOR(ClientConnect)
49-
DEFINE_MANAGER_ACCESSOR(ClientDisconnect)
50-
DEFINE_MANAGER_ACCESSOR(ClientFullyConnect)
51-
DEFINE_MANAGER_ACCESSOR(ClientPutInServer)
52-
DEFINE_MANAGER_ACCESSOR(ClientSettingsChanged)
53-
DEFINE_MANAGER_ACCESSOR(LevelInit)
54-
DEFINE_MANAGER_ACCESSOR(LevelShutdown)
55-
DEFINE_MANAGER_ACCESSOR(NetworkidValidated)
56-
DEFINE_MANAGER_ACCESSOR(OnEdictAllocated)
57-
DEFINE_MANAGER_ACCESSOR(OnEdictFreed)
58-
DEFINE_MANAGER_ACCESSOR(OnQueryCvarValueFinished)
59-
DEFINE_MANAGER_ACCESSOR(ServerActivate)
60-
DEFINE_MANAGER_ACCESSOR(Tick)
61-
6246
#endif // _LISTENERMANAGER_H

src/core/modules/listeners/listeners_wrap_python.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@
3131
#include "utility/wrap_macros.h"
3232
#include "listenermanager.h"
3333

34-
//-----------------------------------------------------------------------------
35-
// Functions that expose tick listener functionality to us.
36-
//-----------------------------------------------------------------------------
37-
void export_listener_managers();
34+
35+
// Create manager accessor functions
36+
DEFINE_MANAGER_ACCESSOR(ClientActive)
37+
DEFINE_MANAGER_ACCESSOR(ClientConnect)
38+
DEFINE_MANAGER_ACCESSOR(ClientDisconnect)
39+
DEFINE_MANAGER_ACCESSOR(ClientFullyConnect)
40+
DEFINE_MANAGER_ACCESSOR(ClientPutInServer)
41+
DEFINE_MANAGER_ACCESSOR(ClientSettingsChanged)
42+
DEFINE_MANAGER_ACCESSOR(LevelInit)
43+
DEFINE_MANAGER_ACCESSOR(LevelShutdown)
44+
DEFINE_MANAGER_ACCESSOR(NetworkidValidated)
45+
DEFINE_MANAGER_ACCESSOR(OnEdictAllocated)
46+
DEFINE_MANAGER_ACCESSOR(OnEdictFreed)
47+
DEFINE_MANAGER_ACCESSOR(OnQueryCvarValueFinished)
48+
DEFINE_MANAGER_ACCESSOR(ServerActivate)
49+
DEFINE_MANAGER_ACCESSOR(Tick)
3850

3951
//-----------------------------------------------------------------------------
4052
// Exposes the listener_c module.
4153
//-----------------------------------------------------------------------------
54+
void export_listener_managers();
55+
4256
DECLARE_SP_MODULE(listener_c)
4357
{
4458
export_listener_managers();
@@ -56,7 +70,7 @@ void export_listener_managers()
5670
args("callable")
5771
)
5872

59-
.def("register_listener",
73+
.def("unregister_listener",
6074
&CListenerManager::UnregisterListener,
6175
"Removes a callable object. If it was not registered nothing will happen.",
6276
args("callable")

0 commit comments

Comments
 (0)