More callback fixes

This commit is contained in:
Henrik Rydgård committed 2023-03-31 11:05:33 +02:00
1 parent 7dfa587fe2
commit ca300a4dfd
4 files changed
+15 -16

No files matched your search

+9 -12
View File
@@ -71,7 +71,7 @@ void ControlMapper::SetCallbacks(
std::function<void(int, bool)> setPSPButtonState,
std::function<void(int, float, float)> setPSPAnalog) {
onVKey_ = onVKey;
onVKeyAnalog_ = onVKey;
onVKeyAnalog_ = onVKeyAnalog;
setAllPSPButtonStates_ = setAllPSPButtonStates;
setPSPButtonState_ = setPSPButtonState;
setPSPAnalog_ = setPSPAnalog;
@@ -113,12 +113,9 @@ void ControlMapper::SetPSPAxis(int device, int stick, char axis, float value) {
if (!ignore) {
history_[stick][axisId] = value;
float x = history_[stick][0];
float y = history_[stick][1];
float convertedX, convertedY;
ConvertAnalogStick(x, y, &convertedX, &convertedY);
setPSPAnalog_(stick, convertedX, convertedY);
float x, y;
ConvertAnalogStick(history_[stick][0], history_[stick][1], &x, &y);
setPSPAnalog_(stick, x, y);
}
}
@@ -187,13 +184,13 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) {
std::vector<InputMapping> inputMappings;
if (!KeyMap::InputMappingsFromPspButton(vkId, &inputMappings, false))
continue;
float value = 0.0f;
// If a mapping could consist of a combo, we could trivially check it here.
// Save the first device ID so we can pass it into onVKeyDown, which in turn needs it for the analog
// mapping which gets a little hacky.
float threshold = 1.0f;
bool touchedByMapping = false;
float value = 0.0f;
for (auto &mapping : inputMappings) {
if (mapping == changedMapping) {
touchedByMapping = true;
@@ -203,10 +200,8 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) {
if (iter != curInput_.end()) {
if (mapping.IsAxis()) {
threshold = GetDeviceAxisThreshold(iter->first.deviceId);
value += iter->second;
} else {
value += iter->second;
}
value += iter->second;
}
}
@@ -222,11 +217,13 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping) {
if (virtKeys_[i] != value) {
// INFO_LOG(G3D, "vkeyanalog %s : %f", KeyMap::GetVirtKeyName(vkId), value);
onVKeyAnalog(changedMapping.deviceId, vkId, value);
virtKeys_[i] = value;
}
virtKeys_[i] = value;
if (!bPrevValue && bValue) {
// INFO_LOG(G3D, "vkeyon %s", KeyMap::GetVirtKeyName(vkId));
onVKey(vkId, true);
} else if (bPrevValue && !bValue) {
// INFO_LOG(G3D, "vkeyoff %s", KeyMap::GetVirtKeyName(vkId));
onVKey(vkId, false);
}
}
-3
View File
@@ -44,9 +44,6 @@ private:
// To track mappable virtual keys. We can have as many as we want.
float virtKeys_[VIRTKEY_COUNT]{};
// De-noise mapped axis updates
int axisState_[JOYSTICK_AXIS_MAX]{};
int lastNonDeadzoneDeviceID_[2]{};
float history_[2][2]{};
+5 -1
View File
@@ -177,7 +177,7 @@ EmuScreen::EmuScreen(const Path &filename)
startDumping = false;
controlMapper_.SetCallbacks(
std::bind(&EmuScreen::onVKey, this, _1, _2),
[](int vkey, float analogValue) {},
std::bind(&EmuScreen::onVKeyAnalog, this, _1, _2),
[](uint32_t bitsToSet, uint32_t bitsToClear) {
__CtrlSetAllButtons(bitsToSet, bitsToClear);
},
@@ -763,6 +763,10 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
}
}
void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) {
}
bool EmuScreen::key(const KeyInput &key) {
Core_NotifyActivity();
+1
View File
@@ -69,6 +69,7 @@ private:
void renderUI();
void onVKey(int virtualKeyCode, bool down);
void onVKeyAnalog(int virtualKeyCode, float value);
void autoLoad();
void checkPowerDown();