2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-09-20 23:41:15 +02:00
|
|
|
|
|
|
|
#pragma once
|
2022-01-24 17:42:05 +01:00
|
|
|
|
|
|
|
#include "common/param_package.h"
|
2021-09-20 23:41:15 +02:00
|
|
|
#include "common/threadsafe_queue.h"
|
|
|
|
|
2022-01-24 17:42:05 +01:00
|
|
|
namespace InputCommon::Polling {
|
|
|
|
enum class InputType;
|
|
|
|
}
|
|
|
|
|
2021-09-20 23:41:15 +02:00
|
|
|
namespace InputCommon {
|
|
|
|
class InputEngine;
|
|
|
|
struct MappingData;
|
|
|
|
|
|
|
|
class MappingFactory {
|
|
|
|
public:
|
|
|
|
MappingFactory();
|
|
|
|
|
|
|
|
/**
|
2021-12-14 02:31:57 +01:00
|
|
|
* Resets all variables to begin the mapping process
|
|
|
|
* @param type type of input desired to be returned
|
2021-09-20 23:41:15 +02:00
|
|
|
*/
|
|
|
|
void BeginMapping(Polling::InputType type);
|
|
|
|
|
|
|
|
/// Returns an input event with mapping information from the input_queue
|
2022-01-24 17:39:17 +01:00
|
|
|
[[nodiscard]] Common::ParamPackage GetNextInput();
|
2021-09-20 23:41:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers mapping input data from the driver
|
2021-12-14 02:31:57 +01:00
|
|
|
* @param data A struct containing all the information needed to create a proper
|
|
|
|
* ParamPackage
|
2021-09-20 23:41:15 +02:00
|
|
|
*/
|
|
|
|
void RegisterInput(const MappingData& data);
|
|
|
|
|
|
|
|
/// Stop polling from all backends
|
|
|
|
void StopMapping();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-12-14 02:31:57 +01:00
|
|
|
* If provided data satisfies the requirements it will push an element to the input_queue
|
2021-09-20 23:41:15 +02:00
|
|
|
* Supported input:
|
|
|
|
* - Button: Creates a basic button ParamPackage
|
|
|
|
* - HatButton: Creates a basic hat button ParamPackage
|
|
|
|
* - Analog: Creates a basic analog ParamPackage
|
2021-12-14 02:31:57 +01:00
|
|
|
* @param data A struct containing all the information needed to create a proper
|
2021-09-20 23:41:15 +02:00
|
|
|
* ParamPackage
|
|
|
|
*/
|
|
|
|
void RegisterButton(const MappingData& data);
|
|
|
|
|
|
|
|
/**
|
2021-12-14 02:31:57 +01:00
|
|
|
* If provided data satisfies the requirements it will push an element to the input_queue
|
2021-09-20 23:41:15 +02:00
|
|
|
* Supported input:
|
|
|
|
* - Button, HatButton: Pass the data to RegisterButton
|
|
|
|
* - Analog: Stores the first axis and on the second axis creates a basic stick ParamPackage
|
2021-12-14 02:31:57 +01:00
|
|
|
* @param data A struct containing all the information needed to create a proper
|
|
|
|
* ParamPackage
|
2021-09-20 23:41:15 +02:00
|
|
|
*/
|
|
|
|
void RegisterStick(const MappingData& data);
|
|
|
|
|
|
|
|
/**
|
2021-12-14 02:31:57 +01:00
|
|
|
* If provided data satisfies the requirements it will push an element to the input_queue
|
2021-09-20 23:41:15 +02:00
|
|
|
* Supported input:
|
|
|
|
* - Button, HatButton: Pass the data to RegisterButton
|
|
|
|
* - Analog: Stores the first two axis and on the third axis creates a basic Motion
|
|
|
|
* ParamPackage
|
|
|
|
* - Motion: Creates a basic Motion ParamPackage
|
2021-12-14 02:31:57 +01:00
|
|
|
* @param data A struct containing all the information needed to create a proper
|
|
|
|
* ParamPackage
|
2021-09-20 23:41:15 +02:00
|
|
|
*/
|
|
|
|
void RegisterMotion(const MappingData& data);
|
|
|
|
|
2021-11-14 17:45:07 +01:00
|
|
|
/**
|
|
|
|
* Returns true if driver can be mapped
|
2021-12-14 02:31:57 +01:00
|
|
|
* @param data A struct containing all the information needed to create a proper
|
|
|
|
* ParamPackage
|
2021-11-14 17:45:07 +01:00
|
|
|
*/
|
|
|
|
bool IsDriverValid(const MappingData& data) const;
|
|
|
|
|
2021-09-20 23:41:15 +02:00
|
|
|
Common::SPSCQueue<Common::ParamPackage> input_queue;
|
|
|
|
Polling::InputType input_type{Polling::InputType::None};
|
|
|
|
bool is_enabled{};
|
|
|
|
int first_axis = -1;
|
|
|
|
int second_axis = -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace InputCommon
|