mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 01:36:20 +02:00
Lock joystick states for thread safety.
This commit is contained in:
parent
5a2f61084e
commit
20eadab970
2 changed files with 9 additions and 1 deletions
|
@ -44,10 +44,16 @@ JoystickManager::~JoystickManager() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<JoystickState> JoystickManager::getJoystickStates() {
|
||||||
|
QMutexLocker locker(&_joystickMutex);
|
||||||
|
return _joystickStates;
|
||||||
|
}
|
||||||
|
|
||||||
void JoystickManager::update() {
|
void JoystickManager::update() {
|
||||||
#ifdef HAVE_SDL
|
#ifdef HAVE_SDL
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
|
|
||||||
|
QMutexLocker locker(&_joystickMutex);
|
||||||
for (int i = 0; i < _joystickStates.size(); i++) {
|
for (int i = 0; i < _joystickStates.size(); i++) {
|
||||||
SDL_Joystick* joystick = _joysticks.at(i);
|
SDL_Joystick* joystick = _joysticks.at(i);
|
||||||
JoystickState& state = _joystickStates[i];
|
JoystickState& state = _joystickStates[i];
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#ifndef hifi_JoystickManager_h
|
#ifndef hifi_JoystickManager_h
|
||||||
#define hifi_JoystickManager_h
|
#define hifi_JoystickManager_h
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
@ -31,12 +32,13 @@ public:
|
||||||
JoystickManager();
|
JoystickManager();
|
||||||
virtual ~JoystickManager();
|
virtual ~JoystickManager();
|
||||||
|
|
||||||
const QVector<JoystickState>& getJoystickStates() const { return _joystickStates; }
|
QVector<JoystickState> getJoystickStates();
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<JoystickState> _joystickStates;
|
QVector<JoystickState> _joystickStates;
|
||||||
|
QMutex _joystickMutex;
|
||||||
|
|
||||||
#ifdef HAVE_SDL
|
#ifdef HAVE_SDL
|
||||||
QVector<SDL_Joystick*> _joysticks;
|
QVector<SDL_Joystick*> _joysticks;
|
||||||
|
|
Loading…
Reference in a new issue