Skip to content

Commit 7a39f3a

Browse files
Refactored BitWriter to BitWriterDeprecated
Refactored BitReader to BitReaderDeprecated Refactored BinaryWriter to BitWriter Refactored BinaryReader to BitReader Fixed infinite recursion bug with WriteNibble
1 parent a2fd752 commit 7a39f3a

24 files changed

+2964
-2914
lines changed

MLAPI.Tests/NetworkingManagerComponents/Binary/BitStreamTest.cs

Lines changed: 146 additions & 100 deletions
Large diffs are not rendered by default.

MLAPI.Tests/NetworkingManagerComponents/Binary/BitWriterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BitWriterTest
1212
[Test]
1313
public void TestWritingTrue()
1414
{
15-
BitWriter bitWriter = BitWriter.Get();
15+
BitWriterDeprecated bitWriter = BitWriterDeprecated.Get();
1616

1717
bitWriter.WriteBool(true);
1818

MLAPI/Data/FieldType.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ internal static bool IsRefType(Type t)
7474
return (!t.IsValueType && t != typeof(string)) || (t.IsArray && IsRefType(t.GetElementType()));
7575
}
7676

77-
internal static void WriteFieldType(BitWriter writer, object newValue)
77+
internal static void WriteFieldType(BitWriterDeprecated writer, object newValue)
7878
{
7979
WriteFieldType(writer, newValue, null);
8080
}
8181

82-
internal static void WriteFieldType(BitWriter writer, object newValue, object oldValue)
82+
internal static void WriteFieldType(BitWriterDeprecated writer, object newValue, object oldValue)
8383
{
8484
oldValue = null;
8585
Type newValueType = newValue.GetType();
@@ -172,12 +172,12 @@ internal static void WriteFieldType(BitWriter writer, object newValue, object ol
172172
}
173173
}
174174

175-
internal static object ReadFieldType(BitReader reader, Type type)
175+
internal static object ReadFieldType(BitReaderDeprecated reader, Type type)
176176
{
177177
return ReadFieldType(reader, type, null);
178178
}
179179

