1
0
Fork 0

Multiplayer: ensure lag/ properties always exist

Create lag/foo properties used by the Pilot-list UI in bind(). This avoids
a race condition where motion info was not yet updated, but Nasal tries
to retrieve the lag properties and errors out.
This commit is contained in:
James Turner 2022-02-26 17:33:15 +00:00
parent 3fb81a34f5
commit 1ec67f05ff
2 changed files with 16 additions and 11 deletions

View file

@ -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 <config.h>
#endif
#include <config.h>
#include <string>
#include <stdio.h>
@ -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<FGAIMultiplayer, type>(*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);
}
}

View file

@ -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;