forked from Misaki/GhostEngine
Refactor component registration, update deps, improve JSON
- Updated Misaki.HighPerformance package versions in Core and Graphics projects. - Added IsTrimmable to Ghost.Engine.csproj for trimming support. - Renamed GetOrRegisterComponent to GetOrRegisterComponentID and updated all usages. - Component registration codegen now uses a static class with [ModuleInitializer], no longer requires [EngineEntry]. - Improved JSON serialization: added string support, introduced Utf8JsonObjectScope/ArrayScope, and new extension methods for cleaner JSON writing. - Removed [SkipLocalsInit] from Hierarchy and LocalToWorld. - Fixed Entity.Invalid to use INVALID_ID for both fields. - Minor cleanup: clarified comments, reorganized Ghost.Generator in solution, and disabled component serialization generator.
This commit is contained in:
@@ -11,7 +11,6 @@ namespace Ghost.Generator
|
||||
{
|
||||
private string GetJsonWriteCall(ITypeSymbol type, string fieldName)
|
||||
{
|
||||
// 1. PRIMITIVES (Fastest)
|
||||
switch (type.SpecialType)
|
||||
{
|
||||
case SpecialType.System_Byte:
|
||||
@@ -32,26 +31,10 @@ namespace Ghost.Generator
|
||||
return $@"writer.WriteBoolean(""{fieldName}"", value.{fieldName});";
|
||||
case SpecialType.System_Char:
|
||||
return $@"writer.WriteString(""{fieldName}"", [value.{fieldName}]);";
|
||||
case SpecialType.System_String:
|
||||
return $@"writer.WriteString(""{fieldName}"", value.{fieldName});";
|
||||
}
|
||||
|
||||
// TODO: Add well-known types like float3, Vector3, etc.
|
||||
#if false
|
||||
// 2. KNOWN MATH TYPES (Optimized Arrays)
|
||||
// Checking by name is simple and effective for standard math libs
|
||||
if (type.Name == "float3" || type.Name == "Vector3")
|
||||
{
|
||||
return $@"writer.WritePropertyName(""{fieldName}"");
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.{fieldName}.x);
|
||||
writer.WriteNumberValue(value.{fieldName}.y);
|
||||
writer.WriteNumberValue(value.{fieldName}.z);
|
||||
writer.WriteEndArray();";
|
||||
}
|
||||
#endif
|
||||
|
||||
// 3. FALLBACK: System.Text.Json (Reflection)
|
||||
// If we don't know what it is, let the standard serializer handle it.
|
||||
// This handles float4x4, List<T>, and other nested structs automatically.
|
||||
return $@"writer.WritePropertyName(""{fieldName}""); global::System.Text.Json.JsonSerializer.Serialize(writer, value.{fieldName}, options);";
|
||||
}
|
||||
|
||||
@@ -70,17 +53,14 @@ namespace Ghost.Generator
|
||||
case SpecialType.System_UInt16: return "reader.GetUInt16()";
|
||||
case SpecialType.System_UInt32: return "reader.GetUInt32()";
|
||||
case SpecialType.System_UInt64: return "reader.GetUInt64()";
|
||||
case SpecialType.System_IntPtr: return "reader.GetInt64()"; // Note: IntPtr size varies by platform
|
||||
case SpecialType.System_UIntPtr: return "reader.GetUInt64()"; // Note: UIntPtr size varies by platform
|
||||
// Note: the size of IntPtr and UIntPtr varies by platform, we use Int64/UInt64 to ensure compatibility
|
||||
case SpecialType.System_IntPtr: return "reader.GetInt64()";
|
||||
case SpecialType.System_UIntPtr: return "reader.GetUInt64()";
|
||||
case SpecialType.System_Boolean: return "reader.GetBoolean()";
|
||||
case SpecialType.System_Char: return "reader.GetString()[0]";
|
||||
case SpecialType.System_String: return "reader.GetString()";
|
||||
}
|
||||
|
||||
#if false
|
||||
// For custom math types, you'd need to generate code to read the array back
|
||||
if (type.Name == "float3") return "new float3(reader.GetSingle(), reader.GetSingle(), reader.GetSingle())"; // Simplified
|
||||
#endif
|
||||
|
||||
return $"global::System.Text.Json.JsonSerializer.Deserialize<{type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}>(ref reader, options)";
|
||||
}
|
||||
|
||||
@@ -125,6 +105,7 @@ namespace Ghost.Generator
|
||||
// 2. The Main Template using $@
|
||||
// Watch the double braces {{ }} and double quotes "" ""
|
||||
var sourceCode = $@"// <auto-generated/>
|
||||
#nullable enable
|
||||
|
||||
namespace {namespaceName}
|
||||
{{
|
||||
@@ -207,6 +188,8 @@ namespace {namespaceName}
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
return;
|
||||
|
||||
var componentCandidates = context.SyntaxProvider
|
||||
.CreateSyntaxProvider(
|
||||
predicate: (syntaxNode, _) => syntaxNode is StructDeclarationSyntax,
|
||||
|
||||
Reference in New Issue
Block a user