00001 // Filename: eventQueue.cxx 00002 // Created by: drose (08Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "eventQueue.h" 00016 #include "config_event.h" 00017 #include "lightMutexHolder.h" 00018 00019 EventQueue *EventQueue::_global_event_queue = NULL; 00020 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: EventQueue::Constructor 00024 // Access: Published 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 EventQueue:: 00028 EventQueue() : _lock("EventQueue::_lock") { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: EventQueue::Destructor 00033 // Access: Published 00034 // Description: 00035 //////////////////////////////////////////////////////////////////// 00036 EventQueue:: 00037 ~EventQueue() { 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: EventQueue::queue_event 00042 // Access: Published 00043 // Description: 00044 //////////////////////////////////////////////////////////////////// 00045 void EventQueue:: 00046 queue_event(CPT_Event event) { 00047 nassertv(!event.is_null()); 00048 if (event->get_name().empty()) { 00049 // Never mind. 00050 return; 00051 } 00052 00053 LightMutexHolder holder(_lock); 00054 00055 _queue.push_back(event); 00056 if (event_cat.is_spam() || event_cat.is_debug()) { 00057 if (event->get_name() == "NewFrame") { 00058 // Don't bother us with this particularly spammy event. 00059 event_cat.spam() 00060 << "Throwing event " << *event << "\n"; 00061 } else { 00062 event_cat.debug() 00063 << "Throwing event " << *event << "\n"; 00064 } 00065 } 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: EventQueue::clear 00070 // Access: Published 00071 // Description: Empties all events on the queue, throwing them on the 00072 // floor. 00073 //////////////////////////////////////////////////////////////////// 00074 void EventQueue:: 00075 clear() { 00076 LightMutexHolder holder(_lock); 00077 00078 _queue.clear(); 00079 } 00080 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: EventQueue::is_queue_empty 00084 // Access: Published 00085 // Description: 00086 //////////////////////////////////////////////////////////////////// 00087 bool EventQueue:: 00088 is_queue_empty() const { 00089 LightMutexHolder holder(_lock); 00090 return _queue.empty(); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: EventQueue::is_queue_full 00095 // Access: Published 00096 // Description: This function is deprecated--the queue is never full 00097 // these days. 00098 //////////////////////////////////////////////////////////////////// 00099 bool EventQueue:: 00100 is_queue_full() const { 00101 return false; 00102 } 00103 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: EventQueue::dequeue_event 00107 // Access: Published 00108 // Description: 00109 //////////////////////////////////////////////////////////////////// 00110 CPT_Event EventQueue:: 00111 dequeue_event() { 00112 LightMutexHolder holder(_lock); 00113 00114 CPT_Event result = _queue.front(); 00115 _queue.pop_front(); 00116 00117 nassertr(!result.is_null(), result); 00118 return result; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: EventQueue::make_global_event_queue 00123 // Access: Protected, Static 00124 // Description: 00125 //////////////////////////////////////////////////////////////////// 00126 void EventQueue:: 00127 make_global_event_queue() { 00128 _global_event_queue = new EventQueue; 00129 }