Ejemplo n.º 1
0
        public override bool Write(ref UdpBitStream bitstream, Frame frame)
        {
            // Base class does some forceUpdate checking, keep it around.
            bool         forceUpdate = IsUpdateForced(frame);
            ElementFrame e           = frames[frame.frameid];

            e.compXform = Compress();
            e.xform     = Localized;
            CompressedElement newComp = e.compXform;

            if (rotationType == RotationType.Quaternion)
            {
                // For frames between forced updates, we need to first send a flag bit for if this element is being sent
                if (!forceUpdate)
                {
                    bool hasChanged = newComp.quat != lastSentCompressed.quat && sendCullMask.OnChanges();
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return(false);
                    }
                }

                bitstream.WriteULong(newComp.quat, totalBitsForQuat);

                lastSentCompressed.quat = newComp.quat;
                lastSentTransform       = e.xform;

                return(true);
            }

            else
            {
                // 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(newComp, lastSentCompressed) && sendCullMask.OnChanges();
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return(false);
                    }
                }

                for (int axis = 0; axis < 3; axis++)
                {
                    if (includedAxes.IsXYZ(axis))
                    {
                        bitstream.WriteUInt(newComp[axis], axes[axis].bits);
                        lastSentCompressed[axis] = newComp[axis];
                    }
                }

                return(true);
            }
        }
Ejemplo n.º 2
0
        public override void WriteToBitstream(ref UdpBitStream bitstream, MsgType msgType, bool forceUpdate, bool isKeyframe)
        {
            // Base class does some forceUpdate checking, keep it around.
            //forceUpdate = base.WriteToBitstream(ref bitstream, msgType, forceUpdate);
            //bool hasChanged = false;

            if (rotationType == XType.Quaternion)
            {
                ulong compressedQuat = QuatCompress.CompressQuatToBitsBuffer(Localized, totalBitsForQuat);

                // For frames between forced updates, we need to first send a flag bit for if this element is being sent
                if (!forceUpdate)
                {
                    bool hasChanged = compressedQuat != lastSentCompressed;
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return;
                    }
                }

                bitstream.WriteULong(compressedQuat, totalBitsForQuat);
                lastSentCompressed = compressedQuat;
                return;
            }

            else
            {
                // Euler types...

                CompressedElement newValues = new CompressedElement(0, 0, 0);

                // populate the new compressed position, and test if any of the axes have changed.
                for (int axis = 0; axis < 3; axis++)
                {
                    if (rotationType.IsXYZ(axis))
                    {
                        newValues[axis] = CompressFloat(((Vector3)Localized)[axis], axis);
                    }
                }

                // 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(newValues, lastSentCompressed);
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return;
                    }
                }

                for (int axis = 0; axis < 3; axis++)
                {
                    if (rotationType.IsXYZ(axis))
                    {
                        bitstream.WriteUInt(newValues[axis], xyzBits[axis]);
                        lastSentCompressed[axis] = newValues[axis];
                    }
                }
            }
        }