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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public static void WriteEntity(this BasePacket packet, Entity entity) { if (packet.WriteBool((entity != null) && entity.IsAttached)) { packet.WriteNetworkId(entity.NetworkId); } }
public static void WriteContinueMarker(this BasePacket stream) { if (stream.CanWrite()) { stream.WriteBool(true); } }
public static void WriteStopMarker(this BasePacket stream) { if (stream.CanWrite()) { stream.WriteBool(false); } }
public static Plane ReadPlane(this BasePacket stream) { return(new Plane( ReadVector3(stream), stream.ReadFloat() )); }
public static Ray ReadRay(this BasePacket stream) { return(new Ray( ReadVector3(stream), ReadVector3(stream) )); }
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)); }
public static bool ReadStopMarker(this BasePacket stream) { if (stream.CanRead()) { return(stream.ReadBool()); } return(false); }
public static Entity ReadEntity(this BasePacket packet) { if (packet.ReadBool()) { return(Core.FindEntity(packet.ReadNetworkId())); } return(null); }
public static Rect ReadRect(this BasePacket stream) { return(new Rect( stream.ReadFloat(), stream.ReadFloat(), stream.ReadFloat(), stream.ReadFloat() )); }
public static AscensionEntity ReadBoltEntity(this BasePacket packet) { Entity entity = ReadEntity(packet); if (entity) { return(entity.UnityObject); } return(null); }
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); }
public void Release(BasePacket stream) { NetAssert.False(stream.isPooled); lock (pool) { stream.Size = 0; stream.Position = 0; stream.isPooled = true; pool.Push(stream); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
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); }
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); }