From 9e2e6759bd39f1217561850b4c04594a9916e44a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 18 Jun 2023 15:33:57 +0200 Subject: [PATCH] Implement proper POD types check in C# network replication codegen --- .../Flax.Build/Bindings/StructureInfo.cs | 2 +- .../Build/Plugins/NetworkingPlugin.cs | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/StructureInfo.cs b/Source/Tools/Flax.Build/Bindings/StructureInfo.cs index d9dd87215..70fa17c36 100644 --- a/Source/Tools/Flax.Build/Bindings/StructureInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/StructureInfo.cs @@ -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++) { diff --git a/Source/Tools/Flax.Build/Build/Plugins/NetworkingPlugin.cs b/Source/Tools/Flax.Build/Build/Plugins/NetworkingPlugin.cs index f153bf30d..e047f5116 100644 --- a/Source/Tools/Flax.Build/Build/Plugins/NetworkingPlugin.cs +++ b/Source/Tools/Flax.Build/Build/Plugins/NetworkingPlugin.cs @@ -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)