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:
parent
3fb81a34f5
commit
1ec67f05ff
2 changed files with 16 additions and 11 deletions
|
@ -21,9 +21,7 @@
|
||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -80,7 +78,8 @@ bool FGAIMultiplayer::init(ModelSearchOrder searchOrder)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIMultiplayer::bind() {
|
void FGAIMultiplayer::bind()
|
||||||
|
{
|
||||||
FGAIBase::bind();
|
FGAIBase::bind();
|
||||||
|
|
||||||
//2018.1 mp-clock-mode indicates the clock mode that the client is running, so for backwards
|
//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_ai_latch = props->getNode("ai-latch", true /*create*/);
|
||||||
m_node_log_multiplayer = globals->get_props()->getNode("/sim/log-multiplayer-callsign", 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) \
|
#define AIMPROProp(type, name) \
|
||||||
SGRawValueMethods<FGAIMultiplayer, type>(*this, &FGAIMultiplayer::get##name)
|
SGRawValueMethods<FGAIMultiplayer, type>(*this, &FGAIMultiplayer::get##name)
|
||||||
|
|
||||||
|
@ -489,8 +491,8 @@ void FGAIMultiplayer::update(double dt)
|
||||||
mTimeOffset = curentPkgTime - curtime - lag;
|
mTimeOffset = curentPkgTime - curtime - lag;
|
||||||
lastTime = curentPkgTime;
|
lastTime = curentPkgTime;
|
||||||
lagModAveraged = remainder((curentPkgTime - curtime), 3600.0);
|
lagModAveraged = remainder((curentPkgTime - curtime), 3600.0);
|
||||||
props->setDoubleValue("lag/pps-averaged", lagPpsAveraged);
|
m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged);
|
||||||
props->setDoubleValue("lag/lag-mod-averaged", lagModAveraged);
|
m_lagModAveragedNode->setDoubleValue(lagModAveraged);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -500,8 +502,8 @@ void FGAIMultiplayer::update(double dt)
|
||||||
lastTime = curentPkgTime;
|
lastTime = curentPkgTime;
|
||||||
rawLagMod = remainder(rawLag, 3600.0);
|
rawLagMod = remainder(rawLag, 3600.0);
|
||||||
lagModAveraged = lagModAveraged *0.99 + 0.01 * rawLagMod;
|
lagModAveraged = lagModAveraged *0.99 + 0.01 * rawLagMod;
|
||||||
props->setDoubleValue("lag/pps-averaged", lagPpsAveraged);
|
m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged);
|
||||||
props->setDoubleValue("lag/lag-mod-averaged", lagModAveraged);
|
m_lagModAveragedNode->setDoubleValue(lagModAveraged);
|
||||||
}
|
}
|
||||||
|
|
||||||
double offset = 0.0;
|
double offset = 0.0;
|
||||||
|
@ -830,12 +832,12 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo,
|
||||||
// m_simple_time_offset_smoothed will usually be too big to be
|
// m_simple_time_offset_smoothed will usually be too big to be
|
||||||
// useful here.
|
// useful here.
|
||||||
//
|
//
|
||||||
props->setDoubleValue("lag/lag-mod-averaged", 0);
|
m_lagModAveragedNode->setDoubleValue(0.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_simple_time_compensation = 0;
|
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);
|
m_node_simple_time_latest->setDoubleValue(motionInfo.time);
|
||||||
|
@ -851,7 +853,7 @@ FGAIMultiplayer::addMotionInfo(FGExternalMotionData& motionInfo,
|
||||||
{
|
{
|
||||||
double ep = 0.05;
|
double ep = 0.05;
|
||||||
lagPpsAveraged = (1-ep) * lagPpsAveraged + ep * (1/dt);
|
lagPpsAveraged = (1-ep) * lagPpsAveraged + ep * (1/dt);
|
||||||
props->setDoubleValue("lag/pps-averaged", lagPpsAveraged);
|
m_lagPPSAveragedNode->setDoubleValue(lagPpsAveraged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,9 @@ private:
|
||||||
double m_simple_time_compensation = 0.0;
|
double m_simple_time_compensation = 0.0;
|
||||||
double m_simple_time_recent_packet_time = 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_latest;
|
||||||
SGPropertyNode_ptr m_node_simple_time_offset;
|
SGPropertyNode_ptr m_node_simple_time_offset;
|
||||||
SGPropertyNode_ptr m_node_simple_time_offset_smoothed;
|
SGPropertyNode_ptr m_node_simple_time_offset_smoothed;
|
||||||
|
|
Loading…
Reference in a new issue