Beispiel #1
0
        public override void WriteToBitstream(ref UdpKit.UdpBitStream bitstream, MsgType msgType, bool forceUpdate, bool isKeyframe)
        {
            // Compress the current element rotation using the selected compression method.
            CompressedElement newCPos = CompressElement();

            // For frames between forced updates, we need to first send a flag bit for if this element is being sent
            if (!forceUpdate)
            {
                bool hasChanged = !CompressedElement.Compare(newCPos, lastSentCompressed);
                bitstream.WriteBool(hasChanged);
                // if no changes have occured we are done.
                if (!hasChanged)
                {
                    return;
                }
            }

            //TODO insert haschanged tests here
            for (int axis = 0; axis < 3; axis++)
            {
                if (axisRanges[axis].useAxis)
                {
                    highestChangedBit[axis] = CompressedElement.HighestDifferentBit(newCPos[axis], lastSentCompressed[axis]);
                }
            }

            for (int axis = 0; axis < 3; axis++)
            {
                if (axisRanges[axis].useAxis)
                {
                    if (compression == Compression.HalfFloat)
                    {
                        bitstream.WriteUInt(newCPos[axis], 16);
                    }

                    //else if (compression == Compression.Global)
                    //{
                    //	newCPos[axis].WriteCompressedAxisToBitstream(axis, ref bitstream, (cullUpperBits && !isKeyframe));
                    //}

                    else if (compression == Compression.LocalRange)
                    {
                        bitstream.WriteUInt(newCPos[axis], axisRanges[axis].bits);
                    }

                    else
                    {
                        bitstream.WriteUInt(newCPos[axis], 32);
                    }
                }
            }

            lastSentCompressed = newCPos;
        }