ce16653cc8
* Implement the basics of controller auto mapping. From testing doesn't currenlty work. Opening the controller requires the device index, but it is only known and guaranteed at boot time or when a controller is connected. * Use the SDL_INIT_GAMECONTROLLER flag to initialize the controller subsystem. It automatically initializes the joystick subsystem too, so SDL_INIT_JOYSTICK is not needed. * Implement the SDLGameController class to handle open game controllers. Based on the SDLJoystick implementation. * Address review comments * Changes SDLJoystick and SDLGameController to use a custom default constructible destructor, to improve readability. The only deleters used previously were SDL_JoystickClose and SDL_GameControllerClose, respectively, plus null lambdas. Given that both SDL functions accept null pointers with just an early return, this should be functionally the same. with just an early return * warn the user when a controller mapping is not found * Get axis direction and threshold from SDL_ExtendedGameControllerBind * Reject analog bind if it's not axis, for the couple of examples present in SDL2.0.10's db. Also add SDL_CONTROLLER_BINDTYPE_NONE for the button bind switch, with a better log message. * sdl_impl.cpp: Log the error returned by SDL_GetError upon failure to open joystick * sdl: only use extended binding on SDL2.0.6 and up * sdl_impl.cpp: minor changes
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
// Copyright 2017 Citra Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Common {
|
|
class ParamPackage;
|
|
}
|
|
|
|
namespace InputCommon {
|
|
|
|
/// Initializes and registers all built-in input device factories.
|
|
void Init();
|
|
|
|
/// Deregisters all built-in input device factories and shuts them down.
|
|
void Shutdown();
|
|
|
|
class Keyboard;
|
|
|
|
/// Gets the keyboard button device factory.
|
|
Keyboard* GetKeyboard();
|
|
|
|
class MotionEmu;
|
|
|
|
/// Gets the motion emulation factory.
|
|
MotionEmu* GetMotionEmu();
|
|
|
|
/// Generates a serialized param package for creating a keyboard button device
|
|
std::string GenerateKeyboardParam(int key_code);
|
|
|
|
/// Generates a serialized param package for creating an analog device taking input from keyboard
|
|
std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
|
|
int key_modifier, float modifier_scale);
|
|
|
|
Common::ParamPackage GetSDLControllerButtonBindByGUID(const std::string& guid, int port,
|
|
int button);
|
|
Common::ParamPackage GetSDLControllerAnalogBindByGUID(const std::string& guid, int port,
|
|
int analog);
|
|
|
|
/// Reloads the input devices
|
|
void ReloadInputDevices();
|
|
|
|
namespace Polling {
|
|
|
|
enum class DeviceType { Button, Analog };
|
|
|
|
/**
|
|
* A class that can be used to get inputs from an input device like controllers without having to
|
|
* poll the device's status yourself
|
|
*/
|
|
class DevicePoller {
|
|
public:
|
|
virtual ~DevicePoller() = default;
|
|
/// Setup and start polling for inputs, should be called before GetNextInput
|
|
virtual void Start() = 0;
|
|
/// Stop polling
|
|
virtual void Stop() = 0;
|
|
/**
|
|
* Every call to this function returns the next input recorded since calling Start
|
|
* @return A ParamPackage of the recorded input, which can be used to create an InputDevice.
|
|
* If there has been no input, the package is empty
|
|
*/
|
|
virtual Common::ParamPackage GetNextInput() = 0;
|
|
};
|
|
|
|
// Get all DevicePoller from all backends for a specific device type
|
|
std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type);
|
|
} // namespace Polling
|
|
} // namespace InputCommon
|