Implement proper POD types check in C# network replication codegen

This commit is contained in:
Wojtek Figat
2023-06-18 15:33:57 +02:00
parent 1a6e706e57
commit 9e2e6759bd
2 changed files with 19 additions and 3 deletions

View File

@@ -32,7 +32,7 @@ namespace Flax.Build.Bindings
return;
}
// Structure is POD (plain old data) only if all of it's fields are (and has no base type ro base type is also POD)
// Structure is POD (plain old data) only if all of it's fields are (and has no base type or base type is also POD)
_isPod = BaseType == null || (BaseType?.IsPod ?? false);
for (int i = 0; _isPod && i < Fields.Count; i++)
{

View File

@@ -367,8 +367,24 @@ namespace Flax.Build.Plugins
private static bool IsRawPOD(TypeReference type)
{
// TODO:
return type.IsValueType;
if (type.FullName == "System.ValueType")
return true;
if (type.IsValueType)
{
var typeDef = type.Resolve();
if (typeDef.IsEnum)
return true;
var baseType = typeDef.BaseType;
if (baseType != null && !IsRawPOD(baseType))
return false;
foreach (var field in typeDef.Fields)
{
if (!field.IsStatic && field.FieldType != type && !IsRawPOD(field.FieldType))
return false;
}
return true;
}
return false;
}
private void OnGenerateCppTypeSerializeData(Builder.BuildData buildData, ApiTypeInfo caller, StringBuilder contents, TypeInfo type, string name, bool serialize)