Skip to content

Commit 5c5eba3

Browse files
committed
Began replacing BitWriter & Reader with Streams
1 parent 04df5e4 commit 5c5eba3

27 files changed

+806
-1123
lines changed

MLAPI/Data/AttributeMessageMode.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Reflection;
34
using MLAPI.NetworkingManagerComponents.Binary;
45

@@ -12,7 +13,7 @@ public enum AttributeMessageMode
1213
WovenEightByte
1314
}
1415

15-
public delegate void RpcDelegate(uint clientId, BitReader reader);
16+
public delegate void RpcDelegate(uint clientId, Stream stream);
1617

1718
public class ReflectionMehtod
1819
{
@@ -33,12 +34,12 @@ public ReflectionMehtod(MethodInfo methodInfo)
3334
}
3435
}
3536

36-
public void Invoke(object instance, BitReader reader)
37+
public void Invoke(object instance, Stream stream)
3738
{
39+
BitReader reader = new BitReader(stream);
3840
for (int i = 0; i < parameterTypes.Length; i++)
3941
{
40-
//TODO: BitReader ReadType
41-
parameterRefs[i] = reader.ReadObject(parameterTypes[i]);
42+
parameterRefs[i] = reader.ReadObjectPacked(parameterTypes[i]);
4243
}
4344

4445
method.Invoke(instance, parameterRefs);

MLAPI/Data/FieldType.cs

Lines changed: 0 additions & 289 deletions
This file was deleted.

MLAPI/Data/NetworkConfig.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private void Sort()
157157
/// Returns a base64 encoded version of the config
158158
/// </summary>
159159
/// <returns></returns>
160+
/*
160161
public string ToBase64()
161162
{
162163
NetworkConfig config = this;
@@ -282,6 +283,7 @@ public void FromBase64(string base64, bool createDummyObject = false)
282283
config.AttributeMessageMode = (AttributeMessageMode)reader.ReadBits(3);
283284
}
284285
}
286+
*/
285287

286288
private ulong? ConfigHash = null;
287289
/// <summary>
@@ -296,9 +298,10 @@ public ulong GetConfig(bool cache = true)
296298

297299
Sort();
298300

299-
using (BitWriter writer = BitWriter.Get())
301+
using (PooledBitStream stream = PooledBitStream.Get())
300302
{
301-
writer.WriteUShort(ProtocolVersion);
303+
BitWriter writer = new BitWriter(stream);
304+
writer.WriteUInt16Packed(ProtocolVersion);
302305
writer.WriteString(MLAPIConstants.MLAPI_PROTOCOL_VERSION);
303306

304307
for (int i = 0; i < Channels.Count; i++)
@@ -331,10 +334,10 @@ public ulong GetConfig(bool cache = true)
331334
// Returns a 160 bit / 20 byte / 5 int checksum of the config
332335
if (cache)
333336
{
334-
ConfigHash = writer.Finalize().GetStableHash64();
337+
ConfigHash = stream.ToArray().GetStableHash64();
335338
return ConfigHash.Value;
336339
}
337-
return writer.Finalize().GetStableHash64();
340+
return stream.ToArray().GetStableHash64();
338341
}
339342
}
340343

0 commit comments

Comments
 (0)