mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
breaking: NetworkBehaviour.SerializeSyncVars return type changed from bool to void to simplify weaver (and reduce branches)
This commit is contained in:
parent
7c7f83362b
commit
9c5e10f71b
@ -971,10 +971,8 @@ public virtual void OnDeserialize(NetworkReader reader, bool initialState)
|
||||
}
|
||||
|
||||
// USED BY WEAVER
|
||||
protected virtual bool SerializeSyncVars(NetworkWriter writer, bool initialState)
|
||||
protected virtual void SerializeSyncVars(NetworkWriter writer, bool initialState)
|
||||
{
|
||||
return false;
|
||||
|
||||
// SyncVar are written here in subclass
|
||||
|
||||
// if initialState
|
||||
@ -996,21 +994,17 @@ protected virtual void DeserializeSyncVars(NetworkReader reader, bool initialSta
|
||||
// read dirty SyncVars
|
||||
}
|
||||
|
||||
public bool SerializeObjectsAll(NetworkWriter writer)
|
||||
public void SerializeObjectsAll(NetworkWriter writer)
|
||||
{
|
||||
bool dirty = false;
|
||||
for (int i = 0; i < syncObjects.Count; i++)
|
||||
{
|
||||
SyncObject syncObject = syncObjects[i];
|
||||
syncObject.OnSerializeAll(writer);
|
||||
dirty = true;
|
||||
}
|
||||
return dirty;
|
||||
}
|
||||
|
||||
public bool SerializeObjectsDelta(NetworkWriter writer)
|
||||
public void SerializeObjectsDelta(NetworkWriter writer)
|
||||
{
|
||||
bool dirty = false;
|
||||
// write the mask
|
||||
writer.WriteULong(syncObjectDirtyBits);
|
||||
// serializable objects, such as synclists
|
||||
@ -1021,10 +1015,8 @@ public bool SerializeObjectsDelta(NetworkWriter writer)
|
||||
if ((syncObjectDirtyBits & (1UL << i)) != 0)
|
||||
{
|
||||
syncObject.OnSerializeDelta(writer);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
return dirty;
|
||||
}
|
||||
|
||||
internal void DeSerializeObjectsAll(NetworkReader reader)
|
||||
|
@ -397,7 +397,7 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
|
||||
MethodDefinition serialize = new MethodDefinition(SerializeMethodName,
|
||||
MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
|
||||
weaverTypes.Import<bool>());
|
||||
weaverTypes.Import(typeof(void)));
|
||||
|
||||
serialize.Parameters.Add(new ParameterDefinition("writer", ParameterAttributes.None, weaverTypes.Import<NetworkWriter>()));
|
||||
serialize.Parameters.Add(new ParameterDefinition("forceAll", ParameterAttributes.None, weaverTypes.Import<bool>()));
|
||||
@ -405,11 +405,7 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
|
||||
serialize.Body.InitLocals = true;
|
||||
|
||||
// loc_0, this local variable is to determine if any variable was dirty
|
||||
VariableDefinition dirtyLocal = new VariableDefinition(weaverTypes.Import<bool>());
|
||||
serialize.Body.Variables.Add(dirtyLocal);
|
||||
|
||||
// bool result = base.SerializeSyncVars(writer, forceAll);
|
||||
// base.SerializeSyncVars(writer, forceAll);
|
||||
MethodReference baseSerialize = Resolvers.TryResolveMethodInParents(netBehaviourSubclass.BaseType, assembly, SerializeMethodName);
|
||||
if (baseSerialize != null)
|
||||
{
|
||||
@ -420,8 +416,6 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
// forceAll
|
||||
worker.Emit(OpCodes.Ldarg_2);
|
||||
worker.Emit(OpCodes.Call, baseSerialize);
|
||||
// set dirtyLocal to result of base.OnSerialize()
|
||||
worker.Emit(OpCodes.Stloc_0);
|
||||
}
|
||||
|
||||
// Generates:
|
||||
@ -429,7 +423,6 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
// {
|
||||
// writer.WriteInt(health);
|
||||
// ...
|
||||
// return true;
|
||||
// }
|
||||
Instruction initialStateLabel = worker.Create(OpCodes.Nop);
|
||||
// forceAll
|
||||
@ -463,8 +456,7 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
}
|
||||
}
|
||||
|
||||
// if (forceAll) then always return true at the end of the 'if' case
|
||||
worker.Emit(OpCodes.Ldc_I4_1);
|
||||
// if (forceAll) then always return at the end of the 'if' case
|
||||
worker.Emit(OpCodes.Ret);
|
||||
|
||||
// end the 'if' case for "if (forceAll)"
|
||||
@ -488,7 +480,6 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
int dirtyBit = syncVarAccessLists.GetSyncVarStart(netBehaviourSubclass.BaseType.FullName);
|
||||
foreach (FieldDefinition syncVarDef in syncVars)
|
||||
{
|
||||
|
||||
FieldReference syncVar = syncVarDef;
|
||||
if (netBehaviourSubclass.HasGenericParameters)
|
||||
{
|
||||
@ -524,11 +515,6 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
return;
|
||||
}
|
||||
|
||||
// something was dirty
|
||||
worker.Emit(OpCodes.Ldc_I4_1);
|
||||
// set dirtyLocal to true
|
||||
worker.Emit(OpCodes.Stloc_0);
|
||||
|
||||
worker.Append(varLabel);
|
||||
dirtyBit += 1;
|
||||
}
|
||||
@ -537,8 +523,7 @@ void GenerateSerialization(ref bool WeavingFailed)
|
||||
//worker.Emit(OpCodes.Ldstr, $"Injected Serialize {netBehaviourSubclass.Name}");
|
||||
//worker.Emit(OpCodes.Call, WeaverTypes.logErrorReference);
|
||||
|
||||
// generate: return dirtyLocal
|
||||
worker.Emit(OpCodes.Ldloc_0);
|
||||
// generate: return
|
||||
worker.Emit(OpCodes.Ret);
|
||||
netBehaviourSubclass.Methods.Add(serialize);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user