From 46539ef81638bde7d608c054897f13a78d24ace9 Mon Sep 17 00:00:00 2001 From: vis2k Date: Tue, 18 May 2021 13:22:32 +0800 Subject: [PATCH] NetworkWriter API cleanup: WriteInt16 => WriteShort etc. --- .../Discovery/NetworkDiscoveryBase.cs | 8 +- Assets/Mirror/Components/NetworkAnimator.cs | 18 +- .../Mirror/Components/NetworkTransformBase.cs | 4 +- Assets/Mirror/Editor/Weaver/Writers.cs | 5 +- Assets/Mirror/Runtime/MessagePacking.cs | 2 +- Assets/Mirror/Runtime/NetworkBehaviour.cs | 2 +- Assets/Mirror/Runtime/NetworkIdentity.cs | 4 +- Assets/Mirror/Runtime/NetworkWriter.cs | 174 ++++++++++-------- Assets/Mirror/Runtime/SyncDictionary.cs | 8 +- Assets/Mirror/Runtime/SyncList.cs | 10 +- Assets/Mirror/Runtime/SyncSet.cs | 6 +- .../Tests/Editor/ClientSceneTests_OnSpawn.cs | 2 +- Assets/Mirror/Tests/Editor/CustomRWTest.cs | 2 +- .../Mirror/Tests/Editor/EnumReadWriteTests.cs | 4 +- .../Editor/NetworkBehaviourSerializeTest.cs | 6 +- .../Tests/Editor/NetworkIdentityTests.cs | 6 +- .../Tests/Editor/NetworkMessageTests.cs | 2 +- .../Mirror/Tests/Editor/NetworkServerTest.cs | 2 +- .../Editor/NetworkWriterCollectionTest.cs | 2 +- .../Mirror/Tests/Editor/NetworkWriterTest.cs | 44 ++--- .../ExtraAssembly/SomeDataWithWriter.cs | 2 +- .../WeaverGeneratedReaderWriterTests.cs | 2 +- 22 files changed, 171 insertions(+), 144 deletions(-) diff --git a/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs b/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs index 47796a1b1..d5a160011 100644 --- a/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs +++ b/Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs @@ -30,11 +30,11 @@ public abstract class NetworkDiscoveryBase : MonoBehaviour [SerializeField] [Tooltip("The UDP port the server will listen for multi-cast messages")] protected int serverBroadcastListenPort = 47777; - + [SerializeField] [Tooltip("If true, broadcasts a discovery request every ActiveDiscoveryInterval seconds")] public bool enableActiveDiscovery = true; - + [SerializeField] [Tooltip("Time in seconds between multi-cast messages")] [Range(1, 60)] @@ -195,7 +195,7 @@ protected virtual void ProcessClientRequest(Request request, IPEndPoint endpoint { try { - writer.WriteInt64(secretHandshake); + writer.WriteLong(secretHandshake); writer.Write(info); @@ -302,7 +302,7 @@ public void BroadcastDiscoveryRequest() using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter()) { - writer.WriteInt64(secretHandshake); + writer.WriteLong(secretHandshake); try { diff --git a/Assets/Mirror/Components/NetworkAnimator.cs b/Assets/Mirror/Components/NetworkAnimator.cs index 64042e7bd..cea62515e 100644 --- a/Assets/Mirror/Components/NetworkAnimator.cs +++ b/Assets/Mirror/Components/NetworkAnimator.cs @@ -311,7 +311,7 @@ ulong NextDirtyBits() bool WriteParameters(NetworkWriter writer, bool forceAll = false) { ulong dirtyBits = forceAll ? (~0ul) : NextDirtyBits(); - writer.WriteUInt64(dirtyBits); + writer.WriteULong(dirtyBits); for (int i = 0; i < parameters.Length; i++) { if ((dirtyBits & (1ul << i)) == 0) @@ -321,17 +321,17 @@ bool WriteParameters(NetworkWriter writer, bool forceAll = false) if (par.type == AnimatorControllerParameterType.Int) { int newIntValue = animator.GetInteger(par.nameHash); - writer.WriteInt32(newIntValue); + writer.WriteInt(newIntValue); } else if (par.type == AnimatorControllerParameterType.Float) { float newFloatValue = animator.GetFloat(par.nameHash); - writer.WriteSingle(newFloatValue); + writer.WriteFloat(newFloatValue); } else if (par.type == AnimatorControllerParameterType.Bool) { bool newBoolValue = animator.GetBool(par.nameHash); - writer.WriteBoolean(newBoolValue); + writer.WriteBool(newBoolValue); } } return dirtyBits != 0; @@ -386,16 +386,16 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState) if (animator.IsInTransition(i)) { AnimatorStateInfo st = animator.GetNextAnimatorStateInfo(i); - writer.WriteInt32(st.fullPathHash); - writer.WriteSingle(st.normalizedTime); + writer.WriteInt(st.fullPathHash); + writer.WriteFloat(st.normalizedTime); } else { AnimatorStateInfo st = animator.GetCurrentAnimatorStateInfo(i); - writer.WriteInt32(st.fullPathHash); - writer.WriteSingle(st.normalizedTime); + writer.WriteInt(st.fullPathHash); + writer.WriteFloat(st.normalizedTime); } - writer.WriteSingle(animator.GetLayerWeight(i)); + writer.WriteFloat(animator.GetLayerWeight(i)); } WriteParameters(writer, initialState); return true; diff --git a/Assets/Mirror/Components/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransformBase.cs index 9fe6512b5..e14fedfea 100644 --- a/Assets/Mirror/Components/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransformBase.cs @@ -100,7 +100,7 @@ public static void SerializeIntoWriter(NetworkWriter writer, Vector3 position, Q if (compressRotation) { // smalles three compression for 3D - writer.WriteUInt32(Compression.CompressQuaternion(rotation)); + writer.WriteUInt(Compression.CompressQuaternion(rotation)); } else { @@ -146,7 +146,7 @@ void DeserializeFromReader(NetworkReader reader) localScale = targetComponent.localScale, timeStamp = Time.time }; - + if (syncScale) { // Reader length is checked here, 12 is used as thats the current Vector3 (3 floats) amount. diff --git a/Assets/Mirror/Editor/Weaver/Writers.cs b/Assets/Mirror/Editor/Weaver/Writers.cs index f3cc8bc24..c813b66ed 100644 --- a/Assets/Mirror/Editor/Weaver/Writers.cs +++ b/Assets/Mirror/Editor/Weaver/Writers.cs @@ -19,7 +19,10 @@ public static void Register(TypeReference dataType, MethodReference methodRefere { if (writeFuncs.ContainsKey(dataType)) { - Weaver.Warning($"Registering a Write method for {dataType.FullName} when one already exists", methodReference); + // TODO enable this again later. + // Writer has some obsolete functions that were renamed. + // Don't want weaver warnings for all of them. + //Weaver.Warning($"Registering a Write method for {dataType.FullName} when one already exists", methodReference); } // we need to import type when we Initialize Writers so import here in case it is used anywhere else diff --git a/Assets/Mirror/Runtime/MessagePacking.cs b/Assets/Mirror/Runtime/MessagePacking.cs index 47c212c09..e74a2e3ce 100644 --- a/Assets/Mirror/Runtime/MessagePacking.cs +++ b/Assets/Mirror/Runtime/MessagePacking.cs @@ -34,7 +34,7 @@ public static void Pack(T message, NetworkWriter writer) where T : struct, NetworkMessage { ushort msgType = GetId(); - writer.WriteUInt16(msgType); + writer.WriteUShort(msgType); // serialize message into writer writer.Write(message); diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index 6a5f36e54..77e418c19 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -640,7 +640,7 @@ public bool SerializeObjectsDelta(NetworkWriter writer) { bool dirty = false; // write the mask - writer.WriteUInt64(DirtyObjectBits()); + writer.WriteULong(DirtyObjectBits()); // serializable objects, such as synclists for (int i = 0; i < syncObjects.Count; i++) { diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index 35285c386..6e0b98d18 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -816,7 +816,7 @@ bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, bool initial // (jumping back later is WAY faster than allocating a temporary // writer for the payload, then writing payload.size, payload) int headerPosition = writer.Position; - writer.WriteInt32(0); + writer.WriteInt(0); int contentPosition = writer.Position; // write payload @@ -834,7 +834,7 @@ bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, bool initial // fill in length now writer.Position = headerPosition; - writer.WriteInt32(endPosition - contentPosition); + writer.WriteInt(endPosition - contentPosition); writer.Position = endPosition; // Debug.Log("OnSerializeSafely written for object=" + comp.name + " component=" + comp.GetType() + " sceneId=" + sceneId.ToString("X") + "header@" + headerPosition + " content@" + contentPosition + " end@" + endPosition + " contentSize=" + (endPosition - contentPosition)); diff --git a/Assets/Mirror/Runtime/NetworkWriter.cs b/Assets/Mirror/Runtime/NetworkWriter.cs index 25a6cc847..9881bdb37 100644 --- a/Assets/Mirror/Runtime/NetworkWriter.cs +++ b/Assets/Mirror/Runtime/NetworkWriter.cs @@ -103,19 +103,31 @@ public static class NetworkWriterExtensions public static void WriteSByte(this NetworkWriter writer, sbyte value) => writer.WriteByte((byte)value); - public static void WriteChar(this NetworkWriter writer, char value) => writer.WriteUInt16(value); + public static void WriteChar(this NetworkWriter writer, char value) => writer.WriteUShort(value); - public static void WriteBoolean(this NetworkWriter writer, bool value) => writer.WriteByte((byte)(value ? 1 : 0)); + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteBool instead.")] + public static void WriteBoolean(this NetworkWriter writer, bool value) => writer.WriteBool(value); + public static void WriteBool(this NetworkWriter writer, bool value) => writer.WriteByte((byte)(value ? 1 : 0)); - public static void WriteUInt16(this NetworkWriter writer, ushort value) + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteUShort instead.")] + public static void WriteUInt16(this NetworkWriter writer, ushort value) => writer.WriteUShort(value); + public static void WriteUShort(this NetworkWriter writer, ushort value) { writer.WriteByte((byte)value); writer.WriteByte((byte)(value >> 8)); } - public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteUInt16((ushort)value); + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteShort instead.")] + public static void WriteInt16(this NetworkWriter writer, short value) => writer.WriteShort(value); + public static void WriteShort(this NetworkWriter writer, short value) => writer.WriteUShort((ushort)value); - public static void WriteUInt32(this NetworkWriter writer, uint value) + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteUInt instead.")] + public static void WriteUInt32(this NetworkWriter writer, uint value) => writer.WriteUInt(value); + public static void WriteUInt(this NetworkWriter writer, uint value) { writer.WriteByte((byte)value); writer.WriteByte((byte)(value >> 8)); @@ -123,9 +135,15 @@ public static void WriteUInt32(this NetworkWriter writer, uint value) writer.WriteByte((byte)(value >> 24)); } - public static void WriteInt32(this NetworkWriter writer, int value) => writer.WriteUInt32((uint)value); + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteInt instead.")] + public static void WriteInt32(this NetworkWriter writer, int value) => writer.WriteInt(value); + public static void WriteInt(this NetworkWriter writer, int value) => writer.WriteUInt((uint)value); - public static void WriteUInt64(this NetworkWriter writer, ulong value) + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteULong instead.")] + public static void WriteUInt64(this NetworkWriter writer, ulong value) => writer.WriteULong(value); + public static void WriteULong(this NetworkWriter writer, ulong value) { writer.WriteByte((byte)value); writer.WriteByte((byte)(value >> 8)); @@ -137,15 +155,21 @@ public static void WriteUInt64(this NetworkWriter writer, ulong value) writer.WriteByte((byte)(value >> 56)); } - public static void WriteInt64(this NetworkWriter writer, long value) => writer.WriteUInt64((ulong)value); + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteLong instead.")] + public static void WriteInt64(this NetworkWriter writer, long value) => writer.WriteLong(value); + public static void WriteLong(this NetworkWriter writer, long value) => writer.WriteULong((ulong)value); - public static void WriteSingle(this NetworkWriter writer, float value) + // Deprecated 2021-05-18 + [Obsolete("We've cleaned up the API. Use WriteFloat instead.")] + public static void WriteSingle(this NetworkWriter writer, float value) => writer.WriteFloat(value); + public static void WriteFloat(this NetworkWriter writer, float value) { UIntFloat converter = new UIntFloat { floatValue = value }; - writer.WriteUInt32(converter.intValue); + writer.WriteUInt(converter.intValue); } public static void WriteDouble(this NetworkWriter writer, double value) @@ -154,7 +178,7 @@ public static void WriteDouble(this NetworkWriter writer, double value) { doubleValue = value }; - writer.WriteUInt64(converter.longValue); + writer.WriteULong(converter.longValue); } public static void WriteDecimal(this NetworkWriter writer, decimal value) @@ -166,8 +190,8 @@ public static void WriteDecimal(this NetworkWriter writer, decimal value) { decimalValue = value }; - writer.WriteUInt64(converter.longValue1); - writer.WriteUInt64(converter.longValue2); + writer.WriteULong(converter.longValue1); + writer.WriteULong(converter.longValue2); } public static void WriteString(this NetworkWriter writer, string value) @@ -178,7 +202,7 @@ public static void WriteString(this NetworkWriter writer, string value) // on the client) if (value == null) { - writer.WriteUInt16(0); + writer.WriteUShort(0); return; } @@ -193,7 +217,7 @@ public static void WriteString(this NetworkWriter writer, string value) } // write size and bytes - writer.WriteUInt16(checked((ushort)(size + 1))); + writer.WriteUShort(checked((ushort)(size + 1))); writer.WriteBytes(stringBuffer, 0, size); } @@ -206,10 +230,10 @@ public static void WriteBytesAndSize(this NetworkWriter writer, byte[] buffer, i // (using size=-1 for null would limit max size to 32kb instead of 64kb) if (buffer == null) { - writer.WriteUInt32(0u); + writer.WriteUInt(0u); return; } - writer.WriteUInt32(checked((uint)count) + 1u); + writer.WriteUInt(checked((uint)count) + 1u); writer.WriteBytes(buffer, offset, count); } @@ -228,44 +252,44 @@ public static void WriteBytesAndSizeSegment(this NetworkWriter writer, ArraySegm public static void WriteVector2(this NetworkWriter writer, Vector2 value) { - writer.WriteSingle(value.x); - writer.WriteSingle(value.y); + writer.WriteFloat(value.x); + writer.WriteFloat(value.y); } public static void WriteVector3(this NetworkWriter writer, Vector3 value) { - writer.WriteSingle(value.x); - writer.WriteSingle(value.y); - writer.WriteSingle(value.z); + writer.WriteFloat(value.x); + writer.WriteFloat(value.y); + writer.WriteFloat(value.z); } public static void WriteVector4(this NetworkWriter writer, Vector4 value) { - writer.WriteSingle(value.x); - writer.WriteSingle(value.y); - writer.WriteSingle(value.z); - writer.WriteSingle(value.w); + writer.WriteFloat(value.x); + writer.WriteFloat(value.y); + writer.WriteFloat(value.z); + writer.WriteFloat(value.w); } public static void WriteVector2Int(this NetworkWriter writer, Vector2Int value) { - writer.WriteInt32(value.x); - writer.WriteInt32(value.y); + writer.WriteInt(value.x); + writer.WriteInt(value.y); } public static void WriteVector3Int(this NetworkWriter writer, Vector3Int value) { - writer.WriteInt32(value.x); - writer.WriteInt32(value.y); - writer.WriteInt32(value.z); + writer.WriteInt(value.x); + writer.WriteInt(value.y); + writer.WriteInt(value.z); } public static void WriteColor(this NetworkWriter writer, Color value) { - writer.WriteSingle(value.r); - writer.WriteSingle(value.g); - writer.WriteSingle(value.b); - writer.WriteSingle(value.a); + writer.WriteFloat(value.r); + writer.WriteFloat(value.g); + writer.WriteFloat(value.b); + writer.WriteFloat(value.a); } public static void WriteColor32(this NetworkWriter writer, Color32 value) @@ -278,24 +302,24 @@ public static void WriteColor32(this NetworkWriter writer, Color32 value) public static void WriteQuaternion(this NetworkWriter writer, Quaternion value) { - writer.WriteSingle(value.x); - writer.WriteSingle(value.y); - writer.WriteSingle(value.z); - writer.WriteSingle(value.w); + writer.WriteFloat(value.x); + writer.WriteFloat(value.y); + writer.WriteFloat(value.z); + writer.WriteFloat(value.w); } public static void WriteRect(this NetworkWriter writer, Rect value) { - writer.WriteSingle(value.xMin); - writer.WriteSingle(value.yMin); - writer.WriteSingle(value.width); - writer.WriteSingle(value.height); + writer.WriteFloat(value.xMin); + writer.WriteFloat(value.yMin); + writer.WriteFloat(value.width); + writer.WriteFloat(value.height); } public static void WritePlane(this NetworkWriter writer, Plane value) { writer.WriteVector3(value.normal); - writer.WriteSingle(value.distance); + writer.WriteFloat(value.distance); } public static void WriteRay(this NetworkWriter writer, Ray value) @@ -306,22 +330,22 @@ public static void WriteRay(this NetworkWriter writer, Ray value) public static void WriteMatrix4x4(this NetworkWriter writer, Matrix4x4 value) { - writer.WriteSingle(value.m00); - writer.WriteSingle(value.m01); - writer.WriteSingle(value.m02); - writer.WriteSingle(value.m03); - writer.WriteSingle(value.m10); - writer.WriteSingle(value.m11); - writer.WriteSingle(value.m12); - writer.WriteSingle(value.m13); - writer.WriteSingle(value.m20); - writer.WriteSingle(value.m21); - writer.WriteSingle(value.m22); - writer.WriteSingle(value.m23); - writer.WriteSingle(value.m30); - writer.WriteSingle(value.m31); - writer.WriteSingle(value.m32); - writer.WriteSingle(value.m33); + writer.WriteFloat(value.m00); + writer.WriteFloat(value.m01); + writer.WriteFloat(value.m02); + writer.WriteFloat(value.m03); + writer.WriteFloat(value.m10); + writer.WriteFloat(value.m11); + writer.WriteFloat(value.m12); + writer.WriteFloat(value.m13); + writer.WriteFloat(value.m20); + writer.WriteFloat(value.m21); + writer.WriteFloat(value.m22); + writer.WriteFloat(value.m23); + writer.WriteFloat(value.m30); + writer.WriteFloat(value.m31); + writer.WriteFloat(value.m32); + writer.WriteFloat(value.m33); } public static void WriteGuid(this NetworkWriter writer, Guid value) @@ -334,20 +358,20 @@ public static void WriteNetworkIdentity(this NetworkWriter writer, NetworkIdenti { if (value == null) { - writer.WriteUInt32(0); + writer.WriteUInt(0); return; } - writer.WriteUInt32(value.netId); + writer.WriteUInt(value.netId); } public static void WriteNetworkBehaviour(this NetworkWriter writer, NetworkBehaviour value) { if (value == null) { - writer.WriteUInt32(0); + writer.WriteUInt(0); return; } - writer.WriteUInt32(value.netId); + writer.WriteUInt(value.netId); writer.WriteByte((byte)value.ComponentIndex); } @@ -355,18 +379,18 @@ public static void WriteTransform(this NetworkWriter writer, Transform value) { if (value == null) { - writer.WriteUInt32(0); + writer.WriteUInt(0); return; } NetworkIdentity identity = value.GetComponent(); if (identity != null) { - writer.WriteUInt32(identity.netId); + writer.WriteUInt(identity.netId); } else { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); - writer.WriteUInt32(0); + writer.WriteUInt(0); } } @@ -374,18 +398,18 @@ public static void WriteGameObject(this NetworkWriter writer, GameObject value) { if (value == null) { - writer.WriteUInt32(0); + writer.WriteUInt(0); return; } NetworkIdentity identity = value.GetComponent(); if (identity != null) { - writer.WriteUInt32(identity.netId); + writer.WriteUInt(identity.netId); } else { Debug.LogWarning("NetworkWriter " + value + " has no NetworkIdentity"); - writer.WriteUInt32(0); + writer.WriteUInt(0); } } @@ -398,10 +422,10 @@ public static void WriteList(this NetworkWriter writer, List list) { if (list is null) { - writer.WriteInt32(-1); + writer.WriteInt(-1); return; } - writer.WriteInt32(list.Count); + writer.WriteInt(list.Count); for (int i = 0; i < list.Count; i++) writer.Write(list[i]); } @@ -410,10 +434,10 @@ public static void WriteArray(this NetworkWriter writer, T[] array) { if (array is null) { - writer.WriteInt32(-1); + writer.WriteInt(-1); return; } - writer.WriteInt32(array.Length); + writer.WriteInt(array.Length); for (int i = 0; i < array.Length; i++) writer.Write(array[i]); } @@ -421,7 +445,7 @@ public static void WriteArray(this NetworkWriter writer, T[] array) public static void WriteArraySegment(this NetworkWriter writer, ArraySegment segment) { int length = segment.Count; - writer.WriteInt32(length); + writer.WriteInt(length); for (int i = 0; i < length; i++) { writer.Write(segment.Array[segment.Offset + i]); diff --git a/Assets/Mirror/Runtime/SyncDictionary.cs b/Assets/Mirror/Runtime/SyncDictionary.cs index 437137126..14ff268ec 100644 --- a/Assets/Mirror/Runtime/SyncDictionary.cs +++ b/Assets/Mirror/Runtime/SyncDictionary.cs @@ -84,8 +84,8 @@ void AddOperation(Operation op, TKey key, TValue item) public void OnSerializeAll(NetworkWriter writer) { - // if init, write the full list content - writer.WriteUInt32((uint)objects.Count); + // if init, write the full list content + writer.WriteUInt((uint)objects.Count); foreach (KeyValuePair syncItem in objects) { @@ -97,13 +97,13 @@ public void OnSerializeAll(NetworkWriter writer) // thus the client will need to skip all the pending changes // or they would be applied again. // So we write how many changes are pending - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); } public void OnSerializeDelta(NetworkWriter writer) { // write all the queued up changes - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); for (int i = 0; i < changes.Count; i++) { diff --git a/Assets/Mirror/Runtime/SyncList.cs b/Assets/Mirror/Runtime/SyncList.cs index a9f3699ab..4c6f679a6 100644 --- a/Assets/Mirror/Runtime/SyncList.cs +++ b/Assets/Mirror/Runtime/SyncList.cs @@ -108,7 +108,7 @@ void AddOperation(Operation op, int itemIndex, T oldItem, T newItem) public void OnSerializeAll(NetworkWriter writer) { // if init, write the full list content - writer.WriteUInt32((uint)objects.Count); + writer.WriteUInt((uint)objects.Count); for (int i = 0; i < objects.Count; i++) { @@ -120,13 +120,13 @@ public void OnSerializeAll(NetworkWriter writer) // thus the client will need to skip all the pending changes // or they would be applied again. // So we write how many changes are pending - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); } public void OnSerializeDelta(NetworkWriter writer) { // write all the queued up changes - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); for (int i = 0; i < changes.Count; i++) { @@ -143,12 +143,12 @@ public void OnSerializeDelta(NetworkWriter writer) break; case Operation.OP_REMOVEAT: - writer.WriteUInt32((uint)change.index); + writer.WriteUInt((uint)change.index); break; case Operation.OP_INSERT: case Operation.OP_SET: - writer.WriteUInt32((uint)change.index); + writer.WriteUInt((uint)change.index); writer.Write(change.item); break; } diff --git a/Assets/Mirror/Runtime/SyncSet.cs b/Assets/Mirror/Runtime/SyncSet.cs index d8a8c47d5..0c98d065d 100644 --- a/Assets/Mirror/Runtime/SyncSet.cs +++ b/Assets/Mirror/Runtime/SyncSet.cs @@ -76,7 +76,7 @@ void AddOperation(Operation op, T item) public void OnSerializeAll(NetworkWriter writer) { // if init, write the full list content - writer.WriteUInt32((uint)objects.Count); + writer.WriteUInt((uint)objects.Count); foreach (T obj in objects) { @@ -87,13 +87,13 @@ public void OnSerializeAll(NetworkWriter writer) // thus the client will need to skip all the pending changes // or they would be applied again. // So we write how many changes are pending - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); } public void OnSerializeDelta(NetworkWriter writer) { // write all the queued up changes - writer.WriteUInt32((uint)changes.Count); + writer.WriteUInt((uint)changes.Count); for (int i = 0; i < changes.Count; i++) { diff --git a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs index 2f1e0f5c1..5cb85da0d 100644 --- a/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs +++ b/Assets/Mirror/Tests/Editor/ClientSceneTests_OnSpawn.cs @@ -18,7 +18,7 @@ public override bool OnSerialize(NetworkWriter writer, bool initialState) { base.OnSerialize(writer, initialState); - writer.WriteInt32(value); + writer.WriteInt(value); writer.WriteVector3(direction); OnSerializeCalled?.Invoke(); diff --git a/Assets/Mirror/Tests/Editor/CustomRWTest.cs b/Assets/Mirror/Tests/Editor/CustomRWTest.cs index 1674aa4e1..972b2d3e0 100644 --- a/Assets/Mirror/Tests/Editor/CustomRWTest.cs +++ b/Assets/Mirror/Tests/Editor/CustomRWTest.cs @@ -21,7 +21,7 @@ public static class MockQuestReaderWriter { public static void WriteQuest(this NetworkWriter writer, MockQuest quest) { - writer.WriteInt32(quest.Id); + writer.WriteInt(quest.Id); } public static MockQuest WriteQuest(this NetworkReader reader) { diff --git a/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs b/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs index 36c4699ed..1b75b2ee5 100644 --- a/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs +++ b/Assets/Mirror/Tests/Editor/EnumReadWriteTests.cs @@ -9,11 +9,11 @@ public static void WriteMyCustomEnum(this NetworkWriter networkWriter, EnumReadW // if O write N if (customEnum == EnumReadWriteTests.MyCustomEnum.O) { - networkWriter.WriteInt32((int)EnumReadWriteTests.MyCustomEnum.N); + networkWriter.WriteInt((int)EnumReadWriteTests.MyCustomEnum.N); } else { - networkWriter.WriteInt32((int)customEnum); + networkWriter.WriteInt((int)customEnum); } } public static EnumReadWriteTests.MyCustomEnum ReadMyCustomEnum(this NetworkReader networkReader) diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourSerializeTest.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourSerializeTest.cs index 70130f9ec..8f651f338 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourSerializeTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourSerializeTest.cs @@ -78,7 +78,7 @@ class BehaviourWithSyncVarWithOnSerialize : NetworkBehaviour public override bool OnSerialize(NetworkWriter writer, bool initialState) { - writer.WriteSingle(customSerializeField); + writer.WriteFloat(customSerializeField); return base.OnSerialize(writer, initialState); } public override void OnDeserialize(NetworkReader reader, bool initialState) @@ -94,7 +94,7 @@ class OverrideBehaviourFromSyncVarWithOnSerialize : AbstractBehaviour public override bool OnSerialize(NetworkWriter writer, bool initialState) { - writer.WriteSingle(customSerializeField); + writer.WriteFloat(customSerializeField); return base.OnSerialize(writer, initialState); } public override void OnDeserialize(NetworkReader reader, bool initialState) @@ -115,7 +115,7 @@ class OverrideBehaviourWithSyncVarFromSyncVarWithOnSerialize : AbstractBehaviour public override bool OnSerialize(NetworkWriter writer, bool initialState) { - writer.WriteSingle(customSerializeField); + writer.WriteFloat(customSerializeField); return base.OnSerialize(writer, initialState); } public override void OnDeserialize(NetworkReader reader, bool initialState) diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index a391497be..bdd843327 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -126,7 +126,7 @@ class SerializeTest1NetworkBehaviour : NetworkBehaviour public int value; public override bool OnSerialize(NetworkWriter writer, bool initialState) { - writer.WriteInt32(value); + writer.WriteInt(value); return true; } public override void OnDeserialize(NetworkReader reader, bool initialState) @@ -166,9 +166,9 @@ class SerializeMismatchNetworkBehaviour : NetworkBehaviour public int value; public override bool OnSerialize(NetworkWriter writer, bool initialState) { - writer.WriteInt32(value); + writer.WriteInt(value); // one too many - writer.WriteInt32(value); + writer.WriteInt(value); return true; } public override void OnDeserialize(NetworkReader reader, bool initialState) diff --git a/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs b/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs index fff0bc459..7da0f1177 100644 --- a/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkMessageTests.cs @@ -24,7 +24,7 @@ public void Deserialize(NetworkReader reader) public void Serialize(NetworkWriter writer) { - writer.WriteInt32(IntValue); + writer.WriteInt(IntValue); writer.WriteString(StringValue); writer.WriteDouble(DoubleValue); } diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index e7e2fa460..4d55af389 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -30,7 +30,7 @@ public void Deserialize(NetworkReader reader) public void Serialize(NetworkWriter writer) { - writer.WriteInt32(IntValue); + writer.WriteInt(IntValue); writer.WriteString(StringValue); writer.WriteDouble(DoubleValue); } diff --git a/Assets/Mirror/Tests/Editor/NetworkWriterCollectionTest.cs b/Assets/Mirror/Tests/Editor/NetworkWriterCollectionTest.cs index 5bba67cf6..86393154a 100644 --- a/Assets/Mirror/Tests/Editor/NetworkWriterCollectionTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkWriterCollectionTest.cs @@ -11,7 +11,7 @@ public void HasWriteFunctionForInt() { Assert.That(Writer.write, Is.Not.Null, "int write function was not found"); - Action action = NetworkWriterExtensions.WriteInt32; + Action action = NetworkWriterExtensions.WriteInt; Assert.That(Writer.write, Is.EqualTo(action), "int write function was incorrect value"); } diff --git a/Assets/Mirror/Tests/Editor/NetworkWriterTest.cs b/Assets/Mirror/Tests/Editor/NetworkWriterTest.cs index 93a8c977c..8ab734650 100644 --- a/Assets/Mirror/Tests/Editor/NetworkWriterTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkWriterTest.cs @@ -31,7 +31,7 @@ public void TestWritingSmallMessage() // try serializing less than 32kb and see what happens NetworkWriter writer = new NetworkWriter(); for (int i = 0; i < 30000 / 4; ++i) - writer.WriteInt32(i); + writer.WriteInt(i); Assert.That(writer.Position, Is.EqualTo(30000)); } @@ -41,7 +41,7 @@ public void TestWritingLargeMessage() // try serializing more than 32kb and see what happens NetworkWriter writer = new NetworkWriter(); for (int i = 0; i < 40000 / 4; ++i) - writer.WriteInt32(i); + writer.WriteInt(i); Assert.That(writer.Position, Is.EqualTo(40000)); } @@ -109,7 +109,7 @@ public void TestResetSetsPotionAndLength() { NetworkWriter writer = new NetworkWriter(); writer.WriteString("I saw"); - writer.WriteInt64(0xA_FADED_DEAD_EEL); + writer.WriteLong(0xA_FADED_DEAD_EEL); writer.WriteString("and ate it"); writer.Reset(); @@ -616,7 +616,7 @@ public void TestFloats() foreach (float weird in weirdFloats) { NetworkWriter writer = new NetworkWriter(); - writer.WriteSingle(weird); + writer.WriteFloat(weird); NetworkReader reader = new NetworkReader(writer.ToArray()); float readFloat = reader.ReadSingle(); Assert.That(readFloat, Is.EqualTo(weird)); @@ -689,7 +689,7 @@ public void TestFloatBinaryCompatibility() NetworkWriter writer = new NetworkWriter(); foreach (float weird in weirdFloats) { - writer.WriteSingle(weird); + writer.WriteFloat(weird); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -756,7 +756,7 @@ public void TestUShortEndianness() NetworkWriter writer = new NetworkWriter(); foreach (ushort value in values) { - writer.WriteUInt16(value); + writer.WriteUShort(value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -769,7 +769,7 @@ public void TestUIntEndianness() NetworkWriter writer = new NetworkWriter(); foreach (uint value in values) { - writer.WriteUInt32(value); + writer.WriteUInt(value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -782,7 +782,7 @@ public void TestULongEndianness() NetworkWriter writer = new NetworkWriter(); foreach (ulong value in values) { - writer.WriteUInt64(value); + writer.WriteULong(value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -808,7 +808,7 @@ public void TestShortEndianness() NetworkWriter writer = new NetworkWriter(); foreach (ushort value in values) { - writer.WriteInt16((short)value); + writer.WriteShort((short)value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -821,7 +821,7 @@ public void TestIntEndianness() NetworkWriter writer = new NetworkWriter(); foreach (uint value in values) { - writer.WriteInt32((int)value); + writer.WriteInt((int)value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -834,7 +834,7 @@ public void TestLongEndianness() NetworkWriter writer = new NetworkWriter(); foreach (ulong value in values) { - writer.WriteInt64((long)value); + writer.WriteLong((long)value); } Assert.That(writer.ToArray(), Is.EqualTo(expected)); } @@ -847,14 +847,14 @@ public void TestWritingAndReading() writer.WriteChar((char)1); writer.WriteByte(2); writer.WriteSByte(3); - writer.WriteBoolean(true); - writer.WriteInt16(4); - writer.WriteUInt16(5); - writer.WriteInt32(6); - writer.WriteUInt32(7U); - writer.WriteInt64(8L); - writer.WriteUInt64(9UL); - writer.WriteSingle(10.0F); + writer.WriteBool(true); + writer.WriteShort(4); + writer.WriteUShort(5); + writer.WriteInt(6); + writer.WriteUInt(7U); + writer.WriteLong(8L); + writer.WriteULong(9UL); + writer.WriteFloat(10.0F); writer.WriteDouble(11.0D); writer.WriteDecimal(12); writer.WriteString(null); @@ -956,7 +956,7 @@ public void TestArrayDoesNotThrowWithCorrectLength() void WriteGoodArray() { - writer.WriteInt32(testArraySize); + writer.WriteInt(testArraySize); int[] array = new int[testArraySize] { 1, 2, 3, 4 }; for (int i = 0; i < array.Length; i++) writer.Write(array[i]); @@ -982,7 +982,7 @@ public void TestArrayThrowsIfLengthIsWrong(int badLength) void WriteBadArray() { - writer.WriteInt32(badLength); + writer.WriteInt(badLength); int[] array = new int[testArraySize] { 1, 2, 3, 4 }; for (int i = 0; i < array.Length; i++) writer.Write(array[i]); @@ -1010,7 +1010,7 @@ public void TestArrayThrowsIfLengthIsTooBig(int badLength) void WriteBadArray() { - writer.WriteInt32(badLength); + writer.WriteInt(badLength); int[] array = new int[testArraySize] { 1, 2, 3, 4 }; for (int i = 0; i < array.Length; i++) writer.Write(array[i]); diff --git a/Assets/Mirror/Tests/Editor/Weaver/ExtraAssembly/SomeDataWithWriter.cs b/Assets/Mirror/Tests/Editor/Weaver/ExtraAssembly/SomeDataWithWriter.cs index cf79dd2a9..31730be73 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/ExtraAssembly/SomeDataWithWriter.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/ExtraAssembly/SomeDataWithWriter.cs @@ -9,7 +9,7 @@ public static class ReadWrite { public static void WriteSomeData(this NetworkWriter writer, SomeDataWithWriter itemData) { - writer.WriteInt32(itemData.usefulNumber); + writer.WriteInt(itemData.usefulNumber); } public static SomeDataWithWriter ReadSomeData(this NetworkReader reader) { diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverGeneratedReaderWriterTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverGeneratedReaderWriterTests.cs index 01bcd80c4..537fc5c4a 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverGeneratedReaderWriterTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverGeneratedReaderWriterTests.cs @@ -204,7 +204,7 @@ public void GivesErrorForInvalidListType() // "System.Collections.Generic.List`1"); } - [Test] + [Test, Ignore("Enable again when we don't have obsoletes in NetworkWriter anymore.")] public void GivesWarningWhenRegisteringExistingExtensionMethod() { const string typeName = "GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.MyType";