Skip to content

Commit d2c60e4

Browse files
refactor!: reformat source files, apply Unity standards (#514)
* remove csc.rsp and delete DISABLE_CRYPTOGRAPHY blocks * fix order of shutdown and singleton=null on NetworkManager.OnDestroy() * remove hail handshake and constants * remove aeskey fields * remove encryption/cryptography from networkconfig * remove SecuritySendFlags * remove security parameter xmldoc * fix BeginAddQueueItemToFrame * remove StdRpc transport channel and stdrpc profiler markers * removed todo comment since removing messagepacker is non-trivial task, leaving for later * rename NetworkingManager to NetworkManager * rename NetworkedObject to NetworkObject * rename NetworkedBehaviour to NetworkBehaviour * rename NetworkedClient to NetworkClient * rename NetworkedPrefab to NetworkPrefab * rename NetworkedVar to NetworkVariable * rename NetworkedVar to NetworkVariable * rename NetworkedTransform to NetworkTransform * rename NetworkedAnimator to NetworkAnimator * rename NetworkedAnimatorEditor to NetworkAnimatorEditor * rename NetworkedNavMeshAgent to NetworkNavMeshAgent * rename SpawnManager to NetworkSpawnManager * rename BitStream/BitSerializer/... to NetworkStream/NetworkSerializer/... * rename NetEventType to NetworkEvent * rename ChannelType to NetworkDelivery * rename Channel to NetworkChannel * rename Transport to NetworkTransport * rename NetworkedDictionary to NetworkDictionary * rename NetworkedList to NetworkList * rename NetworkedSet to NetworkSet * replace remaining *networked* instances with *network* * remove [Obsolete] API * refactor & rename MLAPIConstants to NetworkConstants * refactor (format & rename) Prototyping components * refactor: reformat source files, rename types/methods/fields/properties according to Unity C# Reference standards * fix ILPP on 2020.2+ * merge branch develop into feature/refactor-rename * rename NetworkStream to NetworkBuffer * remove unnecessary MLAPI.* namespace resolution prefix * remove k_* prefixes from internal const fields * other QoL improvements * make ids more explicit * another refactoring pass * rename Unet to UNet * revert k_* prefixes on public and internal constants * revert s_* prefixes on public and internal statics * revert all changes to MLAPIEditor (it's going away soon) * remove properties * refactor profiling stuff * refactor Editor stuff * fix MLAPIProfilerModule * collapse some back-to-back 'using (var ...)' statements * polish profiler stuff * favor string interpolation rather than string concat with + (plus) operator * remove MLAPIEditor meta file * redo refactorings * favor using nameof and string interpolation for profilermarkers * remove unnecessary MLAPI.* namespace scope resolution * minor tweaks after code-review * fix RpcQueueTests after merging develop branch Co-authored-by: Matt Walsh <[email protected]>
1 parent 6e454fa commit d2c60e4

File tree

96 files changed

+3605
-3629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3605
-3629
lines changed

com.unity.multiplayer.mlapi/Editor/CodeGen/CodeGenHelpers.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ public static bool HasInterface(this TypeReference typeReference, string Interfa
8888
}
8989
catch
9090
{
91+
return false;
9192
}
92-
93-
return false;
9493
}
9594

9695
public static bool IsSerializable(this TypeReference typeReference)
@@ -141,16 +140,12 @@ public static TypeReference GetEnumAsInt(this TypeReference typeReference)
141140
try
142141
{
143142
var typeDef = typeReference.Resolve();
144-
if (typeDef.IsEnum)
145-
{
146-
return typeDef.GetEnumUnderlyingType();
147-
}
143+
return typeDef.IsEnum ? typeDef.GetEnumUnderlyingType() : null;
148144
}
149145
catch
150146
{
147+
return null;
151148
}
152-
153-
return null;
154149
}
155150

156151
public static void AddError(this List<DiagnosticMessage> diagnostics, string message)

