mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Add missing locking to control mapper
This commit is contained in:
parent
88e89653b1
commit
ea60ff2235
@ -130,6 +130,7 @@ static int RotatePSPKeyCode(int x) {
|
||||
}
|
||||
}
|
||||
|
||||
// Can only be called from Key or Axis.
|
||||
bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) {
|
||||
// Instead of taking an input key and finding what it outputs, we loop through the OUTPUTS and
|
||||
// see if the input that corresponds to it has a value. That way we can easily implement all sorts
|
||||
@ -247,6 +248,8 @@ bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
|
||||
InputMapping mapping(key.deviceId, key.keyCode);
|
||||
|
||||
if (key.flags & KEY_DOWN) {
|
||||
@ -255,6 +258,7 @@ bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) {
|
||||
curInput_[mapping] = 0.0f;
|
||||
}
|
||||
|
||||
// TODO: See if this can be simplified further somehow.
|
||||
bool mappingFound = KeyMap::InputMappingToPspButton(mapping, nullptr);
|
||||
DEBUG_LOG(SYSTEM, "Key: %d DeviceId: %d", key.keyCode, key.deviceId);
|
||||
if (!mappingFound || key.deviceId == DEVICE_ID_DEFAULT) {
|
||||
@ -268,6 +272,7 @@ bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) {
|
||||
}
|
||||
|
||||
void ControlMapper::Axis(const AxisInput &axis) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (axis.value > 0) {
|
||||
InputMapping mapping(axis.deviceId, axis.axisId, 1);
|
||||
curInput_[mapping] = axis.value;
|
||||
@ -305,6 +310,7 @@ void ControlMapper::Update() {
|
||||
}
|
||||
|
||||
void ControlMapper::PSPKey(int deviceId, int pspKeyCode, int flags) {
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (pspKeyCode >= VIRTKEY_FIRST) {
|
||||
int vk = pspKeyCode - VIRTKEY_FIRST;
|
||||
if (flags & KEY_DOWN) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
// Utilities for mapping input events to PSP inputs and virtual keys.
|
||||
// Main use is of course from EmuScreen.cpp, but also useful from control settings etc.
|
||||
@ -13,6 +14,7 @@ public:
|
||||
void Update();
|
||||
|
||||
// Inputs to the table-based mapping
|
||||
// These functions are free-threaded.
|
||||
bool Key(const KeyInput &key, bool *pauseTrigger);
|
||||
void Axis(const AxisInput &axis);
|
||||
|
||||
@ -50,6 +52,9 @@ private:
|
||||
bool autoRotatingAnalogCW_ = false;
|
||||
bool autoRotatingAnalogCCW_ = false;
|
||||
|
||||
// Protects basically all the state.
|
||||
std::mutex mutex_;
|
||||
|
||||
std::map<InputMapping, float> curInput_;
|
||||
|
||||
// Callbacks
|
||||
|
Loading…
Reference in New Issue
Block a user