diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-09-02 06:03:03 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-09-02 06:03:03 +0400 |
commit | 81ad271d157c70433b36af31581261ae8c2098a4 (patch) | |
tree | 890d6e9eac942613086fde57b8384b5c5ae30256 /source/gameengine/GameLogic | |
parent | aa4e4da8c31a09c8afe0e60d26a1e68dd949e6b8 (diff) |
BGE joystick sensor bugfix, was sending true events logic tick (as if the true pulse option was enabled).
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 24 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.h | 6 |
2 files changed, 28 insertions, 2 deletions
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 325657cbc7f..456401d48df 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -120,7 +120,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) js->cSetPrecision(m_precision); if(m_axisf == 1){ if(js->aUpAxisIsPositive(m_axis)){ - m_istrig =1; + m_istrig = 1; result = true; }else{ if(m_istrig){ @@ -243,11 +243,31 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) printf("Error invalid switch statement\n"); break; } - if(!js->IsTrig()){ + + if (js->IsTrig()) { + /* This test detects changes with the joystick trigger state. + * js->IsTrig() will stay true as long as the key is held. + * even though the event from SDL will only be sent once. + * istrig_js && m_istrig_lastjs - when this is true it means this sensor + * had the same joystick trigger state last time, + * Setting the result false this time means it wont run the sensors + * controller every time (like a pulse sensor) + * + * This is not done with the joystick its self incase other sensors use + * it or become active. + */ + if (m_istrig_lastjs) { + result = false; + } + m_istrig_lastjs = true; + } else { m_istrig = 0; + m_istrig_lastjs = false; } + if (reset) result = true; + return result; } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index a21146b568b..8b74f6e0296 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -69,6 +69,12 @@ class SCA_JoystickSensor :public SCA_ISensor */ bool m_istrig; /** + * Last trigger state for this sensors joystick, + * Otherwise it will trigger all the time + * this is used to see if the trigger state changes. + */ + bool m_istrig_lastjs; + /** * The mode to determine axis,button or hat */ short int m_joymode; |