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