mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
InputCommon: Split Device stuff out
The ExpressionParser needs this to be out of here to prevent issues with cyclic references.
This commit is contained in:
parent
143d2eccb4
commit
877106b027
@ -184,13 +184,13 @@ void ControlDialog::UpdateListContents()
|
|||||||
{
|
{
|
||||||
control_lbox->Clear();
|
control_lbox->Clear();
|
||||||
|
|
||||||
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(m_devq);
|
Device* const dev = g_controller_interface.FindDevice(m_devq);
|
||||||
if (dev)
|
if (dev)
|
||||||
{
|
{
|
||||||
if (control_reference->is_input)
|
if (control_reference->is_input)
|
||||||
{
|
{
|
||||||
// for inputs
|
// for inputs
|
||||||
std::vector<ControllerInterface::Device::Input*>::const_iterator
|
std::vector<Device::Input*>::const_iterator
|
||||||
i = dev->Inputs().begin(),
|
i = dev->Inputs().begin(),
|
||||||
e = dev->Inputs().end();
|
e = dev->Inputs().end();
|
||||||
for (; i!=e; ++i)
|
for (; i!=e; ++i)
|
||||||
@ -199,7 +199,7 @@ void ControlDialog::UpdateListContents()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// for outputs
|
// for outputs
|
||||||
std::vector<ControllerInterface::Device::Output*>::const_iterator
|
std::vector<Device::Output*>::const_iterator
|
||||||
i = dev->Outputs().begin(),
|
i = dev->Outputs().begin(),
|
||||||
e = dev->Outputs().end();
|
e = dev->Outputs().end();
|
||||||
for (; i!=e; ++i)
|
for (; i!=e; ++i)
|
||||||
@ -418,7 +418,7 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
|
|||||||
wxButton* const btn = (wxButton*)event.GetEventObject();
|
wxButton* const btn = (wxButton*)event.GetEventObject();
|
||||||
const wxString lbl = btn->GetLabel();
|
const wxString lbl = btn->GetLabel();
|
||||||
|
|
||||||
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(m_devq);
|
Device* const dev = g_controller_interface.FindDevice(m_devq);
|
||||||
if (dev)
|
if (dev)
|
||||||
{
|
{
|
||||||
btn->SetLabel(_("[ waiting ]"));
|
btn->SetLabel(_("[ waiting ]"));
|
||||||
@ -427,7 +427,7 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
|
|||||||
wxTheApp->Yield();
|
wxTheApp->Yield();
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
|
std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
|
||||||
ControllerInterface::Device::Control* const ctrl = control_reference->Detect(DETECT_WAIT_TIME, dev);
|
Device::Control* const ctrl = control_reference->Detect(DETECT_WAIT_TIME, dev);
|
||||||
|
|
||||||
// if we got input, select it in the list
|
// if we got input, select it in the list
|
||||||
if (ctrl)
|
if (ctrl)
|
||||||
@ -442,7 +442,7 @@ void GamepadPage::DetectControl(wxCommandEvent& event)
|
|||||||
ControlButton* btn = (ControlButton*)event.GetEventObject();
|
ControlButton* btn = (ControlButton*)event.GetEventObject();
|
||||||
|
|
||||||
// find device :/
|
// find device :/
|
||||||
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(controller->default_device);
|
Device* const dev = g_controller_interface.FindDevice(controller->default_device);
|
||||||
if (dev)
|
if (dev)
|
||||||
{
|
{
|
||||||
btn->SetLabel(_("[ waiting ]"));
|
btn->SetLabel(_("[ waiting ]"));
|
||||||
@ -451,7 +451,7 @@ void GamepadPage::DetectControl(wxCommandEvent& event)
|
|||||||
wxTheApp->Yield();
|
wxTheApp->Yield();
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
|
std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
|
||||||
ControllerInterface::Device::Control* const ctrl = btn->control_reference->Detect(DETECT_WAIT_TIME, dev);
|
Device::Control* const ctrl = btn->control_reference->Detect(DETECT_WAIT_TIME, dev);
|
||||||
|
|
||||||
// if we got input, update expression and reference
|
// if we got input, update expression and reference
|
||||||
if (ctrl)
|
if (ctrl)
|
||||||
@ -614,11 +614,11 @@ void InputConfigDialog::UpdateDeviceComboBox()
|
|||||||
{
|
{
|
||||||
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
|
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
|
||||||
e = m_padpages.end();
|
e = m_padpages.end();
|
||||||
ControllerInterface::DeviceQualifier dq;
|
DeviceQualifier dq;
|
||||||
for (; i != e; ++i)
|
for (; i != e; ++i)
|
||||||
{
|
{
|
||||||
(*i)->device_cbox->Clear();
|
(*i)->device_cbox->Clear();
|
||||||
std::vector<ControllerInterface::Device*>::const_iterator
|
std::vector<Device*>::const_iterator
|
||||||
di = g_controller_interface.Devices().begin(),
|
di = g_controller_interface.Devices().begin(),
|
||||||
de = g_controller_interface.Devices().end();
|
de = g_controller_interface.Devices().end();
|
||||||
for (; di!=de; ++di)
|
for (; di!=de; ++di)
|
||||||
|
@ -112,7 +112,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
GamepadPage* const m_parent;
|
GamepadPage* const m_parent;
|
||||||
wxStaticText* m_bound_label;
|
wxStaticText* m_bound_label;
|
||||||
ControllerInterface::DeviceQualifier m_devq;
|
DeviceQualifier m_devq;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExtensionButton : public wxButton
|
class ExtensionButton : public wxButton
|
||||||
|
@ -2,7 +2,8 @@ set(SRCS Src/ControllerEmu.cpp
|
|||||||
Src/InputConfig.cpp
|
Src/InputConfig.cpp
|
||||||
Src/UDPWiimote.cpp
|
Src/UDPWiimote.cpp
|
||||||
Src/UDPWrapper.cpp
|
Src/UDPWrapper.cpp
|
||||||
Src/ControllerInterface/ControllerInterface.cpp)
|
Src/ControllerInterface/ControllerInterface.cpp
|
||||||
|
Src/ControllerInterface/Device.cpp)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SRCS ${SRCS}
|
set(SRCS ${SRCS}
|
||||||
|
@ -166,6 +166,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Src\ControllerEmu.cpp" />
|
<ClCompile Include="Src\ControllerEmu.cpp" />
|
||||||
<ClCompile Include="Src\ControllerInterface\ControllerInterface.cpp" />
|
<ClCompile Include="Src\ControllerInterface\ControllerInterface.cpp" />
|
||||||
|
<ClCompile Include="Src\ControllerInterface\Device.cpp" />
|
||||||
<ClCompile Include="Src\ControllerInterface\DInput\DInput.cpp" />
|
<ClCompile Include="Src\ControllerInterface\DInput\DInput.cpp" />
|
||||||
<ClCompile Include="Src\ControllerInterface\DInput\DInputJoystick.cpp" />
|
<ClCompile Include="Src\ControllerInterface\DInput\DInputJoystick.cpp" />
|
||||||
<ClCompile Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.cpp" />
|
<ClCompile Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.cpp" />
|
||||||
@ -178,6 +179,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Src\ControllerEmu.h" />
|
<ClInclude Include="Src\ControllerEmu.h" />
|
||||||
<ClInclude Include="Src\ControllerInterface\ControllerInterface.h" />
|
<ClInclude Include="Src\ControllerInterface\ControllerInterface.h" />
|
||||||
|
<ClInclude Include="Src\ControllerInterface\Device.h" />
|
||||||
<ClInclude Include="Src\ControllerInterface\DInput\DInput.h" />
|
<ClInclude Include="Src\ControllerInterface\DInput\DInput.h" />
|
||||||
<ClInclude Include="Src\ControllerInterface\DInput\DInputJoystick.h" />
|
<ClInclude Include="Src\ControllerInterface\DInput\DInputJoystick.h" />
|
||||||
<ClInclude Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.h" />
|
<ClInclude Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.h" />
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
<ClInclude Include="Src\ControllerInterface\ControllerInterface.h">
|
<ClInclude Include="Src\ControllerInterface\ControllerInterface.h">
|
||||||
<Filter>ControllerInterface</Filter>
|
<Filter>ControllerInterface</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Src\ControllerInterface\Device.h">
|
||||||
|
<Filter>ControllerInterface\Device</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="Src\ControllerInterface\DInput\NamedKeys.h">
|
<ClInclude Include="Src\ControllerInterface\DInput\NamedKeys.h">
|
||||||
<Filter>ControllerInterface\DInput</Filter>
|
<Filter>ControllerInterface\DInput</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -449,8 +449,7 @@ public:
|
|||||||
|
|
||||||
std::vector< ControlGroup* > groups;
|
std::vector< ControlGroup* > groups;
|
||||||
|
|
||||||
ControllerInterface::DeviceQualifier default_device;
|
DeviceQualifier default_device;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace ciface
|
|||||||
namespace Android
|
namespace Android
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices )
|
void Init( std::vector<Core::Device*>& devices )
|
||||||
{
|
{
|
||||||
devices.push_back(new Touchscreen());
|
devices.push_back(new Touchscreen());
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#ifndef _CIFACE_ANDROID_H_
|
#ifndef _CIFACE_ANDROID_H_
|
||||||
#define _CIFACE_ANDROID_H_
|
#define _CIFACE_ANDROID_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
#include "Android/ButtonManager.h"
|
#include "Android/ButtonManager.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
@ -25,8 +25,8 @@ namespace ciface
|
|||||||
namespace Android
|
namespace Android
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices );
|
void Init( std::vector<Core::Device*>& devices );
|
||||||
class Touchscreen : public ControllerInterface::Device
|
class Touchscreen : public Core::Device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
|
@ -179,56 +179,6 @@ bool ControllerInterface::UpdateOutput(const bool force)
|
|||||||
return (m_devices.size() == ok_count);
|
return (m_devices.size() == ok_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// 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
|
// InputReference :: State
|
||||||
//
|
//
|
||||||
@ -303,72 +253,6 @@ ControlState ControllerInterface::OutputReference::State(const ControlState stat
|
|||||||
return state; // just return the output, watever
|
return state; // just return the output, watever
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// 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
|
// UpdateReference
|
||||||
//
|
//
|
||||||
@ -376,7 +260,7 @@ bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface:
|
|||||||
// need to call this to re-parse a control reference's expression after changing it
|
// need to call this to re-parse a control reference's expression after changing it
|
||||||
//
|
//
|
||||||
void ControllerInterface::UpdateReference(ControllerInterface::ControlReference* ref
|
void ControllerInterface::UpdateReference(ControllerInterface::ControlReference* ref
|
||||||
, const ControllerInterface::DeviceQualifier& default_device) const
|
, const DeviceQualifier& default_device) const
|
||||||
{
|
{
|
||||||
ref->m_controls.clear();
|
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
|
// InputReference :: Detect
|
||||||
//
|
//
|
||||||
@ -461,7 +333,7 @@ ControllerInterface::Device* ControllerInterface::FindDevice(const ControllerInt
|
|||||||
// upon input, return pointer to detected Control
|
// upon input, return pointer to detected Control
|
||||||
// else return NULL
|
// 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;
|
unsigned int time = 0;
|
||||||
std::vector<bool> states(device->Inputs().size());
|
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
|
// 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
|
// ignore device
|
||||||
|
|
||||||
@ -534,55 +406,3 @@ ControllerInterface::Device::Control* ControllerInterface::OutputReference::Dete
|
|||||||
}
|
}
|
||||||
return NULL;
|
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);
|
|
||||||
}
|
|
||||||
|
@ -9,18 +9,13 @@
|
|||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
|
#include "Device.h"
|
||||||
|
|
||||||
// enable disable sources
|
// enable disable sources
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define CIFACE_USE_XINPUT
|
#define CIFACE_USE_XINPUT
|
||||||
#define CIFACE_USE_DINPUT_JOYSTICK
|
|
||||||
#define CIFACE_USE_DINPUT_KBM
|
|
||||||
#define CIFACE_USE_DINPUT
|
#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
|
#define CIFACE_USE_SDL
|
||||||
//#endif
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_X11) && HAVE_X11
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
#define CIFACE_USE_XLIB
|
#define CIFACE_USE_XLIB
|
||||||
@ -33,8 +28,7 @@
|
|||||||
#define CIFACE_USE_ANDROID
|
#define CIFACE_USE_ANDROID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// idk in case I wanted to change it to double or something, idk what's best
|
using namespace ciface::Core;
|
||||||
typedef float ControlState;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// ControllerInterface
|
// ControllerInterface
|
||||||
@ -42,148 +36,10 @@ typedef float ControlState;
|
|||||||
// some crazy shit I made to control different device inputs and outputs
|
// some crazy shit I made to control different device inputs and outputs
|
||||||
// from lots of different sources, hopefully more easily
|
// from lots of different sources, hopefully more easily
|
||||||
//
|
//
|
||||||
class ControllerInterface
|
class ControllerInterface : public DeviceContainer
|
||||||
{
|
{
|
||||||
public:
|
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
|
// ControlReference
|
||||||
//
|
//
|
||||||
@ -260,22 +116,13 @@ public:
|
|||||||
bool UpdateInput(const bool force = false);
|
bool UpdateInput(const bool force = false);
|
||||||
bool UpdateOutput(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;
|
std::recursive_mutex update_lock;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_init;
|
bool m_is_init;
|
||||||
std::vector<Device*> m_devices;
|
|
||||||
void* m_hwnd;
|
void* m_hwnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<ControllerInterface::Device*> DeviceList;
|
|
||||||
|
|
||||||
extern ControllerInterface g_controller_interface;
|
extern ControllerInterface g_controller_interface;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
#include "../ControllerInterface.h"
|
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT
|
|
||||||
|
|
||||||
#include "DInput.h"
|
#include "DInput.h"
|
||||||
|
|
||||||
#include "StringUtil.h"
|
#include "StringUtil.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT_JOYSTICK
|
|
||||||
#include "DInputJoystick.h"
|
#include "DInputJoystick.h"
|
||||||
#endif
|
|
||||||
#ifdef CIFACE_USE_DINPUT_KBM
|
|
||||||
#include "DInputKeyboardMouse.h"
|
#include "DInputKeyboardMouse.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma comment(lib, "Dinput8.lib")
|
#pragma comment(lib, "Dinput8.lib")
|
||||||
#pragma comment(lib, "dxguid.lib")
|
#pragma comment(lib, "dxguid.lib")
|
||||||
@ -55,18 +48,14 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
|
void Init(std::vector<Core::Device*>& devices, HWND hwnd)
|
||||||
{
|
{
|
||||||
IDirectInput8* idi8;
|
IDirectInput8* idi8;
|
||||||
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL)))
|
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT_KBM
|
|
||||||
InitKeyboardMouse(idi8, devices, hwnd);
|
InitKeyboardMouse(idi8, devices, hwnd);
|
||||||
#endif
|
|
||||||
#ifdef CIFACE_USE_DINPUT_JOYSTICK
|
|
||||||
InitJoystick(idi8, devices, hwnd);
|
InitJoystick(idi8, devices, hwnd);
|
||||||
#endif
|
|
||||||
|
|
||||||
idi8->Release();
|
idi8->Release();
|
||||||
|
|
||||||
@ -74,5 +63,3 @@ void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_DINPUT_H_
|
#ifndef _CIFACE_DINPUT_H_
|
||||||
#define _CIFACE_DINPUT_H_
|
#define _CIFACE_DINPUT_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#define DINPUT_SOURCE_NAME "DInput"
|
#define DINPUT_SOURCE_NAME "DInput"
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVO
|
|||||||
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
|
BOOL CALLBACK DIEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
|
||||||
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device);
|
std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device);
|
||||||
|
|
||||||
void Init(std::vector<ControllerInterface::Device*>& devices, HWND hwnd);
|
void Init(std::vector<Core::Device*>& devices, HWND hwnd);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "../ControllerInterface.h"
|
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT_JOYSTICK
|
|
||||||
|
|
||||||
#include "DInputJoystick.h"
|
#include "DInputJoystick.h"
|
||||||
#include "DInput.h"
|
#include "DInput.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DInput
|
namespace DInput
|
||||||
@ -142,7 +143,7 @@ LCleanup:
|
|||||||
}
|
}
|
||||||
#endif
|
#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;
|
std::list<DIDEVICEINSTANCE> joysticks;
|
||||||
idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY );
|
idi8->EnumDevices( DI8DEVCLASS_GAMECTRL, DIEnumDevicesCallback, (LPVOID)&joysticks, DIEDFL_ATTACHEDONLY );
|
||||||
@ -599,5 +600,3 @@ Joystick::Force<P>::Force(u8 index, EffectState& state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_DINPUT_JOYSTICK_H_
|
#ifndef _CIFACE_DINPUT_JOYSTICK_H_
|
||||||
#define _CIFACE_DINPUT_JOYSTICK_H_
|
#define _CIFACE_DINPUT_JOYSTICK_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -11,21 +11,14 @@
|
|||||||
|
|
||||||
#include <list>
|
#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 ciface
|
||||||
{
|
{
|
||||||
namespace DInput
|
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:
|
private:
|
||||||
struct EffectState
|
struct EffectState
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#include "../ControllerInterface.h"
|
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT_KBM
|
|
||||||
|
|
||||||
#include "DInputKeyboardMouse.h"
|
#include "DInputKeyboardMouse.h"
|
||||||
#include "DInput.h"
|
#include "DInput.h"
|
||||||
@ -42,7 +39,7 @@ static const struct
|
|||||||
// lil silly
|
// lil silly
|
||||||
static HWND hwnd;
|
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;
|
hwnd = _hwnd;
|
||||||
|
|
||||||
@ -252,16 +249,6 @@ std::string KeyboardMouse::GetSource() const
|
|||||||
return DINPUT_SOURCE_NAME;
|
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
|
// names
|
||||||
std::string KeyboardMouse::Key::GetName() const
|
std::string KeyboardMouse::Key::GetName() const
|
||||||
{
|
{
|
||||||
@ -322,5 +309,3 @@ void KeyboardMouse::Light::SetState(const ControlState state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_DINPUT_KBM_H_
|
#ifndef _CIFACE_DINPUT_KBM_H_
|
||||||
#define _CIFACE_DINPUT_KBM_H_
|
#define _CIFACE_DINPUT_KBM_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -14,9 +14,9 @@ namespace ciface
|
|||||||
namespace DInput
|
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:
|
private:
|
||||||
struct State
|
struct State
|
||||||
|
193
Source/Core/InputCommon/Src/ControllerInterface/Device.cpp
Normal file
193
Source/Core/InputCommon/Src/ControllerInterface/Device.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
171
Source/Core/InputCommon/Src/ControllerInterface/Device.h
Normal file
171
Source/Core/InputCommon/Src/ControllerInterface/Device.h
Normal file
@ -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
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init(std::vector<ControllerInterface::Device*>& devices, void *window);
|
void Init(std::vector<Core::Device*>& devices, void *window);
|
||||||
void DeInit();
|
void DeInit();
|
||||||
|
|
||||||
void DeviceElementDebugPrint(const void *, void *);
|
void DeviceElementDebugPrint(const void *, void *);
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
#include <IOKit/hid/IOHIDLib.h>
|
#include <IOKit/hid/IOHIDLib.h>
|
||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
|
||||||
#include "OSX.h"
|
#include "OSX.h"
|
||||||
#include "OSXKeyboard.h"
|
#include "OSXKeyboard.h"
|
||||||
#include "OSXJoystick.h"
|
#include "OSXJoystick.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
@ -145,8 +146,8 @@ static void DeviceMatching_callback(void* inContext,
|
|||||||
|
|
||||||
DeviceDebugPrint(inIOHIDDeviceRef);
|
DeviceDebugPrint(inIOHIDDeviceRef);
|
||||||
|
|
||||||
std::vector<ControllerInterface::Device*> *devices =
|
std::vector<Core::Device*> *devices =
|
||||||
(std::vector<ControllerInterface::Device*> *)inContext;
|
(std::vector<Core::Device*> *)inContext;
|
||||||
|
|
||||||
// Add to the devices vector if it's of a type we want
|
// Add to the devices vector if it's of a type we want
|
||||||
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
||||||
@ -164,7 +165,7 @@ static void DeviceMatching_callback(void* inContext,
|
|||||||
name, joy_name_counts[name]++));
|
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,
|
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault,
|
||||||
kIOHIDOptionsTypeNone);
|
kIOHIDOptionsTypeNone);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include <IOKit/hid/IOHIDLib.h>
|
#include <IOKit/hid/IOHIDLib.h>
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
{
|
{
|
||||||
|
|
||||||
class Joystick : public ControllerInterface::Device
|
class Joystick : public Core::Device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <IOKit/hid/IOHIDLib.h>
|
#include <IOKit/hid/IOHIDLib.h>
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
|
||||||
#include "OSXJoystick.h"
|
#include "OSXJoystick.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include <IOKit/hid/IOHIDLib.h>
|
#include <IOKit/hid/IOHIDLib.h>
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
{
|
{
|
||||||
|
|
||||||
class Keyboard : public ControllerInterface::Device
|
class Keyboard : public Core::Device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Key : public Input
|
class Key : public Input
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#include <wx/wx.h> // wxWidgets
|
#include <wx/wx.h> // wxWidgets
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
|
||||||
#include "OSXKeyboard.h"
|
#include "OSXKeyboard.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace OSX
|
namespace OSX
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#include "../ControllerInterface.h"
|
|
||||||
|
|
||||||
#ifdef CIFACE_USE_SDL
|
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include <StringUtil.h>
|
#include <StringUtil.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||||
#pragma comment(lib, "SDL.1.3.lib")
|
#pragma comment(lib, "SDL.1.3.lib")
|
||||||
@ -27,7 +28,7 @@ std::string GetJoystickName(int index)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices )
|
void Init( std::vector<Core::Device*>& devices )
|
||||||
{
|
{
|
||||||
// this is used to number the joysticks
|
// this is used to number the joysticks
|
||||||
// multiple joysticks with the same name shall get unique ids starting at 0
|
// multiple joysticks with the same name shall get unique ids starting at 0
|
||||||
@ -399,5 +400,3 @@ ControlState Joystick::Hat::GetState() const
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_SDL_H_
|
#ifndef _CIFACE_SDL_H_
|
||||||
#define _CIFACE_SDL_H_
|
#define _CIFACE_SDL_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@ -23,9 +23,9 @@ namespace ciface
|
|||||||
namespace SDL
|
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:
|
private:
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ private:
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Core::Device::Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
@ -51,7 +51,7 @@ private:
|
|||||||
const u8 m_index;
|
const u8 m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Axis : public Input
|
class Axis : public Core::Device::Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#include "../ControllerInterface.h"
|
|
||||||
|
|
||||||
#ifdef CIFACE_USE_XINPUT
|
|
||||||
|
|
||||||
#include "XInput.h"
|
#include "XInput.h"
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ static const char* const named_motors[] =
|
|||||||
"Motor R"
|
"Motor R"
|
||||||
};
|
};
|
||||||
|
|
||||||
void Init(DeviceList& devices)
|
void Init(std::vector<Core::Device*>& devices)
|
||||||
{
|
{
|
||||||
XINPUT_CAPABILITIES caps;
|
XINPUT_CAPABILITIES caps;
|
||||||
for (int i = 0; i != 4; ++i)
|
for (int i = 0; i != 4; ++i)
|
||||||
@ -210,5 +207,3 @@ void Device::Motor::SetState(ControlState state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_XINPUT_H_
|
#ifndef _CIFACE_XINPUT_H_
|
||||||
#define _CIFACE_XINPUT_H_
|
#define _CIFACE_XINPUT_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@ -12,12 +12,12 @@ namespace ciface
|
|||||||
namespace XInput
|
namespace XInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init(DeviceList& devices);
|
void Init(std::vector<Core::Device*>& devices);
|
||||||
|
|
||||||
class Device : public ControllerInterface::Device
|
class Device : public Core::Device
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Button : public Input
|
class Button : public Core::Device::Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
@ -28,7 +28,7 @@ private:
|
|||||||
u8 m_index;
|
u8 m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Axis : public Input
|
class Axis : public Core::Device::Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
@ -40,7 +40,7 @@ private:
|
|||||||
const u8 m_index;
|
const u8 m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Trigger : public Input
|
class Trigger : public Core::Device::Input
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
@ -52,7 +52,7 @@ private:
|
|||||||
const u8 m_index;
|
const u8 m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Motor : public Output
|
class Motor : public Core::Device::Output
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
|
@ -7,7 +7,7 @@ namespace ciface
|
|||||||
namespace Xlib
|
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));
|
devices.push_back(new KeyboardMouse((Window)hwnd));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef _CIFACE_XLIB_H_
|
#ifndef _CIFACE_XLIB_H_
|
||||||
#define _CIFACE_XLIB_H_
|
#define _CIFACE_XLIB_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../Device.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
@ -11,9 +11,9 @@ namespace ciface
|
|||||||
namespace Xlib
|
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:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user