2222
2323TypeHandle EventHandler::_type_handle;
2424
25+ EventHandler *EventHandler::_global_event_handler = 0 ;
26+
27+
2528// //////////////////////////////////////////////////////////////////
2629// Function: EventHandler::Constructor
2730// Access: Public
@@ -54,6 +57,7 @@ process_events() {
5457// //////////////////////////////////////////////////////////////////
5558void EventHandler::
5659dispatch_event (const CPT_Event &event) {
60+ nassertv (!event.is_null ());
5761 // Is the event name defined in the hook table? It will be if
5862 // anyone has ever assigned a hook to this particular event name.
5963 Hooks::const_iterator hi;
@@ -66,10 +70,11 @@ dispatch_event(const CPT_Event &event) {
6670
6771 Functions::const_iterator fi;
6872 for (fi = copy_functions.begin (); fi != copy_functions.end (); ++fi) {
69- if (event_cat.is_spam ())
70- event_cat->spam () << " calling callback 0x" << (void *)(*fi)
73+ if (event_cat.is_spam ()) {
74+ event_cat->spam () << " calling callback 0x" << (void *)(*fi)
7175 << " for event '" << event->get_name () << " '"
7276 << endl;
77+ }
7378 (*fi)(event);
7479 }
7580 }
@@ -107,11 +112,9 @@ write(ostream &out) const {
107112 if ((*hi).first < (*cbhi).first ) {
108113 write_hook (out, *hi);
109114 ++hi;
110-
111115 } else if ((*cbhi).first < (*hi).first ) {
112116 write_cbhook (out, *cbhi);
113117 ++cbhi;
114-
115118 } else {
116119 write_hook (out, *hi);
117120 write_cbhook (out, *cbhi);
@@ -144,9 +147,12 @@ write(ostream &out) const {
144147// //////////////////////////////////////////////////////////////////
145148bool EventHandler::
146149add_hook (const string &event_name, EventFunction *function) {
147- if (event_cat.is_debug ())
150+ if (event_cat.is_debug ()) {
148151 event_cat.debug () << " adding hook for event '" << event_name
149152 << " ' with function 0x" << (void *)function << endl;
153+ }
154+ assert (!event_name.empty ());
155+ assert (function);
150156 return _hooks[event_name].insert (function).second ;
151157}
152158
@@ -164,6 +170,8 @@ add_hook(const string &event_name, EventFunction *function) {
164170bool EventHandler::
165171add_hook (const string &event_name, EventCallbackFunction *function,
166172 void *data) {
173+ assert (!event_name.empty ());
174+ assert (function);
167175 return _cbhooks[event_name].insert (CallbackFunction (function, data)).second ;
168176}
169177
@@ -175,6 +183,7 @@ add_hook(const string &event_name, EventCallbackFunction *function,
175183// //////////////////////////////////////////////////////////////////
176184bool EventHandler::
177185has_hook (const string &event_name) const {
186+ assert (!event_name.empty ());
178187 Hooks::const_iterator hi;
179188 hi = _hooks.find (event_name);
180189 if (hi != _hooks.end ()) {
@@ -204,6 +213,8 @@ has_hook(const string &event_name) const {
204213// //////////////////////////////////////////////////////////////////
205214bool EventHandler::
206215remove_hook (const string &event_name, EventFunction *function) {
216+ assert (!event_name.empty ());
217+ assert (function);
207218 return _hooks[event_name].erase (function) != 0 ;
208219}
209220
@@ -219,6 +230,8 @@ remove_hook(const string &event_name, EventFunction *function) {
219230bool EventHandler::
220231remove_hook (const string &event_name, EventCallbackFunction *function,
221232 void *data) {
233+ assert (!event_name.empty ());
234+ assert (function);
222235 return _cbhooks[event_name].erase (CallbackFunction (function, data)) != 0 ;
223236}
224237
@@ -234,6 +247,17 @@ remove_all_hooks() {
234247 _cbhooks.clear ();
235248}
236249
250+ // //////////////////////////////////////////////////////////////////
251+ // Function: EventHandler::make_global_event_handler
252+ // Access: Protected, Static
253+ // Description:
254+ // //////////////////////////////////////////////////////////////////
255+ void EventHandler::
256+ make_global_event_handler (EventQueue *queue) {
257+ assert (queue);
258+ _global_event_handler = new EventHandler (queue);
259+ }
260+
237261
238262// //////////////////////////////////////////////////////////////////
239263// Function: EventHandler::write_hook
0 commit comments