Example #1
0
        void Network.IStreamWriter.WriteToStream(Player player, Network.ByteOutStream stream)
        {
            stream.WriteByte(HeaderBytes.ActorStateStream);
            stream.WriteUShort(Id);
            stream.WriteByte(StateStreamer.Size);

            StateStreamer.Pack(stream);
        }
Example #2
0
        public void Pack(Network.ByteOutStream stream)
        {
            Vector3    p;
            Quaternion r;
            byte       angle = 0;

            if (Actor.Context.IsServer)
            {
                p = position;
                r = rotation;

                if (yawOnly)
                {
                    angle = (byte)(yaw * 0.71111f);
                }
            }
            else
            {
                p = Actor.Transform.Position;
                r = Actor.Transform.Rotation;

                if (yawOnly)
                {
                    angle = (byte)(Vector3.SignedAngle(Vector3.Forward, Actor.Transform.Forward, Vector3.Up) * 0.71111f);
                }
            }

            if (compressPosition)
            {
                stream.WriteUShort(HalfUtilities.Pack(p.X));
                stream.WriteUShort(HalfUtilities.Pack(p.Y));
                stream.WriteUShort(HalfUtilities.Pack(p.Z));
            }
            else
            {
                stream.WriteVector3(p);
            }

            if (yawOnly)
            {
                stream.WriteByte(angle);
            }
            else
            {
                p = r.Axis;
                stream.WriteUShort(HalfUtilities.Pack(p.X));
                stream.WriteUShort(HalfUtilities.Pack(p.Y));
                stream.WriteUShort(HalfUtilities.Pack(p.Z));
                stream.WriteByte((byte)(r.Angle * SlimMath.Single.Rad2Deg * 0.71111f));
            }
        }
Example #3
0
        internal void PackSyncData(uint indexes, Network.ByteOutStream stream)
        {
            if (indexes == 0 || !IsActive)
            {
                return;
            }

            log.Debug("Sending data for {0}", Actor);

            stream.WriteByte(HeaderBytes.Synchronizable);
            stream.WriteActor(Actor);
            stream.WriteUShort((ushort)DataSize);
            stream.WriteUInt(indexes);

            for (int i = 0; i < Values.Length; ++i)
            {
                if ((indexes & ((uint)1 << i)) != 0)
                {
                    Values[i].Pack(stream);
                }
            }

            return;
        }