Serialize initial message by setting all dirty flags

This commit is contained in:
Paul Pacheco 2018-07-31 23:47:49 -05:00
parent e7403a8983
commit 50df4d1b1f
3 changed files with 10 additions and 90 deletions

View File

@ -548,6 +548,12 @@ public void ClearAllDirtyBits()
m_SyncVarDirtyBits = 0L;
}
public void SetAllDirtyBits()
{
m_LastSendTime = float.MinValue;
m_SyncVarDirtyBits = ~0uL;
}
internal bool IsDirty()
{
return

View File

@ -467,6 +467,10 @@ internal bool OnSerializeAllSafely(NetworkBehaviour[] components, NetworkWriter
// set bit #i to 1 in dirty mask
dirtyComponentsMask |= (ulong)(1L << i);
if (initialState)
{
comp.SetAllDirtyBits();
}
// serialize and clear dirty bits in any case, since the component was clearly dirty if we got here
if (LogFilter.logDebug) { Debug.Log("OnSerializeAllSafely: " + name + " -> " + comp.GetType() + " initial=" + initialState + " channelId=" + channelId); }
OnSerializeSafely(comp, payload, initialState);

View File

@ -514,7 +514,6 @@ void GenerateSerialization()
serialize.Body.Variables.Add(dirtyLocal);
// call base class
bool baseClassSerialize = false;
if (m_td.BaseType.FullName != Weaver.NetworkBehaviourType.FullName)
{
MethodReference baseSerialize = Weaver.ResolveMethod(m_td.BaseType, "OnSerialize");
@ -525,7 +524,6 @@ void GenerateSerialization()
serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); // forceAll
serWorker.Append(serWorker.Create(OpCodes.Call, baseSerialize));
serWorker.Append(serWorker.Create(OpCodes.Stloc_0)); // set dirtyLocal to result of base.OnSerialize()
baseClassSerialize = true;
}
}
@ -539,39 +537,6 @@ void GenerateSerialization()
return;
}
// Generates: if (forceAll);
Instruction initialStateLabel = serWorker.Create(OpCodes.Nop);
serWorker.Append(serWorker.Create(OpCodes.Ldarg_2)); // forceAll
serWorker.Append(serWorker.Create(OpCodes.Brfalse, initialStateLabel));
foreach (FieldDefinition syncVar in m_SyncVars)
{
// Generates a writer call for each sync variable
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); // writer
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0)); // this
serWorker.Append(serWorker.Create(OpCodes.Ldfld, syncVar));
MethodReference writeFunc = Weaver.GetWriteFunc(syncVar.FieldType);
if (writeFunc != null)
{
serWorker.Append(serWorker.Create(OpCodes.Call, writeFunc));
}
else
{
Weaver.fail = true;
Log.Error("GenerateSerialization for " + m_td.Name + " unknown type [" + syncVar.FieldType + "]. UNet [SyncVar] member variables must be basic types.");
return;
}
}
// always return true if forceAll
// Generates: return true
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4_1));
serWorker.Append(serWorker.Create(OpCodes.Ret));
// Generates: end if (forceAll);
serWorker.Append(initialStateLabel);
// write dirty bits before the data fields
// Generates: writer.WritePackedUInt64 (base.get_syncVarDirtyBits ());
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1)); // writer
@ -869,61 +834,6 @@ void GenerateDeSerialization()
return;
}
// Generates: if (initialState);
Instruction initialStateLabel = serWorker.Create(OpCodes.Nop);
serWorker.Append(serWorker.Create(OpCodes.Ldarg_2));
serWorker.Append(serWorker.Create(OpCodes.Brfalse, initialStateLabel));
foreach (var syncVar in m_SyncVars)
{
MethodReference readByReferenceFunc = Weaver.GetReadByReferenceFunc(syncVar.FieldType);
if (readByReferenceFunc != null)
{
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
serWorker.Append(serWorker.Create(OpCodes.Ldfld, syncVar));
serWorker.Append(serWorker.Create(OpCodes.Call, readByReferenceFunc));
}
else
{
// assign value
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
if (syncVar.FieldType.FullName == Weaver.gameObjectType.FullName)
{
// GameObject SyncVar - assign to generated netId var
FieldDefinition netIdField = m_SyncVarNetIds[m_NetIdFieldCounter];
m_NetIdFieldCounter += 1;
serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadNetworkInstanceId));
serWorker.Append(serWorker.Create(OpCodes.Stfld, netIdField));
}
else
{
MethodReference readFunc = Weaver.GetReadFunc(syncVar.FieldType);
if (readFunc != null)
{
serWorker.Append(serWorker.Create(OpCodes.Call, readFunc));
}
else
{
Log.Error("GenerateDeSerialization for " + m_td.Name + " unknown type [" + syncVar.FieldType + "]. UNet [SyncVar] member variables must be basic types.");
Weaver.fail = true;
return;
}
serWorker.Append(serWorker.Create(OpCodes.Stfld, syncVar));
}
}
}
serWorker.Append(serWorker.Create(OpCodes.Ret));
// Generates: end if (initialState);
serWorker.Append(initialStateLabel);
// setup local for dirty bits
serialize.Body.InitLocals = true;
VariableDefinition dirtyBitsLocal = new VariableDefinition(Weaver.int64Type);