mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Light cleanup to a little bit of InputCommon. Replaces much of the iterators that litter this section of the codebase.
Also clean up a little bit of the comments that describe the interface classes.
This commit is contained in:
@ -11,38 +11,23 @@
|
|||||||
ControllerEmu::~ControllerEmu()
|
ControllerEmu::~ControllerEmu()
|
||||||
{
|
{
|
||||||
// control groups
|
// control groups
|
||||||
std::vector<ControlGroup*>::const_iterator
|
for (ControlGroup* cg : groups)
|
||||||
i = groups.begin(),
|
delete cg;
|
||||||
e = groups.end();
|
|
||||||
for (; i!=e; ++i)
|
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::ControlGroup::~ControlGroup()
|
ControllerEmu::ControlGroup::~ControlGroup()
|
||||||
{
|
{
|
||||||
// controls
|
for (Control* c : controls)
|
||||||
std::vector<Control*>::const_iterator
|
delete c;
|
||||||
ci = controls.begin(),
|
|
||||||
ce = controls.end();
|
|
||||||
for (; ci!=ce; ++ci)
|
|
||||||
delete *ci;
|
|
||||||
|
|
||||||
// settings
|
for (Setting* s : settings)
|
||||||
std::vector<Setting*>::const_iterator
|
delete s;
|
||||||
si = settings.begin(),
|
|
||||||
se = settings.end();
|
|
||||||
for (; si!=se; ++si)
|
|
||||||
delete *si;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::Extension::~Extension()
|
ControllerEmu::Extension::~Extension()
|
||||||
{
|
{
|
||||||
// attachments
|
for (ControllerEmu* ai : attachments)
|
||||||
std::vector<ControllerEmu*>::const_iterator
|
delete ai;
|
||||||
ai = attachments.begin(),
|
|
||||||
ae = attachments.end();
|
|
||||||
for (; ai!=ae; ++ai)
|
|
||||||
delete *ai;
|
|
||||||
}
|
}
|
||||||
ControllerEmu::ControlGroup::Control::~Control()
|
ControllerEmu::ControlGroup::Control::~Control()
|
||||||
{
|
{
|
||||||
@ -51,52 +36,31 @@ ControllerEmu::ControlGroup::Control::~Control()
|
|||||||
|
|
||||||
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
||||||
{
|
{
|
||||||
std::vector<ControlGroup*>::const_iterator
|
for (ControlGroup* cg : groups)
|
||||||
i = groups.begin(),
|
|
||||||
e = groups.end();
|
|
||||||
for (; i!=e; ++i)
|
|
||||||
{
|
{
|
||||||
std::vector<ControlGroup::Control*>::const_iterator
|
for (ControlGroup::Control* control : cg->controls)
|
||||||
ci = (*i)->controls.begin(),
|
devi.UpdateReference(control->control_ref, default_device);
|
||||||
ce = (*i)->controls.end();
|
|
||||||
for (; ci!=ce; ++ci)
|
|
||||||
devi.UpdateReference((*ci)->control_ref, default_device);
|
|
||||||
|
|
||||||
// extension
|
// extension
|
||||||
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
if (GROUP_TYPE_EXTENSION == cg->type)
|
||||||
{
|
{
|
||||||
std::vector<ControllerEmu*>::const_iterator
|
for (ControllerEmu* ai : ((Extension*)cg)->attachments)
|
||||||
ai = ((Extension*)*i)->attachments.begin(),
|
ai->UpdateReferences(devi);
|
||||||
ae = ((Extension*)*i)->attachments.end();
|
|
||||||
for (; ai!=ae; ++ai)
|
|
||||||
(*ai)->UpdateReferences(devi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerEmu::UpdateDefaultDevice()
|
void ControllerEmu::UpdateDefaultDevice()
|
||||||
{
|
{
|
||||||
std::vector<ControlGroup*>::const_iterator
|
for (ControlGroup* cg : groups)
|
||||||
i = groups.begin(),
|
|
||||||
e = groups.end();
|
|
||||||
for (; i!=e; ++i)
|
|
||||||
{
|
{
|
||||||
//std::vector<ControlGroup::Control*>::const_iterator
|
|
||||||
//ci = (*i)->controls.begin(),
|
|
||||||
//ce = (*i)->controls.end();
|
|
||||||
//for (; ci!=ce; ++ci)
|
|
||||||
//(*ci)->control_ref->device_qualifier = default_device;
|
|
||||||
|
|
||||||
// extension
|
// extension
|
||||||
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
if (GROUP_TYPE_EXTENSION == cg->type)
|
||||||
{
|
{
|
||||||
std::vector<ControllerEmu*>::const_iterator
|
for (ControllerEmu* ai : ((Extension*)cg)->attachments)
|
||||||
ai = ((Extension*)*i)->attachments.begin(),
|
|
||||||
ae = ((Extension*)*i)->attachments.end();
|
|
||||||
for (; ai!=ae; ++ai)
|
|
||||||
{
|
{
|
||||||
(*ai)->default_device = default_device;
|
ai->default_device = default_device;
|
||||||
(*ai)->UpdateDefaultDevice();
|
ai->UpdateDefaultDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,50 +71,43 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
|
|||||||
std::string group(base + name); group += "/";
|
std::string group(base + name); group += "/";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator
|
for (Setting* s : settings)
|
||||||
si = settings.begin(),
|
|
||||||
se = settings.end();
|
|
||||||
for (; si!=se; ++si)
|
|
||||||
{
|
{
|
||||||
sec->Get((group+(*si)->name).c_str(), &(*si)->value, (*si)->default_value*100);
|
sec->Get((group + s->name).c_str(), &s->value, s->default_value * 100);
|
||||||
(*si)->value /= 100;
|
s->value /= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator
|
for (Control* c : controls)
|
||||||
ci = controls.begin(),
|
|
||||||
ce = controls.end();
|
|
||||||
for (; ci!=ce; ++ci)
|
|
||||||
{
|
{
|
||||||
// control expression
|
// control expression
|
||||||
sec->Get((group + (*ci)->name).c_str(), &(*ci)->control_ref->expression, "");
|
sec->Get((group + c->name).c_str(), &c->control_ref->expression, "");
|
||||||
|
|
||||||
// range
|
// range
|
||||||
sec->Get((group+(*ci)->name+"/Range").c_str(), &(*ci)->control_ref->range, 100.0f);
|
sec->Get((group + c->name + "/Range").c_str(), &c->control_ref->range, 100.0f);
|
||||||
(*ci)->control_ref->range /= 100;
|
c->control_ref->range /= 100;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
if (GROUP_TYPE_EXTENSION == type)
|
if (GROUP_TYPE_EXTENSION == type)
|
||||||
{
|
{
|
||||||
Extension* const ex = ((Extension*)this);
|
Extension* const ext = ((Extension*)this);
|
||||||
|
|
||||||
ex->switch_extension = 0;
|
ext->switch_extension = 0;
|
||||||
unsigned int n = 0;
|
unsigned int n = 0;
|
||||||
std::string extname;
|
std::string extname;
|
||||||
sec->Get((base + name).c_str(), &extname, "");
|
sec->Get((base + name).c_str(), &extname, "");
|
||||||
|
|
||||||
std::vector<ControllerEmu*>::const_iterator
|
for (ControllerEmu* ai : ext->attachments)
|
||||||
ai = ((Extension*)this)->attachments.begin(),
|
|
||||||
ae = ((Extension*)this)->attachments.end();
|
|
||||||
for (; ai!=ae; ++ai,++n)
|
|
||||||
{
|
{
|
||||||
(*ai)->default_device.FromString(defdev);
|
ai->default_device.FromString(defdev);
|
||||||
(*ai)->LoadConfig(sec, base + (*ai)->GetName() + "/");
|
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
||||||
|
|
||||||
if ((*ai)->GetName() == extname)
|
if (ai->GetName() == extname)
|
||||||
ex->switch_extension = n;
|
ext->switch_extension = n;
|
||||||
|
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,10 +120,9 @@ void ControllerEmu::LoadConfig(IniFile::Section *sec, const std::string& base)
|
|||||||
sec->Get((base + "Device").c_str(), &defdev, "");
|
sec->Get((base + "Device").c_str(), &defdev, "");
|
||||||
default_device.FromString(defdev);
|
default_device.FromString(defdev);
|
||||||
}
|
}
|
||||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
|
||||||
e = groups.end();
|
for (ControlGroup* cg : groups)
|
||||||
for (; i!=e; ++i)
|
cg->LoadConfig(sec, defdev, base);
|
||||||
(*i)->LoadConfig(sec, defdev, base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base)
|
void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base)
|
||||||
@ -174,23 +130,17 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
|
|||||||
std::string group(base + name); group += "/";
|
std::string group(base + name); group += "/";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator
|
for (Setting* s : settings)
|
||||||
si = settings.begin(),
|
sec->Set((group + s->name).c_str(), s->value*100.0f, s->default_value*100.0f);
|
||||||
se = settings.end();
|
|
||||||
for (; si!=se; ++si)
|
|
||||||
sec->Set((group+(*si)->name).c_str(), (*si)->value*100.0f, (*si)->default_value*100.0f);
|
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator
|
for (Control* c : controls)
|
||||||
ci = controls.begin(),
|
|
||||||
ce = controls.end();
|
|
||||||
for (; ci!=ce; ++ci)
|
|
||||||
{
|
{
|
||||||
// control expression
|
// control expression
|
||||||
sec->Set((group+(*ci)->name).c_str(), (*ci)->control_ref->expression, "");
|
sec->Set((group + c->name).c_str(), c->control_ref->expression, "");
|
||||||
|
|
||||||
// range
|
// range
|
||||||
sec->Set((group+(*ci)->name+"/Range").c_str(), (*ci)->control_ref->range*100.0f, 100.0f);
|
sec->Set((group + c->name + "/Range").c_str(), c->control_ref->range*100.0f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
@ -199,11 +149,8 @@ void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::s
|
|||||||
Extension* const ext = ((Extension*)this);
|
Extension* const ext = ((Extension*)this);
|
||||||
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
|
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
|
||||||
|
|
||||||
std::vector<ControllerEmu*>::const_iterator
|
for (ControllerEmu* ai : ext->attachments)
|
||||||
ai = ((Extension*)this)->attachments.begin(),
|
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
||||||
ae = ((Extension*)this)->attachments.end();
|
|
||||||
for (; ai!=ae; ++ai)
|
|
||||||
(*ai)->SaveConfig(sec, base + (*ai)->GetName() + "/");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +160,8 @@ void ControllerEmu::SaveConfig(IniFile::Section *sec, const std::string& base)
|
|||||||
if (base.empty())
|
if (base.empty())
|
||||||
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
|
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
|
||||||
|
|
||||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
for (ControlGroup* cg : groups)
|
||||||
e = groups.end();
|
cg->SaveConfig(sec, defdev, base);
|
||||||
for (; i!=e; ++i)
|
|
||||||
(*i)->SaveConfig(sec, defdev, base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::AnalogStick::AnalogStick(const char* const _name) : ControlGroup(_name, GROUP_TYPE_STICK)
|
ControllerEmu::AnalogStick::AnalogStick(const char* const _name) : ControlGroup(_name, GROUP_TYPE_STICK)
|
||||||
|
@ -194,14 +194,12 @@ public:
|
|||||||
template <typename C>
|
template <typename C>
|
||||||
void GetState(C* const buttons, const C* bitmasks)
|
void GetState(C* const buttons, const C* bitmasks)
|
||||||
{
|
{
|
||||||
std::vector<Control*>::iterator
|
for (Control* control : controls)
|
||||||
i = controls.begin(),
|
|
||||||
e = controls.end();
|
|
||||||
|
|
||||||
for (; i!=e; ++i, ++bitmasks)
|
|
||||||
{
|
{
|
||||||
if ((*i)->control_ref->State() > settings[0]->value) // threshold
|
if (control->control_ref->State() > settings[0]->value) // threshold
|
||||||
*buttons |= *bitmasks;
|
*buttons |= *bitmasks;
|
||||||
|
|
||||||
|
bitmasks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +289,7 @@ public:
|
|||||||
ax = tmpf;
|
ax = tmpf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_swing[3];
|
float m_swing[3];
|
||||||
};
|
};
|
||||||
@ -370,6 +369,7 @@ public:
|
|||||||
*y = C(m_tilt[1] * angle * range + base);
|
*y = C(m_tilt[1] * angle * range + base);
|
||||||
*x = C(m_tilt[0] * angle * range + base);
|
*x = C(m_tilt[0] * angle * range + base);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_tilt[2];
|
float m_tilt[2];
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@ ControllerInterface g_controller_interface;
|
|||||||
//
|
//
|
||||||
// Init
|
// Init
|
||||||
//
|
//
|
||||||
// detect devices and inputs outputs / will make refresh function later
|
// Detect devices and inputs outputs / will make refresh function later
|
||||||
//
|
//
|
||||||
void ControllerInterface::Initialize()
|
void ControllerInterface::Initialize()
|
||||||
{
|
{
|
||||||
@ -81,29 +81,24 @@ if (GLWin.platform == EGL_PLATFORM_X11) {
|
|||||||
//
|
//
|
||||||
// DeInit
|
// DeInit
|
||||||
//
|
//
|
||||||
// remove all devices/ call library cleanup functions
|
// Remove all devices/ call library cleanup functions
|
||||||
//
|
//
|
||||||
void ControllerInterface::Shutdown()
|
void ControllerInterface::Shutdown()
|
||||||
{
|
{
|
||||||
if (false == m_is_init)
|
if (!m_is_init)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<Device*>::const_iterator
|
for (Device* d : m_devices)
|
||||||
d = m_devices.begin(),
|
|
||||||
de = m_devices.end();
|
|
||||||
for ( ;d != de; ++d )
|
|
||||||
{
|
{
|
||||||
std::vector<Device::Output*>::const_iterator
|
// Set outputs to ZERO before destroying device
|
||||||
o = (*d)->Outputs().begin(),
|
for (Device::Output* o : d->Outputs())
|
||||||
oe = (*d)->Outputs().end();
|
o->SetState(0);
|
||||||
// set outputs to ZERO before destroying device
|
|
||||||
for ( ;o!=oe; ++o)
|
|
||||||
(*o)->SetState(0);
|
|
||||||
// update output
|
|
||||||
(*d)->UpdateOutput();
|
|
||||||
|
|
||||||
//delete device
|
// Update output
|
||||||
delete *d;
|
d->UpdateOutput();
|
||||||
|
|
||||||
|
// Delete device
|
||||||
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_devices.clear();
|
m_devices.clear();
|
||||||
@ -134,7 +129,7 @@ void ControllerInterface::Shutdown()
|
|||||||
//
|
//
|
||||||
// SetHwnd
|
// SetHwnd
|
||||||
//
|
//
|
||||||
// sets the hwnd used for some crap when initializing, use before calling Init
|
// Sets the hwnd used for some crap when initializing, use before calling Init
|
||||||
//
|
//
|
||||||
void ControllerInterface::SetHwnd( void* const hwnd )
|
void ControllerInterface::SetHwnd( void* const hwnd )
|
||||||
{
|
{
|
||||||
@ -144,7 +139,7 @@ void ControllerInterface::SetHwnd( void* const hwnd )
|
|||||||
//
|
//
|
||||||
// UpdateInput
|
// UpdateInput
|
||||||
//
|
//
|
||||||
// update input for all devices, return true if all devices returned successful
|
// Update input for all devices, return true if all devices returned successful
|
||||||
//
|
//
|
||||||
bool ControllerInterface::UpdateInput(const bool force)
|
bool ControllerInterface::UpdateInput(const bool force)
|
||||||
{
|
{
|
||||||
@ -157,12 +152,9 @@ bool ControllerInterface::UpdateInput(const bool force)
|
|||||||
|
|
||||||
size_t ok_count = 0;
|
size_t ok_count = 0;
|
||||||
|
|
||||||
std::vector<Device*>::const_iterator
|
for (Device* d : m_devices)
|
||||||
d = m_devices.begin(),
|
|
||||||
e = m_devices.end();
|
|
||||||
for ( ;d != e; ++d )
|
|
||||||
{
|
{
|
||||||
if ((*d)->UpdateInput())
|
if (d->UpdateInput())
|
||||||
++ok_count;
|
++ok_count;
|
||||||
//else
|
//else
|
||||||
// disabled. it might be causing problems
|
// disabled. it might be causing problems
|
||||||
@ -175,7 +167,7 @@ bool ControllerInterface::UpdateInput(const bool force)
|
|||||||
//
|
//
|
||||||
// UpdateOutput
|
// UpdateOutput
|
||||||
//
|
//
|
||||||
// update output for all devices, return true if all devices returned successful
|
// Update output for all devices, return true if all devices returned successful
|
||||||
//
|
//
|
||||||
bool ControllerInterface::UpdateOutput(const bool force)
|
bool ControllerInterface::UpdateOutput(const bool force)
|
||||||
{
|
{
|
||||||
@ -188,9 +180,9 @@ bool ControllerInterface::UpdateOutput(const bool force)
|
|||||||
|
|
||||||
size_t ok_count = 0;
|
size_t ok_count = 0;
|
||||||
|
|
||||||
for (auto d = m_devices.cbegin(); d != m_devices.cend(); ++d)
|
for (Device* d : m_devices)
|
||||||
{
|
{
|
||||||
if ((*d)->UpdateOutput())
|
if (d->UpdateOutput())
|
||||||
++ok_count;
|
++ok_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +192,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
|
|||||||
//
|
//
|
||||||
// InputReference :: State
|
// InputReference :: State
|
||||||
//
|
//
|
||||||
// get the state of an input reference
|
// Gets the state of an input reference
|
||||||
// override function for ControlReference::State ...
|
// override function for ControlReference::State ...
|
||||||
//
|
//
|
||||||
ControlState ControllerInterface::InputReference::State( const ControlState ignore )
|
ControlState ControllerInterface::InputReference::State( const ControlState ignore )
|
||||||
@ -214,9 +206,9 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno
|
|||||||
//
|
//
|
||||||
// OutputReference :: State
|
// OutputReference :: State
|
||||||
//
|
//
|
||||||
// set the state of all binded outputs
|
// Set the state of all binded outputs
|
||||||
// overrides ControlReference::State .. combined them so i could make the gui simple / inputs == same as outputs one list
|
// overrides ControlReference::State .. combined them so I could make the GUI simple / inputs == same as outputs one list
|
||||||
// i was lazy and it works so watever
|
// I was lazy and it works so watever
|
||||||
//
|
//
|
||||||
ControlState ControllerInterface::OutputReference::State(const ControlState state)
|
ControlState ControllerInterface::OutputReference::State(const ControlState state)
|
||||||
{
|
{
|
||||||
@ -228,7 +220,7 @@ ControlState ControllerInterface::OutputReference::State(const ControlState stat
|
|||||||
//
|
//
|
||||||
// UpdateReference
|
// UpdateReference
|
||||||
//
|
//
|
||||||
// updates a controlreference's binded devices/controls
|
// Updates a controlreference's binded devices/controls
|
||||||
// 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
|
||||||
@ -244,7 +236,7 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
|
|||||||
//
|
//
|
||||||
// InputReference :: Detect
|
// InputReference :: Detect
|
||||||
//
|
//
|
||||||
// wait for input on all binded devices
|
// Wait for input on all binded devices
|
||||||
// supports not detecting inputs that were held down at the time of Detect start,
|
// supports not detecting inputs that were held down at the time of Detect start,
|
||||||
// which is useful for those crazy flightsticks that have certain buttons that are always held down
|
// which is useful for those crazy flightsticks that have certain buttons that are always held down
|
||||||
// or some crazy axes or something
|
// or some crazy axes or something
|
||||||
|
@ -37,8 +37,8 @@ using namespace ciface::Core;
|
|||||||
//
|
//
|
||||||
// ControllerInterface
|
// ControllerInterface
|
||||||
//
|
//
|
||||||
// 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 : public DeviceContainer
|
class ControllerInterface : public DeviceContainer
|
||||||
{
|
{
|
||||||
@ -47,9 +47,9 @@ public:
|
|||||||
//
|
//
|
||||||
// ControlReference
|
// ControlReference
|
||||||
//
|
//
|
||||||
// these are what you create to actually use the inputs, InputReference or OutputReference
|
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
||||||
//
|
//
|
||||||
// after being bound to devices and controls with ControllerInterface::UpdateReference,
|
// After being bound to devices and controls with ControllerInterface::UpdateReference,
|
||||||
// each one can link to multiple devices and controls
|
// each one can link to multiple devices and controls
|
||||||
// when you change a ControlReference's expression,
|
// when you change a ControlReference's expression,
|
||||||
// you must use ControllerInterface::UpdateReference on it to rebind controls
|
// you must use ControllerInterface::UpdateReference on it to rebind controls
|
||||||
@ -66,11 +66,13 @@ public:
|
|||||||
const bool is_input;
|
const bool is_input;
|
||||||
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
||||||
|
|
||||||
virtual ~ControlReference() {
|
virtual ~ControlReference()
|
||||||
|
{
|
||||||
delete parsed_expression;
|
delete parsed_expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoundCount() {
|
int BoundCount()
|
||||||
|
{
|
||||||
if (parsed_expression)
|
if (parsed_expression)
|
||||||
return parsed_expression->num_controls;
|
return parsed_expression->num_controls;
|
||||||
else
|
else
|
||||||
@ -85,7 +87,7 @@ public:
|
|||||||
//
|
//
|
||||||
// InputReference
|
// InputReference
|
||||||
//
|
//
|
||||||
// control reference for inputs
|
// Control reference for inputs
|
||||||
//
|
//
|
||||||
class InputReference : public ControlReference
|
class InputReference : public ControlReference
|
||||||
{
|
{
|
||||||
@ -98,7 +100,7 @@ public:
|
|||||||
//
|
//
|
||||||
// OutputReference
|
// OutputReference
|
||||||
//
|
//
|
||||||
// control reference for outputs
|
// Control reference for outputs
|
||||||
//
|
//
|
||||||
class OutputReference : public ControlReference
|
class OutputReference : public ControlReference
|
||||||
{
|
{
|
||||||
|
@ -156,17 +156,14 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
|||||||
std::vector<DWORD> xinput_guids;
|
std::vector<DWORD> xinput_guids;
|
||||||
GetXInputGUIDS( xinput_guids );
|
GetXInputGUIDS( xinput_guids );
|
||||||
|
|
||||||
std::list<DIDEVICEINSTANCE>::iterator
|
for (DIDEVICEINSTANCE& joystick : joysticks)
|
||||||
i = joysticks.begin(),
|
|
||||||
e = joysticks.end();
|
|
||||||
for ( ; i!=e; ++i )
|
|
||||||
{
|
{
|
||||||
// skip XInput Devices
|
// skip XInput Devices
|
||||||
if ( std::find( xinput_guids.begin(), xinput_guids.end(), i->guidProduct.Data1 ) != xinput_guids.end() )
|
if (std::find(xinput_guids.begin(), xinput_guids.end(), joystick.guidProduct.Data1) != xinput_guids.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LPDIRECTINPUTDEVICE8 js_device;
|
LPDIRECTINPUTDEVICE8 js_device;
|
||||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &js_device, NULL)))
|
if (SUCCEEDED(idi8->CreateDevice(joystick.guidInstance, &js_device, NULL)))
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
|
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
|
||||||
{
|
{
|
||||||
@ -182,7 +179,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName]++);
|
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[joystick.tszInstanceName]++);
|
||||||
// only add if it has some inputs/outputs
|
// only add if it has some inputs/outputs
|
||||||
if (js->Inputs().size() || js->Outputs().size())
|
if (js->Inputs().size() || js->Outputs().size())
|
||||||
devices.push_back(js);
|
devices.push_back(js);
|
||||||
@ -359,14 +356,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
|
|||||||
Joystick::~Joystick()
|
Joystick::~Joystick()
|
||||||
{
|
{
|
||||||
// release the ff effect iface's
|
// release the ff effect iface's
|
||||||
std::list<EffectState>::iterator
|
for (EffectState& state : m_state_out)
|
||||||
i = m_state_out.begin(),
|
|
||||||
e = m_state_out.end();
|
|
||||||
for (; i!=e; ++i)
|
|
||||||
{
|
{
|
||||||
i->iface->Stop();
|
state.iface->Stop();
|
||||||
i->iface->Unload();
|
state.iface->Unload();
|
||||||
i->iface->Release();
|
state.iface->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_device->Unacquire();
|
m_device->Unacquire();
|
||||||
@ -449,26 +443,23 @@ bool Joystick::UpdateOutput()
|
|||||||
eff.dwSize = sizeof(DIEFFECT);
|
eff.dwSize = sizeof(DIEFFECT);
|
||||||
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||||
|
|
||||||
std::list<EffectState>::iterator
|
for (EffectState& state : m_state_out)
|
||||||
i = m_state_out.begin(),
|
|
||||||
e = m_state_out.end();
|
|
||||||
for (; i!=e; ++i)
|
|
||||||
{
|
{
|
||||||
if (i->params)
|
if (state.params)
|
||||||
{
|
{
|
||||||
if (i->size)
|
if (state.size)
|
||||||
{
|
{
|
||||||
eff.cbTypeSpecificParams = i->size;
|
eff.cbTypeSpecificParams = state.size;
|
||||||
eff.lpvTypeSpecificParams = i->params;
|
eff.lpvTypeSpecificParams = state.params;
|
||||||
// set params and start effect
|
// set params and start effect
|
||||||
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
ok_count += SUCCEEDED(state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ok_count += SUCCEEDED(i->iface->Stop());
|
ok_count += SUCCEEDED(state.iface->Stop());
|
||||||
}
|
}
|
||||||
|
|
||||||
i->params = NULL;
|
state.params = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -540,6 +531,7 @@ ControlState Joystick::Hat::GetState() const
|
|||||||
// hat centered code from MSDN
|
// hat centered code from MSDN
|
||||||
if (0xFFFF == LOWORD(m_hat))
|
if (0xFFFF == LOWORD(m_hat))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
|
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,24 +15,14 @@ namespace Core
|
|||||||
// Destructor, delete all inputs/outputs on device destruction
|
// Destructor, delete all inputs/outputs on device destruction
|
||||||
//
|
//
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
|
||||||
{
|
{
|
||||||
// delete inputs
|
// delete inputs
|
||||||
std::vector<Device::Input*>::iterator
|
for (Device::Input* input : m_inputs)
|
||||||
i = m_inputs.begin(),
|
delete input;
|
||||||
e = m_inputs.end();
|
|
||||||
for ( ;i!=e; ++i)
|
|
||||||
delete *i;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// delete outputs
|
// delete outputs
|
||||||
std::vector<Device::Output*>::iterator
|
for (Device::Output* output: m_outputs)
|
||||||
o = m_outputs.begin(),
|
delete output;
|
||||||
e = m_outputs.end();
|
|
||||||
for ( ;o!=e; ++o)
|
|
||||||
delete *o;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::AddInput(Device::Input* const i)
|
void Device::AddInput(Device::Input* const i)
|
||||||
@ -47,24 +37,22 @@ void Device::AddOutput(Device::Output* const o)
|
|||||||
|
|
||||||
Device::Input* Device::FindInput(const std::string &name) const
|
Device::Input* Device::FindInput(const std::string &name) const
|
||||||
{
|
{
|
||||||
std::vector<Input*>::const_iterator
|
for (Input* input : m_inputs)
|
||||||
it = m_inputs.begin(),
|
{
|
||||||
itend = m_inputs.end();
|
if (input->GetName() == name)
|
||||||
for (; it != itend; ++it)
|
return input;
|
||||||
if ((*it)->GetName() == name)
|
}
|
||||||
return *it;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Output* Device::FindOutput(const std::string &name) const
|
Device::Output* Device::FindOutput(const std::string &name) const
|
||||||
{
|
{
|
||||||
std::vector<Output*>::const_iterator
|
for (Output* output : m_outputs)
|
||||||
it = m_outputs.begin(),
|
{
|
||||||
itend = m_outputs.end();
|
if (output->GetName() == name)
|
||||||
for (; it != itend; ++it)
|
return output;
|
||||||
if ((*it)->GetName() == name)
|
}
|
||||||
return *it;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -86,24 +74,26 @@ void Device::ClearInputState()
|
|||||||
//
|
//
|
||||||
// DeviceQualifier :: ToString
|
// DeviceQualifier :: ToString
|
||||||
//
|
//
|
||||||
// get string from a device qualifier / serialize
|
// Get string from a device qualifier / serialize
|
||||||
//
|
//
|
||||||
std::string DeviceQualifier::ToString() const
|
std::string DeviceQualifier::ToString() const
|
||||||
{
|
{
|
||||||
if (source.empty() && (cid < 0) && name.empty())
|
if (source.empty() && (cid < 0) && name.empty())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << source << '/';
|
ss << source << '/';
|
||||||
if (cid > -1)
|
if (cid > -1)
|
||||||
ss << cid;
|
ss << cid;
|
||||||
ss << '/' << name;
|
ss << '/' << name;
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// DeviceQualifier :: FromString
|
// DeviceQualifier :: FromString
|
||||||
//
|
//
|
||||||
// set a device qualifier from a string / unserialize
|
// Set a device qualifier from a string / unserialize
|
||||||
//
|
//
|
||||||
void DeviceQualifier::FromString(const std::string& str)
|
void DeviceQualifier::FromString(const std::string& str)
|
||||||
{
|
{
|
||||||
@ -121,7 +111,7 @@ void DeviceQualifier::FromString(const std::string& str)
|
|||||||
//
|
//
|
||||||
// DeviceQualifier :: FromDevice
|
// DeviceQualifier :: FromDevice
|
||||||
//
|
//
|
||||||
// set a device qualifier from a device
|
// Set a device qualifier from a device
|
||||||
//
|
//
|
||||||
void DeviceQualifier::FromDevice(const Device* const dev)
|
void DeviceQualifier::FromDevice(const Device* const dev)
|
||||||
{
|
{
|
||||||
@ -136,6 +126,7 @@ bool DeviceQualifier::operator==(const Device* const dev) const
|
|||||||
if (dev->GetName() == name)
|
if (dev->GetName() == name)
|
||||||
if (dev->GetSource() == source)
|
if (dev->GetSource() == source)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +142,11 @@ bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
|
|||||||
|
|
||||||
Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
||||||
{
|
{
|
||||||
std::vector<Device*>::const_iterator
|
for (Device* d : m_devices)
|
||||||
di = m_devices.begin(),
|
{
|
||||||
de = m_devices.end();
|
if (devq == d)
|
||||||
for (; di!=de; ++di)
|
return d;
|
||||||
if (devq == *di)
|
}
|
||||||
return *di;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -170,12 +160,9 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device*
|
|||||||
return inp;
|
return inp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Device*>::const_iterator
|
for (Device* d : m_devices)
|
||||||
di = m_devices.begin(),
|
|
||||||
de = m_devices.end();
|
|
||||||
for (; di != de; ++di)
|
|
||||||
{
|
{
|
||||||
Device::Input* const i = (*di)->FindInput(name);
|
Device::Input* const i = d->FindInput(name);
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
return i;
|
return i;
|
||||||
|
@ -21,7 +21,7 @@ class DeviceQualifier;
|
|||||||
//
|
//
|
||||||
// Device
|
// Device
|
||||||
//
|
//
|
||||||
// a device class
|
// A device class
|
||||||
//
|
//
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ public:
|
|||||||
//
|
//
|
||||||
// Control
|
// Control
|
||||||
//
|
//
|
||||||
// control includes inputs and outputs
|
// Control includes inputs and outputs
|
||||||
//
|
//
|
||||||
class Control // input or output
|
class Control // input or output
|
||||||
{
|
{
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
//
|
//
|
||||||
// Input
|
// Input
|
||||||
//
|
//
|
||||||
// an input on a device
|
// An input on a device
|
||||||
//
|
//
|
||||||
class Input : public Control
|
class Input : public Control
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ public:
|
|||||||
//
|
//
|
||||||
// Output
|
// Output
|
||||||
//
|
//
|
||||||
// an output on a device
|
// An output on a device
|
||||||
//
|
//
|
||||||
class Output : public Control
|
class Output : public Control
|
||||||
{
|
{
|
||||||
@ -133,8 +133,8 @@ private:
|
|||||||
//
|
//
|
||||||
// DeviceQualifier
|
// DeviceQualifier
|
||||||
//
|
//
|
||||||
// device qualifier used to match devices
|
// Device qualifier used to match devices.
|
||||||
// currently has ( source, id, name ) properties which match a device
|
// Currently has ( source, id, name ) properties which match a device
|
||||||
//
|
//
|
||||||
class DeviceQualifier
|
class DeviceQualifier
|
||||||
{
|
{
|
||||||
|
@ -10,10 +10,8 @@
|
|||||||
InputPlugin::~InputPlugin()
|
InputPlugin::~InputPlugin()
|
||||||
{
|
{
|
||||||
// delete pads
|
// delete pads
|
||||||
std::vector<ControllerEmu*>::const_iterator i = controllers.begin(),
|
for (ControllerEmu* pad : controllers)
|
||||||
e = controllers.end();
|
delete pad;
|
||||||
for ( ; i != e; ++i )
|
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputPlugin::LoadConfig(bool isGC)
|
bool InputPlugin::LoadConfig(bool isGC)
|
||||||
@ -58,25 +56,26 @@ bool InputPlugin::LoadConfig(bool isGC)
|
|||||||
|
|
||||||
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini"))
|
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini"))
|
||||||
{
|
{
|
||||||
std::vector< ControllerEmu* >::const_iterator
|
int n = 0;
|
||||||
i = controllers.begin(),
|
for (ControllerEmu* pad : controllers)
|
||||||
e = controllers.end();
|
|
||||||
for (int n = 0; i!=e; ++i, ++n)
|
|
||||||
{
|
{
|
||||||
// load settings from ini
|
// Load settings from ini
|
||||||
if (useProfile[n])
|
if (useProfile[n])
|
||||||
{
|
{
|
||||||
IniFile profile_ini;
|
IniFile profile_ini;
|
||||||
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini");
|
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini");
|
||||||
(*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
pad->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
|
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// update refs
|
// Update refs
|
||||||
(*i)->UpdateReferences(g_controller_interface);
|
pad->UpdateReferences(g_controller_interface);
|
||||||
|
|
||||||
|
// Next profile
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -95,10 +94,8 @@ void InputPlugin::SaveConfig()
|
|||||||
IniFile inifile;
|
IniFile inifile;
|
||||||
inifile.Load(ini_filename);
|
inifile.Load(ini_filename);
|
||||||
|
|
||||||
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
for (ControllerEmu* pad : controllers)
|
||||||
e = controllers.end();
|
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
|
||||||
for ( ; i!=e; ++i )
|
|
||||||
(*i)->SaveConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
|
|
||||||
|
|
||||||
inifile.Save(ini_filename);
|
inifile.Save(ini_filename);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user