summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2014-02-09 15:04:51 +0900
committerJules Blok <jules.blok@gmail.com>2014-02-09 17:01:45 +0900
commit992b91c082365c7f8faaee4d717556a947dbcca8 (patch)
tree869d49e41e57b839914aa0d1accc3e47d182e77d /Source/Core/InputCommon/ControllerInterface
parentc6d650c0588cd054ed9a5028d56624bc293d6db3 (diff)
ForceFeedback: Don't depend on the force_type_name index.
Instead use a for-each loop, compare GUIDs and save the name pointers.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp32
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h4
2 files changed, 18 insertions, 18 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp
index a2adbd5e6b..744df7fc4a 100644
--- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.cpp
@@ -14,11 +14,13 @@ template class ForceFeedbackDevice::Force<DICONSTANTFORCE>;
template class ForceFeedbackDevice::Force<DIRAMPFORCE>;
template class ForceFeedbackDevice::Force<DIPERIODIC>;
-static const struct
+typedef struct
{
GUID guid;
const char* name;
-} force_type_names[] =
+} ForceType;
+
+static const ForceType force_type_names[] =
{
{GUID_ConstantForce, "Constant"}, // DICONSTANTFORCE
{GUID_RampForce, "Ramp"}, // DIRAMPFORCE
@@ -79,17 +81,16 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i
//ZeroMemory(&env, sizeof(env));
//env.dwSize = sizeof(env);
- for (unsigned int f = 0; f < sizeof(force_type_names)/sizeof(*force_type_names); ++f)
+ for (const ForceType& f : force_type_names)
{
- // ugly if ladder
- if (0 == f)
+ if (f.guid == GUID_ConstantForce)
{
DICONSTANTFORCE diCF = {-10000};
diCF.lMagnitude = DI_FFNOMINALMAX;
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &diCF;
}
- else if (1 == f)
+ else if (f.guid == GUID_RampForce)
{
eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
}
@@ -99,17 +100,16 @@ bool ForceFeedbackDevice::InitForceFeedback(const LPDIRECTINPUTDEVICE8 device, i
}
LPDIRECTINPUTEFFECT pEffect;
- if (SUCCEEDED(device->CreateEffect(force_type_names[f].guid, &eff, &pEffect, NULL)))
+ if (SUCCEEDED(device->CreateEffect(f.guid, &eff, &pEffect, NULL)))
{
m_state_out.push_back(EffectState(pEffect));
- // ugly if ladder again :/
- if (0 == f)
- AddOutput(new ForceConstant(f, m_state_out.back()));
- else if (1 == f)
- AddOutput(new ForceRamp(f, m_state_out.back()));
+ if (f.guid == GUID_ConstantForce)
+ AddOutput(new ForceConstant(f.name, m_state_out.back()));
+ else if (f.guid == GUID_RampForce)
+ AddOutput(new ForceRamp(f.name, m_state_out.back()));
else
- AddOutput(new ForcePeriodic(f, m_state_out.back()));
+ AddOutput(new ForcePeriodic(f.name, m_state_out.back()));
}
}
@@ -214,8 +214,8 @@ void ForceFeedbackDevice::ForcePeriodic::SetState(const ControlState state)
}
template <typename P>
-ForceFeedbackDevice::Force<P>::Force(u8 index, EffectState& state)
-: m_index(index), m_state(state)
+ForceFeedbackDevice::Force<P>::Force(const char* name, EffectState& state)
+: m_name(name), m_state(state)
{
memset(&params, 0, sizeof(params));
}
@@ -223,7 +223,7 @@ ForceFeedbackDevice::Force<P>::Force(u8 index, EffectState& state)
template <typename P>
std::string ForceFeedbackDevice::Force<P>::GetName() const
{
- return force_type_names[m_index].name;
+ return m_name;
}
}
diff --git a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h
index e857790ea0..3035273fa8 100644
--- a/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h
+++ b/Source/Core/InputCommon/ControllerInterface/ForceFeedback/ForceFeedbackDevice.h
@@ -42,10 +42,10 @@ private:
{
public:
std::string GetName() const;
- Force(u8 index, EffectState& state);
+ Force(const char* name, EffectState& state);
void SetState(ControlState state);
private:
- const u8 m_index;
+ const char* m_name;
EffectState& m_state;
P params;
};