introduction of a zero lag mode when pilots are synched in time, eg using ntp.
This commit is contained in:
parent
1a7783c358
commit
db295a9afc
2 changed files with 77 additions and 43 deletions
|
@ -50,6 +50,12 @@ FGAIMultiplayer::FGAIMultiplayer() :
|
||||||
lastUpdateTime = 0;
|
lastUpdateTime = 0;
|
||||||
playerLag = 0.03;
|
playerLag = 0.03;
|
||||||
compensateLag = 1;
|
compensateLag = 1;
|
||||||
|
realTime = false;
|
||||||
|
lastTime=0.0;
|
||||||
|
lagPpsAveraged = 1.0;
|
||||||
|
rawLag = 0.0;
|
||||||
|
rawLagMod = 0.0;
|
||||||
|
lagModAveraged = 0.0;
|
||||||
_searchOrder = PREFER_DATA;
|
_searchOrder = PREFER_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +158,27 @@ void FGAIMultiplayer::update(double dt)
|
||||||
// requested time to the most recent available packet. This is the
|
// requested time to the most recent available packet. This is the
|
||||||
// target we want to reach in average.
|
// target we want to reach in average.
|
||||||
double lag = it->second.lag;
|
double lag = it->second.lag;
|
||||||
|
|
||||||
|
rawLag = curentPkgTime - curtime;
|
||||||
|
realTime = false; //default behaviour
|
||||||
|
|
||||||
if (!mTimeOffsetSet) {
|
if (!mTimeOffsetSet) {
|
||||||
mTimeOffsetSet = true;
|
mTimeOffsetSet = true;
|
||||||
mTimeOffset = curentPkgTime - curtime - lag;
|
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 {
|
} 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;
|
double offset = 0.0;
|
||||||
|
|
||||||
//spectator mode, more late to be in the interpolation zone
|
//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
|
// using the prediction mode to display the mpaircraft in the futur/past with given playerlag value
|
||||||
//currently compensatelag = 2
|
//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;
|
} else { offset = curentPkgTime - curtime + 0.48*lag + playerLag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!realTime) {
|
||||||
|
|
||||||
if ((!mAllowExtrapolation && offset + lag < mTimeOffset)
|
if ((!mAllowExtrapolation && offset + lag < mTimeOffset)
|
||||||
|| (offset - 10 > mTimeOffset)) {
|
|| (offset - 10 > mTimeOffset)) {
|
||||||
mTimeOffset = offset;
|
mTimeOffset = offset;
|
||||||
|
@ -181,7 +211,6 @@ void FGAIMultiplayer::update(double dt)
|
||||||
// arriving packets will pessimize the overall lag much more than
|
// arriving packets will pessimize the overall lag much more than
|
||||||
// early packets will shorten the overall lag
|
// early packets will shorten the overall lag
|
||||||
double sysSpeed;
|
double sysSpeed;
|
||||||
|
|
||||||
//trying to slow the rudderlag phenomenon thus using more the prediction system
|
//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 we are off by less than 1.5s, do a little correction, and bigger step above 1.5s
|
||||||
if (fabs(err) < 1.5) {
|
if (fabs(err) < 1.5) {
|
||||||
|
@ -217,7 +246,7 @@ void FGAIMultiplayer::update(double dt)
|
||||||
<< fabs(norm(it->second.linearVel)*systemIncrement));
|
<< fabs(norm(it->second.linearVel)*systemIncrement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the time in the feeders time scale which fits the current time
|
// Compute the time in the feeders time scale which fits the current time
|
||||||
// we need to
|
// we need to
|
||||||
|
@ -227,9 +256,10 @@ void FGAIMultiplayer::update(double dt)
|
||||||
SGQuatf ecOrient;
|
SGQuatf ecOrient;
|
||||||
SGVec3f ecLinearVel;
|
SGVec3f ecLinearVel;
|
||||||
|
|
||||||
if (tInterp <= curentPkgTime) {
|
if (tInterp < curentPkgTime) {
|
||||||
// Ok, we need a time prevous to the last available packet,
|
// Ok, we need a time prevous to the last available packet,
|
||||||
// that is good ...
|
// 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
|
// Find the first packet before the target time
|
||||||
MotionInfo::iterator nextIt = mMotionInfo.upper_bound(tInterp);
|
MotionInfo::iterator nextIt = mMotionInfo.upper_bound(tInterp);
|
||||||
|
|
|
@ -86,11 +86,15 @@ private:
|
||||||
typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
|
typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
|
||||||
PropertyMap mPropertyMap;
|
PropertyMap mPropertyMap;
|
||||||
|
|
||||||
double mTimeOffset;
|
|
||||||
bool mTimeOffsetSet;
|
bool mTimeOffsetSet;
|
||||||
double playerLag;
|
bool realTime;
|
||||||
int compensateLag;
|
int compensateLag;
|
||||||
|
double playerLag;
|
||||||
|
double mTimeOffset;
|
||||||
double lastUpdateTime;
|
double lastUpdateTime;
|
||||||
|
double lastTime;
|
||||||
|
double lagPpsAveraged;
|
||||||
|
double rawLag, rawLagMod, lagModAveraged;
|
||||||
|
|
||||||
/// Properties which are for now exposed for testing
|
/// Properties which are for now exposed for testing
|
||||||
bool mAllowExtrapolation;
|
bool mAllowExtrapolation;
|
||||||
|
|
Loading…
Add table
Reference in a new issue