com.unity.multiplayer.mlapi/Editor/CodeGen/ILPostProcessorProgram.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static ILPostProcessor[] FindAllPostProcessors()
3737
}
3838
catch (Exception exception)
3939
{
40-
Debug.LogError($"Could not create ILPostProcessor ({typeCollection.FullName}):{Environment.NewLine}{exception.StackTrace}");
40+
Debug.LogError($"Could not create {nameof(ILPostProcessor)} ({typeCollection.FullName}):{Environment.NewLine}{exception.StackTrace}");
4141
}
4242
}
4343

@@ -185,22 +185,21 @@ void WriteAssembly(InMemoryAssembly inMemoryAssembly, string outputPath, string
185185
foreach (var i in s_ILPostProcessors)
186186
{
187187
var result = i.Process(targetCompiledAssembly);
188-
if (result == null)
189-
continue;
188+
if (result == null) continue;
190189

191190
if (result.Diagnostics.Count > 0)
192191
{
193-
Debug.LogError($"ILPostProcessor - {i.GetType().Name} failed to run on {targetCompiledAssembly.Name}");
192+
Debug.LogError($"{nameof(ILPostProcessor)} - {i.GetType().Name} failed to run on {targetCompiledAssembly.Name}");
194193

195194
foreach (var message in result.Diagnostics)
196195
{
197196
switch (message.DiagnosticType)
198197
{
199198
case DiagnosticType.Error:
200-
Debug.LogError($"ILPostProcessor Error - {message.MessageData} {message.File}:{message.Line}");
199+
Debug.LogError($"{nameof(ILPostProcessor)} Error - {message.MessageData} {message.File}:{message.Line}");
201200
break;
202201
case DiagnosticType.Warning:
203-
Debug.LogWarning($"ILPostProcessor Warning - {message.MessageData} {message.File}:{message.Line}");
202+
Debug.LogWarning($"{nameof(ILPostProcessor)} Warning - {message.MessageData} {message.File}:{message.Line}");
204203
break;
205204
}
206205
}

com.unity.multiplayer.mlapi/Editor/CodeGen/PostProcessorReflectionImporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace MLAPI.Editor.CodeGen
66
{
77
internal class PostProcessorReflectionImporter : DefaultReflectionImporter
88
{
9-
private const string SystemPrivateCoreLib = "System.Private.CoreLib";
9+
private const string k_SystemPrivateCoreLib = "System.Private.CoreLib";
1010
private readonly AssemblyNameReference m_CorrectCorlib;
1111

1212
public PostProcessorReflectionImporter(ModuleDefinition module) : base(module)
1313
{
14-
m_CorrectCorlib = module.AssemblyReferences.FirstOrDefault(a => a.Name == "mscorlib" || a.Name == "netstandard" || a.Name == SystemPrivateCoreLib);
14+
m_CorrectCorlib = module.AssemblyReferences.FirstOrDefault(a => a.Name == "mscorlib" || a.Name == "netstandard" || a.Name == k_SystemPrivateCoreLib);
1515
}
1616

1717
public override AssemblyNameReference ImportReference(AssemblyName reference)
1818
{
19-
return m_CorrectCorlib != null && reference.Name == SystemPrivateCoreLib ? m_CorrectCorlib : base.ImportReference(reference);
19+
return m_CorrectCorlib != null && reference.Name == k_SystemPrivateCoreLib ? m_CorrectCorlib : base.ImportReference(reference);
2020
}
2121
}
2222
}

com.unity.multiplayer.mlapi/Editor/CodeGen/XXHash/XXHash.cs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ namespace MLAPI.Editor.CodeGen
1414
/// </summary>
1515
internal static class XXHash
1616
{
17-
private const ulong prime64v1 = 11400714785074694791ul;
18-
private const ulong prime64v2 = 14029467366897019727ul;
19-
private const ulong prime64v3 = 1609587929392839161ul;
20-
private const ulong prime64v4 = 9650029242287828579ul;
21-
private const ulong prime64v5 = 2870177450012600261ul;
22-
23-
private const uint prime32v1 = 2654435761u;
24-
private const uint prime32v2 = 2246822519u;
25-
private const uint prime32v3 = 3266489917u;
26-
private const uint prime32v4 = 668265263u;
27-
private const uint prime32v5 = 374761393u;
17+
private const ulong k_Prime64v1 = 11400714785074694791ul;
18+
private const ulong k_Prime64v2 = 14029467366897019727ul;
19+
private const ulong k_Prime64v3 = 1609587929392839161ul;
20+
private const ulong k_Prime64v4 = 9650029242287828579ul;
21+
private const ulong k_Prime64v5 = 2870177450012600261ul;
22+
23+
private const uint k_Prime32v1 = 2654435761u;
24+
private const uint k_Prime32v2 = 2246822519u;
25+
private const uint k_Prime32v3 = 3266489917u;
26+
private const uint k_Prime32v4 = 668265263u;
27+
private const uint k_Prime32v5 = 374761393u;
2828

2929
/// <summary>
3030
/// Generate a 32-bit xxHash value.
@@ -44,10 +44,10 @@ public static unsafe uint Hash32(byte* buffer, int bufferLength, uint seed = 0)
4444
byte* pInput = buffer;
4545
if (len >= stripeLength)
4646
{
47-
uint acc1 = seed + prime32v1 + prime32v2;
48-
uint acc2 = seed + prime32v2;
47+
uint acc1 = seed + k_Prime32v1 + k_Prime32v2;
48+
uint acc2 = seed + k_Prime32v2;
4949
uint acc3 = seed;
50-
uint acc4 = seed - prime32v1;
50+
uint acc4 = seed - k_Prime32v1;
5151

5252
do
5353
{
@@ -57,7 +57,7 @@ public static unsafe uint Hash32(byte* buffer, int bufferLength, uint seed = 0)
5757
}
5858
else
5959
{
60-
acc = seed + prime32v5;
60+
acc = seed + k_Prime32v5;
6161
}
6262

6363
acc += (uint)len;
@@ -84,10 +84,10 @@ public static unsafe ulong Hash64(byte* buffer, int bufferLength, ulong seed = 0
8484
byte* pInput = buffer;
8585
if (len >= stripeLength)
8686
{
87-
ulong acc1 = seed + prime64v1 + prime64v2;
88-
ulong acc2 = seed + prime64v2;
87+
ulong acc1 = seed + k_Prime64v1 + k_Prime64v2;
88+
ulong acc2 = seed + k_Prime64v2;
8989
ulong acc3 = seed;
90-
ulong acc4 = seed - prime64v1;
90+
ulong acc4 = seed - k_Prime64v1;
9191

9292
do
9393
{
@@ -97,7 +97,7 @@ public static unsafe ulong Hash64(byte* buffer, int bufferLength, ulong seed = 0
9797
}
9898
else
9999
{
100-
acc = seed + prime64v5;
100+
acc = seed + k_Prime64v5;
101101
}
102102

103103
acc += (ulong)len;
@@ -151,24 +151,24 @@ private static unsafe ulong processRemaining64(
151151
lane = *(ulong*)pInput;
152152

153153
acc ^= round64(0, lane);
154-
acc = Bits.RotateLeft(acc, 27) * prime64v1;
155-
acc += prime64v4;
154+
acc = Bits.RotateLeft(acc, 27) * k_Prime64v1;
155+
acc += k_Prime64v4;
156156
}
157157

158158
for (uint lane32; remainingLen >= 4; remainingLen -= 4, pInput += 4)
159159
{
160160
lane32 = *(uint*)pInput;
161161

162-
acc ^= lane32 * prime64v1;
163-
acc = Bits.RotateLeft(acc, 23) * prime64v2;
164-
acc += prime64v3;
162+
acc ^= lane32 * k_Prime64v1;
163+
acc = Bits.RotateLeft(acc, 23) * k_Prime64v2;
164+
acc += k_Prime64v3;
165165
}
166166

167167
for (byte lane8; remainingLen >= 1; remainingLen--, pInput++)
168168
{
169169
lane8 = *pInput;
170-
acc ^= lane8 * prime64v5;
171-
acc = Bits.RotateLeft(acc, 11) * prime64v1;
170+
acc ^= lane8 * k_Prime64v5;
171+
acc = Bits.RotateLeft(acc, 11) * k_Prime64v1;
172172
}
173173

174174
return acc;
@@ -178,26 +178,26 @@ private static unsafe ulong processRemaining64(
178178
private static ulong avalanche64(ulong acc)
179179
{
180180
acc ^= acc >> 33;
181-
acc *= prime64v2;
181+
acc *= k_Prime64v2;
182182
acc ^= acc >> 29;
183-
acc *= prime64v3;
183+
acc *= k_Prime64v3;
184184
acc ^= acc >> 32;
185185
return acc;
186186
}
187187

188188
[MethodImpl(MethodImplOptions.AggressiveInlining)]
189189
private static ulong round64(ulong accn, ulong lane)
190190
{
191-
accn += lane * prime64v2;
192-
return Bits.RotateLeft(accn, 31) * prime64v1;
191+
accn += lane * k_Prime64v2;
192+
return Bits.RotateLeft(accn, 31) * k_Prime64v1;
193193
}
194194

195195
[MethodImpl(MethodImplOptions.AggressiveInlining)]
196196
private static void mergeAccumulator64(ref ulong acc, ulong accn)
197197
{
198198
acc ^= round64(0, accn);
199-
acc *= prime64v1;
200-
acc += prime64v4;
199+
acc *= k_Prime64v1;
200+
acc += k_Prime64v4;
201201
}
202202

203203
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -236,15 +236,15 @@ private static unsafe uint processRemaining32(
236236
for (uint lane; remainingLen >= 4; remainingLen -= 4, pInput += 4)
237237
{
238238
lane = *(uint*)pInput;
239-
acc += lane * prime32v3;
240-
acc = Bits.RotateLeft(acc, 17) * prime32v4;
239+
acc += lane * k_Prime32v3;
240+
acc = Bits.RotateLeft(acc, 17) * k_Prime32v4;
241241
}
242242

243243
for (byte lane; remainingLen >= 1; remainingLen--, pInput++)
244244
{
245245
lane = *pInput;
246-
acc += lane * prime32v5;
247-
acc = Bits.RotateLeft(acc, 11) * prime32v1;
246+
acc += lane * k_Prime32v5;
247+
acc = Bits.RotateLeft(acc, 11) * k_Prime32v1;
248248
}
249249

250250
return acc;
@@ -253,19 +253,19 @@ private static unsafe uint processRemaining32(
253253
[MethodImpl(MethodImplOptions.AggressiveInlining)]
254254
private static uint round32(uint accn, uint lane)
255255
{
256-
accn += lane * prime32v2;
256+
accn += lane * k_Prime32v2;
257257
accn = Bits.RotateLeft(accn, 13);
258-
accn *= prime32v1;
258+
accn *= k_Prime32v1;
259259
return accn;
260260
}
261261

262262
[MethodImpl(MethodImplOptions.AggressiveInlining)]
263263
private static uint avalanche32(uint acc)
264264
{
265265
acc ^= acc >> 15;
266-
acc *= prime32v2;
266+
acc *= k_Prime32v2;
267267
acc ^= acc >> 13;
268-
acc *= prime32v3;
268+
acc *= k_Prime32v3;
269269
acc ^= acc >> 16;
270270
return acc;
271271
}

0 commit comments

Comments
 (0)