mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Refactor reader function generation
This commit is contained in:
parent
fe061ac792
commit
2dc280d292
@ -138,21 +138,11 @@ static MethodDefinition GenerateArrayReadFunc(TypeReference variable, int recurs
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string functionName = "_Read_" + variable.FullName;
|
MethodDefinition readerFunc = GenerateReaderFunction(variable);
|
||||||
|
|
||||||
// create new reader for this type
|
|
||||||
MethodDefinition readerFunc = new MethodDefinition(functionName,
|
|
||||||
MethodAttributes.Public |
|
|
||||||
MethodAttributes.Static |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
variable);
|
|
||||||
|
|
||||||
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<Mirror.NetworkReader>()));
|
|
||||||
|
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
readerFunc.Body.InitLocals = true;
|
|
||||||
|
|
||||||
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
||||||
|
|
||||||
@ -214,19 +204,7 @@ static MethodDefinition GenerateArrayReadFunc(TypeReference variable, int recurs
|
|||||||
|
|
||||||
static MethodDefinition GenerateEnumReadFunc(TypeReference variable)
|
static MethodDefinition GenerateEnumReadFunc(TypeReference variable)
|
||||||
{
|
{
|
||||||
string functionName = "_Read_" + variable.FullName;
|
MethodDefinition readerFunc = GenerateReaderFunction(variable);
|
||||||
|
|
||||||
// create new reader for this type
|
|
||||||
var readerFunc = new MethodDefinition(functionName,
|
|
||||||
MethodAttributes.Public |
|
|
||||||
MethodAttributes.Static |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
Weaver.CurrentAssembly.MainModule.ImportReference(variable));
|
|
||||||
|
|
||||||
// create local for return value
|
|
||||||
readerFunc.Body.InitLocals = true;
|
|
||||||
|
|
||||||
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<NetworkReader>()));
|
|
||||||
|
|
||||||
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
||||||
|
|
||||||
@ -252,16 +230,7 @@ static MethodDefinition GenerateArraySegmentReadFunc(TypeReference variable, int
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string functionName = "_Read_" + variable.FullName;
|
MethodDefinition readerFunc = GenerateReaderFunction(variable);
|
||||||
|
|
||||||
// create new reader for this type
|
|
||||||
MethodDefinition readerFunc = new MethodDefinition(functionName,
|
|
||||||
MethodAttributes.Public |
|
|
||||||
MethodAttributes.Static |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
variable);
|
|
||||||
|
|
||||||
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<Mirror.NetworkReader>()));
|
|
||||||
|
|
||||||
// int lengh
|
// int lengh
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
@ -269,7 +238,7 @@ static MethodDefinition GenerateArraySegmentReadFunc(TypeReference variable, int
|
|||||||
readerFunc.Body.Variables.Add(new VariableDefinition(elementType.MakeArrayType()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(elementType.MakeArrayType()));
|
||||||
// int i;
|
// int i;
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
readerFunc.Body.InitLocals = true;
|
|
||||||
|
|
||||||
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
||||||
|
|
||||||
@ -323,6 +292,22 @@ static MethodDefinition GenerateArraySegmentReadFunc(TypeReference variable, int
|
|||||||
return readerFunc;
|
return readerFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MethodDefinition GenerateReaderFunction(TypeReference variable)
|
||||||
|
{
|
||||||
|
string functionName = "_Read_" + variable.FullName;
|
||||||
|
|
||||||
|
// create new reader for this type
|
||||||
|
var readerFunc = new MethodDefinition(functionName,
|
||||||
|
MethodAttributes.Public |
|
||||||
|
MethodAttributes.Static |
|
||||||
|
MethodAttributes.HideBySig,
|
||||||
|
Weaver.CurrentAssembly.MainModule.ImportReference(variable));
|
||||||
|
|
||||||
|
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<Mirror.NetworkReader>()));
|
||||||
|
readerFunc.Body.InitLocals = true;
|
||||||
|
return readerFunc;
|
||||||
|
}
|
||||||
|
|
||||||
static MethodDefinition GenerateListReadFunc(TypeReference variable, int recursionCount)
|
static MethodDefinition GenerateListReadFunc(TypeReference variable, int recursionCount)
|
||||||
{
|
{
|
||||||
GenericInstanceType genericInstance = (GenericInstanceType)variable;
|
GenericInstanceType genericInstance = (GenericInstanceType)variable;
|
||||||
@ -335,21 +320,11 @@ static MethodDefinition GenerateListReadFunc(TypeReference variable, int recursi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string functionName = "_Read_" + variable.FullName + "_";
|
MethodDefinition readerFunc = GenerateReaderFunction(variable);
|
||||||
|
|
||||||
// create new reader for this type
|
|
||||||
MethodDefinition readerFunc = new MethodDefinition(functionName,
|
|
||||||
MethodAttributes.Public |
|
|
||||||
MethodAttributes.Static |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
variable);
|
|
||||||
|
|
||||||
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<Mirror.NetworkReader>()));
|
|
||||||
|
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
readerFunc.Body.Variables.Add(new VariableDefinition(WeaverTypes.Import<int>()));
|
||||||
readerFunc.Body.InitLocals = true;
|
|
||||||
|
|
||||||
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
||||||
|
|
||||||
@ -428,20 +403,10 @@ static MethodDefinition GenerateClassOrStructReadFunction(TypeReference variable
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string functionName = "_Read_" + variable.FullName;
|
MethodDefinition readerFunc = GenerateReaderFunction(variable);
|
||||||
|
|
||||||
// create new reader for this type
|
|
||||||
MethodDefinition readerFunc = new MethodDefinition(functionName,
|
|
||||||
MethodAttributes.Public |
|
|
||||||
MethodAttributes.Static |
|
|
||||||
MethodAttributes.HideBySig,
|
|
||||||
variable);
|
|
||||||
|
|
||||||
// create local for return value
|
// create local for return value
|
||||||
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
readerFunc.Body.Variables.Add(new VariableDefinition(variable));
|
||||||
readerFunc.Body.InitLocals = true;
|
|
||||||
|
|
||||||
readerFunc.Parameters.Add(new ParameterDefinition("reader", ParameterAttributes.None, WeaverTypes.Import<Mirror.NetworkReader>()));
|
|
||||||
|
|
||||||
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
ILProcessor worker = readerFunc.Body.GetILProcessor();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user