/// ------------------------------------------------------------------------------------------------------------------------------------------- /// 1. Owner sends compressed transform updates FixedUpdate tick /// ------------------------------------------------------------------------------------------------------------------------------------------- private void FixedUpdate() { if (!hasAuthority) { return; } // We compress the transform, which returns a CompressedMatrix. var cm = crusher.Compress(transform); // Convert the CompressedMatrix to a ulong[] array. Note the explicit cast. var fragments = (ulong[])cm; /// Our compression settings add up to a compressed value of 72, but the largest primitive we can send with RPCs is a 64 bits /// so we need to break the CompressedMatrix into multiple compressed values. /// We send the first 64 bits as the first argument, which is in the first array element fragment[0]. /// The second array element fragment[1] contains the remaining 8 bits and that becomes the second argument. /// Rather than sending the whole 64 bits of the second fragment, we should instead just cast down to (byte), /// since the upper/left bits of the second fragment will always be zeros, and we only need the first 8 bytes. /// Frag[0] = QQQQQQQQ-QQQQQQQQ-QQQQQQQQ-QQQQQQQQ-ZZZZZZZZ-ZZYYYYYY-YYYYXXXX-XXXXXXXX /// Frag[1] = ........-........-........-........-........-........-........-SSSSSSSS // Send the fragments to the server using a command rpc CmdServerRPC(fragments[0], (byte)fragments[1]); }
protected override void InterpolateFrame(Frame targframe, Frame startframe, Frame endframe, float t) { ////return FrameContents.Empty; //if (GetComponent<SyncPickup>()) // Debug.Log("<b> Interp Frame</b> " + prevFrame.content + " : " + snapFrame.content + " " + start.parentHash + " : " + end.parentHash); /// Don't interpolate if parent has changed - -2 indicates unknown. Checking for -2 so that both being -2 doesn't get treated as "same". if (startframe.parentHash == -2 || startframe.parentHash != endframe.parentHash) { targFrame.content = FrameContents.Empty; //targ.CopyFrom(end); } else { targframe.CopyFrom(endframe); Matrix.Lerp(targframe.m, startframe.hasTeleported ? startframe.telem : startframe.m, endframe.m, t); transformCrusher.Compress(targframe.cm, targframe.m); } }
protected override FrameContents InterpolateFrame(Frame targ, Frame start, Frame end, float t) { //return FrameContents.Empty; /// Don't interpolate if parent has changed - -2 indicates unknown. Checking for -2 so that both being -2 doesn't get treated as "same". if (start.parentHash == -2 || start.parentHash != end.parentHash) { return(FrameContents.Empty); //targ.CopyFrom(end); } else { targ.CopyFrom(end); Matrix.Lerp(targ.m, start.hasTeleported ? start.telem : start.m, end.m, t); transformCrusher.Compress(targ.cm, targ.m); } return(FrameContents.Complete); }
/// <summary> /// Compress this matrix using the crusher it was previously created with. /// </summary> /// <returns></returns> public void Compress(CompressedMatrix nonalloc) { crusher.Compress(nonalloc, this); }