dolphin/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.h
Filoppi 125971d9f2 InputCommon: fix default input config default device not being loaded/found
Fixes bug: https://bugs.dolphin-emu.org/issues/12744

Before e1e3db13ba
the ControllerInterface m_devices_mutex was "wrongfully" locked for the whole Initialize() call, which included the first device population refresh,
this has the unwanted (accidental) consequence of often preventing the different pads (GC Pad, Wii Contollers, ...) input configs from loading
until that mutex was released (the input config defaults loading was blocked in EmulatedController::LoadDefaults()), which meant that the devices
population would often have the time to finish adding its first device, which would then be selected as default device (by design, the first device
added to the CI is the default default device, usually the "Keyboard and Mouse" device).

After the commit mentioned above removed the unnecessary m_devices_mutex calls, the default default device would fail to load (be found)
causing the default input mappings, which are specifically written for the default default device on every platform, to not be bound to any
physical device input, breaking input on new dolphin installations (until a user tried to customize the default device manually).

Default devices are now always added synchronously to avoid the problem, and so they should in the future (I added comments and warnings to help with that)
2021-12-05 23:35:47 +02:00

79 lines
1.7 KiB
C++

// Copyright 2010 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "InputCommon/ControllerInterface/CoreDevice.h"
#include "InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h"
namespace ciface::DInput
{
void InitJoystick(IDirectInput8* const idi8, HWND hwnd);
class Joystick : public ForceFeedback::ForceFeedbackDevice
{
private:
class Button : public Input
{
public:
Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {}
std::string GetName() const override;
ControlState GetState() const override;
private:
const BYTE& m_button;
const u8 m_index;
};
class Axis : public Input
{
public:
Axis(u8 index, const LONG& axis, LONG base, LONG range)
: m_axis(axis), m_base(base), m_range(range), m_index(index)
{
}
std::string GetName() const override;
ControlState GetState() const override;
private:
const LONG& m_axis;
const LONG m_base, m_range;
const u8 m_index;
};
class Hat : public Input
{
public:
Hat(u8 index, const DWORD& hat, u8 direction)
: m_hat(hat), m_direction(direction), m_index(index)
{
}
std::string GetName() const override;
ControlState GetState() const override;
private:
const DWORD& m_hat;
const u8 m_index, m_direction;
};
public:
void UpdateInput() override;
Joystick(const LPDIRECTINPUTDEVICE8 device);
~Joystick();
std::string GetName() const override;
std::string GetSource() const override;
int GetSortPriority() const override { return -2; }
bool IsValid() const final override;
private:
const LPDIRECTINPUTDEVICE8 m_device;
DIJOYSTATE m_state_in{};
bool m_buffered;
};
} // namespace ciface::DInput