mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
Added Thread Safty
This commit is contained in:
parent
32bcebc766
commit
e9dd59bdd9
@ -23,6 +23,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE GraphicsWindowInputDevice::
|
INLINE GraphicsWindowInputDevice::
|
||||||
GraphicsWindowInputDevice() {
|
GraphicsWindowInputDevice() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_flags = 0;
|
_flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ GraphicsWindowInputDevice() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE string GraphicsWindowInputDevice::
|
INLINE string GraphicsWindowInputDevice::
|
||||||
get_name() const {
|
get_name() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +45,7 @@ get_name() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE bool GraphicsWindowInputDevice::
|
INLINE bool GraphicsWindowInputDevice::
|
||||||
has_pointer() const {
|
has_pointer() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return ((_flags & IDF_has_pointer) != 0);
|
return ((_flags & IDF_has_pointer) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +56,7 @@ has_pointer() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE bool GraphicsWindowInputDevice::
|
INLINE bool GraphicsWindowInputDevice::
|
||||||
has_keyboard() const {
|
has_keyboard() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return ((_flags & IDF_has_keyboard) != 0);
|
return ((_flags & IDF_has_keyboard) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +68,7 @@ has_keyboard() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE const MouseData &GraphicsWindowInputDevice::
|
INLINE const MouseData &GraphicsWindowInputDevice::
|
||||||
get_pointer() const {
|
get_pointer() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return _mouse_data;
|
return _mouse_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +81,7 @@ get_pointer() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE const MouseData &GraphicsWindowInputDevice::
|
INLINE const MouseData &GraphicsWindowInputDevice::
|
||||||
get_raw_pointer() const {
|
get_raw_pointer() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return _true_mouse_data;
|
return _true_mouse_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +94,7 @@ get_raw_pointer() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GraphicsWindowInputDevice::
|
INLINE void GraphicsWindowInputDevice::
|
||||||
set_device_index(int index) {
|
set_device_index(int index) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_device_index = index;
|
_device_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +105,7 @@ set_device_index(int index) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GraphicsWindowInputDevice::
|
INLINE void GraphicsWindowInputDevice::
|
||||||
enable_pointer_events() {
|
enable_pointer_events() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_enable_pointer_events = true;
|
_enable_pointer_events = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +116,7 @@ enable_pointer_events() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GraphicsWindowInputDevice::
|
INLINE void GraphicsWindowInputDevice::
|
||||||
disable_pointer_events() {
|
disable_pointer_events() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_enable_pointer_events = false;
|
_enable_pointer_events = false;
|
||||||
_pointer_events.clear();
|
_pointer_events.clear();
|
||||||
}
|
}
|
||||||
@ -121,6 +130,7 @@ disable_pointer_events() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GraphicsWindowInputDevice::
|
INLINE void GraphicsWindowInputDevice::
|
||||||
set_pointer_in_window(int x, int y, double time) {
|
set_pointer_in_window(int x, int y, double time) {
|
||||||
|
// mutex is handled in set pointer .. convience function
|
||||||
set_pointer(true, x, y, time);
|
set_pointer(true, x, y, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +143,7 @@ set_pointer_in_window(int x, int y, double time) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GraphicsWindowInputDevice::
|
INLINE void GraphicsWindowInputDevice::
|
||||||
set_pointer_out_of_window(double time) {
|
set_pointer_out_of_window(double time) {
|
||||||
|
// mutex is handled in set pointer .. convience function
|
||||||
set_pointer(false, _mouse_data._xpos, _mouse_data._ypos, time);
|
set_pointer(false, _mouse_data._xpos, _mouse_data._ypos, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,22 +99,9 @@ pointer_and_keyboard(GraphicsWindow *host, const string &name) {
|
|||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
GraphicsWindowInputDevice::
|
GraphicsWindowInputDevice::
|
||||||
GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©) :
|
GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©)
|
||||||
_host(copy._host),
|
|
||||||
_name(copy._name),
|
|
||||||
_flags(copy._flags),
|
|
||||||
_device_index(copy._device_index),
|
|
||||||
_event_sequence(copy._event_sequence),
|
|
||||||
_pointer_mode_enable(copy._pointer_mode_enable),
|
|
||||||
_pointer_speed(copy._pointer_speed),
|
|
||||||
_pointer_true_x(copy._pointer_true_x),
|
|
||||||
_pointer_true_y(copy._pointer_true_y),
|
|
||||||
_enable_pointer_events(copy._enable_pointer_events),
|
|
||||||
_mouse_data(copy._mouse_data),
|
|
||||||
_true_mouse_data(copy._true_mouse_data),
|
|
||||||
_button_events(copy._button_events),
|
|
||||||
_pointer_events(copy._pointer_events)
|
|
||||||
{
|
{
|
||||||
|
*this = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -123,7 +110,10 @@ GraphicsWindowInputDevice(const GraphicsWindowInputDevice ©) :
|
|||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
operator = (const GraphicsWindowInputDevice ©) {
|
operator = (const GraphicsWindowInputDevice ©)
|
||||||
|
{
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
MutexHolder holder1(copy._lock);
|
||||||
_host = copy._host;
|
_host = copy._host;
|
||||||
_name = copy._name;
|
_name = copy._name;
|
||||||
_flags = copy._flags;
|
_flags = copy._flags;
|
||||||
@ -160,6 +150,7 @@ GraphicsWindowInputDevice::
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool GraphicsWindowInputDevice::
|
bool GraphicsWindowInputDevice::
|
||||||
has_button_event() const {
|
has_button_event() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return !_button_events.empty();
|
return !_button_events.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +162,7 @@ has_button_event() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
ButtonEvent GraphicsWindowInputDevice::
|
ButtonEvent GraphicsWindowInputDevice::
|
||||||
get_button_event() {
|
get_button_event() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
ButtonEvent be = _button_events.front();
|
ButtonEvent be = _button_events.front();
|
||||||
_button_events.pop_front();
|
_button_events.pop_front();
|
||||||
return be;
|
return be;
|
||||||
@ -186,6 +178,7 @@ get_button_event() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool GraphicsWindowInputDevice::
|
bool GraphicsWindowInputDevice::
|
||||||
has_pointer_event() const {
|
has_pointer_event() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
return (_pointer_events != 0);
|
return (_pointer_events != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +190,7 @@ has_pointer_event() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PT(PointerEventList) GraphicsWindowInputDevice::
|
PT(PointerEventList) GraphicsWindowInputDevice::
|
||||||
get_pointer_events() {
|
get_pointer_events() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
PT(PointerEventList) result = _pointer_events;
|
PT(PointerEventList) result = _pointer_events;
|
||||||
_pointer_events = 0;
|
_pointer_events = 0;
|
||||||
return result;
|
return result;
|
||||||
@ -222,6 +216,7 @@ get_pointer_events() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
enable_pointer_mode(double speed) {
|
enable_pointer_mode(double speed) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
nassertv(_device_index != 0);
|
nassertv(_device_index != 0);
|
||||||
_pointer_mode_enable = true;
|
_pointer_mode_enable = true;
|
||||||
_pointer_speed = speed;
|
_pointer_speed = speed;
|
||||||
@ -239,6 +234,7 @@ enable_pointer_mode(double speed) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
disable_pointer_mode() {
|
disable_pointer_mode() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
nassertv(_device_index != 0);
|
nassertv(_device_index != 0);
|
||||||
_pointer_mode_enable = false;
|
_pointer_mode_enable = false;
|
||||||
_pointer_speed = 1.0;
|
_pointer_speed = 1.0;
|
||||||
@ -254,6 +250,8 @@ disable_pointer_mode() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
set_pointer(bool inwin, int x, int y, double time) {
|
set_pointer(bool inwin, int x, int y, double time) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
int delta_x = x - _true_mouse_data._xpos;
|
int delta_x = x - _true_mouse_data._xpos;
|
||||||
int delta_y = y - _true_mouse_data._ypos;
|
int delta_y = y - _true_mouse_data._ypos;
|
||||||
_true_mouse_data._in_window = inwin;
|
_true_mouse_data._in_window = inwin;
|
||||||
@ -295,6 +293,7 @@ set_pointer(bool inwin, int x, int y, double time) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
button_down(ButtonHandle button, double time) {
|
button_down(ButtonHandle button, double time) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_down, time));
|
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_down, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,6 +307,7 @@ button_down(ButtonHandle button, double time) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
button_resume_down(ButtonHandle button, double time) {
|
button_resume_down(ButtonHandle button, double time) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_resume_down, time));
|
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_resume_down, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,6 +318,7 @@ button_resume_down(ButtonHandle button, double time) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
button_up(ButtonHandle button, double time) {
|
button_up(ButtonHandle button, double time) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_up, time));
|
_button_events.push_back(ButtonEvent(button, ButtonEvent::T_up, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,6 +330,7 @@ button_up(ButtonHandle button, double time) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
keystroke(int keycode, double time) {
|
keystroke(int keycode, double time) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_button_events.push_back(ButtonEvent(keycode, time));
|
_button_events.push_back(ButtonEvent(keycode, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +343,7 @@ keystroke(int keycode, double time) {
|
|||||||
void GraphicsWindowInputDevice::
|
void GraphicsWindowInputDevice::
|
||||||
candidate(const wstring &candidate_string, size_t highlight_start,
|
candidate(const wstring &candidate_string, size_t highlight_start,
|
||||||
size_t highlight_end, size_t cursor_pos) {
|
size_t highlight_end, size_t cursor_pos) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
_button_events.push_back(ButtonEvent(candidate_string,
|
_button_events.push_back(ButtonEvent(candidate_string,
|
||||||
highlight_start, highlight_end,
|
highlight_start, highlight_end,
|
||||||
cursor_pos));
|
cursor_pos));
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
#include "pdeque.h"
|
#include "pdeque.h"
|
||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
|
#include "pmutex.h"
|
||||||
|
#include "mutexHolder.h"
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : GraphicsWindowInputDevice
|
// Class : GraphicsWindowInputDevice
|
||||||
@ -58,8 +61,8 @@ public:
|
|||||||
|
|
||||||
INLINE void set_device_index(int index);
|
INLINE void set_device_index(int index);
|
||||||
|
|
||||||
INLINE const MouseData &get_pointer() const;
|
INLINE MouseData get_pointer() const;
|
||||||
INLINE const MouseData &get_raw_pointer() const;
|
INLINE MouseData get_raw_pointer() const;
|
||||||
|
|
||||||
INLINE void enable_pointer_events();
|
INLINE void enable_pointer_events();
|
||||||
INLINE void disable_pointer_events();
|
INLINE void disable_pointer_events();
|
||||||
@ -101,6 +104,8 @@ private:
|
|||||||
};
|
};
|
||||||
typedef pdeque<ButtonEvent> ButtonEvents;
|
typedef pdeque<ButtonEvent> ButtonEvents;
|
||||||
|
|
||||||
|
Mutex _lock;
|
||||||
|
|
||||||
GraphicsWindow *_host;
|
GraphicsWindow *_host;
|
||||||
|
|
||||||
string _name;
|
string _name;
|
||||||
@ -118,6 +123,7 @@ private:
|
|||||||
MouseData _true_mouse_data;
|
MouseData _true_mouse_data;
|
||||||
ButtonEvents _button_events;
|
ButtonEvents _button_events;
|
||||||
PT(PointerEventList) _pointer_events;
|
PT(PointerEventList) _pointer_events;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "graphicsWindowInputDevice.I"
|
#include "graphicsWindowInputDevice.I"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user