splitting code into multiple functions (#1903)

This commit is contained in:
James Frowen 2020-05-19 13:50:44 +01:00 committed by GitHub
parent f989b0fb11
commit 866808438a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -424,7 +424,37 @@ void DeserializeField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefi
// check for Hook function // check for Hook function
MethodDefinition hookMethod = SyncVarProcessor.GetHookMethod(netBehaviourSubclass, syncVar); MethodDefinition hookMethod = SyncVarProcessor.GetHookMethod(netBehaviourSubclass, syncVar);
// [SyncVar] GameObject/NetworkIdentity? if (IsNetworkIdentityField(syncVar))
{
DeserializeNetworkIdentityField(syncVar, serWorker, deserialize, hookMethod);
}
else
{
DeserializeNormalField(syncVar, serWorker, deserialize, hookMethod);
}
}
/// <summary>
/// Is the field a NetworkIdentity or GameObject
/// </summary>
/// <param name="syncVar"></param>
/// <returns></returns>
static bool IsNetworkIdentityField(FieldDefinition syncVar)
{
return syncVar.FieldType.FullName == Weaver.gameObjectType.FullName ||
syncVar.FieldType.FullName == Weaver.NetworkIdentityType.FullName;
}
/// <summary>
/// [SyncVar] GameObject/NetworkIdentity?
/// </summary>
/// <param name="syncVar"></param>
/// <param name="serWorker"></param>
/// <param name="deserialize"></param>
/// <param name="initialState"></param>
/// <param name="hookResult"></param>
void DeserializeNetworkIdentityField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefinition deserialize, MethodDefinition hookMethod)
{
/* /*
Generates code like: Generates code like:
uint oldNetId = ___qNetId; uint oldNetId = ___qNetId;
@ -437,9 +467,7 @@ void DeserializeField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefi
OnSetQ(oldSyncVar, syncvar.getter); OnSetQ(oldSyncVar, syncvar.getter);
} }
*/ */
if (syncVar.FieldType.FullName == Weaver.gameObjectType.FullName ||
syncVar.FieldType.FullName == Weaver.NetworkIdentityType.FullName)
{
// GameObject/NetworkIdentity SyncVar: // GameObject/NetworkIdentity SyncVar:
// OnSerialize sends writer.Write(go); // OnSerialize sends writer.Write(go);
// OnDeserialize reads to __netId manually so we can use // OnDeserialize reads to __netId manually so we can use
@ -530,7 +558,17 @@ void DeserializeField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefi
serWorker.Append(syncVarEqualLabel); serWorker.Append(syncVarEqualLabel);
} }
} }
// [SyncVar] int/float/struct/etc.?
/// <summary>
/// [SyncVar] int/float/struct/etc.?
/// </summary>
/// <param name="syncVar"></param>
/// <param name="serWorker"></param>
/// <param name="deserialize"></param>
/// <param name="initialState"></param>
/// <param name="hookResult"></param>
void DeserializeNormalField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefinition deserialize, MethodDefinition hookMethod)
{
/* /*
Generates code like: Generates code like:
// for hook // for hook
@ -541,8 +579,7 @@ void DeserializeField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefi
OnSetA(oldValue, Networka); OnSetA(oldValue, Networka);
} }
*/ */
else
{
MethodReference readFunc = Readers.GetReadFunc(syncVar.FieldType); MethodReference readFunc = Readers.GetReadFunc(syncVar.FieldType);
if (readFunc == null) if (readFunc == null)
{ {
@ -614,7 +651,6 @@ void DeserializeField(FieldDefinition syncVar, ILProcessor serWorker, MethodDefi
serWorker.Append(syncVarEqualLabel); serWorker.Append(syncVarEqualLabel);
} }
} }
}
void GenerateDeSerialization() void GenerateDeSerialization()
{ {