ControllerInterface: Don't pass m_devices to the backends

Previously, the devices vector would be passed to all backends. They
would then manually push_back to it to add new devices. This was fine
but caused issues when trying to add synchronisation.

Instead, backends now call AddDevice() to fill m_devices so that it is
not accessible from the outside.
This commit is contained in:
Léo Lam
2016-06-12 17:08:04 +02:00
parent 8a1bbaa563
commit fd29e5c4cc
24 changed files with 69 additions and 72 deletions

View File

@ -2,9 +2,9 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInputJoystick.h"
#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h"
@ -44,7 +44,7 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
return result;
}
void Init(std::vector<Core::Device*>& devices, HWND hwnd)
void Init(HWND hwnd)
{
IDirectInput8* idi8;
if (FAILED(DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8,
@ -53,8 +53,8 @@ void Init(std::vector<Core::Device*>& devices, HWND hwnd)
return;
}
InitKeyboardMouse(idi8, devices, hwnd);
InitJoystick(idi8, devices, hwnd);
InitKeyboardMouse(idi8, hwnd);
InitJoystick(idi8, hwnd);
idi8->Release();
}

View File

@ -10,7 +10,6 @@
#include <windows.h>
#include "InputCommon/ControllerInterface/DInput/DInput8.h"
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface
{
@ -21,6 +20,6 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVO
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device);
void Init(std::vector<Core::Device*>& devices, HWND hwnd);
void Init(HWND hwnd);
}
}

View File

@ -6,6 +6,7 @@
#include <map>
#include <sstream>
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
#include "InputCommon/ControllerInterface/DInput/DInputJoystick.h"
#include "InputCommon/ControllerInterface/DInput/XInputFilter.h"
@ -16,7 +17,7 @@ namespace DInput
{
#define DATA_BUFFER_SIZE 32
void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND hwnd)
void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
{
std::list<DIDEVICEINSTANCE> joysticks;
idi8->EnumDevices(DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks,
@ -60,7 +61,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
Joystick* js = new Joystick(/*&*i, */ js_device, name_counts[joystick.tszInstanceName]++);
// only add if it has some inputs/outputs
if (js->Inputs().size() || js->Outputs().size())
devices.push_back(js);
g_controller_interface.AddDevice(js);
else
delete js;
}

View File

@ -11,7 +11,7 @@ namespace ciface
{
namespace DInput
{
void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND hwnd);
void InitJoystick(IDirectInput8* const idi8, HWND hwnd);
class Joystick : public ForceFeedback::ForceFeedbackDevice
{

View File

@ -4,6 +4,7 @@
#include <algorithm>
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h"
@ -31,7 +32,7 @@ static const struct
// lil silly
static HWND m_hwnd;
void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND _hwnd)
void InitKeyboardMouse(IDirectInput8* const idi8, HWND _hwnd)
{
m_hwnd = _hwnd;
@ -56,7 +57,7 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& de
if (SUCCEEDED(
mo_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
g_controller_interface.AddDevice(new KeyboardMouse(kb_device, mo_device));
return;
}
}

View File

@ -13,7 +13,7 @@ namespace ciface
{
namespace DInput
{
void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND _hwnd);
void InitKeyboardMouse(IDirectInput8* const idi8, HWND _hwnd);
class KeyboardMouse : public Core::Device
{