Exemple #1
0
        public override void MirrorToClients(ref UdpBitStream outstream, Frame frame, bool hasChanged)
        {
            // Write the used flag (if this is not a forced update) and determine if an update needs to be written.
            if (WriteUpdateFlag(ref outstream, frame, hasChanged) == false)
            {
                return;
            }

            if (rotationType == RotationType.Quaternion)
            {
                outstream.WriteULong(frame.elements[index].compTrans, totalBitsForQuat);
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    if (includedAxes.IsXYZ(i))
                    {
                        outstream.WriteUInt(frame.elements[index].compTrans[i], axes[i].bits);
                    }
                }
            }

            lastSentCompressed = frame.elements[index].compTrans;
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public void Pack(UdpBitStream buffer, UdpSocket socket)
        {
            buffer.WriteUShort(PadSequence(ObjSequence), 16);
            buffer.WriteUShort(PadSequence(AckSequence), 16);
            buffer.WriteULong(AckHistory, socket.Config.AckRedundancy);

            if (socket.Config.CalculateNetworkPing) {
                buffer.WriteUShort(AckTime, 16);
            }

            if (socket.Config.WritePacketBitSize) {
                buffer.WriteUShort(BitSize, 16);
            }
        }
Exemple #4
0
        public void Pack(UdpBitStream buffer, UdpSocket socket)
        {
            buffer.WriteUShort(PadSequence(ObjSequence), 16);
            buffer.WriteUShort(PadSequence(AckSequence), 16);
            buffer.WriteULong(AckHistory, socket.Config.AckRedundancy);

            if (socket.Config.CalculateNetworkPing)
            {
                buffer.WriteUShort(AckTime, 16);
            }

            if (socket.Config.WritePacketBitSize)
            {
                buffer.WriteUShort(BitSize, 16);
            }
        }
Exemple #5
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];
                    }
                }
            }
        }