WeaverLists.replacedFields and replacementProperties merged into replacementSetterProperties dict for easier code and more obvious naming.

This commit is contained in:
vis2k 2019-01-13 21:21:11 +01:00
parent 4fa584e72a
commit 266f262665
2 changed files with 10 additions and 17 deletions

View File

@ -159,7 +159,6 @@ public static void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, List<Fi
{ {
string originalName = fd.Name; string originalName = fd.Name;
Weaver.lists.replacedFields.Add(fd);
Weaver.DLog(td, "Sync Var " + fd.Name + " " + fd.FieldType + " " + Weaver.gameObjectType); Weaver.DLog(td, "Sync Var " + fd.Name + " " + fd.FieldType + " " + Weaver.gameObjectType);
// GameObject SyncVars have a new field for netId // GameObject SyncVars have a new field for netId
@ -188,7 +187,7 @@ public static void ProcessSyncVar(TypeDefinition td, FieldDefinition fd, List<Fi
td.Methods.Add(get); td.Methods.Add(get);
td.Methods.Add(set); td.Methods.Add(set);
td.Properties.Add(propertyDefinition); td.Properties.Add(propertyDefinition);
Weaver.lists.replacementProperties.Add(set); Weaver.lists.replacementSetterProperties[fd] = set;
} }
public static void ProcessSyncVars(TypeDefinition td, List<FieldDefinition> syncVars, List<FieldDefinition> syncObjects, List<FieldDefinition> syncVarNetIds) public static void ProcessSyncVars(TypeDefinition td, List<FieldDefinition> syncVars, List<FieldDefinition> syncObjects, List<FieldDefinition> syncVarNetIds)

View File

@ -13,10 +13,8 @@ namespace Mirror.Weaver
// This data is flushed each time - if we are run multiple times in the same process/domain // This data is flushed each time - if we are run multiple times in the same process/domain
class WeaverLists class WeaverLists
{ {
// [SyncVar] member variables that should be replaced // setter functions that replace [SyncVar] member variable references. dict<field, replacement>
public List<FieldDefinition> replacedFields = new List<FieldDefinition>(); public Dictionary<FieldDefinition, MethodDefinition> replacementSetterProperties = new Dictionary<FieldDefinition, MethodDefinition>();
// setter functions that replace [SyncVar] member variable references
public List<MethodDefinition> replacementProperties = new List<MethodDefinition>();
// GameObject SyncVar generated netId fields // GameObject SyncVar generated netId fields
public List<FieldDefinition> netIdFields = new List<FieldDefinition>(); public List<FieldDefinition> netIdFields = new List<FieldDefinition>();
@ -751,18 +749,14 @@ static void ProcessInstructionSetterField(TypeDefinition td, MethodDefinition md
return; return;
// does it set a field that we replaced? // does it set a field that we replaced?
for (int n = 0; n < lists.replacedFields.Count; n++) MethodDefinition replacement;
{ if (lists.replacementSetterProperties.TryGetValue(opField, out replacement))
FieldDefinition fd = lists.replacedFields[n];
if (opField == fd)
{ {
//replace with property //replace with property
//DLog(td, " replacing " + md.Name + ":" + i); //DLog(td, " replacing " + md.Name + ":" + i);
i.OpCode = OpCodes.Call; i.OpCode = OpCodes.Call;
i.Operand = lists.replacementProperties[n]; i.Operand = replacement;
//DLog(td, " replaced " + md.Name + ":" + i); //DLog(td, " replaced " + md.Name + ":" + i);
break;
}
} }
} }