Skip to content

Commit 5d68949

Browse files
committed
Now uses universal call_listener method; though currently only int, char and edict_t are supported.
1 parent 087150b commit 5d68949

13 files changed

+83
-129
lines changed

src/core/addons/sp_addon.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ CAddonManager::~CAddonManager( void )
6767
void CAddonManager::GameFrame()
6868
{
6969
// Dispatch all tick listeners
70-
get_tick_listener_manager()->call_listeners();
70+
get_tick_listener_manager()->call_listeners(0);
7171
}
7272

7373
//---------------------------------------------------------------------------------
7474
// Calls network id validated listeners.
7575
//---------------------------------------------------------------------------------
7676
void CAddonManager::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
7777
{
78+
// Wrap the parameters
79+
CListenerManager::Param p1, p2;
80+
p1.name="pszUserName"; p1.type=CListenerManager::CHAR; p1.char_ptr = pszUserName;
81+
p2.name="pszNetworkID"; p2.type=CListenerManager::CHAR; p2.char_ptr = pszNetworkID;
7882
// Dispatch all NetwordIDValidatedListeners
79-
get_networkid_validated_listener_manager()->call_listeners(pszUserName, pszNetworkID);
83+
get_networkid_validated_listener_manager()->call_listeners(2, p1, p2);
8084
}

src/core/modules/listeners/client_put_in_server_listeners_wrap.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@
3535
//-----------------------------------------------------------------------------
3636
static CClientPutInServerListenerManager s_ClientPutInServerListenerManager;
3737

38-
//-----------------------------------------------------------------------------
39-
// Overload for passing the arguments
40-
//-----------------------------------------------------------------------------
41-
void CClientPutInServerListenerManager::call_listeners( edict_t *pEntity, char const *playername )
42-
{
43-
for(int i = 0; i < m_vecCallables.Count(); i++)
44-
{
45-
BEGIN_BOOST_PY()
46-
47-
// Get the PyObject instance of the callable
48-
PyObject* pCallable = m_vecCallables[i].ptr();
49-
50-
// Call the callable
51-
CALL_PY_FUNC(pCallable, pEntity, playername);
52-
53-
END_BOOST_PY_NORET()
54-
}
55-
}
56-
5738
//-----------------------------------------------------------------------------
5839
// ClientPutInServerkListenerManager accessor.
5940
//-----------------------------------------------------------------------------

src/core/modules/listeners/client_put_in_server_listeners_wrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
//-----------------------------------------------------------------------------
3939
class CClientPutInServerListenerManager: public CListenerManager
4040
{
41-
void call_listeners( edict_t *pEntity, char const *playername );
4241
};
4342

4443
CClientPutInServerListenerManager* get_client_put_in_server_listener_manager();

src/core/modules/listeners/level_init_listeners_wrap.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@
3535
//-----------------------------------------------------------------------------
3636
static CLevelInitListenerManager s_LevelInitListenerManager;
3737

38-
//-----------------------------------------------------------------------------
39-
// Overload for passing the arguments
40-
//-----------------------------------------------------------------------------
41-
void CLevelInitListenerManager::call_listeners( char const *pMapName )
42-
{
43-
for(int i = 0; i < m_vecCallables.Count(); i++)
44-
{
45-
BEGIN_BOOST_PY()
46-
47-
// Get the PyObject instance of the callable
48-
PyObject* pCallable = m_vecCallables[i].ptr();
49-
50-
// Call the callable
51-
CALL_PY_FUNC(pCallable, pMapName);
52-
53-
END_BOOST_PY_NORET()
54-
}
55-
}
56-
5738
//-----------------------------------------------------------------------------
5839
// LevelInitListenerManager accessor.
5940
//-----------------------------------------------------------------------------

src/core/modules/listeners/level_init_listeners_wrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
//-----------------------------------------------------------------------------
3939
class CLevelInitListenerManager: public CListenerManager
4040
{
41-
void call_listeners( char const *pMapName );
4241
};
4342

4443
CLevelInitListenerManager* get_level_init_listener_manager();

src/core/modules/listeners/listenermanager.cpp

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "listenermanager.h"
55
#include "utility/call_python.h"
66
#include "boost/python.hpp"
7+
#include "modules/entities/entities_wrap.h"
8+
#include <stdarg.h> // For va_list, va_end etc
79

