From 8fedc3db383b8a39f756f4d1f037e0e45662d41a Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 14 Mar 2011 01:20:11 +0000 Subject: Clean up "ControllerInterface" a bit. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7339 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../ControllerInterface/DInput/DInputJoystick.cpp | 73 +++++++++------------ .../ControllerInterface/DInput/DInputJoystick.h | 72 ++++++--------------- .../DInput/DInputKeyboardMouse.cpp | 58 +++++++++-------- .../DInput/DInputKeyboardMouse.h | 75 +++++++--------------- 4 files changed, 106 insertions(+), 172 deletions(-) (limited to 'Source/Core/InputCommon/Src/ControllerInterface/DInput') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index 40823d617d..0867017ac1 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -233,15 +233,15 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI //m_must_poll = (js_caps.dwFlags & DIDC_POLLEDDATAFORMAT) != 0; // buttons - for ( unsigned int i = 0; i < js_caps.dwButtons; ++i ) - AddInput( new Button( i ) ); + for (u8 i = 0; i != js_caps.dwButtons; ++i) + AddInput(new Button(i, m_state_in.rgbButtons[m_index])); // hats - for ( unsigned int i = 0; i < js_caps.dwPOVs; ++i ) + for (u8 i = 0; i != js_caps.dwPOVs; ++i) { // each hat gets 4 input instances associated with it, (up down left right) - for ( unsigned int d = 0; d<4; ++d ) - AddInput( new Hat( i, d ) ); + for (u8 d = 0; d != 4; ++d) + AddInput(new Hat(i, m_state_in.rgdwPOV[m_index], d)); } // get up to 6 axes and 2 sliders @@ -264,9 +264,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI if (SUCCEEDED(m_device->GetProperty(DIPROP_RANGE, &range.diph))) { const LONG base = (range.lMin + range.lMax) / 2; + const LONG& ax = (&m_state_in.lX)[m_index]; + // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(offset, base, range.lMin-base)); - AddInput(new Axis(offset, base, range.lMax-base)); + AddInput(new Axis(offset, ax, base, range.lMin-base)); + AddInput(new Axis(offset, ax, base, range.lMax-base)); } } @@ -319,11 +321,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI { // ugly if ladder again :/ if (0 == f) - AddOutput(new ForceConstant(i, f)); + AddOutput(new ForceConstant(f, m_state_out[i])); else if (1 == f) - AddOutput(new ForceRamp(i, f)); + AddOutput(new ForceRamp(f, m_state_out[i])); else - AddOutput(new ForcePeriodic(i, f)); + AddOutput(new ForcePeriodic(f, m_state_out[i])); ++i; m_state_out.push_back(EffectState(pEffect)); @@ -501,44 +503,31 @@ std::string Joystick::Hat::GetName() const template std::string Joystick::Force

