Ejemplo n.º 1
0
        public BasePacket Acquire()
        {
            BasePacket stream = null;

            lock (pool)
            {
                if (pool.Count > 0)
                {
                    stream = pool.Pop();
                }
            }

            if (stream == null)
            {
                stream      = new BasePacket(new byte[1500]);
                stream.pool = this;
            }

            NetAssert.True(stream.isPooled);

            stream.isPooled = false;
            stream.Position = 0;
            stream.Size     = (1500) << 3;

            return(stream);
        }
Ejemplo n.º 2
0
 public static void WriteUniqueId(this BasePacket stream, UniqueId id)
 {
     stream.WriteUInt(id.uint0);
     stream.WriteUInt(id.uint1);
     stream.WriteUInt(id.uint2);
     stream.WriteUInt(id.uint3);
 }
Ejemplo n.º 3
0
 public static void ReadRigidbody(this BasePacket stream, Rigidbody rigidbody)
 {
     rigidbody.position        = ReadVector3(stream);
     rigidbody.rotation        = ReadQuaternion(stream);
     rigidbody.velocity        = ReadVector3(stream);
     rigidbody.angularVelocity = ReadVector3(stream);
 }
Ejemplo n.º 4
0
 public static void WriteQuaternion(this BasePacket stream, Quaternion value)
 {
     stream.WriteFloat(value.x);
     stream.WriteFloat(value.y);
     stream.WriteFloat(value.z);
     stream.WriteFloat(value.w);
 }
Ejemplo n.º 5
0
 public static void WriteRigidbody(this BasePacket stream, Rigidbody rigidbody)
 {
     WriteVector3(stream, rigidbody.position);
     WriteQuaternion(stream, rigidbody.rotation);
     WriteVector3(stream, rigidbody.velocity);
     WriteVector3(stream, rigidbody.angularVelocity);
 }
Ejemplo n.º 6
0
 public static void WriteColorRGBA(this BasePacket stream, Color value)
 {
     stream.WriteFloat(value.r);
     stream.WriteFloat(value.g);
     stream.WriteFloat(value.b);
     stream.WriteFloat(value.a);
 }
Ejemplo n.º 7
0
 public static void WriteVector4(this BasePacket stream, Vector4 value)
 {
     stream.WriteFloat(value.x);
     stream.WriteFloat(value.y);
     stream.WriteFloat(value.z);
     stream.WriteFloat(value.w);
 }
Ejemplo n.º 8
0
 public static void WriteColor32RGBA(this BasePacket stream, Color32 value)
 {
     stream.WriteByte(value.r, 8);
     stream.WriteByte(value.g, 8);
     stream.WriteByte(value.b, 8);
     stream.WriteByte(value.a, 8);
 }
Ejemplo n.º 9
0
 public static void ReadRigidbody(this BasePacket stream, out Vector3 position, out Quaternion rotation, out Vector3 velocity, out Vector3 angularVelocity)
 {
     position        = ReadVector3(stream);
     rotation        = ReadQuaternion(stream);
     velocity        = ReadVector3(stream);
     angularVelocity = ReadVector3(stream);
 }
Ejemplo n.º 10
0
 public static void WriteRect(this BasePacket stream, Rect rect)
 {
     stream.WriteFloat(rect.xMin);
     stream.WriteFloat(rect.yMin);
     stream.WriteFloat(rect.width);
     stream.WriteFloat(rect.height);
 }
Ejemplo n.º 11
0
 public static void WriteEntity(this BasePacket packet, Entity entity)
 {
     if (packet.WriteBool((entity != null) && entity.IsAttached))
     {
         packet.WriteNetworkId(entity.NetworkId);
     }
 }
Ejemplo n.º 12
0
 public static void WriteContinueMarker(this BasePacket stream)
 {
     if (stream.CanWrite())
     {
         stream.WriteBool(true);
     }
 }
Ejemplo n.º 13
0
 public static void WriteStopMarker(this BasePacket stream)
 {
     if (stream.CanWrite())
     {
         stream.WriteBool(false);
     }
 }
Ejemplo n.º 14
0
 public static Plane ReadPlane(this BasePacket stream)
 {
     return(new Plane(
                ReadVector3(stream),
                stream.ReadFloat()
                ));
 }
Ejemplo n.º 15
0
 public static Ray ReadRay(this BasePacket stream)
 {
     return(new Ray(
                ReadVector3(stream),
                ReadVector3(stream)
                ));
 }
Ejemplo n.º 16
0
        public static NetworkId ReadNetworkId(this BasePacket packet)
        {
            uint connection = packet.ReadUIntVB();
            uint entity     = packet.ReadUIntVB();

            NetAssert.True(connection != uint.MaxValue);
            return(new NetworkId(connection, entity));
        }
Ejemplo n.º 17
0
        public static bool ReadStopMarker(this BasePacket stream)
        {
            if (stream.CanRead())
            {
                return(stream.ReadBool());
            }

            return(false);
        }
Ejemplo n.º 18
0
        public static Entity ReadEntity(this BasePacket packet)
        {
            if (packet.ReadBool())
            {
                return(Core.FindEntity(packet.ReadNetworkId()));
            }

            return(null);
        }
