2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 23:09:55 -04:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-12 17:15:16 +00:00
|
|
|
|
2014-02-10 13:54:46 -05:00
|
|
|
#pragma once
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2019-02-02 14:25:48 -06:00
|
|
|
#include <cmath>
|
2014-02-01 17:20:35 -05:00
|
|
|
#include <memory>
|
2016-07-14 17:45:59 +02:00
|
|
|
#include <mutex>
|
2010-06-13 09:26:00 +00:00
|
|
|
#include <string>
|
2019-02-02 14:25:48 -06:00
|
|
|
#include <type_traits>
|
2014-02-17 05:18:15 -05:00
|
|
|
#include <vector>
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2018-03-30 21:42:26 +02:00
|
|
|
#include "Common/Common.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Common/IniFile.h"
|
2017-04-04 15:37:31 -04:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
|
|
|
|
|
|
|
class ControllerInterface;
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2018-03-30 21:42:26 +02:00
|
|
|
const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"),
|
|
|
|
_trans("Right")};
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
namespace ControllerEmu
|
2011-11-10 09:27:33 +01:00
|
|
|
{
|
2017-02-08 22:15:43 -05:00
|
|
|
class ControlGroup;
|
2010-06-03 18:05:08 +00:00
|
|
|
|
2017-02-08 22:15:43 -05:00
|
|
|
class EmulatedController
|
2010-06-03 18:05:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-02-08 22:15:43 -05:00
|
|
|
virtual ~EmulatedController();
|
2019-05-01 17:25:48 -05:00
|
|
|
|
2010-06-03 18:05:08 +00:00
|
|
|
virtual std::string GetName() const = 0;
|
2019-05-01 17:25:48 -05:00
|
|
|
virtual std::string GetDisplayName() const;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
virtual void LoadDefaults(const ControllerInterface& ciface);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2010-07-05 10:46:32 +00:00
|
|
|
virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
|
|
|
|
virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");
|
2017-11-04 14:08:26 -07:00
|
|
|
|
2017-02-07 16:25:27 -08:00
|
|
|
bool IsDefaultDeviceConnected() const;
|
2017-11-04 14:08:26 -07:00
|
|
|
const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
|
|
|
|
void SetDefaultDevice(const std::string& device);
|
|
|
|
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-02-11 00:29:22 -05:00
|
|
|
void UpdateReferences(const ControllerInterface& devi);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2016-07-14 17:45:59 +02:00
|
|
|
// This returns a lock that should be held before calling State() on any control
|
|
|
|
// references and GetState(), by extension. This prevents a race condition
|
|
|
|
// which happens while handling a hotplug event because a control reference's State()
|
|
|
|
// could be called before we have finished updating the reference.
|
|
|
|
static std::unique_lock<std::recursive_mutex> GetStateLock();
|
|
|
|
|
2014-02-01 17:20:35 -05:00
|
|
|
std::vector<std::unique_ptr<ControlGroup>> groups;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-02-02 14:25:48 -06:00
|
|
|
// Maps a float from -1.0..+1.0 to an integer of the provided values.
|
|
|
|
template <typename T, typename F>
|
|
|
|
static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
|
|
|
T pos_1_value = std::numeric_limits<T>::max())
|
|
|
|
{
|
|
|
|
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
|
|
|
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
|
|
|
|
|
|
|
static_assert(std::numeric_limits<long>::min() <= std::numeric_limits<T>::min() &&
|
|
|
|
std::numeric_limits<long>::max() >= std::numeric_limits<T>::max(),
|
|
|
|
"long is not a superset of T. use of std::lround is not sane.");
|
|
|
|
|
|
|
|
// Here we round when converting from float to int.
|
|
|
|
// After applying our deadzone, resizing, and reshaping math
|
|
|
|
// we sometimes have a near-zero value which is slightly negative. (e.g. -0.0001)
|
|
|
|
// Casting would round down but rounding will yield our "zero_value".
|
|
|
|
|
|
|
|
if (input_value > 0)
|
|
|
|
return T(std::lround((pos_1_value - zero_value) * input_value + zero_value));
|
|
|
|
else
|
|
|
|
return T(std::lround((zero_value - neg_1_value) * input_value + zero_value));
|
|
|
|
}
|
|
|
|
|
2017-11-04 14:08:26 -07:00
|
|
|
private:
|
|
|
|
ciface::Core::DeviceQualifier m_default_device;
|
2017-02-07 16:25:27 -08:00
|
|
|
bool m_default_device_is_connected{false};
|
2010-06-03 18:05:08 +00:00
|
|
|
};
|
2017-02-08 22:15:43 -05:00
|
|
|
} // namespace ControllerEmu
|