#pragma once #include "Common/Input/InputState.h" #include "Core/KeyMap.h" #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. // 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. class ControlMapper { public: void Update(); bool Key(const KeyInput &key, bool *pauseTrigger); void pspKey(int pspKeyCode, int flags); bool Axis(const AxisInput &axis); // Required callbacks void SetCallbacks( std::function onVKeyDown, std::function onVKeyUp, std::function setPSPAnalog); // Optional callback, only used in config void SetRawCallback(std::function setRawAnalog); private: void processAxis(const AxisInput &axis, int direction); void setVKeyAnalog(char axis, int stick, int virtualKeyMin, int virtualKeyMax, bool setZero = true); void SetPSPAxis(char axis, float value, int stick); 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]{}; // Mappable auto-rotation. Useful for keyboard/dpad->analog in a few games. bool autoRotatingAnalogCW_ = false; bool autoRotatingAnalogCCW_ = false; // Callbacks std::function onVKeyDown_; std::function onVKeyUp_; std::function setPSPAnalog_; std::function setRawAnalog_; }; void ConvertAnalogStick(float &x, float &y);