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+ /*
6399void 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+ */
0 commit comments