public override bool ReadFromBitstream(ref UdpBitStream bitstream, MsgType msgType, Frame targetFrame, int i, bool forcedUpdate, bool isKeyframe) { // Only read for the sent bit if not forced, there is no check bit for forced updates (since all clients and server know it is forced) bool hasChanged = forcedUpdate || bitstream.ReadBool(); if (!hasChanged) { targetFrame.rotations[i] = GenericX.NULL; } else if (rotationType == XType.Quaternion) { targetFrame.rotations[i] = bitstream.ReadULong(totalBitsForQuat).DecompressBitBufferToQuat(totalBitsForQuat); } else { targetFrame.rotations[i] = new GenericX( (rotationType.IsX()) ? (bitstream.ReadUInt(xyzBits[0]) * xyzUnmult[0] + xyzMin[0]) : 0, (rotationType.IsY()) ? (bitstream.ReadUInt(xyzBits[1]) * xyzUnmult[1] + xyzMin[1]) : 0, (rotationType.IsZ()) ? (bitstream.ReadUInt(xyzBits[2]) * xyzUnmult[2] + xyzMin[2]) : 0, rotationType); } return(hasChanged); }
public void Unpack(UdpBitStream buffer, UdpSocket socket) { ObjSequence = TrimSequence(buffer.ReadUShort(16)); AckSequence = TrimSequence(buffer.ReadUShort(16)); AckHistory = buffer.ReadULong(socket.Config.AckRedundancy); if (socket.Config.CalculateNetworkPing) { AckTime = buffer.ReadUShort(16); } if (socket.Config.WritePacketBitSize) { BitSize = buffer.ReadUShort(16); } }
public override bool Read(ref UdpBitStream bitstream, Frame frame, Frame currentFrame) { ElementFrame e = frames[frame.frameid]; bool forcedUpdate = IsUpdateForced(frame); bool applyToGhost = ShouldApplyToGhost(frame); bool isCurrentFrame = frame == currentFrame; // Only read for the sent bit if not forced, there is no check bit for forced updates (since all clients and server know it is required) bool hasChanged = forcedUpdate || bitstream.ReadBool(); if (!hasChanged) { // Leave the transform as is if this is the current friend and hasn't changed - it has already been extrapolated and is mid-lerp // So leave it alone. Otherwise set it to GenericX.NULL just to make debugging easier. Eventually can remove this. if (!isCurrentFrame) { e.xform = GenericX.NULL; e.compXform = CompressedElement.zero; } return(false); } if (rotationType == RotationType.Quaternion) { e.compXform = bitstream.ReadULong(totalBitsForQuat); e.xform = e.compXform.quat.DecompressToQuat(totalBitsForQuat); } else { for (int axisId = 0; axisId < 3; axisId++) { bool useAxis = includedAxes.IsXYZ(axisId); cvals[axisId] = (useAxis) ? bitstream.ReadUInt(axes[axisId].bits) : 0; vals[axisId] = (useAxis) ? cvals[axisId] * axes[axisId].unmult + axes[axisId].min : 0; } e.xform = new GenericX(vals[0], vals[1], vals[2], (XType)includedAxes); e.compXform = new CompressedElement(cvals[0], cvals[1], cvals[2]); } if (applyToGhost) { Apply(e.xform, rewindGO); // e.transform.ApplyRotation(rewindGO.transform, useLocal); } return(hasChanged); }