From 60dcf00f2b9e76a2e613060861174c59f643d7fa Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 15 Jun 2020 16:11:11 +0100 Subject: [PATCH] Fix zero-interval repeat on pick/knob animation See: https://sourceforge.net/p/flightgear/codetickets/2241/ Note did not adjust bug in knob-animation ignoring repeatable flag (always marked repeatable) since this might break some aircraft. --- simgear/scene/model/SGPickAnimation.cxx | 32 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/simgear/scene/model/SGPickAnimation.cxx b/simgear/scene/model/SGPickAnimation.cxx index 05d4ca5b..142af6d4 100644 --- a/simgear/scene/model/SGPickAnimation.cxx +++ b/simgear/scene/model/SGPickAnimation.cxx @@ -136,11 +136,19 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea) virtual void update(double dt, int keyModState) { - if (!_condition || _condition->test()) { - SG_UNUSED(keyModState); - if (!_repeatable) - return; + SG_UNUSED(keyModState); + if (_condition && !_condition->test()) { + return; + } + if (!_repeatable) + return; + + const bool zeroInterval = (_repeatInterval <= 0.0); + if (zeroInterval) { + // fire once per frame + fireBindingList(_bindingsDown); + } else { _repeatTime += dt; while (_repeatInterval < _repeatTime) { _repeatTime -= _repeatInterval; @@ -678,12 +686,18 @@ public: if (_hasDragged) { return; } - - _repeatTime += dt; - while (_repeatInterval < _repeatTime) { - _repeatTime -= _repeatInterval; + + const bool zeroInterval = (_repeatInterval <= 0.0); + if (zeroInterval) { + // fire once per frame fire(keyModState & osgGA::GUIEventAdapter::MODKEY_SHIFT, _direction); - } // of repeat iteration + } else { + _repeatTime += dt; + while (_repeatInterval < _repeatTime) { + _repeatTime -= _repeatInterval; + fire(keyModState & osgGA::GUIEventAdapter::MODKEY_SHIFT, _direction); + } // of repeat iteration + } } bool hover( const osg::Vec2d& windowPos, const Info& ) override