::GetName() const { - return force_type_names[m_type].name; -} - -// get / set state - -ControlState Joystick::GetInputState( const ControllerInterface::Device::Input* const input ) const -{ - return ((Input*)input)->GetState( &m_state_in ); -} - -void Joystick::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ) -{ - ((Output*)output)->SetState( state, &m_state_out[0] ); + return force_type_names[m_index].name; } // get / set state -ControlState Joystick::Axis::GetState( const DIJOYSTATE* const joystate ) const +ControlState Joystick::Axis::GetState() const { - return std::max( 0.0f, ControlState((&joystate->lX)[m_index]-m_base) / m_range ); + return std::max(0.0f, ControlState(m_axis - m_base) / m_range); } -ControlState Joystick::Button::GetState( const DIJOYSTATE* const joystate ) const +ControlState Joystick::Button::GetState() const { - return ControlState( joystate->rgbButtons[m_index] > 0 ); + return ControlState(m_button > 0); } -ControlState Joystick::Hat::GetState( const DIJOYSTATE* const joystate ) const +ControlState Joystick::Hat::GetState() const { // can this func be simplified ? - const DWORD val = joystate->rgdwPOV[m_index]; // hat centered code from msdn - if ( 0xFFFF == LOWORD(val) ) + if (0xFFFF == LOWORD(m_hat)) return 0; - return ( abs( (int)(val/4500-m_direction*2+8)%8 - 4) > 2 ); + return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2); } -void Joystick::ForceConstant::SetState(const ControlState state, Joystick::EffectState* const joystate) +void Joystick::ForceConstant::SetState(const ControlState state) { const LONG new_val = LONG(10000 * state); @@ -546,28 +535,28 @@ void Joystick::ForceConstant::SetState(const ControlState state, Joystick::Effec if (val != new_val) { val = new_val; - joystate[m_index].params = ¶ms; // tells UpdateOutput the state has changed + m_state.params = ¶ms; // tells UpdateOutput the state has changed // tells UpdateOutput to either start or stop the force - joystate[m_index].size = new_val ? sizeof(params) : 0; + m_state.size = new_val ? sizeof(params) : 0; } } -void Joystick::ForceRamp::SetState(const ControlState state, Joystick::EffectState* const joystate) +void Joystick::ForceRamp::SetState(const ControlState state) { const LONG new_val = LONG(10000 * state); if (params.lStart != new_val) { params.lStart = params.lEnd = new_val; - joystate[m_index].params = ¶ms; // tells UpdateOutput the state has changed + m_state.params = ¶ms; // tells UpdateOutput the state has changed // tells UpdateOutput to either start or stop the force - joystate[m_index].size = new_val ? sizeof(params) : 0; + m_state.size = new_val ? sizeof(params) : 0; } } -void Joystick::ForcePeriodic::SetState(const ControlState state, Joystick::EffectState* const joystate) +void Joystick::ForcePeriodic::SetState(const ControlState state) { const LONG new_val = LONG(10000 * state); @@ -577,16 +566,16 @@ void Joystick::ForcePeriodic::SetState(const ControlState state, Joystick::Effec val = new_val; //params.dwPeriod = 0;//DWORD(0.05 * DI_SECONDS); // zero is working fine for me - joystate[m_index].params = ¶ms; // tells UpdateOutput the state has changed + m_state.params = ¶ms; // tells UpdateOutput the state has changed // tells UpdateOutput to either start or stop the force - joystate[m_index].size = new_val ? sizeof(params) : 0; + m_state.size = new_val ? sizeof(params) : 0; } } template -Joystick::Force

::Force(const unsigned int index, const unsigned int type) - : m_index(index), m_type(type) +Joystick::Force

