summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/Src/ControllerInterface
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-06-16 20:07:10 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2013-06-25 00:58:30 -0400
commit877106b027431c6edb2d2c702fa6d811dac3d250 (patch)
treea0d83be190efea7ad4915db7db9ac40f9192b251 /Source/Core/InputCommon/Src/ControllerInterface
parent143d2eccb49b700ccd00dfa229b03d1d1a51533c (diff)
InputCommon: Split Device stuff out
The ExpressionParser needs this to be out of here to prevent issues with cyclic references.
Diffstat (limited to 'Source/Core/InputCommon/Src/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp2
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h6
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp186
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h161
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp19
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.h4
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp11
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h13
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp17
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h6
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Device.cpp193
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Device.h171
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h4
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm9
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h4
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm3
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h4
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm3
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp11
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h10
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp7
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.h14
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp2
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h6
24 files changed, 429 insertions, 437 deletions
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp
index 6469945971..ef95f9b363 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp
@@ -23,7 +23,7 @@ namespace ciface
namespace Android
{
-void Init( std::vector<ControllerInterface::Device*>& devices )
+void Init( std::vector<Core::Device*>& devices )
{
devices.push_back(new Touchscreen());
}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h
index 21f35165f1..e38c6a221a 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h
@@ -17,7 +17,7 @@
#ifndef _CIFACE_ANDROID_H_
#define _CIFACE_ANDROID_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#include "Android/ButtonManager.h"
namespace ciface
@@ -25,8 +25,8 @@ namespace ciface
namespace Android
{
-void Init( std::vector<ControllerInterface::Device*>& devices );
-class Touchscreen : public ControllerInterface::Device
+void Init( std::vector<Core::Device*>& devices );
+class Touchscreen : public Core::Device
{
private:
class Button : public Input
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
index 6db79605a7..e672e4598c 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
@@ -180,56 +180,6 @@ bool ControllerInterface::UpdateOutput(const bool force)
}
//
-// Device :: ~Device
-//
-// Destructor, delete all inputs/outputs on device destruction
-//
-ControllerInterface::Device::~Device()
-{
- {
- // delete inputs
- std::vector<Device::Input*>::iterator
- i = m_inputs.begin(),
- e = m_inputs.end();
- for ( ;i!=e; ++i)
- delete *i;
- }
-
- {
- // delete outputs
- std::vector<Device::Output*>::iterator
- o = m_outputs.begin(),
- e = m_outputs.end();
- for ( ;o!=e; ++o)
- delete *o;
- }
-}
-
-void ControllerInterface::Device::AddInput(Input* const i)
-{
- m_inputs.push_back(i);
-}
-
-void ControllerInterface::Device::AddOutput(Output* const o)
-{
- m_outputs.push_back(o);
-}
-
-//
-// Device :: ClearInputState
-//
-// Device classes should override this function
-// ControllerInterface will call this when the device returns failure during UpdateInput
-// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play
-// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging
-//
-void ControllerInterface::Device::ClearInputState()
-{
- // this is going to be called for every UpdateInput call that fails
- // kinda slow but, w/e, should only happen when user unplugs a device while playing
-}
-
-//
// InputReference :: State
//
// get the state of an input reference
@@ -304,79 +254,13 @@ ControlState ControllerInterface::OutputReference::State(const ControlState stat
}
//
-// DeviceQualifier :: ToString
-//
-// get string from a device qualifier / serialize
-//
-std::string ControllerInterface::DeviceQualifier::ToString() const
-{
- if (source.empty() && (cid < 0) && name.empty())
- return "";
- std::ostringstream ss;
- ss << source << '/';
- if ( cid > -1 )
- ss << cid;
- ss << '/' << name;
- return ss.str();
-}
-
-//
-// DeviceQualifier :: FromString
-//
-// set a device qualifier from a string / unserialize
-//
-void ControllerInterface::DeviceQualifier::FromString(const std::string& str)
-{
- std::istringstream ss(str);
-
- std::getline(ss, source = "", '/');
-
- // silly
- std::getline(ss, name, '/');
- std::istringstream(name) >> (cid = -1);
-
- std::getline(ss, name = "");
-}
-
-//
-// DeviceQualifier :: FromDevice
-//
-// set a device qualifier from a device
-//
-void ControllerInterface::DeviceQualifier::FromDevice(const ControllerInterface::Device* const dev)
-{
- name = dev->GetName();
- cid = dev->GetId();
- source= dev->GetSource();
-}
-
-bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface::Device* const dev) const
-{
- if (dev->GetId() == cid)
- if (dev->GetName() == name)
- if (dev->GetSource() == source)
- return true;
- return false;
-}
-
-bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface::DeviceQualifier& devq) const
-{
- if (cid == devq.cid)
- if (name == devq.name)
- if (source == devq.source)
- return true;
-
- return false;
-}
-
-//
// UpdateReference
//
// updates a controlreference's binded devices/controls
// need to call this to re-parse a control reference's expression after changing it
//
void ControllerInterface::UpdateReference(ControllerInterface::ControlReference* ref
- , const ControllerInterface::DeviceQualifier& default_device) const
+ , const DeviceQualifier& default_device) const
{
ref->m_controls.clear();
@@ -439,18 +323,6 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
}
}
-ControllerInterface::Device* ControllerInterface::FindDevice(const ControllerInterface::DeviceQualifier& devq) const
-{
- std::vector<ControllerInterface::Device*>::const_iterator
- di = m_devices.begin(),
- de = m_devices.end();
- for (; di!=de; ++di)
- if (devq == *di)
- return *di;
-
- return NULL;
-}
-
//
// InputReference :: Detect
//
@@ -461,7 +333,7 @@ ControllerInterface::Device* ControllerInterface::FindDevice(const ControllerInt
// upon input, return pointer to detected Control
// else return NULL
//
-ControllerInterface::Device::Control* ControllerInterface::InputReference::Detect(const unsigned int ms, Device* const device)
+Device::Control* ControllerInterface::InputReference::Detect(const unsigned int ms, Device* const device)
{
unsigned int time = 0;
std::vector<bool> states(device->Inputs().size());
@@ -511,7 +383,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
//
// set all binded outputs to <range> power for x milliseconds return false
//
-ControllerInterface::Device::Control* ControllerInterface::OutputReference::Detect(const unsigned int ms, Device* const device)
+Device::Control* ControllerInterface::OutputReference::Detect(const unsigned int ms, Device* const device)
{
// ignore device
@@ -534,55 +406,3 @@ ControllerInterface::Device::Control* ControllerInterface::OutputReference::Dete
}
return NULL;
}
-
-ControllerInterface::Device::Input* ControllerInterface::Device::FindInput(const std::string &name) const
-{
- std::vector<Input*>::const_iterator
- it = m_inputs.begin(),
- itend = m_inputs.end();
- for (; it != itend; ++it)
- if ((*it)->GetName() == name)
- return *it;
-
- return NULL;
-}
-
-ControllerInterface::Device::Output* ControllerInterface::Device::FindOutput(const std::string &name) const
-{
- std::vector<Output*>::const_iterator
- it = m_outputs.begin(),
- itend = m_outputs.end();
- for (; it != itend; ++it)
- if ((*it)->GetName() == name)
- return *it;
-
- return NULL;
-}
-
-ControllerInterface::Device::Input* ControllerInterface::FindInput(const std::string& name, const Device* def_dev) const
-{
- if (def_dev)
- {
- Device::Input* const inp = def_dev->FindInput(name);
- if (inp)
- return inp;
- }
-
- std::vector<Device*>::const_iterator
- di = m_devices.begin(),
- de = m_devices.end();
- for (; di != de; ++di)
- {
- Device::Input* const i = (*di)->FindInput(name);
-
- if (i)
- return i;
- }
-
- return NULL;
-}
-
-ControllerInterface::Device::Output* ControllerInterface::FindOutput(const std::string& name, const Device* def_dev) const
-{
- return def_dev->FindOutput(name);
-}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
index 8c1a044860..db3a82bf3b 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
@@ -9,18 +9,13 @@
#include "Common.h"
#include "Thread.h"
+#include "Device.h"
// enable disable sources
#ifdef _WIN32
#define CIFACE_USE_XINPUT
- #define CIFACE_USE_DINPUT_JOYSTICK
- #define CIFACE_USE_DINPUT_KBM
#define CIFACE_USE_DINPUT
-//#ifndef CIFACE_USE_DINPUT_JOYSTICK
-// enable SDL 1.2 in addition to DirectInput on windows,
-// to support a few gamepads that aren't behaving with DInput
#define CIFACE_USE_SDL
-//#endif
#endif
#if defined(HAVE_X11) && HAVE_X11
#define CIFACE_USE_XLIB
@@ -32,9 +27,8 @@
#ifdef ANDROID
#define CIFACE_USE_ANDROID
#endif
-
-// idk in case I wanted to change it to double or something, idk what's best
-typedef float ControlState;
+
+using namespace ciface::Core;
//
// ControllerInterface
@@ -42,148 +36,10 @@ typedef float ControlState;
// some crazy shit I made to control different device inputs and outputs
// from lots of different sources, hopefully more easily
//
-class ControllerInterface
+class ControllerInterface : public DeviceContainer
{
public:
- // Forward declarations
- class DeviceQualifier;
-
- //
- // Device
- //
- // a device class
- //
- class Device
- {
- public:
- class Input;
- class Output;
-
- //
- // Control
- //
- // control includes inputs and outputs
- //
- class Control // input or output
- {
- public:
- virtual std::string GetName() const = 0;
- virtual ~Control() {}
-
- virtual Input* ToInput() { return NULL; }
- virtual Output* ToOutput() { return NULL; }
- };
-
- //
- // Input
- //
- // an input on a device
- //
- class Input : public Control
- {
- public:
- // things like absolute axes/ absolute mouse position will override this
- virtual bool IsDetectable() { return true; }
-
- virtual ControlState GetState() const = 0;
-
- Input* ToInput() { return this; }
- };
-
- //
- // Output
- //
- // an output on a device
- //
- class Output : public Control
- {
- public:
- virtual ~Output() {}
-
- virtual void SetState(ControlState state) = 0;
-
- Output* ToOutput() { return this; }
- };
-
- virtual ~Device();
-
- virtual std::string GetName() const = 0;
- virtual int GetId() const = 0;
- virtual std::string GetSource() const = 0;
- virtual bool UpdateInput() = 0;
- virtual bool UpdateOutput() = 0;
-
- virtual void ClearInputState();
-
- const std::vector<Input*>& Inputs() const { return m_inputs; }
- const std::vector<Output*>& Outputs() const { return m_outputs; }
-
- Input* FindInput(const std::string& name) const;
- Output* FindOutput(const std::string& name) const;
-
- protected:
- void AddInput(Input* const i);
- void AddOutput(Output* const o);
-
- class FullAnalogSurface : public Input
- {
- public:
- FullAnalogSurface(Input* low, Input* high)
- : m_low(*low), m_high(*high)
- {}
-
- ControlState GetState() const
- {
- return (1 + m_high.GetState() - m_low.GetState()) / 2;
- }
-
- std::string GetName() const
- {
- return m_low.GetName() + *m_high.GetName().rbegin();
- }
-
- private:
- Input& m_low;
- Input& m_high;
- };
-
- void AddAnalogInputs(Input* low, Input* high)
- {
- AddInput(low);
- AddInput(high);
- AddInput(new FullAnalogSurface(low, high));
- AddInput(new FullAnalogSurface(high, low));
- }
-
- private:
- std::vector<Input*> m_inputs;
- std::vector<Output*> m_outputs;
- };
-
- //
- // DeviceQualifier
- //
- // device qualifier used to match devices
- // currently has ( source, id, name ) properties which match a device
- //
- class DeviceQualifier
- {
- public:
- DeviceQualifier() : cid(-1) {}
- DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
- : source(_source), cid(_id), name(_name) {}
- void FromDevice(const Device* const dev);
- void FromString(const std::string& str);
- std::string ToString() const;
- bool operator==(const DeviceQualifier& devq) const;
- bool operator==(const Device* const dev) const;
-
- std::string source;
- int cid;
- std::string name;
- };
-
//
// ControlReference
//
@@ -260,22 +116,13 @@ public:
bool UpdateInput(const bool force = false);
bool UpdateOutput(const bool force = false);
- Device::Input* FindInput(const std::string& name, const Device* def_dev) const;
- Device::Output* FindOutput(const std::string& name, const Device* def_dev) const;
-
- const std::vector<Device*>& Devices() const { return m_devices; }
- Device* FindDevice(const DeviceQualifier& devq) const;
-
std::recursive_mutex update_lock;
private:
bool m_is_init;
- std::vector<Device*> m_devices;
void* m_hwnd;
};
-typedef std::vector<ControllerInterface::Device*> DeviceList;
-
extern ControllerInterface g_controller_interface;
#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp
index 01baf9cf1a..6b7b492ea9 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.cpp
@@ -1,17 +1,10 @@
-#include "../ControllerInterface.h"
-
-#ifdef CIFACE_USE_DINPUT
#include "DInput.h"
#include "StringUtil.h"
-#ifdef CIFACE_USE_DINPUT_JOYSTICK
- #include "DInputJoystick.h"
-#endif
-#ifdef CIFACE_USE_DINPUT_KBM
- #include "DInputKeyboardMouse.h"
-#endif
+#include "DInputJoystick.h"
+#include "DInputKeyboardMouse.h"
#pragma comment(lib, "Dinput8.lib")
#pragma comment(lib, "dxguid.lib")
@@ -55,18 +48,14 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
return result;
}
-void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
+void Init(std::vector<Core::Device*>& devices, HWND hwnd)
{
IDirectInput8* idi8;
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL)))
return;
-#ifdef CIFACE_USE_DINPUT_KBM
InitKeyboardMouse(idi8, devices, hwnd);
-#endif
-#ifdef CIFACE_USE_DINPUT_JOYSTICK
InitJoystick(idi8, devices, hwnd);
-#endif
idi8->Release();
@@ -74,5 +63,3 @@ void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
}
}
-
-#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.h b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.h
index 9ee48c190f..86452c23ab 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInput.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_DINPUT_H_
#define _CIFACE_DINPUT_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#define DINPUT_SOURCE_NAME "DInput"
@@ -23,7 +23,7 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVO
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device);
-void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd);
+void Init(std::vector<Core::Device*>& devices, HWND hwnd);
}
}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
index 916d142149..24502e7a8a 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
@@ -1,10 +1,11 @@
-#include "../ControllerInterface.h"
-
-#ifdef CIFACE_USE_DINPUT_JOYSTICK
#include "DInputJoystick.h"
#include "DInput.h"
+#include <map>
+#include <sstream>
+#include <algorithm>
+
namespace ciface
{
namespace DInput
@@ -142,7 +143,7 @@ LCleanup:
}
#endif
-void InitJoystick(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
+void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND hwnd)
{
std::list<DIDEVICEINSTANCE> joysticks;
idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY );
@@ -599,5 +600,3 @@ Joystick::Force<P>::Force(u8 index, EffectState& state)
}
}
-
-#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h
index a783381154..ad383bd764 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_DINPUT_JOYSTICK_H_
#define _CIFACE_DINPUT_JOYSTICK_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#define DIRECTINPUT_VERSION 0x0800
#define WIN32_LEAN_AND_MEAN
@@ -11,21 +11,14 @@
#include <list>
-#ifdef CIFACE_USE_XINPUT
- // this takes so long, idk if it should be enabled :(
- #define NO_DUPLICATE_DINPUT_XINPUT
- #include <wbemidl.h>
- #include <oleauto.h>
-#endif
-
namespace ciface
{
namespace DInput
{
-void InitJoystick(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND hwnd);
+void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND hwnd);
-class Joystick : public ControllerInterface::Device
+class Joystick : public Core::Device
{
private:
struct EffectState
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
index ea6452376d..850ff27281 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
@@ -1,6 +1,3 @@
-#include "../ControllerInterface.h"
-
-#ifdef CIFACE_USE_DINPUT_KBM
#include "DInputKeyboardMouse.h"
#include "DInput.h"
@@ -42,7 +39,7 @@ static const struct
// lil silly
static HWND hwnd;
-void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND _hwnd)
+void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND _hwnd)
{
hwnd = _hwnd;
@@ -252,16 +249,6 @@ std::string KeyboardMouse::GetSource() const
return DINPUT_SOURCE_NAME;
}
-//ControlState KeyboardMouse::GetInputState(const ControllerInterface::Device::Input* const input) const
-//{
-// return (((Input*)input)->GetState(&m_state_in));
-//}
-//
-//void KeyboardMouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
-//{
-// ((Output*)output)->SetState(state, m_state_out);
-//}
-
// names
std::string KeyboardMouse::Key::GetName() const
{
@@ -322,5 +309,3 @@ void KeyboardMouse::Light::SetState(const ControlState state)
}
}
-
-#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h
index cacef516b0..73398ca1b1 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_DINPUT_KBM_H_
#define _CIFACE_DINPUT_KBM_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#define DIRECTINPUT_VERSION 0x0800
#define WIN32_LEAN_AND_MEAN
@@ -14,9 +14,9 @@ namespace ciface
namespace DInput
{
-void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices, HWND _hwnd);
+void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND _hwnd);
-class KeyboardMouse : public ControllerInterface::Device
+class KeyboardMouse : public Core::Device
{
private:
struct State
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Device.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Device.cpp
new file mode 100644
index 0000000000..965ecfc817
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Device.cpp
@@ -0,0 +1,193 @@
+
+#include "Device.h"
+
+#include <string>
+#include <sstream>
+
+namespace ciface
+{
+namespace Core
+{
+
+//
+// Device :: ~Device
+//
+// Destructor, delete all inputs/outputs on device destruction
+//
+Device::~Device()
+{
+ {
+ // delete inputs
+ std::vector<Device::Input*>::iterator
+ i = m_inputs.begin(),
+ e = m_inputs.end();
+ for ( ;i!=e; ++i)
+ delete *i;
+ }
+
+ {
+ // delete outputs
+ std::vector<Device::Output*>::iterator
+ o = m_outputs.begin(),
+ e = m_outputs.end();
+ for ( ;o!=e; ++o)
+ delete *o;
+ }
+}
+
+void Device::AddInput(Device::Input* const i)
+{
+ m_inputs.push_back(i);
+}
+
+void Device::AddOutput(Device::Output* const o)
+{
+ m_outputs.push_back(o);
+}
+
+Device::Input* Device::FindInput(const std::string &name) const
+{
+ std::vector<Input*>::const_iterator
+ it = m_inputs.begin(),
+ itend = m_inputs.end();
+ for (; it != itend; ++it)
+ if ((*it)->GetName() == name)
+ return *it;
+
+ return NULL;
+}
+
+Device::Output* Device::FindOutput(const std::string &name) const
+{
+ std::vector<Output*>::const_iterator
+ it = m_outputs.begin(),
+ itend = m_outputs.end();
+ for (; it != itend; ++it)
+ if ((*it)->GetName() == name)
+ return *it;
+
+ return NULL;
+}
+
+//
+// Device :: ClearInputState
+//
+// Device classes should override this function
+// ControllerInterface will call this when the device returns failure during UpdateInput
+// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play
+// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging
+//
+void Device::ClearInputState()
+{
+ // this is going to be called for every UpdateInput call that fails
+ // kinda slow but, w/e, should only happen when user unplugs a device while playing
+}
+
+//
+// DeviceQualifier :: ToString
+//
+// get string from a device qualifier / serialize
+//
+std::string DeviceQualifier::ToString() const
+{
+ if (source.empty() && (cid < 0) && name.empty())
+ return "";
+ std::ostringstream ss;
+ ss << source << '/';
+ if ( cid > -1 )
+ ss << cid;
+ ss << '/' << name;
+ return ss.str();
+}
+
+//
+// DeviceQualifier :: FromString
+//
+// set a device qualifier from a string / unserialize
+//
+void DeviceQualifier::FromString(const std::string& str)
+{
+ std::istringstream ss(str);
+
+ std::getline(ss, source = "", '/');
+
+ // silly
+ std::getline(ss, name, '/');
+ std::istringstream(name) >> (cid = -1);
+
+ std::getline(ss, name = "");
+}
+
+//
+// DeviceQualifier :: FromDevice
+//
+// set a device qualifier from a device
+//
+void DeviceQualifier::FromDevice(const Device* const dev)
+{
+ name = dev->GetName();
+ cid = dev->GetId();
+ source= dev->GetSource();
+}
+
+bool DeviceQualifier::operator==(const Device* const dev) const
+{
+ if (dev->GetId() == cid)
+ if (dev->GetName() == name)
+ if (dev->GetSource() == source)
+ return true;
+ return false;
+}
+
+bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
+{
+ if (cid == devq.cid)
+ if (name == devq.name)
+ if (source == devq.source)
+ return true;
+
+ return false;
+}
+
+Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
+{
+ std::vector<Device*>::const_iterator
+ di = m_devices.begin(),
+ de = m_devices.end();
+ for (; di!=de; ++di)
+ if (devq == *di)
+ return *di;
+
+ return NULL;
+}
+
+Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const
+{
+ if (def_dev)
+ {
+ Device::Input* const inp = def_dev->FindInput(name);
+ if (inp)
+ return inp;
+ }
+
+ std::vector<Device*>::const_iterator
+ di = m_devices.begin(),
+ de = m_devices.end();
+ for (; di != de; ++di)
+ {
+ Device::Input* const i = (*di)->FindInput(name);
+
+ if (i)
+ return i;
+ }
+
+ return NULL;
+}
+
+Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const
+{
+ return def_dev->FindOutput(name);
+}
+
+}
+}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Device.h b/Source/Core/InputCommon/Src/ControllerInterface/Device.h
new file mode 100644
index 0000000000..a7c26b867d
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Device.h
@@ -0,0 +1,171 @@
+
+#ifndef _DEVICE_H_
+#define _DEVICE_H_
+
+#include <string>
+#include <vector>
+
+#include "Common.h"
+
+// idk in case I wanted to change it to double or something, idk what's best
+typedef float ControlState;
+
+namespace ciface
+{
+namespace Core
+{
+
+// Forward declarations
+class DeviceQualifier;
+
+//
+// Device
+//
+// a device class
+//
+class Device
+{
+public:
+ class Input;
+ class Output;
+
+ //
+ // Control
+ //
+ // control includes inputs and outputs
+ //
+ class Control // input or output
+ {
+ public:
+ virtual std::string GetName() const = 0;
+ virtual ~Control() {}
+
+ virtual Input* ToInput() { return NULL; }
+ virtual Output* ToOutput() { return NULL; }
+ };
+
+ //
+ // Input
+ //
+ // an input on a device
+ //
+ class Input : public Control
+ {
+ public:
+ // things like absolute axes/ absolute mouse position will override this
+ virtual bool IsDetectable() { return true; }
+
+ virtual ControlState GetState() const = 0;
+
+ Input* ToInput() { return this; }
+ };
+
+ //
+ // Output
+ //
+ // an output on a device
+ //
+ class Output : public Control
+ {
+ public:
+ virtual ~Output() {}
+
+ virtual void SetState(ControlState state) = 0;
+
+ Output* ToOutput() { return this; }
+ };
+
+ virtual ~Device();
+
+ virtual std::string GetName() const = 0;
+ virtual int GetId() const = 0;
+ virtual std::string GetSource() const = 0;
+ virtual bool UpdateInput() = 0;
+ virtual bool UpdateOutput() = 0;
+
+ virtual void ClearInputState();
+
+ const std::vector<Input*>& Inputs() const { return m_inputs; }
+ const std::vector<Output*>& Outputs() const { return m_outputs; }
+
+ Input* FindInput(const std::string& name) const;
+ Output* FindOutput(const std::string& name) const;
+
+protected:
+ void AddInput(Input* const i);
+ void AddOutput(Output* const o);
+
+ class FullAnalogSurface : public Input
+ {
+ public:
+ FullAnalogSurface(Input* low, Input* high)
+ : m_low(*low), m_high(*high)
+ {}
+
+ ControlState GetState() const
+ {
+ return (1 + m_high.GetState() - m_low.GetState()) / 2;
+ }
+
+ std::string GetName() const
+ {
+ return m_low.GetName() + *m_high.GetName().rbegin();
+ }
+
+ private:
+ Input& m_low;
+ Input& m_high;
+ };
+
+ void AddAnalogInputs(Input* low, Input* high)
+ {
+ AddInput(low);
+ AddInput(high);
+ AddInput(new FullAnalogSurface(low, high));
+ AddInput(new FullAnalogSurface(high, low));
+ }
+
+private:
+ std::vector<Input*> m_inputs;
+ std::vector<Output*> m_outputs;
+};
+
+//
+// DeviceQualifier
+//
+// device qualifier used to match devices
+// currently has ( source, id, name ) properties which match a device
+//
+class DeviceQualifier
+{
+public:
+ DeviceQualifier() : cid(-1) {}
+ DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
+ : source(_source), cid(_id), name(_name) {}
+ void FromDevice(const Device* const dev);
+ void FromString(const std::string& str);
+ std::string ToString() const;
+ bool operator==(const DeviceQualifier& devq) const;
+ bool operator==(const Device* const dev) const;
+
+ std::string source;
+ int cid;
+ std::string name;
+};
+
+class DeviceContainer
+{
+public:
+ Device::Input* FindInput(const std::string& name, const Device* def_dev) const;
+ Device::Output* FindOutput(const std::string& name, const Device* def_dev) const;
+
+ const std::vector<Device*>& Devices() const { return m_devices; }
+ Device* FindDevice(const DeviceQualifier& devq) const;
+protected:
+ std::vector<Device*> m_devices;
+};
+
+}
+}
+
+#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h
index 225906c35d..a922e3f2dd 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.h
@@ -1,13 +1,13 @@
#pragma once
-#include "../ControllerInterface.h"
+#include "../Device.h"
namespace ciface
{
namespace OSX
{
-void Init(std::vector<ControllerInterface::Device*>& devices, void *window);
+void Init(std::vector<Core::Device*>& devices, void *window);
void DeInit();
void DeviceElementDebugPrint(const void *, void *);
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm
index aef8f283c1..8a859f46c8 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm
@@ -2,11 +2,12 @@
#include <IOKit/hid/IOHIDLib.h>
#include <Cocoa/Cocoa.h>
-#include "../ControllerInterface.h"
#include "OSX.h"
#include "OSXKeyboard.h"
#include "OSXJoystick.h"
+#include <map>
+
namespace ciface
{
namespace OSX
@@ -145,8 +146,8 @@ static void DeviceMatching_callback(void* inContext,
DeviceDebugPrint(inIOHIDDeviceRef);
- std::vector<ControllerInterface::Device*> *devices =
- (std::vector<ControllerInterface::Device*> *)inContext;
+ std::vector<Core::Device*> *devices =
+ (std::vector<Core::Device*> *)inContext;
// Add to the devices vector if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
@@ -164,7 +165,7 @@ static void DeviceMatching_callback(void* inContext,
name, joy_name_counts[name]++));
}
-void Init(std::vector<ControllerInterface::Device*>& devices, void *window)
+void Init(std::vector<Core::Device*>& devices, void *window)
{
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault,
kIOHIDOptionsTypeNone);
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h
index ecc443ad3a..ebe908522b 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h
@@ -1,13 +1,13 @@
#include <IOKit/hid/IOHIDLib.h>
-#include "../ControllerInterface.h"
+#include "../Device.h"
namespace ciface
{
namespace OSX
{
-class Joystick : public ControllerInterface::Device
+class Joystick : public Core::Device
{
private:
class Button : public Input
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm
index 0d89c2e393..ebd713d142 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm
@@ -1,9 +1,10 @@
#include <Foundation/Foundation.h>
#include <IOKit/hid/IOHIDLib.h>
-#include "../ControllerInterface.h"
#include "OSXJoystick.h"
+#include <sstream>
+
namespace ciface
{
namespace OSX
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h
index d59651c98a..930f849a17 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h
@@ -1,13 +1,13 @@
#include <IOKit/hid/IOHIDLib.h>
-#include "../ControllerInterface.h"
+#include "../Device.h"
namespace ciface
{
namespace OSX
{
-class Keyboard : public ControllerInterface::Device
+class Keyboard : public Core::Device
{
private:
class Key : public Input
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm
index c22e267044..003240d4a9 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm
+++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm
@@ -3,9 +3,10 @@
#include <Cocoa/Cocoa.h>
#include <wx/wx.h> // wxWidgets
-#include "../ControllerInterface.h"
#include "OSXKeyboard.h"
+#include <sstream>
+
namespace ciface
{
namespace OSX
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
index 6c74c55d97..006b82d4ac 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
@@ -1,10 +1,11 @@
-#include "../ControllerInterface.h"
-
-#ifdef CIFACE_USE_SDL
#include "SDL.h"
#include <StringUtil.h>
+#include <map>
+#include <sstream>
+#include <algorithm>
+
#ifdef _WIN32
#if SDL_VERSION_ATLEAST(1, 3, 0)
#pragma comment(lib, "SDL.1.3.lib")
@@ -27,7 +28,7 @@ std::string GetJoystickName(int index)
#endif
}
-void Init( std::vector<ControllerInterface::Device*>& devices )
+void Init( std::vector<Core::Device*>& devices )
{
// this is used to number the joysticks
// multiple joysticks with the same name shall get unique ids starting at 0
@@ -399,5 +400,3 @@ ControlState Joystick::Hat::GetState() const
}
}
-
-#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h
index fa770c403d..6a65efeedb 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_SDL_H_
#define _CIFACE_SDL_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#include <list>
@@ -23,9 +23,9 @@ namespace ciface
namespace SDL
{
-void Init( std::vector<ControllerInterface::Device*>& devices );
+void Init( std::vector<Core::Device*>& devices );
-class Joystick : public ControllerInterface::Device
+class Joystick : public Core::Device
{
private:
@@ -40,7 +40,7 @@ private:
};
#endif
- class Button : public Input
+ class Button : public Core::Device::Input
{
public:
std::string GetName() const;
@@ -51,7 +51,7 @@ private:
const u8 m_index;
};
- class Axis : public Input
+ class Axis : public Core::Device::Input
{
public:
std::string GetName() const;
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
index 3c7f3c48ae..c687bef856 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
@@ -1,6 +1,3 @@
-#include "../ControllerInterface.h"
-
-#ifdef CIFACE_USE_XINPUT
#include "XInput.h"
@@ -51,7 +48,7 @@ static const char* const named_motors[] =
"Motor R"
};
-void Init(DeviceList& devices)
+void Init(std::vector<Core::Device*>& devices)
{
XINPUT_CAPABILITIES caps;
for (int i = 0; i != 4; ++i)
@@ -210,5 +207,3 @@ void Device::Motor::SetState(ControlState state)
}
}
-
-#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.h b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.h
index eb51a58779..8fe6dd1dee 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_XINPUT_H_
#define _CIFACE_XINPUT_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#define NOMINMAX
#include <Windows.h>
@@ -12,12 +12,12 @@ namespace ciface
namespace XInput
{
-void Init(DeviceList& devices);
+void Init(std::vector<Core::Device*>& devices);
-class Device : public ControllerInterface::Device
+class Device : public Core::Device
{
private:
- class Button : public Input
+ class Button : public Core::Device::Input
{
public:
std::string GetName() const;
@@ -28,7 +28,7 @@ private:
u8 m_index;
};
- class Axis : public Input
+ class Axis : public Core::Device::Input
{
public:
std::string GetName() const;
@@ -40,7 +40,7 @@ private:
const u8 m_index;
};
- class Trigger : public Input
+ class Trigger : public Core::Device::Input
{
public:
std::string GetName() const;
@@ -52,7 +52,7 @@ private:
const u8 m_index;
};
- class Motor : public Output
+ class Motor : public Core::Device::Output
{
public:
std::string GetName() const;
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp
index dad0c6bbf8..7016c4908b 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.cpp
@@ -7,7 +7,7 @@ namespace ciface
namespace Xlib
{
-void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd)
+void Init(std::vector<Core::Device*>& devices, void* const hwnd)
{
devices.push_back(new KeyboardMouse((Window)hwnd));
}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h
index 2af95ff7f9..c178f1e9b4 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Xlib/Xlib.h
@@ -1,7 +1,7 @@
#ifndef _CIFACE_XLIB_H_
#define _CIFACE_XLIB_H_
-#include "../ControllerInterface.h"
+#include "../Device.h"
#include <X11/Xlib.h>
#include <X11/keysym.h>
@@ -11,9 +11,9 @@ namespace ciface
namespace Xlib
{
-void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd);
+void Init(std::vector<Core::Device*>& devices, void* const hwnd);
-class KeyboardMouse : public ControllerInterface::Device
+class KeyboardMouse : public Core::Device
{
private: