Skip to content

Commit 99cdaec

Browse files
committed
Added XML comments & cleaned API
1 parent a22f534 commit 99cdaec

File tree

15 files changed

+522
-104
lines changed

15 files changed

+522
-104
lines changed

MLAPI/Data/MLAPIConstants.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
namespace MLAPI.Data
22
{
3+
/// <summary>
4+
/// A static class containing MLAPI constants
5+
/// </summary>
36
public static class MLAPIConstants
47
{
8+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
59
public const string MLAPI_PROTOCOL_VERSION = "2.0.0";
6-
10+
711
public const ushort MLAPI_CONNECTION_REQUEST = 0;
812
public const ushort MLAPI_CONNECTION_APPROVED = 1;
913
public const ushort MLAPI_ADD_OBJECT = 2;
@@ -20,5 +24,6 @@ public static class MLAPIConstants
2024
public const ushort MLAPI_SERVER_RPC = 13;
2125
public const ushort MLAPI_CLIENT_RPC = 14;
2226
public const ushort MLAPI_CUSTOM_MESSAGE = 15;
27+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
2328
}
24-
}
29+
}

MLAPI/Data/NetworkProfiler/ProfilerTickData.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public class ProfilerTick
3232
/// </summary>
3333
public readonly List<TickEvent> Events = new List<TickEvent>();
3434

35-
35+
/// <summary>
36+
/// Writes the current ProfilerTick to the stream
37+
/// </summary>
38+
/// <param name="stream">The stream containing</param>
3639
public void SerializeToStream(Stream stream)
3740
{
3841
BitWriter writer = new BitWriter(stream);
@@ -44,6 +47,11 @@ public void SerializeToStream(Stream stream)
4447
}
4548
}
4649

50+
/// <summary>
51+
/// Creates a ProfilerTick from data in the provided stream
52+
/// </summary>
53+
/// <param name="stream">The stream containing the ProfilerTick data</param>
54+
/// <returns>The ProfilerTick with data read from the stream</returns>
4755
public static ProfilerTick FromStream(Stream stream)
4856
{
4957
ProfilerTick tick = new ProfilerTick();
@@ -135,6 +143,10 @@ public class TickEvent
135143
/// </summary>
136144
public bool Closed;
137145

146+
/// <summary>
147+
/// Writes the TickEvent data to the stream
148+
/// </summary>
149+
/// <param name="stream">The stream to write the TickEvent data to</param>
138150
public void SerializeToStream(Stream stream)
139151
{
140152
BitWriter writer = new BitWriter(stream);
@@ -145,16 +157,23 @@ public void SerializeToStream(Stream stream)
145157
writer.WriteBool(Closed);
146158
}
147159

160+
/// <summary>
161+
/// Creates a TickEvent from data in the provided stream
162+
/// </summary>
163+
/// <param name="stream">The stream containing the TickEvent data</param>
164+
/// <returns>The TickEvent with data read from the stream</returns>
148165
public static TickEvent FromStream(Stream stream)
149166
{
150167
BitReader reader = new BitReader(stream);
151-
TickEvent @event = new TickEvent();
152-
@event.EventType = (TickType)reader.ReadByte();
153-
@event.Bytes = reader.ReadUInt32Packed();
154-
@event.ChannelName = reader.ReadStringPacked().ToString();
155-
@event.MessageType = reader.ReadStringPacked().ToString();
156-
@event.Closed = reader.ReadBool();
157-
return @event;
168+
TickEvent @event = new TickEvent
169+
{
170+
EventType = (TickType)reader.ReadByte(),
171+
Bytes = reader.ReadUInt32Packed(),
172+
ChannelName = reader.ReadStringPacked().ToString(),
173+
MessageType = reader.ReadStringPacked().ToString(),
174+
Closed = reader.ReadBool()
175+
};
176+
return @event;
158177
}
159178
}
160179
}