::Force(u8 index, EffectState& state) + : m_index(index), m_state(state) { ZeroMemory(¶ms, sizeof(params)); } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h index a1bdcde0e8..76fa8d2617 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.h @@ -25,11 +25,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector class Force : public Output { - friend class Joystick; public: std::string GetName() const; - protected: - Force(const unsigned int index, const unsigned int type); - void SetState(const ControlState state, EffectState* const joystate); + Force(u8 index, EffectState& state); + void SetState(ControlState state); private: - const unsigned int m_index; - const unsigned int m_type; - P params; + EffectState& m_state; + P params; + const u8 m_index; }; typedef Force ForceConstant; typedef Force ForceRamp; typedef Force ForcePeriodic; +public: bool UpdateInput(); bool UpdateOutput(); - ControlState GetInputState( const ControllerInterface::Device::Input* const input ) const; - void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state ); - void ClearInputState(); -public: - Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVICE8 device, const unsigned int index ); + Joystick(const LPDIRECTINPUTDEVICE8 device, const unsigned int index); ~Joystick(); std::string GetName() const; @@ -130,7 +101,6 @@ public: private: const LPDIRECTINPUTDEVICE8 m_device; const unsigned int m_index; - //const std::string m_name; DIJOYSTATE m_state_in; std::vector m_state_out; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 69ffcf6e75..aea12c065c 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -101,10 +101,10 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC // KEYBOARD // add keys - for (unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i) - AddInput(new Key(i)); + for (u8 i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i) + AddInput(new Key(i, m_state_in.keyboard[named_keys[i].code])); // add lights - for (unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i) + for (u8 i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i) AddOutput(new Light(i)); // MOUSE @@ -114,18 +114,20 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC mouse_caps.dwSize = sizeof(mouse_caps); m_mo_device->GetCapabilities(&mouse_caps); // mouse buttons - for (unsigned int i = 0; i < mouse_caps.dwButtons; ++i) - AddInput(new Button(i)); + for (u8 i = 0; i < mouse_caps.dwButtons; ++i) + AddInput(new Button(i, m_state_in.mouse.rgbButtons[i])); // mouse axes for (unsigned int i = 0; i < mouse_caps.dwAxes; ++i) { + const LONG& ax = (&m_state_in.mouse.lX)[i]; + // each axis gets a negative and a positive input instance associated with it - AddInput(new Axis(i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY)); - AddInput(new Axis(i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY)); + AddInput(new Axis(i, ax, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY)); + AddInput(new Axis(i, ax, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY)); } // cursor, with a hax for-loop for (unsigned int i=0; i<4; ++i) - AddInput(new Cursor(!!(i&2), !!(i&1))); + AddInput(new Cursor(!!(i&2), (&m_state_in.cursor.x)[i/2], !!(i&1))); } void GetMousePos(float* const x, float* const y) @@ -244,15 +246,15 @@ std::string KeyboardMouse::GetSource() const return DINPUT_SOURCE_NAME; } -ControlState KeyboardMouse::GetInputState(const ControllerInterface::Device::Input* const input) const -{ - return (((Input*)input)->GetState(&m_state_in)); -} - -void KeyboardMouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state) -{ - ((Output*)output)->SetState(state, m_state_out); -} +//ControlState KeyboardMouse::GetInputState(const ControllerInterface::Device::Input* const input) const +//{ +// return (((Input*)input)->GetState(&m_state_in)); +//} +// +//void KeyboardMouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state) +//{ +// ((Output*)output)->SetState(state, m_state_out); +//} // names std::string KeyboardMouse::Key::GetName() const @@ -283,33 +285,33 @@ std::string KeyboardMouse::Cursor::GetName() const std::string KeyboardMouse::Light::GetName() const { - return named_lights[ m_index ].name; + return named_lights[m_index].name; } // get/set state -ControlState KeyboardMouse::Key::GetState(const State* const state) const +ControlState KeyboardMouse::Key::GetState() const { - return (state->keyboard[named_keys[m_index].code] != 0); + return (m_key != 0); } -ControlState KeyboardMouse::Button::GetState(const State* const state) const +ControlState KeyboardMouse::Button::GetState() const { - return (state->mouse.rgbButtons[m_index] != 0); + return (m_button != 0); } -ControlState KeyboardMouse::Axis::GetState(const State* const state) const +ControlState KeyboardMouse::Axis::GetState() const { - return std::max(0.0f, ControlState((&state->mouse.lX)[m_index]) / m_range); + return std::max(0.0f, ControlState(m_axis) / m_range); } -ControlState KeyboardMouse::Cursor::GetState(const State* const state) const +ControlState KeyboardMouse::Cursor::GetState() const { - return std::max(0.0f, ControlState((&state->cursor.x)[m_index]) / (m_positive ? 1.0f : -1.0f)); + return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); } -void KeyboardMouse::Light::SetState(const ControlState state, unsigned char* const state_out) +void KeyboardMouse::Light::SetState(const ControlState state) { - state_out[m_index] = (unsigned char)(state * 255); + //state_out[m_index] = (unsigned char)(state * 255); } } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h index d9508ef164..cacef516b0 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.h @@ -18,11 +18,7 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector