-
Notifications
You must be signed in to change notification settings - Fork 461
Implement RFC #1: Standard RPC to replace Convenience and Performance RPCs #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7475bc4
initial chunk
0xFA11 fc0a325
implement rpc params and reliability, refactor ILPP
0xFA11 d9e3174
rename rpc attributes and update xmldoc
0xFA11 7c90db3
implement unity diagnostics error messages
0xFA11 bb467c1
Merge branch 'develop' into feature/std-rpc-api
0xFA11 f36a40e
fix yamato build (using var syntax is not supported by the compiler)
0xFA11 d6c00d7
fix: Fixing an issue with latest trunk and ILPP
wackoisgod 95b8b06
fix: Make codegen great again. Fixed some resolver issues on linux an…
andrews-unity 85edeee
minor refactor
0xFA11 1f647a4
remove convenience and performance RPC implementations alonside with …
0xFA11 11e4cf1
bump yamato editor version from 2020.1 to 2020.2
0xFA11 3b4865c
minor update
0xFA11 465e3fa
merge branch 'develop' into 'feature/std-rpc-api'
0xFA11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...player.mlapi/Runtime/Core/RPCMethods.meta → ...ity.multiplayer.mlapi/Editor/CodeGen.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
196 changes: 196 additions & 0 deletions
196
com.unity.multiplayer.mlapi/Editor/CodeGen/CodeGenHelpers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using MLAPI.Messaging; | ||
| using MLAPI.Serialization; | ||
| using Mono.Cecil; | ||
| using Mono.Cecil.Cil; | ||
| using Mono.Cecil.Rocks; | ||
| using Unity.CompilationPipeline.Common.Diagnostics; | ||
| using Unity.CompilationPipeline.Common.ILPostProcessing; | ||
| using UnityEngine; | ||
|
|
||
| namespace MLAPI.Editor.CodeGen | ||
| { | ||
| internal static class CodeGenHelpers | ||
| { | ||
| public const string RuntimeAssemblyName = "Unity.Multiplayer.MLAPI.Runtime"; | ||
|
|
||
| public static readonly string NetworkBehaviour_FullName = typeof(NetworkedBehaviour).FullName; | ||
| public static readonly string ServerRpcAttribute_FullName = typeof(ServerRpcAttribute).FullName; | ||
| public static readonly string ClientRpcAttribute_FullName = typeof(ClientRpcAttribute).FullName; | ||
| public static readonly string ServerRpcParams_FullName = typeof(ServerRpcParams).FullName; | ||
| public static readonly string ClientRpcParams_FullName = typeof(ClientRpcParams).FullName; | ||
| public static readonly string INetworkSerializable_FullName = typeof(INetworkSerializable).FullName; | ||
| public static readonly string INetworkSerializable_NetworkRead_Name = nameof(INetworkSerializable.NetworkRead); | ||
| public static readonly string INetworkSerializable_NetworkWrite_Name = nameof(INetworkSerializable.NetworkWrite); | ||
| public static readonly string UnityColor_FullName = typeof(Color).FullName; | ||
| public static readonly string UnityVector2_FullName = typeof(Vector2).FullName; | ||
| public static readonly string UnityVector3_FullName = typeof(Vector3).FullName; | ||
| public static readonly string UnityVector4_FullName = typeof(Vector4).FullName; | ||
| public static readonly string UnityQuaternion_FullName = typeof(Quaternion).FullName; | ||
| public static readonly string UnityRay_FullName = typeof(Ray).FullName; | ||
| public static readonly string UnityRay2D_FullName = typeof(Ray2D).FullName; | ||
|
|
||
| public static uint Hash(this MethodDefinition methodDefinition) | ||
| { | ||
| var sigArr = Encoding.UTF8.GetBytes($"{methodDefinition.Module.Name} / {methodDefinition.FullName}"); | ||
| var sigLen = sigArr.Length; | ||
| unsafe | ||
| { | ||
| fixed (byte* sigPtr = sigArr) | ||
| { | ||
| return XXHash.Hash32(sigPtr, sigLen); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static bool IsSubclassOf(this TypeDefinition typeDefinition, string ClassTypeFullName) | ||
| { | ||
| if (!typeDefinition.IsClass) return false; | ||
|
|
||
| var baseTypeRef = typeDefinition.BaseType; | ||
| while (baseTypeRef != null) | ||
| { | ||
| if (baseTypeRef.FullName == ClassTypeFullName) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| baseTypeRef = baseTypeRef.Resolve().BaseType; | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public static bool HasInterface(this TypeReference typeReference, string InterfaceTypeFullName) | ||
| { | ||
| try | ||
| { | ||
| var typeDef = typeReference.Resolve(); | ||
| var typeFaces = typeDef.Interfaces; | ||
| return typeFaces.Any(iface => iface.InterfaceType.FullName == InterfaceTypeFullName); | ||
| } | ||
| catch | ||
| { | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public static bool IsSupportedType(this TypeReference typeReference) | ||
| { | ||
| var typeSystem = typeReference.Module.TypeSystem; | ||
|
|
||
| // common primitives | ||
| if (typeReference == typeSystem.Boolean) return true; | ||
| if (typeReference == typeSystem.Char) return true; | ||
| if (typeReference == typeSystem.SByte) return true; | ||
| if (typeReference == typeSystem.Byte) return true; | ||
| if (typeReference == typeSystem.Int16) return true; | ||
| if (typeReference == typeSystem.UInt16) return true; | ||
| if (typeReference == typeSystem.Int32) return true; | ||
| if (typeReference == typeSystem.UInt32) return true; | ||
| if (typeReference == typeSystem.Int64) return true; | ||
| if (typeReference == typeSystem.UInt64) return true; | ||
| if (typeReference == typeSystem.Single) return true; | ||
| if (typeReference == typeSystem.Double) return true; | ||
| if (typeReference == typeSystem.String) return true; | ||
|
|
||
| // Unity primitives | ||
| if (typeReference.FullName == UnityColor_FullName) return true; | ||
| if (typeReference.FullName == UnityVector2_FullName) return true; | ||
| if (typeReference.FullName == UnityVector3_FullName) return true; | ||
| if (typeReference.FullName == UnityVector4_FullName) return true; | ||
| if (typeReference.FullName == UnityQuaternion_FullName) return true; | ||
| if (typeReference.FullName == UnityRay_FullName) return true; | ||
| if (typeReference.FullName == UnityRay2D_FullName) return true; | ||
|
|
||
| // INetworkSerializable | ||
| if (typeReference.HasInterface(INetworkSerializable_FullName)) return true; | ||
|
|
||
| // Enum | ||
| if (typeReference.GetEnumAsInt() != null) return true; | ||
|
|
||
| // todo: [RFC] Serializable Types | ||
| // StaticArray[] | ||
| // IEnumerable<T> | ||
| // IEnumerable<KeyValuePair<K, V>> | ||
| // IEnumerable<Tuple<T1, T2, T3...T7>> | ||
| // IEnumerable<Tuple<T1, T2...TRest>> | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public static TypeReference GetEnumAsInt(this TypeReference typeReference) | ||
| { | ||
| try | ||
| { | ||
| var typeDef = typeReference.Resolve(); | ||
| if (typeDef.IsEnum) | ||
| { | ||
| return typeDef.GetEnumUnderlyingType(); | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| public static void AddError(this List<DiagnosticMessage> diagnostics, string message) | ||
| { | ||
| diagnostics.AddError((SequencePoint)null, message); | ||
| } | ||
|
|
||
| public static void AddError(this List<DiagnosticMessage> diagnostics, MethodDefinition methodDefinition, string message) | ||
| { | ||
| diagnostics.AddError(methodDefinition.DebugInformation.SequencePoints.FirstOrDefault(), message); | ||
| } | ||
|
|
||
| public static void AddError(this List<DiagnosticMessage> diagnostics, SequencePoint sequencePoint, string message) | ||
| { | ||
| diagnostics.Add(new DiagnosticMessage | ||
| { | ||
| DiagnosticType = DiagnosticType.Error, | ||
| File = sequencePoint?.Document.Url.Replace($"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}", ""), | ||
| Line = sequencePoint?.StartLine ?? 0, | ||
| Column = sequencePoint?.StartColumn ?? 0, | ||
| MessageData = $" - {message}" | ||
| }); | ||
| } | ||
|
|
||
| public static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compiledAssembly) | ||
| { | ||
| var assemblyResolver = new PostProcessorAssemblyResolver(compiledAssembly); | ||
| var readerParameters = new ReaderParameters | ||
| { | ||
| SymbolStream = new MemoryStream(compiledAssembly.InMemoryAssembly.PdbData), | ||
| SymbolReaderProvider = new PortablePdbReaderProvider(), | ||
| AssemblyResolver = assemblyResolver, | ||
| ReflectionImporterProvider = new PostProcessorReflectionImporterProvider(), | ||
| ReadingMode = ReadingMode.Immediate | ||
| }; | ||
|
|
||
| var assemblyDefinition = AssemblyDefinition.ReadAssembly(new MemoryStream(compiledAssembly.InMemoryAssembly.PeData), readerParameters); | ||
|
|
||
| //apparently, it will happen that when we ask to resolve a type that lives inside MLAPI.Runtime, and we | ||
| //are also postprocessing MLAPI.Runtime, type resolving will fail, because we do not actually try to resolve | ||
| //inside the assembly we are processing. Let's make sure we do that, so that we can use postprocessor features inside | ||
| //MLAPI.Runtime itself as well. | ||
| assemblyResolver.AddAssemblyDefinitionBeingOperatedOn(assemblyDefinition); | ||
|
|
||
| return assemblyDefinition; | ||
| } | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...c.InvokeClientRpcOnEveryoneExcept.cs.meta → ...api/Editor/CodeGen/CodeGenHelpers.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this needs a little bit more of a discussion :)