1
0
Fork 0

src/AIModel/AIMultiplayer.*: Improve behaviour if simple-time enabled.

Moved interpolation code into new method
FGAIMultiplayer::FGAIMultiplayerInterpolate().

FGAIMultiplayer::update():
    If simple-time is enabled, always use getMPProtocolClockSec() (or
    /sim/replay/time if replaying) as current time, so that multiple instances
    of Flightgear all using simple-time will all show user and MP aircraft
    in the same relative positions.

    When interpolating, don't special-case single iterator, instead pass the
    single iterator as both args to FGAIMultiplayerInterpolate().

    Fixed removal of outdated frames using mMotionInfo.erase() - previously
    this was not done if we had done extrapolation, and with interpolation we
    left one too many frames in place.

FGAIMultiplayer::addMotionInfo():
    If simple-time is enabled, apply compensation to MP aircraft's .time fields
    if incoming packets' .time field differs significantly from our local UTC
    time.

    This allows simple-time to work with non-simple-time MP aircraft, or with
    simple-time MP aircraft whose UTC clocks differ from local UTC clock. But
    without the guarantee of consistent rendering across Flightgear instances.

    We don't calculate lag when compensating in this way.

With these changes, scripts/python/recordreplay.py --test-motion-mp passes (the
test sets /sim/replay/simple-time").
This commit is contained in:
Julian Smith 2021-04-13 23:41:57 +01:00
parent 10be9a1b60
commit edc6d88993
2 changed files with 640 additions and 374 deletions

File diff suppressed because it is too large Load diff

View file

@ -40,42 +40,68 @@ public:
void setDoubleProperty(const std::string& prop, double val);
long getLastTimestamp(void) const
{ return mLastTimestamp; }
{
return mLastTimestamp;
}
void setAllowExtrapolation(bool allowExtrapolation)
{ mAllowExtrapolation = allowExtrapolation; }
{
mAllowExtrapolation = allowExtrapolation;
}
bool getAllowExtrapolation(void) const
{ return mAllowExtrapolation; }
{
return mAllowExtrapolation;
}
void setLagAdjustSystemSpeed(double lagAdjustSystemSpeed)
{
if (lagAdjustSystemSpeed < 0)
lagAdjustSystemSpeed = 0;
mLagAdjustSystemSpeed = lagAdjustSystemSpeed;
}
double getLagAdjustSystemSpeed(void) const
{ return mLagAdjustSystemSpeed; }
{
return mLagAdjustSystemSpeed;
}
void addPropertyId(unsigned id, const char* name)
{ mPropertyMap[id] = props->getNode(name, true); }
{
mPropertyMap[id] = props->getNode(name, true);
}
double getplayerLag(void) const
{ return playerLag; }
{
return playerLag;
}
void setplayerLag(double mplayerLag)
{playerLag = mplayerLag; }
{
playerLag = mplayerLag;
}
int getcompensateLag(void) const
{ return compensateLag; }
{
return compensateLag;
}
void setcompensateLag(int mcompensateLag)
{compensateLag = mcompensateLag; }
{
compensateLag = mcompensateLag;
}
SGPropertyNode* getPropertyRoot()
{ return props; }
{
return props;
}
void clearMotionInfo();
const char* getTypeString(void) const override { return "multiplayer"; }
const char* getTypeString(void) const override
{
return "multiplayer";
}
private:
@ -87,6 +113,21 @@ private:
// and the property nodes
typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
PropertyMap mPropertyMap;
// Calculates position, orientation and velocity using interpolation between
// *prevIt and *nextIt, specifically (1-tau)*(*prevIt) + tau*(*nextIt).
//
// Cannot call this method 'interpolate' because that would hide the name in
// OSG.
//
void FGAIMultiplayerInterpolate(
MotionInfo::iterator prevIt,
MotionInfo::iterator nextIt,
double tau,
SGVec3d& ecPos,
SGQuatf& ecOrient,
SGVec3f& ecLinearVel
);
bool mTimeOffsetSet;
bool realTime;
@ -113,6 +154,27 @@ private:
SGPropertyNode_ptr _uBodyNode;
SGPropertyNode_ptr _vBodyNode;
SGPropertyNode_ptr _wBodyNode;
// Things for simple-time.
//
SGPropertyNode_ptr m_simple_time_enabled;
SGPropertyNode_ptr m_sim_replay_replay_state;
SGPropertyNode_ptr m_sim_replay_time;
bool m_simple_time_first_time;
double m_simple_time_offset;
double m_simple_time_offset_smoothed;
double m_simple_time_compensation;
double m_simple_time_recent_packet_time;
SGPropertyNode_ptr m_node_simple_time_latest;
SGPropertyNode_ptr m_node_simple_time_offset;
SGPropertyNode_ptr m_node_simple_time_offset_smoothed;
SGPropertyNode_ptr m_node_simple_time_compensation;
// For use with scripts/python/recordreplay.py --test-motion-mp.
SGPropertyNode_ptr mLogRawSpeedMultiplayer;
};
#endif // _FG_AIMultiplayer_HXX