1
0
Fork 0

introduction of a zero lag mode when pilots are synched in time, eg using ntp.

This commit is contained in:
jano 2020-01-14 11:10:28 +01:00
parent 1a7783c358
commit db295a9afc
2 changed files with 77 additions and 43 deletions

View file

@ -50,6 +50,12 @@ FGAIMultiplayer::FGAIMultiplayer() :
lastUpdateTime = 0;
playerLag = 0.03;
compensateLag = 1;
realTime = false;
lastTime=0.0;
lagPpsAveraged = 1.0;
rawLag = 0.0;
rawLagMod = 0.0;
lagModAveraged = 0.0;
_searchOrder = PREFER_DATA;
}
@ -152,10 +158,27 @@ void FGAIMultiplayer::update(double dt)
// requested time to the most recent available packet. This is the
// target we want to reach in average.
double lag = it->second.lag;
rawLag = curentPkgTime - curtime;
realTime = false; //default behaviour
if (!mTimeOffsetSet) {
mTimeOffsetSet = true;
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);
} else {
if ((curentPkgTime - lastTime) != 0) {
lagPpsAveraged = 0.99 * lagPpsAveraged + 0.01 * fabs( 1 / (lastTime - curentPkgTime));
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);
}
double offset = 0.0;
//spectator mode, more late to be in the interpolation zone
@ -166,8 +189,15 @@ void FGAIMultiplayer::update(double dt)
// using the prediction mode to display the mpaircraft in the futur/past with given playerlag value
//currently compensatelag = 2
} else if (fabs(lagModAveraged) < 0.3) {
mTimeOffset = (round(rawLag/3600))*3600; //real time mode if close enough
realTime = true;
} else { offset = curentPkgTime - curtime + 0.48*lag + playerLag;
}
if (!realTime) {
if ((!mAllowExtrapolation && offset + lag < mTimeOffset)
|| (offset - 10 > mTimeOffset)) {
mTimeOffset = offset;
@ -181,7 +211,6 @@ void FGAIMultiplayer::update(double dt)
// arriving packets will pessimize the overall lag much more than
// early packets will shorten the overall lag
double sysSpeed;
//trying to slow the rudderlag phenomenon thus using more the prediction system
//if we are off by less than 1.5s, do a little correction, and bigger step above 1.5s
if (fabs(err) < 1.5) {
@ -217,7 +246,7 @@ void FGAIMultiplayer::update(double dt)
<< fabs(norm(it->second.linearVel)*systemIncrement));
}
}
}
// Compute the time in the feeders time scale which fits the current time
// we need to
@ -227,9 +256,10 @@ void FGAIMultiplayer::update(double dt)
SGQuatf ecOrient;
SGVec3f ecLinearVel;
if (tInterp <= curentPkgTime) {
if (tInterp < curentPkgTime) {
// Ok, we need a time prevous to the last available packet,
// that is good ...
// the case tInterp = curentPkgTime need to be in the interpolation, to avoid a bug zeroing the position
// Find the first packet before the target time
MotionInfo::iterator nextIt = mMotionInfo.upper_bound(tInterp);

View file

@ -86,11 +86,15 @@ private:
typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
PropertyMap mPropertyMap;
double mTimeOffset;
bool mTimeOffsetSet;
double playerLag;
bool realTime;
int compensateLag;
double playerLag;
double mTimeOffset;
double lastUpdateTime;
double lastTime;
double lagPpsAveraged;
double rawLag, rawLagMod, lagModAveraged;
/// Properties which are for now exposed for testing
bool mAllowExtrapolation;