#pragma once #include "Common/Input/InputState.h" #include "Core/KeyMap.h" #include #include // 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. class ControlMapper { public: void Update(); // Inputs to the table-based mapping bool Key(const KeyInput &key, bool *pauseTrigger); void Axis(const AxisInput &axis); // Required callbacks void SetCallbacks( std::function onVKey, std::function onVKeyAnalog, std::function setAllPSPButtonStates_, std::function setPSPButtonState, std::function setPSPAnalog); // Inject raw PSP key input directly, such as from touch screen controls. // Combined with the mapped input. void PSPKey(int deviceId, int pspKeyCode, int flags); // Optional callback, only used in config void SetRawCallback(std::function setRawAnalog); private: bool UpdatePSPState(const InputMapping &changedMapping); void SetPSPAxis(int deviceId, int stick, char axis, float value); void ProcessAnalogSpeed(const AxisInput &axis, bool opposite); void onVKey(int vkey, bool down); void onVKeyAnalog(int deviceId, int vkey, float value); // 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]{}; // Mappable auto-rotation. Useful for keyboard/dpad->analog in a few games. bool autoRotatingAnalogCW_ = false; bool autoRotatingAnalogCCW_ = false; std::map curInput_; // Callbacks std::function onVKey_; std::function onVKeyAnalog_; std::function setAllPSPButtonStates_; std::function setPSPButtonState_; std::function setPSPAnalog_; std::function setRawAnalog_; }; void ConvertAnalogStick(float x, float y, float *outX, float *outY);