MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / unpackUpdate

Method unpackUpdate

Engine/source/T3D/rigidShape.cpp:1581–1663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1579}
1580
1581void RigidShape::unpackUpdate(NetConnection *con, BitStream *stream)
1582{
1583 Parent::unpackUpdate(con,stream);
1584
1585 if (stream->readFlag())
1586 return;
1587
1588 mDelta.move.unpack(stream);
1589
1590 if (stream->readFlag())
1591 {
1592 // Check if we need to jump to the given transform
1593 // rather than interpolate to it.
1594 bool forceUpdate = stream->readFlag();
1595
1596 mPredictionCount = sMaxPredictionTicks;
1597 F32 speed = mRigid.linVelocity.len();
1598 mDelta.warpRot[0] = mRigid.angPosition;
1599
1600 // Read in new position and momentum values
1601 stream->readCompressedPoint(&mRigid.linPosition);
1602 mathRead(*stream, &mRigid.angPosition);
1603 mathRead(*stream, &mRigid.linMomentum);
1604 mathRead(*stream, &mRigid.angMomentum);
1605 mRigid.atRest = stream->readFlag();
1606 mRigid.updateVelocity();
1607
1608 if (!forceUpdate && isProperlyAdded())
1609 {
1610 // Determine number of ticks to warp based on the average
1611 // of the client and server velocities.
1612 Point3F cp = mDelta.pos + mDelta.posVec * mDelta.dt;
1613 mDelta.warpOffset = mRigid.linPosition - cp;
1614
1615 // Calc the distance covered in one tick as the average of
1616 // the old speed and the new speed from the server.
1617 F32 dt,as = (speed + mRigid.linVelocity.len()) * 0.5 * TickSec;
1618
1619 // Cal how many ticks it will take to cover the warp offset.
1620 // If it's less than what's left in the current tick, we'll just
1621 // warp in the remaining time.
1622 if (!as || (dt = mDelta.warpOffset.len() / as) > sMaxWarpTicks)
1623 dt = mDelta.dt + sMaxWarpTicks;
1624 else
1625 dt = (dt <= mDelta.dt)? mDelta.dt : mCeil(dt - mDelta.dt) + mDelta.dt;
1626
1627 // Adjust current frame interpolation
1628 if (mDelta.dt)
1629 {
1630 mDelta.pos = cp + (mDelta.warpOffset * (mDelta.dt / dt));
1631 mDelta.posVec = (cp - mDelta.pos) / mDelta.dt;
1632 QuatF cr;
1633 cr.interpolate(mDelta.rot[1],mDelta.rot[0],mDelta.dt);
1634 mDelta.rot[1].interpolate(cr,mRigid.angPosition,mDelta.dt / dt);
1635 mDelta.rot[0].extrapolate(mDelta.rot[1],cr,mDelta.dt);
1636 }
1637
1638 // Calculated multi-tick warp

Callers

nothing calls this directly

Calls 11

mathReadFunction · 0.85
mCeilFunction · 0.85
mFloorFunction · 0.85
readFlagMethod · 0.80
readCompressedPointMethod · 0.80
setPositionFunction · 0.50
unpackMethod · 0.45
lenMethod · 0.45
updateVelocityMethod · 0.45
interpolateMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected