From 005ddf7c9840402d47cab9807c10d13b9d9fb23d Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 1 Apr 2020 16:20:29 +0100 Subject: [PATCH] Optimisation: avoid property name lookups --- src/Main/fg_props.cxx | 34 +++++++++------------------------- src/Main/fg_props.hxx | 4 ++++ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index eee6d0006..2ff4ef597 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -326,28 +326,6 @@ getGMTString () return buf; } -/** - * Return the current heading in degrees. - */ -static double -getHeadingMag () -{ - double magheading = fgGetDouble("/orientation/heading-deg") - - fgGetDouble("/environment/magnetic-variation-deg"); - return SGMiscd::normalizePeriodic(0, 360, magheading ); -} - -/** - * Return the current track in degrees. - */ -static double -getTrackMag () -{ - double magtrack = fgGetDouble("/orientation/track-deg") - - fgGetDouble("/environment/magnetic-variation-deg"); - return SGMiscd::normalizePeriodic(0, 360, magtrack ); -} - //////////////////////////////////////////////////////////////////////// // Tie the properties. //////////////////////////////////////////////////////////////////////// @@ -439,9 +417,11 @@ FGProperties::bind () _tiedProperties.Tie("/position/latitude-string", getLatitudeString); _tiedProperties.Tie("/position/longitude-string", getLongitudeString); - // Orientation - _tiedProperties.Tie("/orientation/heading-magnetic-deg", getHeadingMag); - _tiedProperties.Tie("/orientation/track-magnetic-deg", getTrackMag); + _headingMagnetic = fgGetNode("/orientation/heading-magnetic-deg", true); + _trackMagnetic = fgGetNode("/orientation/track-magnetic-deg", true); + _magVar = fgGetNode("/environment/magnetic-variation-deg", true); + _trueHeading = fgGetNode("/orientatino/heading-deg", true); + _trueTrack = fgGetNode("/orientation/track-deg", true); } void @@ -481,6 +461,10 @@ FGProperties::update (double dt) _rmin->setIntValue(r->tm_min); _rsec->setIntValue(r->tm_sec); _rwday->setIntValue(r->tm_wday); + + const double magvar = _magVar->getDoubleValue(); + _headingMagnetic->setDoubleValue(_trueHeading->getDoubleValue() - magvar); + _trackMagnetic->setDoubleValue(_trueTrack->getDoubleValue() - magvar); } diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 6399ecbbd..a1a021365 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -43,6 +43,10 @@ private: SGPropertyNode_ptr _offset; SGPropertyNode_ptr _uyear, _umonth, _uday, _uhour, _umin, _usec, _uwday, _udsec; SGPropertyNode_ptr _ryear, _rmonth, _rday, _rhour, _rmin, _rsec, _rwday, _rdsec; + + SGPropertyNode_ptr _headingMagnetic, _trackMagnetic; + SGPropertyNode_ptr _magVar; + SGPropertyNode_ptr _trueHeading, _trueTrack; };