Skip to content

Commit

Permalink
UI: Move to ScreenManager for mapping.
Browse files Browse the repository at this point in the history
Otherwise we'll detect repeated axis for some devices and you won't be
able to map what you want.
  • Loading branch information
unknownbrackets committed May 23, 2021
1 parent e1e5a8b commit b0de7ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
11 changes: 11 additions & 0 deletions Common/UI/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ bool ScreenManager::key(const KeyInput &key) {

bool ScreenManager::axis(const AxisInput &axis) {
std::lock_guard<std::recursive_mutex> guard(inputLock_);

// Ignore duplicate values to prevent axis values overwriting each other.
uint64_t key = ((uint64_t)axis.axisId << 32) | axis.deviceId;
// Center value far from zero just to ensure we send the first zero.
// PSP games can't see higher resolution than this.
int value = 128 + ceilf(axis.value * 127.5f + 127.5f);
if (lastAxis_[key] == value) {
return false;
}
lastAxis_[key] = value;

bool result = false;
// Send center axis to every screen layer.
if (axis.value == 0) {
Expand Down
6 changes: 5 additions & 1 deletion Common/UI/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

#pragma once

#include <vector>
#include <cstdint>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>

#include "Common/Common.h"
#include "Common/Input/InputState.h"
Expand Down Expand Up @@ -165,4 +167,6 @@ class ScreenManager {
// Used for options, in-game menus and other things you expect to be able to back out from onto something.
std::vector<Layer> stack_;
std::vector<Layer> nextStack_;

std::unordered_map<int64_t, int> lastAxis_;
};
10 changes: 0 additions & 10 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,16 +864,6 @@ void EmuScreen::pspKey(int pspKeyCode, int flags) {
bool EmuScreen::axis(const AxisInput &axis) {
Core_NotifyActivity();

// Ignore duplicate values to prevent axis values overwriting each other.
uint64_t key = ((uint64_t)axis.axisId << 32) | axis.deviceId;
// Center value far from zero just to ensure we send the first zero.
// PSP games can't see higher resolution than this.
int value = 128 + ceilf(axis.value * 127.5f + 127.5f);
if (lastAxis_[key] == value) {
return false;
}
lastAxis_[key] = value;

if (axis.value > 0) {
processAxis(axis, 1);
return true;
Expand Down
3 changes: 0 additions & 3 deletions UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

#pragma once

#include <cstdint>
#include <list>
#include <string>
#include <unordered_map>
#include <vector>

#include "Common/File/Path.h"
Expand Down Expand Up @@ -115,5 +113,4 @@ class EmuScreen : public UIScreen {

bool autoRotatingAnalogCW_ = false;
bool autoRotatingAnalogCCW_ = false;
std::unordered_map<int64_t, int> lastAxis_;
};

0 comments on commit b0de7ee

Please sign in to comment.