Merge branch 'full-analog-surface'

Fixes issue 5010.
This commit is contained in:
Jordan Woyak 2013-01-17 15:48:50 -06:00
commit a01bd96d7d
5 changed files with 39 additions and 9 deletions

View File

@ -461,7 +461,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
i = device->Inputs().begin(), i = device->Inputs().begin(),
e = device->Inputs().end(); e = device->Inputs().end();
for (std::vector<bool>::iterator state = states.begin(); i != e; ++i) for (std::vector<bool>::iterator state = states.begin(); i != e; ++i)
*state++ = ((*i)->GetState() > INPUT_DETECT_THRESHOLD); *state++ = ((*i)->GetState() > (1 - INPUT_DETECT_THRESHOLD));
while (time < ms) while (time < ms)
{ {
@ -477,7 +477,7 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
if (false == *state) if (false == *state)
return *i; return *i;
} }
else else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD))
*state = false; *state = false;
} }
Common::SleepCurrentThread(10); time += 10; Common::SleepCurrentThread(10); time += 10;

View File

@ -123,6 +123,36 @@ public:
void AddInput(Input* const i); void AddInput(Input* const i);
void AddOutput(Output* const o); 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: private:
std::vector<Input*> m_inputs; std::vector<Input*> m_inputs;
std::vector<Output*> m_outputs; std::vector<Output*> m_outputs;

View File

@ -267,8 +267,8 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
const LONG& ax = (&m_state_in.lX)[offset]; const LONG& ax = (&m_state_in.lX)[offset];
// each axis gets a negative and a positive input instance associated with it // each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(offset, ax, base, range.lMin-base)); AddAnalogInputs(new Axis(offset, ax, base, range.lMin-base),
AddInput(new Axis(offset, ax, base, range.lMax-base)); new Axis(offset, ax, base, range.lMax-base));
} }
} }

View File

@ -64,8 +64,8 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
AddInput(new Hat(e, m_device, Hat::down)); AddInput(new Hat(e, m_device, Hat::down));
AddInput(new Hat(e, m_device, Hat::left)); AddInput(new Hat(e, m_device, Hat::left));
} else { } else {
AddInput(new Axis(e, m_device, Axis::negative)); AddAnalogInputs(new Axis(e, m_device, Axis::negative),
AddInput(new Axis(e, m_device, Axis::positive)); new Axis(e, m_device, Axis::positive));
} }
} }
CFRelease(axes); CFRelease(axes);

View File

@ -86,8 +86,8 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i) for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i)
{ {
// each axis gets a negative and a positive input instance associated with it // each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, m_joystick, -32768)); AddAnalogInputs(new Axis(i, m_joystick, -32768),
AddInput(new Axis(i, m_joystick, 32767)); new Axis(i, m_joystick, 32767));
} }
#ifdef USE_SDL_HAPTIC #ifdef USE_SDL_HAPTIC