MLAPI/Data/NetworkedCollections/NetworkedDictionary.cs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ namespace MLAPI.Data.NetworkedCollections
1313
/// <typeparam name="TValue">The type for the dctionary values</typeparam>
1414
public class NetworkedDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INetworkedVar
1515
{
16-
internal struct NetworkedDictionaryEvent<TKey, TValue>
17-
{
18-
internal enum NetworkedListEventType
19-
{
20-
Add,
21-
Remove,
22-
RemovePair,
23-
Clear,
24-
Value
25-
}
26-
27-
internal NetworkedListEventType eventType;
28-
internal TKey key;
29-
internal TValue value;
30-
}
31-
3216
/// <summary>
3317
/// Gets the last time the variable was synced
3418
/// </summary>
@@ -40,23 +24,39 @@ internal enum NetworkedListEventType
4024
private readonly IDictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
4125
private NetworkedBehaviour networkedBehaviour;
4226
private readonly List<NetworkedDictionaryEvent<TKey, TValue>> dirtyEvents = new List<NetworkedDictionaryEvent<TKey, TValue>>();
43-
27+
28+
/// <summary>
29+
/// Creates a NetworkedDictionary with the default value and settings
30+
/// </summary>
4431
public NetworkedDictionary()
4532
{
4633

4734
}
48-
35+
36+
/// <summary>
37+
/// Creates a NetworkedDictionary with the default value and custom settings
38+
/// </summary>
39+
/// <param name="settings">The settings to use for the NetworkedDictionary</param>
4940
public NetworkedDictionary(NetworkedVarSettings settings)
5041
{
5142
this.Settings = settings;
5243
}
53-
44+
45+
/// <summary>
46+
/// Creates a NetworkedDictionary with a custom value and custom settings
47+
/// </summary>
48+
/// <param name="settings">The settings to use for the NetworkedDictionary</param>
49+
/// <param name="value">The initial value to use for the NetworkedDictionary</param>
5450
public NetworkedDictionary(NetworkedVarSettings settings, IDictionary<TKey, TValue> value)
5551
{
5652
this.Settings = settings;
5753
this.dictionary = value;
5854
}
59-
55+
56+
/// <summary>
57+
/// Creates a NetworkedDictionary with a custom value and the default settings
58+
/// </summary>
59+
/// <param name="value">The initial value to use for the NetworkedDictionary</param>
6060
public NetworkedDictionary(IDictionary<TKey, TValue> value)
6161
{
6262
this.dictionary = value;
@@ -383,4 +383,20 @@ IEnumerator IEnumerable.GetEnumerator()
383383
return dictionary.GetEnumerator();
384384
}
385385
}
386+
387+
internal struct NetworkedDictionaryEvent<TKey, TValue>
388+
{
389+
internal enum NetworkedListEventType
390+
{
391+
Add,
392+
Remove,
393+
RemovePair,
394+
Clear,
395+
Value
396+
}
397+
398+
internal NetworkedListEventType eventType;
399+
internal TKey key;
400+
internal TValue value;
401+
}
386402
}

