Panda3D
 All Classes Functions Variables Enumerations
eventQueue.cxx
1 // Filename: eventQueue.cxx
2 // Created by: drose (08Feb99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eventQueue.h"
16 #include "config_event.h"
17 #include "lightMutexHolder.h"
18 
19 EventQueue *EventQueue::_global_event_queue = NULL;
20 
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: EventQueue::Constructor
24 // Access: Published
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 EventQueue::
28 EventQueue() : _lock("EventQueue::_lock") {
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: EventQueue::Destructor
33 // Access: Published
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 EventQueue::
37 ~EventQueue() {
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: EventQueue::queue_event
42 // Access: Published
43 // Description:
44 ////////////////////////////////////////////////////////////////////
45 void EventQueue::
46 queue_event(CPT_Event event) {
47  nassertv(!event.is_null());
48  if (event->get_name().empty()) {
49  // Never mind.
50  return;
51  }
52 
53  LightMutexHolder holder(_lock);
54 
55  _queue.push_back(event);
56  if (event_cat.is_spam() || event_cat.is_debug()) {
57  if (event->get_name() == "NewFrame") {
58  // Don't bother us with this particularly spammy event.
59  event_cat.spam()
60  << "Throwing event " << *event << "\n";
61  } else {
62  event_cat.debug()
63  << "Throwing event " << *event << "\n";
64  }
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: EventQueue::clear
70 // Access: Published
71 // Description: Empties all events on the queue, throwing them on the
72 // floor.
73 ////////////////////////////////////////////////////////////////////
74 void EventQueue::
75 clear() {
76  LightMutexHolder holder(_lock);
77 
78  _queue.clear();
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: EventQueue::is_queue_empty
84 // Access: Published
85 // Description:
86 ////////////////////////////////////////////////////////////////////
87 bool EventQueue::
88 is_queue_empty() const {
89  LightMutexHolder holder(_lock);
90  return _queue.empty();
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: EventQueue::is_queue_full
95 // Access: Published
96 // Description: This function is deprecated--the queue is never full
97 // these days.
98 ////////////////////////////////////////////////////////////////////
99 bool EventQueue::
100 is_queue_full() const {
101  return false;
102 }
103 
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: EventQueue::dequeue_event
107 // Access: Published
108 // Description:
109 ////////////////////////////////////////////////////////////////////
110 CPT_Event EventQueue::
111 dequeue_event() {
112  LightMutexHolder holder(_lock);
113 
114  CPT_Event result = _queue.front();
115  _queue.pop_front();
116 
117  nassertr(!result.is_null(), result);
118  return result;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: EventQueue::make_global_event_queue
123 // Access: Protected, Static
124 // Description:
125 ////////////////////////////////////////////////////////////////////
126 void EventQueue::
127 make_global_event_queue() {
128  _global_event_queue = new EventQueue;
129 }
bool is_queue_full() const
This function is deprecated–the queue is never full these days.
Definition: eventQueue.cxx:100
A queue of pending events.
Definition: eventQueue.h:32
Similar to MutexHolder, but for a light mutex.
bool is_null() const
Returns true if the PointerTo is a NULL pointer, false otherwise.
Definition: pointerToVoid.I:54
void clear()
Empties all events on the queue, throwing them on the floor.
Definition: eventQueue.cxx:75
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144