From 4d8da078a4b27b854785350d5ea050ee2a4a29fc Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 20 Jan 2005 09:55:47 +0000 Subject: [PATCH] Roy Vegard Ovesen: I guess it is much more efficient to compare integers than comparing long strings like "double-exponential" every frame. --- src/Autopilot/xmlauto.cxx | 18 +++++++++++++----- src/Autopilot/xmlauto.hxx | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Autopilot/xmlauto.cxx b/src/Autopilot/xmlauto.cxx index 61171a08e..c8b7b9c61 100644 --- a/src/Autopilot/xmlauto.cxx +++ b/src/Autopilot/xmlauto.cxx @@ -607,7 +607,15 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node) } else if ( cname == "debug" ) { debug = child->getBoolValue(); } else if ( cname == "type" ) { - filterType = cval; + if ( cval == "exponential" ) { + filterType = exponential; + } else if (cval == "double-exponential") { + filterType = doubleExponential; + } else if (cval == "moving-average") { + filterType = movingAverage; + } else if (cval == "noise-spike") { + filterType = noiseSpike; + } } else if ( cname == "input" ) { input_prop = fgGetNode( child->getStringValue(), true ); } else if ( cname == "filter-time" ) { @@ -645,7 +653,7 @@ void FGDigitalFilter::update(double dt) * */ - if (filterType == "exponential") + if (filterType == exponential) { double alpha = 1 / ((Tf/dt) + 1); output.push_front(alpha * input[0] + @@ -656,7 +664,7 @@ void FGDigitalFilter::update(double dt) } output.resize(1); } - else if (filterType == "double-exponential") + else if (filterType == doubleExponential) { double alpha = 1 / ((Tf/dt) + 1); output.push_front(alpha * alpha * input[0] + @@ -668,7 +676,7 @@ void FGDigitalFilter::update(double dt) } output.resize(2); } - else if (filterType == "moving-average") + else if (filterType == movingAverage) { output.push_front(output[0] + (input[0] - input.back()) / samples); @@ -678,7 +686,7 @@ void FGDigitalFilter::update(double dt) } output.resize(1); } - else if (filterType == "noise-spike") + else if (filterType == noiseSpike) { double maxChange = rateOfChange * dt; diff --git a/src/Autopilot/xmlauto.hxx b/src/Autopilot/xmlauto.hxx index 8ff6db71d..7d87dc7cf 100644 --- a/src/Autopilot/xmlauto.hxx +++ b/src/Autopilot/xmlauto.hxx @@ -230,7 +230,8 @@ private: double rateOfChange; // The maximum allowable rate of change [1/s] deque output; deque input; - string filterType; + enum filterTypes { exponential, doubleExponential, movingAverage, noiseSpike }; + filterTypes filterType; bool debug; -- 2.39.5