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_debug()) {
50  if (event->get_name() == "NewFrame") {
51  // Don't bother us with this particularly spammy event.
52  if (event_cat.is_spam()) {
53  event_cat.spam()
54  << "Throwing event " << *event << "\n";
55  }
56  } else {
57  event_cat.debug()
58  << "Throwing event " << *event << "\n";
59  }
60  }
61 }
62 
63 /**
64  * Empties all events on the queue, throwing them on the floor.
65  */
67 clear() {
68  LightMutexHolder holder(_lock);
69 
70  _queue.clear();
71 }
72 
73 
74 /**
75  *
76  */
77 bool EventQueue::
78 is_queue_empty() const {
79  LightMutexHolder holder(_lock);
80  return _queue.empty();
81 }
82 
83 /**
84  * @deprecated Always returns false; the queue can never be full.
85  */
87 is_queue_full() const {
88  return false;
89 }
90 
91 
92 /**
93  *
94  */
95 CPT_Event EventQueue::
96 dequeue_event() {
97  LightMutexHolder holder(_lock);
98 
99  CPT_Event result = _queue.front();
100  _queue.pop_front();
101 
102  nassertr(!result.is_null(), result);
103  return result;
104 }
105 
106 /**
107  *
108  */
109 void EventQueue::
110 make_global_event_queue() {
112  _global_event_queue = new EventQueue;
113 }
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition: pointerTo.h:144
A queue of pending events.
Definition: eventQueue.h:29
bool is_queue_full() const
Definition: eventQueue.cxx:87
void clear()
Empties all events on the queue, throwing them on the floor.
Definition: eventQueue.cxx:67
Similar to MutexHolder, but for a light mutex.
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.