Merge pull request #3892 from leoetlino/ciface-synchronisation

ControllerInterface: Add synchronisation
This commit is contained in:
Matthew Parlane 2016-06-26 00:17:08 +12:00 committed by GitHub
commit a7448271a9
25 changed files with 83 additions and 90 deletions

View File

@ -4,21 +4,16 @@
#include "InputCommon/ControllerInterface/Android/Android.h"
#include <sstream>
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ciface
{
namespace Android
{
void Init(std::vector<Core::Device*>& devices)
void Init()
{
devices.push_back(new Touchscreen(0));
devices.push_back(new Touchscreen(1));
devices.push_back(new Touchscreen(2));
devices.push_back(new Touchscreen(3));
devices.push_back(new Touchscreen(4));
devices.push_back(new Touchscreen(5));
devices.push_back(new Touchscreen(6));
devices.push_back(new Touchscreen(7));
for (int i = 0; i < 8; ++i)
g_controller_interface.AddDevice(new Touchscreen(i));
}
// Touchscreens and stuff

View File

@ -4,14 +4,14 @@
#pragma once
#include "InputCommon/ControllerInterface/Device.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "jni/ButtonManager.h"
namespace ciface
{
namespace Android
{
void Init(std::vector<Core::Device*>& devices);
void Init();
class Touchscreen : public Core::Device
{
private:

View File

@ -55,31 +55,31 @@ void ControllerInterface::Initialize(void* const hwnd)
m_hwnd = hwnd;
#ifdef CIFACE_USE_DINPUT
ciface::DInput::Init(m_devices, (HWND)hwnd);
ciface::DInput::Init((HWND)hwnd);
#endif
#ifdef CIFACE_USE_XINPUT
ciface::XInput::Init(m_devices);
ciface::XInput::Init();
#endif
#ifdef CIFACE_USE_XLIB
ciface::Xlib::Init(m_devices, hwnd);
ciface::Xlib::Init(hwnd);
#ifdef CIFACE_USE_X11_XINPUT2
ciface::XInput2::Init(m_devices, hwnd);
ciface::XInput2::Init(hwnd);
#endif
#endif
#ifdef CIFACE_USE_OSX
ciface::OSX::Init(m_devices, hwnd);
ciface::OSX::Init(hwnd);
#endif
#ifdef CIFACE_USE_SDL
ciface::SDL::Init(m_devices);
ciface::SDL::Init();
#endif
#ifdef CIFACE_USE_ANDROID
ciface::Android::Init(m_devices);
ciface::Android::Init();
#endif
#ifdef CIFACE_USE_EVDEV
ciface::evdev::Init(m_devices);
ciface::evdev::Init();
#endif
#ifdef CIFACE_USE_PIPES
ciface::Pipes::Init(m_devices);
ciface::Pipes::Init();
#endif
m_is_init = true;
@ -104,6 +104,8 @@ void ControllerInterface::Shutdown()
if (!m_is_init)
return;
std::lock_guard<std::mutex> lk(m_devices_mutex);
for (ciface::Core::Device* d : m_devices)
{
// Set outputs to ZERO before destroying device
@ -139,6 +141,12 @@ void ControllerInterface::Shutdown()
m_is_init = false;
}
void ControllerInterface::AddDevice(ciface::Core::Device* device)
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
m_devices.push_back(device);
}
//
// UpdateInput
//
@ -146,6 +154,7 @@ void ControllerInterface::Shutdown()
//
void ControllerInterface::UpdateInput()
{
std::lock_guard<std::mutex> lk(m_devices_mutex);
for (ciface::Core::Device* d : m_devices)
d->UpdateInput();
}

View File

@ -6,6 +6,7 @@
#include <algorithm>
#include <map>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>
@ -121,6 +122,7 @@ public:
void Initialize(void* const hwnd);
void Reinitialize();
void Shutdown();
void AddDevice(ciface::Core::Device* device);
bool IsInit() const { return m_is_init; }
void UpdateReference(ControlReference* control,
const ciface::Core::DeviceQualifier& default_device) const;

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;
@ -43,26 +44,15 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& de
LPDIRECTINPUTDEVICE8 kb_device = nullptr;
LPDIRECTINPUTDEVICE8 mo_device = nullptr;
if (SUCCEEDED(idi8->CreateDevice(GUID_SysKeyboard, &kb_device, nullptr)))
if (SUCCEEDED(idi8->CreateDevice(GUID_SysKeyboard, &kb_device, nullptr)) &&
SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)) &&
SUCCEEDED(kb_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)) &&
SUCCEEDED(idi8->CreateDevice(GUID_SysMouse, &mo_device, nullptr)) &&
SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)) &&
SUCCEEDED(mo_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
{
if (SUCCEEDED(kb_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
if (SUCCEEDED(idi8->CreateDevice(GUID_SysMouse, &mo_device, nullptr)))
{
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
{
if (SUCCEEDED(
mo_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
return;
}
}
}
}
}
g_controller_interface.AddDevice(new KeyboardMouse(kb_device, mo_device));
return;
}
if (kb_device)

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
{

View File

@ -4,6 +4,7 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
@ -167,6 +168,7 @@ public:
Device* FindDevice(const DeviceQualifier& devq) const;
protected:
std::mutex m_devices_mutex;
std::vector<Device*> m_devices;
};
}

View File

@ -4,13 +4,11 @@
#pragma once
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface
{
namespace OSX
{
void Init(std::vector<Core::Device*>& devices, void* window);
void Init(void* window);
void DeInit();
void DeviceElementDebugPrint(const void*, void*);

View File

@ -6,6 +6,7 @@
#include <Foundation/Foundation.h>
#include <IOKit/hid/IOHIDLib.h>
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/OSX/OSX.h"
#include "InputCommon/ControllerInterface/OSX/OSXJoystick.h"
#include "InputCommon/ControllerInterface/OSX/OSXKeyboard.h"
@ -140,22 +141,21 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in
DeviceDebugPrint(inIOHIDDeviceRef);
std::vector<Core::Device*>* devices = (std::vector<Core::Device*>*)inContext;
// Add to the devices vector if it's of a type we want
// Add a device if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
devices->push_back(new Keyboard(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
g_controller_interface.AddDevice(
new Keyboard(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
#if 0
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
devices->push_back(new Mouse(inIOHIDDeviceRef,
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef,
name, mouse_name_counts[name]++));
#endif
else
devices->push_back(new Joystick(inIOHIDDeviceRef, name, joy_name_counts[name]++));
g_controller_interface.AddDevice(new Joystick(inIOHIDDeviceRef, name, joy_name_counts[name]++));
}
void Init(std::vector<Core::Device*>& devices, void* window)
void Init(void* window)
{
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
@ -166,7 +166,7 @@ void Init(std::vector<Core::Device*>& devices, void* window)
IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
// Callbacks for acquisition or loss of a matching device
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatching_callback, (void*)&devices);
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, DeviceMatching_callback, nullptr);
// Match devices that are plugged in right now
IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetCurrent(), OurRunLoop);

View File

@ -17,6 +17,7 @@
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/Pipes/Pipes.h"
namespace ciface
@ -40,7 +41,7 @@ static double StringToDouble(const std::string& text)
return result;
}
void Init(std::vector<Core::Device*>& devices)
void Init()
{
// Search the Pipes directory for files that we can open in read-only,
// non-blocking mode. The device name is the virtual name of the file.
@ -60,7 +61,7 @@ void Init(std::vector<Core::Device*>& devices)
int fd = open(child.physicalName.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
continue;
devices.push_back(new PipeDevice(fd, child.virtualName, found++));
g_controller_interface.AddDevice(new PipeDevice(fd, child.virtualName, found++));
}
}

View File

@ -8,8 +8,6 @@
#include <string>
#include <vector>
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface
{
namespace Pipes
@ -24,7 +22,7 @@ namespace Pipes
// SET {L, R} [0, 1]
// SET {MAIN, C} [0, 1] [0, 1]
void Init(std::vector<Core::Device*>& devices);
void Init();
class PipeDevice : public Core::Device
{

View File

@ -7,6 +7,7 @@
#include <sstream>
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/SDL/SDL.h"
#ifdef _WIN32
@ -32,7 +33,7 @@ static std::string GetJoystickName(int index)
#endif
}
void Init(std::vector<Core::Device*>& devices)
void Init()
{
// this is used to number the joysticks
// multiple joysticks with the same name shall get unique ids starting at 0
@ -60,7 +61,7 @@ void Init(std::vector<Core::Device*>& devices)
Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++);
// 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

@ -8,8 +8,6 @@
#include <SDL.h>
#include "InputCommon/ControllerInterface/Device.h"
#if SDL_VERSION_ATLEAST(1, 3, 0)
#define USE_SDL_HAPTIC
#endif
@ -22,7 +20,7 @@ namespace ciface
{
namespace SDL
{
void Init(std::vector<Core::Device*>& devices);
void Init();
class Joystick : public Core::Device
{

View File

@ -50,7 +50,7 @@ static XInputGetState_t PXInputGetState = nullptr;
static bool haveGuideButton = false;
void Init(std::vector<Core::Device*>& devices)
void Init()
{
if (!hXInput)
{
@ -89,7 +89,7 @@ void Init(std::vector<Core::Device*>& devices)
XINPUT_CAPABILITIES caps;
for (int i = 0; i != 4; ++i)
if (ERROR_SUCCESS == PXInputGetCapabilities(i, 0, &caps))
devices.push_back(new Device(caps, i));
g_controller_interface.AddDevice(new Device(caps, i));
}
void DeInit()

View File

@ -12,7 +12,7 @@
#include <XInput.h>
#include <windows.h>
#include "InputCommon/ControllerInterface/Device.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
#error You are building this module against the wrong version of DirectX. You probably need to remove DXSDK_DIR from your include path and/or _WIN32_WINNT is wrong.
@ -22,7 +22,7 @@ namespace ciface
{
namespace XInput
{
void Init(std::vector<Core::Device*>& devices);
void Init();
void DeInit();
class Device : public Core::Device

View File

@ -46,7 +46,7 @@ namespace ciface
namespace XInput2
{
// This function will add zero or more KeyboardMouse objects to devices.
void Init(std::vector<Core::Device*>& devices, void* const hwnd)
void Init(void* const hwnd)
{
Display* dpy = XOpenDisplay(nullptr);
@ -78,8 +78,8 @@ void Init(std::vector<Core::Device*>& devices, void* const hwnd)
if (current_master->use == XIMasterPointer)
// Since current_master is a master pointer, its attachment must
// be a master keyboard.
devices.push_back(new KeyboardMouse((Window)hwnd, xi_opcode, current_master->deviceid,
current_master->attachment));
g_controller_interface.AddDevice(new KeyboardMouse(
(Window)hwnd, xi_opcode, current_master->deviceid, current_master->attachment));
}
XCloseDisplay(dpy);

View File

@ -12,13 +12,13 @@ extern "C" {
#include <X11/keysym.h>
}
#include "InputCommon/ControllerInterface/Device.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ciface
{
namespace XInput2
{
void Init(std::vector<Core::Device*>& devices, void* const hwnd);
void Init(void* const hwnd);
class KeyboardMouse : public Core::Device
{

View File

@ -11,9 +11,9 @@ namespace ciface
{
namespace Xlib
{
void Init(std::vector<Core::Device*>& devices, void* const hwnd)
void Init(void* const hwnd)
{
devices.push_back(new KeyboardMouse((Window)hwnd));
g_controller_interface.AddDevice(new KeyboardMouse((Window)hwnd));
}
KeyboardMouse::KeyboardMouse(Window window) : m_window(window)

View File

@ -7,13 +7,13 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include "InputCommon/ControllerInterface/Device.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ciface
{
namespace Xlib
{
void Init(std::vector<Core::Device*>& devices, void* const hwnd);
void Init(void* const hwnd);
class KeyboardMouse : public Core::Device
{

View File

@ -9,6 +9,7 @@
#include "Common/Assert.h"
#include "Common/Logging/Log.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/evdev/evdev.h"
namespace ciface
@ -31,7 +32,7 @@ static std::string GetName(const std::string& devnode)
return res;
}
void Init(std::vector<Core::Device*>& controllerDevices)
void Init()
{
// this is used to number the joysticks
// multiple joysticks with the same name shall get unique ids starting at 0
@ -71,7 +72,7 @@ void Init(std::vector<Core::Device*>& controllerDevices)
if (input->IsInteresting())
{
controllerDevices.push_back(input);
g_controller_interface.AddDevice(input);
num_controllers++;
}
else

View File

@ -8,13 +8,11 @@
#include <string>
#include <vector>
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface
{
namespace evdev
{
void Init(std::vector<Core::Device*>& devices);
void Init();
class evdevDevice : public Core::Device
{