summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
diff options
context:
space:
mode:
authorMatthew Parlane <parlane@gmail.com>2013-08-16 19:17:07 +1200
committerMatthew Parlane <parlane@gmail.com>2013-08-16 19:17:07 +1200
commit9de7611ff940d24551bc77a5e29b86911e3fa749 (patch)
tree7615ec4cfd3aaba63d96ef1cb3cc33fd0efa516a /Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
parent417552b21e30aee3dc2b720d65c2cd757997a33e (diff)
parentbff2bc1288fa4309e1b2aef1486845ba01311100 (diff)
Merge branch 'master' into wii-network
Conflicts: CMakeLists.txt Source/Core/Core/Core.vcxproj Source/Core/DolphinWX/Dolphin.vcxproj Source/Core/DolphinWX/Dolphin.vcxproj.filters Source/Dolphin_2010.sln Source/VSProps/Dolphin.Win32.props Source/VSProps/Dolphin.x64.props
Diffstat (limited to 'Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp')
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp318
1 files changed, 23 insertions, 295 deletions
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
index 6db79605a7..d2982bba24 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
@@ -8,6 +8,9 @@
#endif
#ifdef CIFACE_USE_XLIB
#include "Xlib/Xlib.h"
+ #ifdef CIFACE_USE_X11_XINPUT2
+ #include "Xlib/XInput2.h"
+ #endif
#endif
#ifdef CIFACE_USE_OSX
#include "OSX/OSX.h"
@@ -21,6 +24,8 @@
#include "Thread.h"
+using namespace ciface::ExpressionParser;
+
namespace
{
const float INPUT_DETECT_THRESHOLD = 0.55f;
@@ -46,6 +51,9 @@ void ControllerInterface::Initialize()
#endif
#ifdef CIFACE_USE_XLIB
ciface::Xlib::Init(m_devices, m_hwnd);
+ #ifdef CIFACE_USE_X11_XINPUT2
+ ciface::XInput2::Init(m_devices, m_hwnd);
+ #endif
#endif
#ifdef CIFACE_USE_OSX
ciface::OSX::Init(m_devices, m_hwnd);
@@ -180,56 +188,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
@@ -237,48 +195,10 @@ void ControllerInterface::Device::ClearInputState()
//
ControlState ControllerInterface::InputReference::State( const ControlState ignore )
{
- //if (NULL == device)
- //return 0;
-
- ControlState state = 0;
-
- std::vector<DeviceControl>::const_iterator
- ci = m_controls.begin(),
- ce = m_controls.end();
-
- // bit of hax for "NOT" to work at start of expression
- if (ci != ce)
- {
- if (ci->mode == 2)
- state = 1;
- }
-
- for (; ci!=ce; ++ci)
- {
- const ControlState istate = ci->control->ToInput()->GetState();
-
- switch (ci->mode)
- {
- // OR
- case 0 :
- state = std::max(state, istate);
- break;
- // AND
- case 1 :
- state = std::min(state, istate);
- break;
- // NOT
- case 2 :
- state = std::max(std::min(state, 1.0f - istate), 0.0f);
- break;
- // ADD
- case 3 :
- state += istate;
- break;
- }
- }
-
- return std::min(1.0f, state * range);
+ if (parsed_expression)
+ return parsed_expression->GetValue();
+ else
+ return 0.0f;
}
//
@@ -290,83 +210,9 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno
//
ControlState ControllerInterface::OutputReference::State(const ControlState state)
{
- const ControlState tmp_state = std::min(1.0f, state * range);
-
- // output ref just ignores the modes ( |&!... )
-
- std::vector<DeviceControl>::iterator
- ci = m_controls.begin(),
- ce = m_controls.end();
- for (; ci != ce; ++ci)
- ci->control->ToOutput()->SetState(tmp_state);
-
- 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;
+ if (parsed_expression)
+ parsed_expression->SetValue(state);
+ return 0.0f;
}
//
@@ -376,79 +222,13 @@ bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface:
// 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
-{
- ref->m_controls.clear();
-
- // adding | to parse the last item, silly
- std::istringstream ss(ref->expression + '|');
-
- const std::string mode_chars("|&!^");
-
- ControlReference::DeviceControl devc;
-
- std::string dev_str;
- std::string ctrl_str;
-
- char c = 0;
- while (ss.read(&c, 1))
- {
- const size_t f = mode_chars.find(c);
-
- if (mode_chars.npos != f)
- {
- // add ctrl
- if (ctrl_str.size())
- {
- DeviceQualifier devq;
-
- // using default device or alterate device inside `backticks`
- if (dev_str.empty())
- devq = default_device;
- else
- devq.FromString(dev_str);
-
- // find device
- Device* const def_device = FindDevice(devq);
-
- if (def_device)
- {
- if (ref->is_input)
- devc.control = FindInput(ctrl_str, def_device);
- else
- devc.control = FindOutput(ctrl_str, def_device);
-
- if (devc.control)
- ref->m_controls.push_back(devc);
- }
- }
- // reset stuff for next ctrl
- devc.mode = (int)f;
- ctrl_str.clear();
- }
- else if ('`' == c)
- {
- // different device
- if (std::getline(ss, dev_str, '`').eof())
- break; // no terminating '`' character
- }
- else
- {
- ctrl_str += c;
- }
- }
-}
-
-ControllerInterface::Device* ControllerInterface::FindDevice(const ControllerInterface::DeviceQualifier& devq) const
+ , const DeviceQualifier& default_device) const
{
- std::vector<ControllerInterface::Device*>::const_iterator
- di = m_devices.begin(),
- de = m_devices.end();
- for (; di!=de; ++di)
- if (devq == *di)
- return *di;
+ delete ref->parsed_expression;
+ ref->parsed_expression = NULL;
- return NULL;
+ ControlFinder finder(*this, default_device, ref->is_input);
+ ref->parse_error = ParseExpression(ref->expression, finder, &ref->parsed_expression);
}
//
@@ -461,7 +241,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,12 +291,12 @@ 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
// don't hang if we don't even have any controls mapped
- if (m_controls.size())
+ if (BoundCount() > 0)
{
State(1);
unsigned int slept = 0;
@@ -534,55 +314,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);
-}