| 1484 | } |
| 1485 | |
| 1486 | void RigidShape::unpackUpdate(NetConnection *con, BitStream *stream) |
| 1487 | { |
| 1488 | Parent::unpackUpdate(con,stream); |
| 1489 | |
| 1490 | if (stream->readFlag()) |
| 1491 | return; |
| 1492 | |
| 1493 | mDelta.move.unpack(stream); |
| 1494 | |
| 1495 | if (stream->readFlag()) |
| 1496 | { |
| 1497 | // Check if we need to jump to the given transform |
| 1498 | // rather than interpolate to it. |
| 1499 | bool forceUpdate = stream->readFlag(); |
| 1500 | |
| 1501 | mPredictionCount = sMaxPredictionTicks; |
| 1502 | F32 speed = mRigid.linVelocity.len(); |
| 1503 | mDelta.warpRot[0] = mRigid.angPosition; |
| 1504 | |
| 1505 | // Read in new position and momentum values |
| 1506 | stream->readCompressedPoint(&mRigid.linPosition); |
| 1507 | mathRead(*stream, &mRigid.angPosition); |
| 1508 | mathRead(*stream, &mRigid.linMomentum); |
| 1509 | mathRead(*stream, &mRigid.angMomentum); |
| 1510 | mRigid.atRest = stream->readFlag(); |
| 1511 | mRigid.updateVelocity(); |
| 1512 | |
| 1513 | if (!forceUpdate && isProperlyAdded()) |
| 1514 | { |
| 1515 | // Determine number of ticks to warp based on the average |
| 1516 | // of the client and server velocities. |
| 1517 | Point3F cp = mDelta.pos + mDelta.posVec * mDelta.dt; |
| 1518 | mDelta.warpOffset = mRigid.linPosition - cp; |
| 1519 | |
| 1520 | // Calc the distance covered in one tick as the average of |
| 1521 | // the old speed and the new speed from the server. |
| 1522 | F32 dt,as = (speed + mRigid.linVelocity.len()) * 0.5 * TickSec; |
| 1523 | |
| 1524 | // Cal how many ticks it will take to cover the warp offset. |
| 1525 | // If it's less than what's left in the current tick, we'll just |
| 1526 | // warp in the remaining time. |
| 1527 | if (!as || (dt = mDelta.warpOffset.len() / as) > sMaxWarpTicks) |
| 1528 | dt = mDelta.dt + sMaxWarpTicks; |
| 1529 | else |
| 1530 | dt = (dt <= mDelta.dt)? mDelta.dt : mCeil(dt - mDelta.dt) + mDelta.dt; |
| 1531 | |
| 1532 | // Adjust current frame interpolation |
| 1533 | if (mDelta.dt) |
| 1534 | { |
| 1535 | mDelta.pos = cp + (mDelta.warpOffset * (mDelta.dt / dt)); |
| 1536 | mDelta.posVec = (cp - mDelta.pos) / mDelta.dt; |
| 1537 | QuatF cr; |
| 1538 | cr.interpolate(mDelta.rot[1],mDelta.rot[0],mDelta.dt); |
| 1539 | mDelta.rot[1].interpolate(cr,mRigid.angPosition,mDelta.dt / dt); |
| 1540 | mDelta.rot[0].extrapolate(mDelta.rot[1],cr,mDelta.dt); |
| 1541 | } |
| 1542 | |
| 1543 | // Calculated multi-tick warp |
nothing calls this directly
no test coverage detected