180-
internal static object ReadFieldType(BitReader reader, Type type, object oldObject)
180+
internal static object ReadFieldType(BitReaderDeprecated reader, Type type, object oldObject)
181181
{
182182
CheckForReferenceTypes(type);
183183
if (type.IsArray)

MLAPI/Data/NetworkConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public class NetworkConfig
161161
public string ToBase64()
162162
{
163163
NetworkConfig config = this;
164-
using (BitWriter writer = BitWriter.Get())
164+
using (BitWriterDeprecated writer = BitWriterDeprecated.Get())
165165
{
166166
writer.WriteUShort(config.ProtocolVersion);
167167
writer.WriteBits((byte)config.Transport, 5);
@@ -226,7 +226,7 @@ public void FromBase64(string base64, bool createDummyObject = false)
226226
{
227227
NetworkConfig config = this;
228228
byte[] binary = Convert.FromBase64String(base64);
229-
using (BitReader reader = BitReader.Get(binary))
229+
using (BitReaderDeprecated reader = BitReaderDeprecated.Get(binary))
230230
{
231231
config.ProtocolVersion = reader.ReadUShort();
232232
config.Transport = (DefaultTransport)reader.ReadBits(5);
@@ -316,7 +316,7 @@ public ulong GetConfig(bool cache = true)
316316
if (ConfigHash != null && cache)
317317
return ConfigHash.Value;
318318

319-
using (BitWriter writer = BitWriter.Get())
319+
using (BitWriterDeprecated writer = BitWriterDeprecated.Get())
320320
{
321321
writer.WriteUShort(ProtocolVersion);
322322
for (int i = 0; i < Channels.Count; i++)

MLAPI/MLAPI.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@
111111
<Compile Include="MonoBehaviours\Prototyping\NetworkedNavMeshAgent.cs" />
112112
<Compile Include="MonoBehaviours\Prototyping\NetworkedProximity.cs" />
113113
<Compile Include="NetworkingManagerComponents\Binary\Arithmetic.cs" />
114-
<Compile Include="NetworkingManagerComponents\Binary\BinaryReader.cs" />
115-
<Compile Include="NetworkingManagerComponents\Binary\BinaryWriter.cs" />
116-
<Compile Include="NetworkingManagerComponents\Binary\BitStream.cs" />
117-
<Compile Include="NetworkingManagerComponents\Binary\BitWriter.cs" />
118114
<Compile Include="NetworkingManagerComponents\Binary\BitReader.cs" />
115+
<Compile Include="NetworkingManagerComponents\Binary\BitWriter.cs" />
116+
<Compile Include="NetworkingManagerComponents\Binary\BitStream.cs" />
117+
<Compile Include="NetworkingManagerComponents\Binary\BitWriterDeprecated.cs" />
118+
<Compile Include="NetworkingManagerComponents\Binary\BitReaderDeprecated.cs" />
119119
<Compile Include="NetworkingManagerComponents\Binary\BinaryHelpers.cs" />
120120
<Compile Include="NetworkingManagerComponents\Binary\BinarySerializer.cs" />
121121
<Compile Include="NetworkingManagerComponents\Binary\ByteBool.cs" />

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 40 additions & 40 deletions
Large diffs are not rendered by default.

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ internal void RebuildObservers(uint? clientId = null)
134134
(!previousObservers.Contains(pair.Key) && observers.Contains(pair.Key)))
135135
{
136136
//Something changed for this client.
137-
using (BitWriter writer = BitWriter.Get())
137+
using (BitWriterDeprecated writer = BitWriterDeprecated.Get())
138138
{
139139
writer.WriteUInt(NetworkId);
140140
writer.WriteBool(observers.Contains(pair.Key));
@@ -173,7 +173,7 @@ private void OnDestroy()
173173
/// <summary>
174174
/// Spawns this GameObject across the network. Can only be called from the Server
175175
/// </summary>
176-
public void Spawn(BitWriter spawnPayload = null)
176+
public void Spawn(BitWriterDeprecated spawnPayload = null)
177177
{
178178
SpawnManager.SpawnObject(this, null, spawnPayload);
179179
}
@@ -191,7 +191,7 @@ public void UnSpawn()
191191
/// </summary>
192192
/// <param name="clientId">The clientId to own the object</param>
193193
/// <param name="spawnPayload">The writer containing the spawn payload</param>
194-
public void SpawnWithOwnership(uint clientId, BitWriter spawnPayload = null)
194+
public void SpawnWithOwnership(uint clientId, BitWriterDeprecated spawnPayload = null)
195195
{
196196
SpawnManager.SpawnObject(this, clientId, spawnPayload);
197197
}
@@ -201,7 +201,7 @@ public void SpawnWithOwnership(uint clientId, BitWriter spawnPayload = null)
201201
/// </summary>
202202
/// <param name="clientId">The clientId whos player object this is</param>
203203
/// <param name="spawnPayload">The writer containing the spawn payload</param>
204-
public void SpawnAsPlayerObject(uint clientId, BitWriter spawnPayload = null)
204+
public void SpawnAsPlayerObject(uint clientId, BitWriterDeprecated spawnPayload = null)
205205
{
206206
SpawnManager.SpawnPlayerObject(this, clientId, spawnPayload);
207207
}
@@ -238,7 +238,7 @@ internal void InvokeBehaviourOnGainedOwnership()
238238
}
239239
}
240240

241-
internal void InvokeBehaviourNetworkSpawn(BitReader reader)
241+
internal void InvokeBehaviourNetworkSpawn(BitReaderDeprecated reader)
242242
{
243243
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
244244
{
@@ -287,7 +287,7 @@ internal static void InvokeSyncvarUpdate()
287287
//as this should only be used for reading SyncedVar data that is to be read by the SetFormattedData method
288288
//*
289289
//The data contains every syncedvar on every behaviour that belongs to this object
290-
internal void WriteFormattedSyncedVarData(BitWriter writer)
290+
internal void WriteFormattedSyncedVarData(BitWriterDeprecated writer)
291291
{
292292
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
293293
{
@@ -301,7 +301,7 @@ internal void WriteFormattedSyncedVarData(BitWriter writer)
301301
}
302302

303303
//Reads formatted data that the "WriteFormattedSyncedVarData" has written and applies the values to SyncedVar fields
304-
internal void SetFormattedSyncedVarData(BitReader reader)
304+
internal void SetFormattedSyncedVarData(BitReaderDeprecated reader)
305305
{
306306
for (int i = 0; i < childNetworkedBehaviours.Count; i++)
307307
{
@@ -344,6 +344,6 @@ internal NetworkedBehaviour GetBehaviourAtOrderIndex(ushort index)
344344
}
345345

346346
//Key: behaviourOrderId, value key: messageType, value value callback
347-
internal Dictionary<ushort, Dictionary<ushort, Action<uint, BitReader>>> targetMessageActions = new Dictionary<ushort, Dictionary<ushort, Action<uint, BitReader>>>();
347+
internal Dictionary<ushort, Dictionary<ushort, Action<uint, BitReaderDeprecated>>> targetMessageActions = new Dictionary<ushort, Dictionary<ushort, Action<uint, BitReaderDeprecated>>>();
348348
}
349349
}

0 commit comments

Comments
 (0)