810
//-----------------------------------------------------------------------------
911
// Adds a callable to the end of the CListenerManager vector.
@@ -36,30 +38,64 @@ void CListenerManager::unregister_listener(PyObject* pCallable)
3638
//-----------------------------------------------------------------------------
3739
// Calls all registered listeners.
3840
//-----------------------------------------------------------------------------
39-
// FSS No C++11 suport? In neither, VS2010 and VS2012?
40-
// template<typename... Types> void CListenerManager::call_listeners(typename... args)
41-
/* Other idea:
42-
typedef struct {
43-
int type;
44-
union {
45-
int int_value;
46-
double double_value;
47-
...
48-
};
49-
} Param;
50-
51-
boost::python::list lReturn = boost::python::list();
52-
53-
va_list varargs;
54-
55-
va_start(varargs, argc);
56-
for (int i = 0; i < argc; i++)
41+
42+
void CListenerManager::call_listeners(int argc, ...)
43+
{
44+
if (argc > 0)
45+
{
46+
boost::python::dict dReturn = boost::python::dict();
47+
48+
va_list varargs;
49+
50+
va_start(varargs, argc);
51+
for (int i = 0; i < argc; i++)
52+
{
53+
Param p = va_arg(varargs, Param);
54+
switch (p.type)
55+
{
56+
case CListenerManager::INTEGER:
57+
dReturn[p.name] = p.int_value;
58+
break;
59+
case CListenerManager::CHAR:
60+
dReturn[p.name] = p.char_ptr;
61+
break;
62+
case CListenerManager::EDICT_T:
63+
dReturn[p.name] = CEdict(p.edict_t_ptr);
64+
}
65+
}
66+
va_end(varargs);
67+
68+
for(int i = 0; i < m_vecCallables.Count(); i++)
69+
{
70+
BEGIN_BOOST_PY()
71+
72+
// Get the PyObject instance of the callable
73+
PyObject* pCallable = m_vecCallables[i].ptr();
74+
75+
// Call the callable
76+
CALL_PY_FUNC(pCallable, dReturn);
77+
78+
END_BOOST_PY_NORET()
79+
}
80+
}
81+
else // For speed reasons (i.e. ticklistener) this sperate, so it doesn't create dictionary objects if no parameters are passed
5782
{
58-
lReturn.append<Param>(va_arg(varargs, Param));
83+
for(int i = 0; i < m_vecCallables.Count(); i++)
84+
{
85+
BEGIN_BOOST_PY()
86+
87+
// Get the PyObject instance of the callable
88+
PyObject* pCallable = m_vecCallables[i].ptr();
89+
90+
// Call the callable
91+
CALL_PY_FUNC(pCallable);
92+
93+
END_BOOST_PY_NORET()
94+
}
5995
}
60-
va_end;
61-
*/
96+
}
6297

98+
/*
6399
void CListenerManager::call_listeners()
64100
{
65101
for(int i = 0; i < m_vecCallables.Count(); i++)
@@ -91,3 +127,4 @@ void CListenerManager::call_listeners( edict_t *pEntity )
91127
END_BOOST_PY_NORET()
92128
}
93129
}
130+
*/

src/core/modules/listeners/listenermanager.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,29 @@ class CListenerManager
1515
{
1616
public:
1717

18+
enum types {
19+
INTEGER=0,
20+
CHAR,
21+
EDICT_T
22+
};
23+
24+
struct Param {
25+
int type;
26+
const char* name; // For naming in the dict
27+
union {
28+
int int_value;
29+
const char* char_ptr;
30+
edict_t* edict_t_ptr;
31+
};
32+
};
33+
1834
void register_listener(PyObject* pCallable);
1935
void unregister_listener(PyObject* pCallable);
2036

21-
void call_listeners();
37+
void call_listeners(int argc, ...);
38+
/*void call_listeners();
2239
// A lot of listener just pass an entity pointer
23-
void call_listeners( edict_t *pEntity );
40+
void call_listeners( edict_t *pEntity );*/
2441

2542
protected:
2643
CUtlVector<object> m_vecCallables;

src/core/modules/listeners/networkid_validated_listeners_wrap.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@
3535
//-----------------------------------------------------------------------------
3636
static CNetworkIDValidatedListenerManager s_NetworkIDValidatedListenerManager;
3737

38-
//-----------------------------------------------------------------------------
39-
// Overload for passing the arguments
40-
//-----------------------------------------------------------------------------
41-
void CNetworkIDValidatedListenerManager::call_listeners( const char *pszUserName, const char *pszNetworkID )
42-
{
43-
for(int i = 0; i < m_vecCallables.Count(); i++)
44-
{
45-
BEGIN_BOOST_PY()
46-
47-
// Get the PyObject instance of the callable
48-
PyObject* pCallable = m_vecCallables[i].ptr();
49-
50-
// Call the callable
51-
CALL_PY_FUNC(pCallable, pszUserName, pszNetworkID);
52-
53-
END_BOOST_PY_NORET()
54-
}
55-
}
56-
5738
//-----------------------------------------------------------------------------
5839
// CNetworkIDValidatedListenerManager accessor.
5940
//-----------------------------------------------------------------------------

src/core/modules/listeners/networkid_validated_listeners_wrap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
//-----------------------------------------------------------------------------
3939
class CNetworkIDValidatedListenerManager: public CListenerManager
4040
{
41-
public:
42-
void call_listeners( const char *pszUserName, const char *pszNetworkID );
4341
};
4442

4543
CNetworkIDValidatedListenerManager* get_networkid_validated_listener_manager();

src/core/modules/listeners/on_query_cvar_value_finished_listeners_wrap.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,6 @@
3535
//-----------------------------------------------------------------------------
3636
static COnQueryCvarValueFinishedListenerManager s_OnQueryCvarValueFinishedListenerManager;
3737

38-
//-----------------------------------------------------------------------------
39-
// Overload for passing the arguments
40-
//-----------------------------------------------------------------------------
41-
void COnQueryCvarValueFinishedListenerManager::call_listeners(
42-
QueryCvarCookie_t iCookie, edict_t *pPlayerEntity,
43-
EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
44-
{
45-
for(int i = 0; i < m_vecCallables.Count(); i++)
46-
{
47-
BEGIN_BOOST_PY()
48-
49-
// Get the PyObject instance of the callable
50-
PyObject* pCallable = m_vecCallables[i].ptr();
51-
52-
// Call the callable
53-
CALL_PY_FUNC(pCallable, iCookie, pPlayerEntity, eStatus, pCvarName, pCvarValue);
54-
55-
END_BOOST_PY_NORET()
56-
}
57-
}
58-
5938
//-----------------------------------------------------------------------------
6039
// OnQueryCvarValueFinishedListenerManager accessor.
6140
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)