Panda3D

Loading...
Searching...
No Matches
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 */
24EventQueue::
25EventQueue() : _lock("EventQueue::_lock") {
26}
27
28/**
29 *
30 */
31EventQueue::
32~EventQueue() {
33}
34
35/**
36 *
37 */
38 void EventQueue::
39queue_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 */
66 void EventQueue::
67 clear() {
68 LightMutexHolder holder(_lock);
69
70 _queue.clear();
71}
72
73
74/**
75 *
76 */
77 bool EventQueue::
78is_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 */
86 bool EventQueue::
87 is_queue_full() const {
88 return false;
89}
90
91
92/**
93 *
94 */
95CPT_Event EventQueue::
96dequeue_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::
110make_global_event_queue() {
111 init_memory_hook();
112 _global_event_queue = new EventQueue;
113}
EventQueue
A queue of pending events.
Definition eventQueue.h:29
EventQueue::is_queue_full
bool is_queue_full() const
Definition eventQueue.cxx:87
EventQueue::clear
void clear()
Empties all events on the queue, throwing them on the floor.
Definition eventQueue.cxx:67
InternalName::get_name
get_name
Returns the complete name represented by the InternalName and all of its parents.
Definition internalName.h:61
LightMutexHolder
Similar to MutexHolder, but for a light mutex.
Definition lightMutexHolder.h:25
PointerToVoid::is_null
constexpr bool is_null() const
Returns true if the PointerTo is a NULL pointer, false otherwise.
Definition pointerToVoid.I:27
config_event.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
init_memory_hook
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
eventQueue.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lightMutexHolder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.