From 37af48b83e4974e61a00c8ea220cd13082f389e7 Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 20 Sep 2021 19:11:20 +0800 Subject: [PATCH] Weaver: WeaverLists renamed to SyncVarAccessLists because that's what it's for --- .../Processors/NetworkBehaviourProcessor.cs | 12 +++---- .../Processors/SyncVarAccessReplacer.cs | 34 +++++++++---------- .../Weaver/Processors/SyncVarProcessor.cs | 14 ++++---- .../{WeaverLists.cs => SyncVarAccessLists.cs} | 2 +- ...sts.cs.meta => SyncVarAccessLists.cs.meta} | 0 Assets/Mirror/Editor/Weaver/Weaver.cs | 8 ++--- 6 files changed, 35 insertions(+), 35 deletions(-) rename Assets/Mirror/Editor/Weaver/{WeaverLists.cs => SyncVarAccessLists.cs} (97%) rename Assets/Mirror/Editor/Weaver/{WeaverLists.cs.meta => SyncVarAccessLists.cs.meta} (100%) diff --git a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs index 505853637..9908d85a0 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs @@ -16,7 +16,7 @@ class NetworkBehaviourProcessor { AssemblyDefinition assembly; WeaverTypes weaverTypes; - WeaverLists weaverLists; + SyncVarAccessLists syncVarAccessLists; SyncVarProcessor syncVarProcessor; Writers writers; Readers readers; @@ -47,15 +47,15 @@ public struct ClientRpcResult public bool includeOwner; } - public NetworkBehaviourProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes, WeaverLists weaverLists, Writers writers, Readers readers, Logger Log, TypeDefinition td) + public NetworkBehaviourProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes, SyncVarAccessLists syncVarAccessLists, Writers writers, Readers readers, Logger Log, TypeDefinition td) { this.assembly = assembly; this.weaverTypes = weaverTypes; - this.weaverLists = weaverLists; + this.syncVarAccessLists = syncVarAccessLists; this.writers = writers; this.readers = readers; this.Log = Log; - syncVarProcessor = new SyncVarProcessor(assembly, weaverTypes, weaverLists, Log); + syncVarProcessor = new SyncVarProcessor(assembly, weaverTypes, syncVarAccessLists, Log); netBehaviourSubclass = td; } @@ -453,7 +453,7 @@ void GenerateSerialization(ref bool WeavingFailed) // generate a writer call for any dirty variable in this class // start at number of syncvars in parent - int dirtyBit = weaverLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); + int dirtyBit = syncVarAccessLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); foreach (FieldDefinition syncVar in syncVars) { Instruction varLabel = worker.Create(OpCodes.Nop); @@ -865,7 +865,7 @@ void GenerateDeSerialization(ref bool WeavingFailed) // conditionally read each syncvar // start at number of syncvars in parent - int dirtyBit = weaverLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); + int dirtyBit = syncVarAccessLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName); foreach (FieldDefinition syncVar in syncVars) { Instruction varLabel = serWorker.Create(OpCodes.Nop); diff --git a/Assets/Mirror/Editor/Weaver/Processors/SyncVarAccessReplacer.cs b/Assets/Mirror/Editor/Weaver/Processors/SyncVarAccessReplacer.cs index 83a627634..8ea5d3f31 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/SyncVarAccessReplacer.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/SyncVarAccessReplacer.cs @@ -11,7 +11,7 @@ namespace Mirror.Weaver public static class SyncVarAccessReplacer { // process the module - public static void Process(ModuleDefinition moduleDef, WeaverLists weaverLists) + public static void Process(ModuleDefinition moduleDef, SyncVarAccessLists syncVarAccessLists) { DateTime startTime = DateTime.Now; @@ -20,31 +20,31 @@ public static void Process(ModuleDefinition moduleDef, WeaverLists weaverLists) { if (td.IsClass) { - ProcessClass(weaverLists, td); + ProcessClass(syncVarAccessLists, td); } } Console.WriteLine($" ProcessSitesModule {moduleDef.Name} elapsed time:{(DateTime.Now - startTime)}"); } - static void ProcessClass(WeaverLists weaverLists, TypeDefinition td) + static void ProcessClass(SyncVarAccessLists syncVarAccessLists, TypeDefinition td) { //Console.WriteLine(" ProcessClass " + td); // process all methods in this class foreach (MethodDefinition md in td.Methods) { - ProcessMethod(weaverLists, md); + ProcessMethod(syncVarAccessLists, md); } // processes all nested classes in this class recursively foreach (TypeDefinition nested in td.NestedTypes) { - ProcessClass(weaverLists, nested); + ProcessClass(syncVarAccessLists, nested); } } - static void ProcessMethod(WeaverLists weaverLists, MethodDefinition md) + static void ProcessMethod(SyncVarAccessLists syncVarAccessLists, MethodDefinition md) { // process all references to replaced members with properties //Weaver.DLog(td, " ProcessSiteMethod " + md); @@ -67,24 +67,24 @@ static void ProcessMethod(WeaverLists weaverLists, MethodDefinition md) for (int i = 0; i < md.Body.Instructions.Count;) { Instruction instr = md.Body.Instructions[i]; - i += ProcessInstruction(weaverLists, md, instr, i); + i += ProcessInstruction(syncVarAccessLists, md, instr, i); } } } - static int ProcessInstruction(WeaverLists weaverLists, MethodDefinition md, Instruction instr, int iCount) + static int ProcessInstruction(SyncVarAccessLists syncVarAccessLists, MethodDefinition md, Instruction instr, int iCount) { // stfld (sets value of a field)? if (instr.OpCode == OpCodes.Stfld && instr.Operand is FieldDefinition opFieldst) { - ProcessSetInstruction(weaverLists, md, instr, opFieldst); + ProcessSetInstruction(syncVarAccessLists, md, instr, opFieldst); } // ldfld (load value of a field)? if (instr.OpCode == OpCodes.Ldfld && instr.Operand is FieldDefinition opFieldld) { // this instruction gets the value of a field. cache the field reference. - ProcessGetInstruction(weaverLists, md, instr, opFieldld); + ProcessGetInstruction(syncVarAccessLists, md, instr, opFieldld); } // ldflda (load field address aka reference) @@ -92,7 +92,7 @@ static int ProcessInstruction(WeaverLists weaverLists, MethodDefinition md, Inst { // watch out for initobj instruction // see https://github.com/vis2k/Mirror/issues/696 - return ProcessLoadAddressInstruction(weaverLists, md, instr, opFieldlda, iCount); + return ProcessLoadAddressInstruction(syncVarAccessLists, md, instr, opFieldlda, iCount); } // we processed one instruction (instr) @@ -100,14 +100,14 @@ static int ProcessInstruction(WeaverLists weaverLists, MethodDefinition md, Inst } // replaces syncvar write access with the NetworkXYZ.set property calls - static void ProcessSetInstruction(WeaverLists weaverLists, MethodDefinition md, Instruction i, FieldDefinition opField) + static void ProcessSetInstruction(SyncVarAccessLists syncVarAccessLists, MethodDefinition md, Instruction i, FieldDefinition opField) { // don't replace property call sites in constructors if (md.Name == ".ctor") return; // does it set a field that we replaced? - if (weaverLists.replacementSetterProperties.TryGetValue(opField, out MethodDefinition replacement)) + if (syncVarAccessLists.replacementSetterProperties.TryGetValue(opField, out MethodDefinition replacement)) { //replace with property //DLog(td, " replacing " + md.Name + ":" + i); @@ -118,14 +118,14 @@ static void ProcessSetInstruction(WeaverLists weaverLists, MethodDefinition md, } // replaces syncvar read access with the NetworkXYZ.get property calls - static void ProcessGetInstruction(WeaverLists weaverLists, MethodDefinition md, Instruction i, FieldDefinition opField) + static void ProcessGetInstruction(SyncVarAccessLists syncVarAccessLists, MethodDefinition md, Instruction i, FieldDefinition opField) { // don't replace property call sites in constructors if (md.Name == ".ctor") return; // does it set a field that we replaced? - if (weaverLists.replacementGetterProperties.TryGetValue(opField, out MethodDefinition replacement)) + if (syncVarAccessLists.replacementGetterProperties.TryGetValue(opField, out MethodDefinition replacement)) { //replace with property //DLog(td, " replacing " + md.Name + ":" + i); @@ -135,14 +135,14 @@ static void ProcessGetInstruction(WeaverLists weaverLists, MethodDefinition md, } } - static int ProcessLoadAddressInstruction(WeaverLists weaverLists, MethodDefinition md, Instruction instr, FieldDefinition opField, int iCount) + static int ProcessLoadAddressInstruction(SyncVarAccessLists syncVarAccessLists, MethodDefinition md, Instruction instr, FieldDefinition opField, int iCount) { // don't replace property call sites in constructors if (md.Name == ".ctor") return 1; // does it set a field that we replaced? - if (weaverLists.replacementSetterProperties.TryGetValue(opField, out MethodDefinition replacement)) + if (syncVarAccessLists.replacementSetterProperties.TryGetValue(opField, out MethodDefinition replacement)) { // we have a replacement for this property // is the next instruction a initobj? diff --git a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs index d321da39c..4ff8dea53 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs @@ -14,17 +14,17 @@ public class SyncVarProcessor AssemblyDefinition assembly; WeaverTypes weaverTypes; - WeaverLists weaverLists; + SyncVarAccessLists syncVarAccessLists; Logger Log; string HookParameterMessage(string hookName, TypeReference ValueType) => $"void {hookName}({ValueType} oldValue, {ValueType} newValue)"; - public SyncVarProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes, WeaverLists weaverLists, Logger Log) + public SyncVarProcessor(AssemblyDefinition assembly, WeaverTypes weaverTypes, SyncVarAccessLists syncVarAccessLists, Logger Log) { this.assembly = assembly; this.weaverTypes = weaverTypes; - this.weaverLists = weaverLists; + this.syncVarAccessLists = syncVarAccessLists; this.Log = Log; } @@ -342,7 +342,7 @@ public void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary public Dictionary replacementSetterProperties = diff --git a/Assets/Mirror/Editor/Weaver/WeaverLists.cs.meta b/Assets/Mirror/Editor/Weaver/SyncVarAccessLists.cs.meta similarity index 100% rename from Assets/Mirror/Editor/Weaver/WeaverLists.cs.meta rename to Assets/Mirror/Editor/Weaver/SyncVarAccessLists.cs.meta diff --git a/Assets/Mirror/Editor/Weaver/Weaver.cs b/Assets/Mirror/Editor/Weaver/Weaver.cs index 3f7709fcf..56947d5b5 100644 --- a/Assets/Mirror/Editor/Weaver/Weaver.cs +++ b/Assets/Mirror/Editor/Weaver/Weaver.cs @@ -20,7 +20,7 @@ internal class Weaver public const string MirrorAssemblyName = "Mirror"; WeaverTypes weaverTypes; - WeaverLists weaverLists; + SyncVarAccessLists syncVarAccessLists; IAssemblyResolver Resolver; AssemblyDefinition CurrentAssembly; Writers writers; @@ -78,7 +78,7 @@ bool WeaveNetworkBehavior(TypeDefinition td) bool modified = false; foreach (TypeDefinition behaviour in behaviourClasses) { - modified |= new NetworkBehaviourProcessor(CurrentAssembly, weaverTypes, weaverLists, writers, readers, Log, behaviour).Process(ref WeavingFailed); + modified |= new NetworkBehaviourProcessor(CurrentAssembly, weaverTypes, syncVarAccessLists, writers, readers, Log, behaviour).Process(ref WeavingFailed); } return modified; } @@ -159,7 +159,7 @@ public bool Weave(AssemblyDefinition assembly, IAssemblyResolver resolver, out b CreateGeneratedCodeClass(); // WeaverList depends on WeaverTypes setup because it uses Import - weaverLists = new WeaverLists(); + syncVarAccessLists = new SyncVarAccessLists(); // initialize readers & writers with this assembly. // we need to do this in every Process() call. @@ -187,7 +187,7 @@ public bool Weave(AssemblyDefinition assembly, IAssemblyResolver resolver, out b if (modified) { - SyncVarAccessReplacer.Process(moduleDefinition, weaverLists); + SyncVarAccessReplacer.Process(moduleDefinition, syncVarAccessLists); // add class that holds read/write functions moduleDefinition.Types.Add(GeneratedCodeClass);