2021-07-08 19:30:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Core/KeyMap.h"
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2021-07-09 09:01:56 +00:00
|
|
|
// At some point I want to refactor this from using callbacks to simply providing lists of events.
|
|
|
|
// Still it won't be able to be completely stateless due to the 2-D processing of analog sticks.
|
2021-07-08 19:30:23 +00:00
|
|
|
|
|
|
|
class ControlMapper {
|
|
|
|
public:
|
2021-07-09 14:14:32 +00:00
|
|
|
void Update();
|
|
|
|
|
2021-07-08 19:30:23 +00:00
|
|
|
bool Key(const KeyInput &key, bool *pauseTrigger);
|
2021-03-04 09:37:35 +00:00
|
|
|
void pspKey(int pspKeyCode, int flags);
|
2021-07-08 19:30:23 +00:00
|
|
|
bool Axis(const AxisInput &axis);
|
|
|
|
|
2021-07-09 11:10:16 +00:00
|
|
|
// Required callbacks
|
2021-07-08 19:30:23 +00:00
|
|
|
void SetCallbacks(
|
|
|
|
std::function<void(int)> onVKeyDown,
|
|
|
|
std::function<void(int)> onVKeyUp,
|
2021-07-09 09:01:56 +00:00
|
|
|
std::function<void(int, float, float)> setPSPAnalog);
|
2021-07-08 19:30:23 +00:00
|
|
|
|
2021-07-09 11:10:16 +00:00
|
|
|
// Optional callback, only used in config
|
|
|
|
void SetRawCallback(std::function<void(int, float, float)> setRawAnalog);
|
|
|
|
|
2021-07-08 19:30:23 +00:00
|
|
|
private:
|
|
|
|
void processAxis(const AxisInput &axis, int direction);
|
|
|
|
void setVKeyAnalog(char axis, int stick, int virtualKeyMin, int virtualKeyMax, bool setZero = true);
|
|
|
|
|
2021-07-09 09:01:56 +00:00
|
|
|
void SetPSPAxis(char axis, float value, int stick);
|
|
|
|
|
2021-07-08 19:30:23 +00:00
|
|
|
void onVKeyDown(int vkey);
|
|
|
|
void onVKeyUp(int vkey);
|
|
|
|
|
|
|
|
// To track mappable virtual keys. We can have as many as we want.
|
|
|
|
bool virtKeys[VIRTKEY_COUNT]{};
|
|
|
|
|
|
|
|
// De-noise mapped axis updates
|
|
|
|
int axisState_[JOYSTICK_AXIS_MAX]{};
|
|
|
|
|
2021-07-09 14:14:32 +00:00
|
|
|
// Mappable auto-rotation. Useful for keyboard/dpad->analog in a few games.
|
|
|
|
bool autoRotatingAnalogCW_ = false;
|
|
|
|
bool autoRotatingAnalogCCW_ = false;
|
|
|
|
|
2021-07-08 19:30:23 +00:00
|
|
|
// Callbacks
|
|
|
|
std::function<void(int)> onVKeyDown_;
|
|
|
|
std::function<void(int)> onVKeyUp_;
|
2021-07-09 09:01:56 +00:00
|
|
|
std::function<void(int, float, float)> setPSPAnalog_;
|
2021-07-09 11:10:16 +00:00
|
|
|
std::function<void(int, float, float)> setRawAnalog_;
|
2021-07-08 19:30:23 +00:00
|
|
|
};
|
2021-07-09 11:10:16 +00:00
|
|
|
|
|
|
|
void ConvertAnalogStick(float &x, float &y);
|