mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Weaver SyncObject code moved into SyncObjectProcessor
This commit is contained in:
parent
32dcaf14e3
commit
b9ec4a5dc5
@ -58,26 +58,6 @@ public static ISymbolReaderProvider GetSymbolReaderProvider(string inputFile)
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool ImplementsSyncObject(TypeReference typeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
// value types cant inherit from SyncObject
|
||||
if (typeRef.IsValueType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Weaver.ImplementsInterface(typeRef.Resolve(), Weaver.SyncObjectType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// sometimes this will fail if we reference a weird library that can't be resolved, so we just swallow that exception and return false
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string DestinationFileFor(string outputDir, string assemblyPath)
|
||||
{
|
||||
string fileName = Path.GetFileName(assemblyPath);
|
||||
|
@ -72,6 +72,7 @@
|
||||
<Compile Include="Processors\NetworkBehaviourProcessor.cs" />
|
||||
<Compile Include="Processors\RpcProcessor.cs" />
|
||||
<Compile Include="Processors\SyncEventProcessor.cs" />
|
||||
<Compile Include="Processors\SyncObjectProcessor.cs" />
|
||||
<Compile Include="Processors\SyncVarProcessor.cs" />
|
||||
<Compile Include="Processors\TargetRpcProcessor.cs" />
|
||||
<Compile Include="Processors\SyncListStructProcessor.cs" />
|
||||
|
@ -25,7 +25,7 @@ static void ProcessSyncVars(TypeDefinition td)
|
||||
}
|
||||
}
|
||||
|
||||
if (Helpers.ImplementsSyncObject(fd.FieldType))
|
||||
if (SyncObjectProcessor.ImplementsSyncObject(fd.FieldType))
|
||||
{
|
||||
Log.Error(string.Format("Script {0} defines field {1} with type {2}, but it's not a NetworkBehaviour", td.FullName, fd.Name, Helpers.PrettyPrintType(fd.FieldType)));
|
||||
Weaver.fail = true;
|
||||
|
@ -267,7 +267,7 @@ void GenerateConstants()
|
||||
foreach (FieldDefinition fd in m_SyncObjects)
|
||||
{
|
||||
GenerateSyncListInstanceInitializer(ctorWorker, fd);
|
||||
GenerateSyncObjectInitializer(ctorWorker, fd);
|
||||
SyncObjectProcessor.GenerateSyncObjectInitializer(ctorWorker, fd);
|
||||
}
|
||||
|
||||
cctorWorker.Append(cctorWorker.Create(OpCodes.Ret));
|
||||
@ -326,19 +326,6 @@ void GenerateRegisterCommandDelegate(ILProcessor awakeWorker, MethodReference re
|
||||
awakeWorker.Append(awakeWorker.Create(OpCodes.Call, registerMethod));
|
||||
}
|
||||
|
||||
/*
|
||||
// generates code like:
|
||||
this.InitSyncObject(m_sizes);
|
||||
*/
|
||||
void GenerateSyncObjectInitializer(ILProcessor methodWorker, FieldReference fd)
|
||||
{
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldarg_0));
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldarg_0));
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldfld, fd));
|
||||
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Call, Weaver.InitSyncObjectReference));
|
||||
}
|
||||
|
||||
void GenerateSerialization()
|
||||
{
|
||||
Weaver.DLog(m_td, " GenerateSerialization");
|
||||
|
43
Mirror/Weaver/Processors/SyncObjectProcessor.cs
Normal file
43
Mirror/Weaver/Processors/SyncObjectProcessor.cs
Normal file
@ -0,0 +1,43 @@
|
||||
// SyncObject code
|
||||
using System.Linq;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
namespace Mirror.Weaver
|
||||
{
|
||||
public static class SyncObjectProcessor
|
||||
{
|
||||
public static bool ImplementsSyncObject(TypeReference typeRef)
|
||||
{
|
||||
try
|
||||
{
|
||||
// value types cant inherit from SyncObject
|
||||
if (typeRef.IsValueType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Weaver.ImplementsInterface(typeRef.Resolve(), Weaver.SyncObjectType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// sometimes this will fail if we reference a weird library that can't be resolved, so we just swallow that exception and return false
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// generates code like:
|
||||
this.InitSyncObject(m_sizes);
|
||||
*/
|
||||
public static void GenerateSyncObjectInitializer(ILProcessor methodWorker, FieldReference fd)
|
||||
{
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldarg_0));
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldarg_0));
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Ldfld, fd));
|
||||
|
||||
methodWorker.Append(methodWorker.Create(OpCodes.Call, Weaver.InitSyncObjectReference));
|
||||
}
|
||||
}
|
||||
}
|
@ -266,7 +266,7 @@ public static void ProcessSyncVars(TypeDefinition td, List<FieldDefinition> sync
|
||||
return;
|
||||
}
|
||||
|
||||
if (Helpers.ImplementsSyncObject(fd.FieldType))
|
||||
if (SyncObjectProcessor.ImplementsSyncObject(fd.FieldType))
|
||||
{
|
||||
Log.Warning(string.Format("Script class [{0}] has [SyncVar] attribute on SyncList field {1}, SyncLists should not be marked with SyncVar.", td.FullName, fd.Name));
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user