From 57b848cc3423bd67b9cc5139f8038c71709b66c1 Mon Sep 17 00:00:00 2001 From: vis2k Date: Tue, 15 Jan 2019 15:54:45 +0100 Subject: [PATCH] SyncVarProcessor.syncVarNetIds converted to Dictionary for easier usage and to avoid the netIdFieldCounters --- .../Weaver/Processors/NetworkBehaviourProcessor.cs | 10 +++------- Assets/Mirror/Weaver/Processors/SyncVarProcessor.cs | 9 +++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs b/Assets/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs index 552ef353c..bf7ffa0ca 100644 --- a/Assets/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs +++ b/Assets/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs @@ -11,7 +11,7 @@ class NetworkBehaviourProcessor { readonly List m_SyncVars = new List(); readonly List m_SyncObjects = new List(); - readonly List m_SyncVarNetIds = new List(); + readonly Dictionary m_SyncVarNetIds = new Dictionary(); // readonly List m_Cmds = new List(); readonly List m_Rpcs = new List(); readonly List m_TargetRpcs = new List(); @@ -486,7 +486,6 @@ void GenerateDeSerialization() serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); serWorker.Append(serWorker.Create(OpCodes.Brfalse, initialStateLabel)); - int netIdFieldCounter = 0; foreach (FieldDefinition syncVar in m_SyncVars) { // assign value @@ -501,8 +500,7 @@ void GenerateDeSerialization() // OnDeserialize reads to __netId manually so we can use // lookups in the getter (so it still works if objects // move in and out of range repeatedly) - FieldDefinition netIdField = m_SyncVarNetIds[netIdFieldCounter]; - netIdFieldCounter += 1; + FieldDefinition netIdField = m_SyncVarNetIds[syncVar]; serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadPacked32)); serWorker.Append(serWorker.Create(OpCodes.Stfld, netIdField)); @@ -540,7 +538,6 @@ void GenerateDeSerialization() serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); // conditionally read each syncvar - netIdFieldCounter = 0; // reset int dirtyBit = Weaver.GetSyncVarStart(m_td.BaseType.FullName); // start at number of syncvars in parent foreach (FieldDefinition syncVar in m_SyncVars) { @@ -567,8 +564,7 @@ void GenerateDeSerialization() // OnDeserialize reads to __netId manually so we can use // lookups in the getter (so it still works if objects // move in and out of range repeatedly) - FieldDefinition netIdField = m_SyncVarNetIds[netIdFieldCounter]; - netIdFieldCounter += 1; + FieldDefinition netIdField = m_SyncVarNetIds[syncVar]; if (foundMethod == null) { diff --git a/Assets/Mirror/Weaver/Processors/SyncVarProcessor.cs b/Assets/Mirror/Weaver/Processors/SyncVarProcessor.cs index 5461daf7c..fe56a7140 100644 --- a/Assets/Mirror/Weaver/Processors/SyncVarProcessor.cs +++ b/Assets/Mirror/Weaver/Processors/SyncVarProcessor.cs @@ -191,7 +191,7 @@ public static MethodDefinition ProcessSyncVarSet(TypeDefinition td, FieldDefinit return set; } - public static void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, List syncVarNetIds, long dirtyBit) + public static void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, Dictionary syncVarNetIds, long dirtyBit) { string originalName = fd.Name; Weaver.DLog(td, "Sync Var " + fd.Name + " " + fd.FieldType + " " + Weaver.gameObjectType); @@ -205,7 +205,7 @@ public static void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, List syncVars, List syncObjects, List syncVarNetIds) + public static void ProcessSyncVars(TypeDefinition td, List syncVars, List syncObjects, Dictionary syncVarNetIds) { int numSyncVars = 0; @@ -353,7 +353,8 @@ public static void ProcessSyncVars(TypeDefinition td, List sync } } - foreach (FieldDefinition fd in syncVarNetIds) + // add all the new SyncVar __netId fields + foreach (FieldDefinition fd in syncVarNetIds.Values) { td.Fields.Add(fd); }