Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
InputCommon: Split Device stuff out
The ExpressionParser needs this to be out of here to prevent issues
with cyclic references.
  • Loading branch information
magcius committed Jun 25, 2013
1 parent 143d2ec commit 877106b
Show file tree
Hide file tree
Showing 30 changed files with 448 additions and 451 deletions.
18 changes: 9 additions & 9 deletions Source/Core/DolphinWX/Src/InputConfigDiag.cpp
Expand Up @@ -184,13 +184,13 @@ void ControlDialog::UpdateListContents()
{
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 (control_reference->is_input)
{
// for inputs
std::vector<ControllerInterface::Device::Input*>::const_iterator
std::vector<Device::Input*>::const_iterator
i = dev->Inputs().begin(),
e = dev->Inputs().end();
for (; i!=e; ++i)
Expand All @@ -199,7 +199,7 @@ void ControlDialog::UpdateListContents()
else
{
// for outputs
std::vector<ControllerInterface::Device::Output*>::const_iterator
std::vector<Device::Output*>::const_iterator
i = dev->Outputs().begin(),
e = dev->Outputs().end();
for (; i!=e; ++i)
Expand Down Expand Up @@ -418,7 +418,7 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
wxButton* const btn = (wxButton*)event.GetEventObject();
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)
{
btn->SetLabel(_("[ waiting ]"));
Expand All @@ -427,7 +427,7 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
wxTheApp->Yield();

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 (ctrl)
Expand All @@ -442,7 +442,7 @@ void GamepadPage::DetectControl(wxCommandEvent& event)
ControlButton* btn = (ControlButton*)event.GetEventObject();

// 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)
{
btn->SetLabel(_("[ waiting ]"));
Expand All @@ -451,7 +451,7 @@ void GamepadPage::DetectControl(wxCommandEvent& event)
wxTheApp->Yield();

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 (ctrl)
Expand Down Expand Up @@ -614,11 +614,11 @@ void InputConfigDialog::UpdateDeviceComboBox()
{
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
e = m_padpages.end();
ControllerInterface::DeviceQualifier dq;
DeviceQualifier dq;
for (; i != e; ++i)
{
(*i)->device_cbox->Clear();
std::vector<ControllerInterface::Device*>::const_iterator
std::vector<Device*>::const_iterator
di = g_controller_interface.Devices().begin(),
de = g_controller_interface.Devices().end();
for (; di!=de; ++di)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Src/InputConfigDiag.h
Expand Up @@ -112,7 +112,7 @@ class ControlDialog : public wxDialog
private:
GamepadPage* const m_parent;
wxStaticText* m_bound_label;
ControllerInterface::DeviceQualifier m_devq;
DeviceQualifier m_devq;
};

class ExtensionButton : public wxButton
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/InputCommon/CMakeLists.txt
Expand Up @@ -2,7 +2,8 @@ set(SRCS Src/ControllerEmu.cpp
Src/InputConfig.cpp
Src/UDPWiimote.cpp
Src/UDPWrapper.cpp
Src/ControllerInterface/ControllerInterface.cpp)
Src/ControllerInterface/ControllerInterface.cpp
Src/ControllerInterface/Device.cpp)

if(WIN32)
set(SRCS ${SRCS}
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/InputCommon/InputCommon.vcxproj
Expand Up @@ -166,6 +166,7 @@
<ItemGroup>
<ClCompile Include="Src\ControllerEmu.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\DInputJoystick.cpp" />
<ClCompile Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.cpp" />
Expand All @@ -178,6 +179,7 @@
<ItemGroup>
<ClInclude Include="Src\ControllerEmu.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\DInputJoystick.h" />
<ClInclude Include="Src\ControllerInterface\DInput\DInputKeyboardMouse.h" />
Expand All @@ -195,4 +197,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions Source/Core/InputCommon/InputCommon.vcxproj.filters
Expand Up @@ -39,6 +39,9 @@
<ClInclude Include="Src\ControllerInterface\ControllerInterface.h">
<Filter>ControllerInterface</Filter>
</ClInclude>
<ClInclude Include="Src\ControllerInterface\Device.h">
<Filter>ControllerInterface\Device</Filter>
</ClInclude>
<ClInclude Include="Src\ControllerInterface\DInput\NamedKeys.h">
<Filter>ControllerInterface\DInput</Filter>
</ClInclude>
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/InputCommon/Src/ControllerEmu.h
Expand Up @@ -449,8 +449,7 @@ class ControllerEmu

std::vector< ControlGroup* > groups;

ControllerInterface::DeviceQualifier default_device;

DeviceQualifier default_device;
};


Expand Down
Expand Up @@ -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());
}
Expand Down
Expand Up @@ -17,16 +17,16 @@
#ifndef _CIFACE_ANDROID_H_
#define _CIFACE_ANDROID_H_

#include "../ControllerInterface.h"
#include "../Device.h"
#include "Android/ButtonManager.h"

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
Expand Down
Expand Up @@ -179,56 +179,6 @@ bool ControllerInterface::UpdateOutput(const bool force)
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
//
Expand Down Expand Up @@ -303,80 +253,14 @@ ControlState ControllerInterface::OutputReference::State(const ControlState stat
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
//
// 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();

Expand Down Expand Up @@ -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
//
Expand All @@ -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());
Expand Down Expand Up @@ -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

Expand All @@ -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);
}

0 comments on commit 877106b

Please sign in to comment.