From 27abc684509bc851c18bdac69b27679094836eea Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 1 Jul 2003 16:32:00 +0000 Subject: [PATCH] Jim Wilson: This patch adds an "interval-sec" property which allows fixing an interval in seconds (or fraction of seconds) for the repeats for emulated axis controls (digital hats) on joysticks. --- src/Input/input.cxx | 30 ++++++++++++++++++------------ src/Input/input.hxx | 4 +++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 9e236f269..f4df2882e 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -195,7 +195,7 @@ void FGInput::update (double dt) { _update_keyboard(); - _update_joystick(); + _update_joystick(dt); _update_mouse(); } @@ -537,6 +537,8 @@ FGInput::_init_joystick () _init_button(axis_node->getChild("high"), a.high, "high"); a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9); + a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0); + a.last_dt = 0.0; } // @@ -690,7 +692,7 @@ FGInput::_update_keyboard () void -FGInput::_update_joystick () +FGInput::_update_joystick (double dt) { int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones? int buttons; @@ -727,17 +729,21 @@ FGInput::_update_joystick () } // do we have to emulate axis buttons? - if (a.low.bindings[modifiers].size()) - _update_button(_joystick_bindings[i].axes[j].low, - modifiers, - axis_values[j] < a.low_threshold, - -1, -1); + a.last_dt += dt; + if(a.last_dt >= a.interval_sec) { + if (a.low.bindings[modifiers].size()) + _update_button(_joystick_bindings[i].axes[j].low, + modifiers, + axis_values[j] < a.low_threshold, + -1, -1); - if (a.high.bindings[modifiers].size()) - _update_button(_joystick_bindings[i].axes[j].high, - modifiers, - axis_values[j] > a.high_threshold, - -1, -1); + if (a.high.bindings[modifiers].size()) + _update_button(_joystick_bindings[i].axes[j].high, + modifiers, + axis_values[j] > a.high_threshold, + -1, -1); + a.last_dt -= a.interval_sec; + } } // Fire bindings for the buttons. diff --git a/src/Input/input.hxx b/src/Input/input.hxx index 2ca5568a6..3fe0783b8 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -297,6 +297,8 @@ private: float high_threshold; struct button low; struct button high; + float interval_sec; + double last_dt; }; @@ -381,7 +383,7 @@ private: /** * Update the joystick. */ - void _update_joystick (); + void _update_joystick (double dt); /**