diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx index 329876b48..58897d8e2 100644 --- a/src/AIModel/AIMultiplayer.cxx +++ b/src/AIModel/AIMultiplayer.cxx @@ -21,9 +21,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#ifdef HAVE_CONFIG_H -# include -#endif +#include #include #include @@ -80,7 +78,8 @@ bool FGAIMultiplayer::init(ModelSearchOrder searchOrder) return result; } -void FGAIMultiplayer::bind() { +void FGAIMultiplayer::bind() +{ FGAIBase::bind(); //2018.1 mp-clock-mode indicates the clock mode that the client is running, so for backwards @@ -99,6 +98,9 @@ void FGAIMultiplayer::bind() { m_node_ai_latch = props->getNode("ai-latch", true /*create*/); m_node_log_multiplayer = globals->get_props()->getNode("/sim/log-multiplayer-callsign", true /*create*/); + m_lagPPSAveragedNode = props->getNode("lag/pps-averaged", true); + m_lagModAveragedNode = props->getNode("lag/lag-mod-averaged", true); + #define AIMPROProp(type, name) \ SGRawValueMethods(*this, &FGAIMultiplayer::get##name) @@ -489,8 +491,8 @@ void FGAIMultiplayer::update(double dt) mTimeOffset = curentPkgTime - curtime - lag; lastTime = curentPkgTime; lagModAveraged = remainder((curentPkgTime - curtime), 3600.0); - props->setDoubleValue("lag/pps-averaged", lagPpsAveraged); - props->setDoubleValue("lag/lag-mod-averaged", lagModAveraged); + m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged); + m_lagModAveragedNode->setDoubleValue(lagModAveraged); } else { @@ -500,8 +502,8 @@ void FGAIMultiplayer::update(double dt) lastTime = curentPkgTime; rawLagMod = remainder(rawLag, 3600.0); lagModAveraged = lagModAveraged *0.99 + 0.01 * rawLagMod; - props->setDoubleValue("lag/pps-averaged", lagPpsAveraged); - props->setDoubleValue("lag/lag-mod-averaged", lagModAveraged); + m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged); + m_lagModAveragedNode->setDoubleValue(lagModAveraged); } double offset = 0.0; @@ -830,12 +832,12 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo, // m_simple_time_offset_smoothed will usually be too big to be // useful here. // - props->setDoubleValue("lag/lag-mod-averaged", 0); + m_lagModAveragedNode->setDoubleValue(0.0); } else { m_simple_time_compensation = 0; - props->setDoubleValue("lag/lag-mod-averaged", m_simple_time_offset_smoothed); + m_lagModAveragedNode->setDoubleValue(m_simple_time_offset_smoothed); } m_node_simple_time_latest->setDoubleValue(motionInfo.time); @@ -851,7 +853,7 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo, { double ep = 0.05; lagPpsAveraged = (1-ep) * lagPpsAveraged + ep * (1/dt); - props->setDoubleValue("lag/pps-averaged", lagPpsAveraged); + m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged); } } diff --git a/src/AIModel/AIMultiplayer.hxx b/src/AIModel/AIMultiplayer.hxx index 0ca93718e..5c89dd208 100644 --- a/src/AIModel/AIMultiplayer.hxx +++ b/src/AIModel/AIMultiplayer.hxx @@ -182,6 +182,9 @@ private: double m_simple_time_compensation = 0.0; double m_simple_time_recent_packet_time = 0.0; + SGPropertyNode_ptr m_lagPPSAveragedNode; + SGPropertyNode_ptr m_lagModAveragedNode; + SGPropertyNode_ptr m_node_simple_time_latest; SGPropertyNode_ptr m_node_simple_time_offset; SGPropertyNode_ptr m_node_simple_time_offset_smoothed;