diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2010-07-26 05:30:50 +0000 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2010-07-26 05:30:50 +0000 |
| commit | 5be58c6772c131cecbc1786a14f5265a9d99e159 (patch) | |
| tree | 271085e1fa4144702e9403dc140fae9c8020cb03 /Source/Core/InputCommon | |
| parent | 0eaa7352fd26ac2bd8ee72678e38e76093e8daf2 (diff) | |
Gecko codes: Added parenthesis where they were needed.(thanks to glennrics and soren) Fixed a copy paste error with write & fill 8bit codes. Also forgot to remove a return false;.(some more codes should work (fixed issue 2968)) New Wiimote Plugin: Added emulated swinging.(seems to work) Changed the emulated calibration data to some nice values. ControllerInterface: moved and constified some stuff.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5980 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/InputCommon')
7 files changed, 48 insertions, 16 deletions
diff --git a/Source/Core/InputCommon/Src/ControllerEmu.cpp b/Source/Core/InputCommon/Src/ControllerEmu.cpp index e57ffc2d0b..44013bea40 100644 --- a/Source/Core/InputCommon/Src/ControllerEmu.cpp +++ b/Source/Core/InputCommon/Src/ControllerEmu.cpp @@ -261,13 +261,15 @@ ControllerEmu::Triggers::Triggers( const char* const _name ) : ControlGroup( _na ControllerEmu::Force::Force( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_FORCE ) { + memset(m_swing, 0, sizeof(m_swing)); + controls.push_back( new Input( "Up" ) ); controls.push_back( new Input( "Down" ) ); controls.push_back( new Input( "Left" ) ); controls.push_back( new Input( "Right" ) ); controls.push_back( new Input( "Forward" ) ); controls.push_back( new Input( "Backward" ) ); - controls.push_back( new Input( "Modifier" ) ); + //controls.push_back( new Input( "Modifier" ) ); settings.push_back( new Setting("Dead Zone", 0, 0, 50 ) ); } @@ -277,8 +279,6 @@ ControllerEmu::Tilt::Tilt( const char* const _name ) { memset(m_tilt, 0, sizeof(m_tilt)); - //for ( unsigned int i = 0; i < 4; ++i ) - //controls.push_back( new Input( named_directions[i] ) ); controls.push_back( new Input( "Forward" ) ); controls.push_back( new Input( "Backward" ) ); controls.push_back( new Input( "Left" ) ); diff --git a/Source/Core/InputCommon/Src/ControllerEmu.h b/Source/Core/InputCommon/Src/ControllerEmu.h index 9197bad3f4..b807b9ef7b 100644 --- a/Source/Core/InputCommon/Src/ControllerEmu.h +++ b/Source/Core/InputCommon/Src/ControllerEmu.h @@ -253,19 +253,35 @@ public: Force( const char* const _name ); template <typename C, typename R> - void GetState( C* axis, const u8 base, const R range ) + void GetState(C* axis, const u8 base, const R range) { const float deadzone = settings[0]->value; - for ( unsigned int i=0; i<6; i+=2 ) + for (unsigned int i=0; i<6; i+=2) { + float tmpf = 0; const float state = controls[i+1]->control_ref->State() - controls[i]->control_ref->State(); if (fabsf(state) > deadzone) - *axis++ = (C)((state - (deadzone * sign(state))) / (1 - deadzone) * range + base); - //*axis++ = state * range + base; + tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone)); else - *axis++ = (C)(base); + tmpf = 0; + + float &ax = m_swing[i >> 1]; + + if (fabs(tmpf) > fabsf(ax)) + { + if (tmpf > ax) + ax = std::min(ax + 0.15f, tmpf); + else if (tmpf < ax) + ax = std::max(ax - 0.15f, tmpf); + } + else + ax = tmpf; + + *axis++ = (C)(ax * range + base); } } + private: + float m_swing[3]; }; class Tilt : public ControlGroup diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp index 36e6bd98f8..235985704a 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp @@ -121,8 +121,13 @@ void ControllerInterface::SetHwnd( void* const hwnd ) // // update input for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateInput() +bool ControllerInterface::UpdateInput(const bool force) { + if (force) + update_lock.Enter(); + else if (false == update_lock.TryEnter()) + return false; + size_t ok_count = 0; std::vector<Device*>::const_iterator @@ -137,6 +142,7 @@ bool ControllerInterface::UpdateInput() //(*d)->ClearInputState(); } + update_lock.Leave(); return (m_devices.size() == ok_count); } @@ -145,8 +151,13 @@ bool ControllerInterface::UpdateInput() // // update output for all devices, return true if all devices returned successful // -bool ControllerInterface::UpdateOutput() +bool ControllerInterface::UpdateOutput(const bool force) { + if (force) + update_lock.Enter(); + else if (false == update_lock.TryEnter()) + return false; + size_t ok_count = 0; std::vector<Device*>::const_iterator @@ -155,6 +166,7 @@ bool ControllerInterface::UpdateOutput() for (;d != e; ++d) (*d)->UpdateOutput(); + update_lock.Leave(); return (m_devices.size() == ok_count); } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h index 903797a6e4..af07b1ac69 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h @@ -6,7 +6,9 @@ #include <sstream> #include <map> #include <algorithm> + #include "Common.h" +#include "Thread.h" // enable disable sources #ifdef _WIN32 @@ -214,12 +216,14 @@ public: bool IsInit() const { return m_is_init; } void UpdateReference(ControlReference* control, const DeviceQualifier& default_device) const; - bool UpdateInput(); - bool UpdateOutput(); + bool UpdateInput(const bool force = false); + bool UpdateOutput(const bool force = false); const std::vector<Device*>& Devices() const { return m_devices; } Device* FindDevice(const DeviceQualifier& devq) const; + Common::CriticalSection update_lock; + private: bool m_is_init; std::vector<Device*> m_devices; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 33101c2507..1cd925c992 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -19,7 +19,7 @@ namespace ciface namespace DInput { -static struct +static const struct { const BYTE code; const char* const name; @@ -28,7 +28,7 @@ static struct #include "NamedKeys.h" }; -static struct +static const struct { const BYTE code; const char* const name; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp index 526c6ffd9a..0e39942396 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp @@ -9,7 +9,7 @@ namespace ciface namespace XInput { -static struct +static const struct { const char* const name; const WORD bitmask; diff --git a/Source/Core/InputCommon/Src/InputConfig.h b/Source/Core/InputCommon/Src/InputConfig.h index 1e2c708df0..2d1e3b6411 100644 --- a/Source/Core/InputCommon/Src/InputConfig.h +++ b/Source/Core/InputCommon/Src/InputConfig.h @@ -44,7 +44,7 @@ public: std::vector< ControllerEmu* > controllers; - Common::CriticalSection controls_crit, interface_crit; // lock controls first + Common::CriticalSection controls_crit; // critical section for changing any control references ControllerInterface controller_interface; const char * const ini_name; |