Ejemplo n.º 19
0
 public static Rect ReadRect(this BasePacket stream)
 {
     return(new Rect(
                stream.ReadFloat(),
                stream.ReadFloat(),
                stream.ReadFloat(),
                stream.ReadFloat()
                ));
 }
Ejemplo n.º 20
0
        public static AscensionEntity ReadBoltEntity(this BasePacket packet)
        {
            Entity entity = ReadEntity(packet);

            if (entity)
            {
                return(entity.UnityObject);
            }

            return(null);
        }
Ejemplo n.º 21
0
        public static UniqueId ReadUniqueId(this BasePacket stream)
        {
            UniqueId id;

            id       = default(UniqueId);
            id.uint0 = stream.ReadUInt();
            id.uint1 = stream.ReadUInt();
            id.uint2 = stream.ReadUInt();
            id.uint3 = stream.ReadUInt();

            return(id);
        }
Ejemplo n.º 22
0
        public void Release(BasePacket stream)
        {
            NetAssert.False(stream.isPooled);

            lock (pool)
            {
                stream.Size     = 0;
                stream.Position = 0;
                stream.isPooled = true;

                pool.Push(stream);
            }
        }
Ejemplo n.º 23
0
        public static void WriteByteArraySimple(this BasePacket stream, byte[] array, int maxLength)
        {
            if (stream.WriteBool(array != null))
            {
                int length = Mathf.Min(array.Length, maxLength);

                if (length < array.Length)
                {
                    NetLog.Warn("Only sending {0}/{1} bytes from byte array", length, array.Length);
                }

                stream.WriteUShort((ushort)length);
                stream.WriteByteArray(array, 0, length);
            }
        }
Ejemplo n.º 24
0
        public static byte[] ReadByteArraySimple(this BasePacket stream)
        {
            if (stream.ReadBool())
            {
                int    length = stream.ReadUShort();
                byte[] data   = new byte[length];

                stream.ReadByteArray(data, 0, data.Length);

                return(data);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 25
0
        public static uint ReadUIntVB(this BasePacket packet)
        {
            uint v = 0U;
            uint b = 0U;

            int s = 0;

            do
            {
                b = packet.ReadByte();
                v = v | ((b & 127U) << s);
                s = s + 7;
            } while (b > 127U);

            return(v);
        }
Ejemplo n.º 26
0
        public static ulong ReadULongVB(this BasePacket p)
        {
            ulong v = 0U;
            ulong b = 0U;

            int s = 0;

            do
            {
                b = p.ReadByte();
                v = v | ((b & 127U) << s);
                s = s + 7;
            } while (b > 127U);

            return(v);
        }
Ejemplo n.º 27
0
        public static void WriteUIntVB(this BasePacket packet, uint v)
        {
            uint b = 0U;

            do
            {
                b = v & 127U;
                v = v >> 7;

                if (v > 0)
                {
                    b |= 128U;
                }

                packet.WriteByte((byte)b);
            } while (v != 0);
        }
Ejemplo n.º 28
0
        public static void WriteULongVB(this BasePacket p, ulong v)
        {
            ulong b = 0U;

            do
            {
                b = v & 127U;
                v = v >> 7;

                if (v > 0)
                {
                    b |= 128U;
                }

                p.WriteByte((byte)b);
            } while (v != 0);
        }
Ejemplo n.º 29
0
 public static void WriteMatrix4x4(this BasePacket stream, Matrix4x4 m)
 {
     stream.WriteFloat(m.m00);
     stream.WriteFloat(m.m01);
     stream.WriteFloat(m.m02);
     stream.WriteFloat(m.m03);
     stream.WriteFloat(m.m10);
     stream.WriteFloat(m.m11);
     stream.WriteFloat(m.m12);
     stream.WriteFloat(m.m13);
     stream.WriteFloat(m.m20);
     stream.WriteFloat(m.m21);
     stream.WriteFloat(m.m22);
     stream.WriteFloat(m.m23);
     stream.WriteFloat(m.m30);
     stream.WriteFloat(m.m31);
     stream.WriteFloat(m.m32);
     stream.WriteFloat(m.m33);
 }
Ejemplo n.º 30
0
        public static Matrix4x4 ReadMatrix4x4(this BasePacket stream)
        {
            Matrix4x4 m = default(Matrix4x4);

            m.m00 = stream.ReadFloat();
            m.m01 = stream.ReadFloat();
            m.m02 = stream.ReadFloat();
            m.m03 = stream.ReadFloat();
            m.m10 = stream.ReadFloat();
            m.m11 = stream.ReadFloat();
            m.m12 = stream.ReadFloat();
            m.m13 = stream.ReadFloat();
            m.m20 = stream.ReadFloat();
            m.m21 = stream.ReadFloat();
            m.m22 = stream.ReadFloat();
            m.m23 = stream.ReadFloat();
            m.m30 = stream.ReadFloat();
            m.m31 = stream.ReadFloat();
            m.m32 = stream.ReadFloat();
            m.m33 = stream.ReadFloat();
            return(m);
        }