MLAPI/Data/NetworkedCollections/NetworkedList.cs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@ namespace MLAPI.Data.NetworkedCollections
1212
/// <typeparam name="T">The type for the list</typeparam>
1313
public class NetworkedList<T> : IList<T>, INetworkedVar
1414
{
15-
internal struct NetworkedListEvent<T>
16-
{
17-
internal enum NetworkedListEventType
18-
{
19-
Add,
20-
Insert,
21-
Remove,
22-
RemoveAt,
23-
Value,
24-
Clear
25-
}
26-
27-
internal NetworkedListEventType eventType;
28-
internal T value;
29-
internal int index;
30-
}
31-
3215
private readonly IList<T> list = new List<T>();
3316
private List<NetworkedListEvent<T>> dirtyEvents = new List<NetworkedListEvent<T>>();
3417
private NetworkedBehaviour networkedBehaviour;
@@ -40,24 +23,39 @@ internal enum NetworkedListEventType
4023
/// The settings for this container
4124
/// </summary>
4225
public readonly NetworkedVarSettings Settings = new NetworkedVarSettings();
43-
44-
26+
27+
/// <summary>
28+
/// Creates a NetworkedList with the default value and settings
29+
/// </summary>
4530
public NetworkedList()
4631
{
4732

4833
}
49-
34+
35+
/// <summary>
36+
/// Creates a NetworkedList with the default value and custom settings
37+
/// </summary>
38+
/// <param name="settings">The settings to use for the NetworkedList</param>
5039
public NetworkedList(NetworkedVarSettings settings)
5140
{
5241
this.Settings = settings;
5342
}
54-
43+
44+
/// <summary>
45+
/// Creates a NetworkedList with a custom value and custom settings
46+
/// </summary>
47+
/// <param name="settings">The settings to use for the NetworkedList</param>
48+
/// <param name="value">The initial value to use for the NetworkedList</param>
5549
public NetworkedList(NetworkedVarSettings settings, IList<T> value)
5650
{
5751
this.Settings = settings;
5852
this.list = value;
5953
}
60-
54+
55+
/// <summary>
56+
/// Creates a NetworkedList with a custom value and the default settings
57+
/// </summary>
58+
/// <param name="value">The initial value to use for the NetworkedList</param>
6159
public NetworkedList(IList<T> value)
6260
{
6361
this.list = value;
@@ -137,35 +135,35 @@ public void WriteDelta(Stream stream)
137135
switch (dirtyEvents[i].eventType)
138136
{
139137
//Fuck me these signatures are proper aids
140-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Add:
138+
case NetworkedListEvent<T>.NetworkedListEventType.Add:
141139
{
142140
writer.WriteObjectPacked(dirtyEvents[i].value); //BOX
143141
}
144142
break;
145-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Insert:
143+
case NetworkedListEvent<T>.NetworkedListEventType.Insert:
146144
{
147145
writer.WriteInt32Packed(dirtyEvents[i].index);
148146
writer.WriteObjectPacked(dirtyEvents[i].value); //BOX
149147
}
150148
break;
151-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Remove:
149+
case NetworkedListEvent<T>.NetworkedListEventType.Remove:
152150
{
153151
writer.WriteObjectPacked(dirtyEvents[i].value); //BOX
154152
}
155153
break;
156-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
154+
case NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
157155
{
158156
writer.WriteInt32Packed(dirtyEvents[i].index);
159157
}
160158
break;
161-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Value:
159+
case NetworkedListEvent<T>.NetworkedListEventType.Value:
162160
{
163161
writer.WriteInt32Packed(dirtyEvents[i].index);
164162
writer.WriteObjectPacked(dirtyEvents[i].value); //BOX
165163
}
166164

167165
break;
168-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Clear:
166+
case NetworkedListEvent<T>.NetworkedListEventType.Clear:
169167
{
170168
//Nothing has to be written
171169
}
@@ -212,30 +210,30 @@ public void ReadDelta(Stream stream)
212210
list.Add((T)reader.ReadObjectPacked(typeof(T))); //BOX
213211
}
214212
break;
215-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Insert:
213+
case NetworkedListEvent<T>.NetworkedListEventType.Insert:
216214
{
217215
int index = reader.ReadInt32Packed();
218216
list.Insert(index, (T)reader.ReadObjectPacked(typeof(T))); //BOX
219217
}
220218
break;
221-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Remove:
219+
case NetworkedListEvent<T>.NetworkedListEventType.Remove:
222220
{
223221
list.Remove((T)reader.ReadObjectPacked(typeof(T))); //BOX
224222
}
225223
break;
226-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
224+
case NetworkedListEvent<T>.NetworkedListEventType.RemoveAt:
227225
{
228226
int index = reader.ReadInt32Packed();
229227
list.RemoveAt(index);
230228
}
231229
break;
232-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Value:
230+
case NetworkedListEvent<T>.NetworkedListEventType.Value:
233231
{
234232
int index = reader.ReadInt32Packed();
235233
if (index < list.Count) list[index] = (T)reader.ReadObjectPacked(typeof(T)); //BOX
236234
}
237235
break;
238-
case NetworkedList<T>.NetworkedListEvent<T>.NetworkedListEventType.Clear:
236+
case NetworkedListEvent<T>.NetworkedListEventType.Clear:
239237
{
240238
//Read nothing
241239
list.Clear();
@@ -364,4 +362,21 @@ public T this[int index]
364362
}
365363
}
366364
}
365+
366+
internal struct NetworkedListEvent<T>
367+
{
368+
internal enum NetworkedListEventType
369+
{
370+
Add,
371+
Insert,
372+
Remove,
373+
RemoveAt,
374+
Value,
375+
Clear
376+
}
377+
378+
internal NetworkedListEventType eventType;
379+
internal T value;
380+
internal int index;
381+
}
367382
}

0 commit comments

Comments
 (0)