mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Made release buildable
This commit is contained in:
@@ -1376,7 +1376,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
private void CopySelectedFiles(bool cutFiles)
|
private void CopySelectedFiles(bool cutFiles)
|
||||||
{
|
{
|
||||||
_filesToCopy.ClearAndDeleteItems();
|
_filesToCopy.ClearAndDeleteItems();
|
||||||
_selectedFiles.Select((file) => new String(file)).ToList(_filesToCopy);
|
_selectedFiles.Select(scope (file) => new String(file)).ToList(_filesToCopy);
|
||||||
_cutFiles = cutFiles;
|
_cutFiles = cutFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Bon.Integrated;
|
||||||
|
using Bon;
|
||||||
|
|
||||||
namespace GlitchyEngine.Benchmark;
|
namespace GlitchyEngine.Benchmark;
|
||||||
|
|
||||||
class BasicBenchmark
|
class BasicBenchmark
|
||||||
@@ -47,6 +50,8 @@ class BasicBenchmark
|
|||||||
Shutdown();
|
Shutdown();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
#define DEBUGGING
|
||||||
|
|
||||||
public static void BenchmarkSerializer()
|
public static void BenchmarkSerializer()
|
||||||
{
|
{
|
||||||
// Before benchmark
|
// Before benchmark
|
||||||
@@ -66,8 +71,15 @@ class BasicBenchmark
|
|||||||
benchmark.BeforeRun = scope [&]() => {
|
benchmark.BeforeRun = scope [&]() => {
|
||||||
serializer = new .();
|
serializer = new .();
|
||||||
};
|
};
|
||||||
|
|
||||||
benchmark.Run = scope [&]() => {
|
benchmark.Run = scope [&]() => {
|
||||||
serializer.SerializeScriptInstances();
|
serializer.SerializeScriptInstances();
|
||||||
|
|
||||||
|
#if DEBUGGING
|
||||||
|
gBonEnv.serializeFlags |= .Verbose; // Output is formatted for editing & readability
|
||||||
|
let serialized = Bon.Bon.Serialize(serializer.[Friend]SerializedObjects, .. scope String());
|
||||||
|
File.WriteAllText("ser.bon", serialized);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
benchmark.AfterRun = scope [&]() => {
|
benchmark.AfterRun = scope [&]() => {
|
||||||
delete serializer;
|
delete serializer;
|
||||||
@@ -76,11 +88,13 @@ class BasicBenchmark
|
|||||||
scene.Stop();
|
scene.Stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !DEBUGGING
|
||||||
Console.WriteLine("Benchmark empty scene:");
|
Console.WriteLine("Benchmark empty scene:");
|
||||||
{
|
{
|
||||||
benchmark.Name = "Empty Scene";
|
benchmark.Name = "Empty Scene";
|
||||||
benchmark.Run(resultCollector);
|
benchmark.Run(resultCollector);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
List<Entity> references = new List<Entity>(1000);
|
List<Entity> references = new List<Entity>(1000);
|
||||||
defer delete references;
|
defer delete references;
|
||||||
@@ -109,12 +123,12 @@ class BasicBenchmark
|
|||||||
|
|
||||||
references.Clear();
|
references.Clear();
|
||||||
}
|
}
|
||||||
|
#if !DEBUGGING
|
||||||
BenchmarkTrivialEntity(1);
|
BenchmarkTrivialEntity(1);
|
||||||
BenchmarkTrivialEntity(10);
|
BenchmarkTrivialEntity(10);
|
||||||
BenchmarkTrivialEntity(100);
|
BenchmarkTrivialEntity(100);
|
||||||
BenchmarkTrivialEntity(1000);
|
BenchmarkTrivialEntity(1000);
|
||||||
|
#endif
|
||||||
void BenchmarkLargeEntity(int entityCount)
|
void BenchmarkLargeEntity(int entityCount)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Benchmark {entityCount} Large Entity:");
|
Console.WriteLine($"Benchmark {entityCount} Large Entity:");
|
||||||
@@ -130,7 +144,12 @@ class BasicBenchmark
|
|||||||
|
|
||||||
benchmark.Name = scope $"Large Entity {entityCount}";
|
benchmark.Name = scope $"Large Entity {entityCount}";
|
||||||
benchmark.RunInfo["EntityCount"] = Variant.Create(entityCount);
|
benchmark.RunInfo["EntityCount"] = Variant.Create(entityCount);
|
||||||
|
|
||||||
|
#if !DEBUGGING
|
||||||
benchmark.Run(resultCollector);
|
benchmark.Run(resultCollector);
|
||||||
|
#else
|
||||||
|
benchmark.Run(resultCollector, 0, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (Entity e in references)
|
for (Entity e in references)
|
||||||
{
|
{
|
||||||
@@ -139,11 +158,15 @@ class BasicBenchmark
|
|||||||
|
|
||||||
references.Clear();
|
references.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !DEBUGGING
|
||||||
BenchmarkLargeEntity(1);
|
BenchmarkLargeEntity(1);
|
||||||
BenchmarkLargeEntity(10);
|
BenchmarkLargeEntity(10);
|
||||||
BenchmarkLargeEntity(100);
|
BenchmarkLargeEntity(100);
|
||||||
BenchmarkLargeEntity(1000);
|
BenchmarkLargeEntity(1000);
|
||||||
|
#else
|
||||||
|
BenchmarkLargeEntity(1000);
|
||||||
|
#endif
|
||||||
|
|
||||||
// After Bench
|
// After Bench
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace GlitchyEngine.Benchmark;
|
|
||||||
|
|
||||||
class SimpleStringList
|
|
||||||
{
|
|
||||||
private append String _buffer = .();
|
|
||||||
private append List<(int start, int length)> _views = .();
|
|
||||||
|
|
||||||
public StringView this[int index]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
let (start, length) = _views[index];
|
|
||||||
return StringView(_buffer, start, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringView Add(StringView text)
|
|
||||||
{
|
|
||||||
int lengthBefore = _buffer.Length;
|
|
||||||
|
|
||||||
_buffer.Append(text);
|
|
||||||
|
|
||||||
StringView newStringView = StringView(_buffer, lengthBefore);
|
|
||||||
_views.Add((lengthBefore, newStringView.Length));
|
|
||||||
|
|
||||||
// Append a null terminator to ensure that every string can easily be a C string.
|
|
||||||
// Append after creating string view so it isn't part of the view.
|
|
||||||
_buffer.Append('\0');
|
|
||||||
|
|
||||||
return newStringView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate void CustomToString(String buffer);
|
|
||||||
|
|
||||||
// Allows adding a string directly into the buffer, using the internal buffer as target for e.g. ToString-opeations.
|
|
||||||
public StringView Add(CustomToString toString)
|
|
||||||
{
|
|
||||||
int lengthBefore = _buffer.Length;
|
|
||||||
|
|
||||||
toString(_buffer);
|
|
||||||
|
|
||||||
StringView newStringView = StringView(_buffer, lengthBefore);
|
|
||||||
_views.Add((lengthBefore, newStringView.Length));
|
|
||||||
|
|
||||||
// Append a null terminator to ensure that every string can easily be a C string.
|
|
||||||
// Append after creating string view so it isn't part of the view.
|
|
||||||
_buffer.Append('\0');
|
|
||||||
|
|
||||||
return newStringView;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,7 @@ PreprocessorMacros = ["IMGUI", "RELEASE", "GE_PROFILE"]
|
|||||||
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
|
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
|
||||||
|
|
||||||
[Configs.Test.Win64]
|
[Configs.Test.Win64]
|
||||||
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
|
PreprocessorMacros = ["TEST", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "IMGUI", "GE_RESOURCE_DEBUG_NAMES"]
|
||||||
|
|
||||||
[Configs.Debug.Win64]
|
[Configs.Debug.Win64]
|
||||||
PreprocessorMacros = ["DEBUG", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "IMGUI", "GE_RESOURCE_DEBUG_NAMES"]
|
PreprocessorMacros = ["DEBUG", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "IMGUI", "GE_RESOURCE_DEBUG_NAMES"]
|
||||||
|
|||||||
@@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Collections;
|
||||||
|
|
||||||
|
struct ListStringView : IHashable
|
||||||
|
{
|
||||||
|
public LessSimpleStringList List;
|
||||||
|
public int Index;
|
||||||
|
|
||||||
|
public static explicit operator StringView(ListStringView view)
|
||||||
|
{
|
||||||
|
return view.List?[view.Index] ?? .();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Commutable]
|
||||||
|
public static bool operator==(ListStringView s1, StringView s2)
|
||||||
|
{
|
||||||
|
return s2.Equals((StringView)s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode()
|
||||||
|
{
|
||||||
|
return ((StringView)this).GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LessSimpleStringList
|
||||||
|
{
|
||||||
|
private append String _buffer = .();
|
||||||
|
private append List<(int start, int length)> _views = .();
|
||||||
|
|
||||||
|
public StringView this[int index]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
let (start, length) = _views[index];
|
||||||
|
return StringView(_buffer, start, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListStringView Add(StringView text)
|
||||||
|
{
|
||||||
|
int lengthBefore = _buffer.Length;
|
||||||
|
|
||||||
|
_buffer.Append(text);
|
||||||
|
|
||||||
|
StringView newStringView = StringView(_buffer, lengthBefore);
|
||||||
|
_views.Add((lengthBefore, newStringView.Length));
|
||||||
|
|
||||||
|
// Append a null terminator to ensure that every string can easily be a C string.
|
||||||
|
// Append after creating string view so it isn't part of the view.
|
||||||
|
_buffer.Append('\0');
|
||||||
|
|
||||||
|
return .()
|
||||||
|
{
|
||||||
|
List = this,
|
||||||
|
Index = _views.Count - 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void CustomToString(String buffer);
|
||||||
|
|
||||||
|
// Allows adding a string directly into the buffer, using the internal buffer as target for e.g. ToString-opeations.
|
||||||
|
public ListStringView Add(CustomToString toString)
|
||||||
|
{
|
||||||
|
int lengthBefore = _buffer.Length;
|
||||||
|
|
||||||
|
toString(_buffer);
|
||||||
|
|
||||||
|
StringView newStringView = StringView(_buffer, lengthBefore);
|
||||||
|
_views.Add((lengthBefore, newStringView.Length));
|
||||||
|
|
||||||
|
// Append a null terminator to ensure that every string can easily be a C string.
|
||||||
|
// Append after creating string view so it isn't part of the view.
|
||||||
|
_buffer.Append('\0');
|
||||||
|
|
||||||
|
return .()
|
||||||
|
{
|
||||||
|
List = this,
|
||||||
|
Index = _views.Count - 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleStringList
|
||||||
|
{
|
||||||
|
private append String _buffer = .();
|
||||||
|
private append List<(int start, int length)> _views = .();
|
||||||
|
|
||||||
|
public StringView this[int index]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
let (start, length) = _views[index];
|
||||||
|
return StringView(_buffer, start, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringView Add(StringView text)
|
||||||
|
{
|
||||||
|
int lengthBefore = _buffer.Length;
|
||||||
|
|
||||||
|
_buffer.Append(text);
|
||||||
|
|
||||||
|
StringView newStringView = StringView(_buffer, lengthBefore);
|
||||||
|
_views.Add((lengthBefore, newStringView.Length));
|
||||||
|
|
||||||
|
// Append a null terminator to ensure that every string can easily be a C string.
|
||||||
|
// Append after creating string view so it isn't part of the view.
|
||||||
|
_buffer.Append('\0');
|
||||||
|
|
||||||
|
return newStringView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void CustomToString(String buffer);
|
||||||
|
|
||||||
|
// Allows adding a string directly into the buffer, using the internal buffer as target for e.g. ToString-opeations.
|
||||||
|
public StringView Add(CustomToString toString)
|
||||||
|
{
|
||||||
|
int lengthBefore = _buffer.Length;
|
||||||
|
|
||||||
|
toString(_buffer);
|
||||||
|
|
||||||
|
StringView newStringView = StringView(_buffer, lengthBefore);
|
||||||
|
_views.Add((lengthBefore, newStringView.Length));
|
||||||
|
|
||||||
|
// Append a null terminator to ensure that every string can easily be a C string.
|
||||||
|
// Append after creating string view so it isn't part of the view.
|
||||||
|
_buffer.Append('\0');
|
||||||
|
|
||||||
|
return newStringView;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -484,7 +484,8 @@ static class ScriptEngine
|
|||||||
s_RootDomain = null;*/
|
s_RootDomain = null;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NewScriptClass GetScriptClass(StringView name)
|
/// Returns the script class with the given name, or null, if no such class exists.
|
||||||
|
private static NewScriptClass GetScriptClass(StringView name)
|
||||||
{
|
{
|
||||||
EntityClasses.TryGetValue(name, let scriptClass);
|
EntityClasses.TryGetValue(name, let scriptClass);
|
||||||
|
|
||||||
|
|||||||
@@ -1442,6 +1442,8 @@ static class ScriptGlue
|
|||||||
[RegisterCall, CallingConvention(.Cdecl)]
|
[RegisterCall, CallingConvention(.Cdecl)]
|
||||||
static void Serialization_SerializeField(void* serializationContext, SerializationType type, StringView fieldName, void* valueObject, StringView fullTypeName)
|
static void Serialization_SerializeField(void* serializationContext, SerializationType type, StringView fieldName, void* valueObject, StringView fullTypeName)
|
||||||
{
|
{
|
||||||
|
Debug.Profiler.ProfileFunction!();
|
||||||
|
|
||||||
SerializedObject context = Internal.UnsafeCastToObject(serializationContext) as SerializedObject;
|
SerializedObject context = Internal.UnsafeCastToObject(serializationContext) as SerializedObject;
|
||||||
|
|
||||||
Log.EngineLogger.AssertDebug(context != null);
|
Log.EngineLogger.AssertDebug(context != null);
|
||||||
@@ -1452,6 +1454,8 @@ static class ScriptGlue
|
|||||||
[RegisterCall, CallingConvention(.Cdecl)]
|
[RegisterCall, CallingConvention(.Cdecl)]
|
||||||
static void Serialization_CreateObject(void* currentContext, bool isStatic, StringView typeName, out void* newContext, out UUID newId)
|
static void Serialization_CreateObject(void* currentContext, bool isStatic, StringView typeName, out void* newContext, out UUID newId)
|
||||||
{
|
{
|
||||||
|
Debug.Profiler.ProfileFunction!();
|
||||||
|
|
||||||
SerializedObject context = Internal.UnsafeCastToObject(currentContext) as SerializedObject;
|
SerializedObject context = Internal.UnsafeCastToObject(currentContext) as SerializedObject;
|
||||||
|
|
||||||
Log.EngineLogger.AssertDebug(context != null);
|
Log.EngineLogger.AssertDebug(context != null);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using System.Collections;
|
|||||||
using Bon.Integrated;
|
using Bon.Integrated;
|
||||||
using Bon;
|
using Bon;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using GlitchyEngine.Debug;
|
||||||
|
using GlitchyEngine.Collections;
|
||||||
|
|
||||||
namespace GlitchyEngine.Serialization;
|
namespace GlitchyEngine.Serialization;
|
||||||
|
|
||||||
@@ -19,12 +21,14 @@ class SerializedObject
|
|||||||
{
|
{
|
||||||
public uint8[16] RawData;
|
public uint8[16] RawData;
|
||||||
public StringView StringView;
|
public StringView StringView;
|
||||||
public (String FullTypeName, UUID ID) EngineObject;
|
public ListStringView ListStringView;
|
||||||
|
public (StringView FullTypeName, UUID ID) EngineObject;
|
||||||
|
public (ListStringView FullTypeName, UUID ID) ListEngineObject;
|
||||||
|
|
||||||
static this()
|
static this()
|
||||||
{
|
{
|
||||||
// This is important, because we expect 16 Bytes on the C# side
|
// This is important, because we expect 24 Bytes on the C# side
|
||||||
Compiler.Assert(sizeof(Self) == 16);
|
Compiler.Assert(sizeof(Self) == 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,13 +43,17 @@ class SerializedObject
|
|||||||
|
|
||||||
public ScriptInstanceSerializer Serializer;
|
public ScriptInstanceSerializer Serializer;
|
||||||
|
|
||||||
private List<String> _ownedString = new List<String>() ~ DeleteContainerAndItems!(_);
|
private append LessSimpleStringList _betterOwnedStrings = .();
|
||||||
|
|
||||||
|
//private List<String> _ownedString = new List<String>() ~ DeleteContainerAndItems!(_);
|
||||||
|
|
||||||
public append Dictionary<StringView, (SerializationType PrimitiveType, FieldData Data)> Fields = .();
|
public append Dictionary<ListStringView, (SerializationType PrimitiveType, FieldData Data)> Fields = .();
|
||||||
|
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(ScriptInstanceSerializer serializer, bool isStatic, StringView? typeName, UUID? id = null)
|
public this(ScriptInstanceSerializer serializer, bool isStatic, StringView? typeName, UUID? id = null)
|
||||||
{
|
{
|
||||||
|
//Profiler.ProfileFunction!();
|
||||||
|
|
||||||
String typeNameCopy = append String(typeName.Value);
|
String typeNameCopy = append String(typeName.Value);
|
||||||
|
|
||||||
Serializer = serializer;
|
Serializer = serializer;
|
||||||
@@ -84,41 +92,47 @@ class SerializedObject
|
|||||||
|
|
||||||
private void AddField(StringView fieldName, SerializationType fieldType, FieldData data)
|
private void AddField(StringView fieldName, SerializationType fieldType, FieldData data)
|
||||||
{
|
{
|
||||||
String nameCopy = new String(fieldName);
|
ListStringView view = _betterOwnedStrings.Add(fieldName);
|
||||||
_ownedString.Add(nameCopy);
|
//String nameCopy = new String(fieldName);
|
||||||
|
//_ownedString.Add(nameCopy);
|
||||||
|
|
||||||
Fields.Add(nameCopy, (fieldType, data));
|
Fields.Add(view, (fieldType, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddField(StringView name, SerializationType primitiveType, void* value, StringView fullTypeName)
|
public void AddField(StringView name, SerializationType primitiveType, void* value, StringView fullTypeName)
|
||||||
{
|
{
|
||||||
|
Profiler.ProfileFunction!();
|
||||||
|
|
||||||
FieldData data = .();
|
FieldData data = .();
|
||||||
|
|
||||||
switch (primitiveType)
|
switch (primitiveType)
|
||||||
{
|
{
|
||||||
case .String, .Enum:
|
case .String, .Enum:
|
||||||
|
Profiler.ProfileScope!("String/Enum");
|
||||||
// If the string is null, we store a nullptr and 0-length
|
// If the string is null, we store a nullptr and 0-length
|
||||||
StringView valueView = StringView(null, 0);
|
ListStringView valueView = .();
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
String stringValue = new String((char8*)value);
|
StringView stringToCopy = *(StringView*)value;
|
||||||
|
//String stringValue = new String(stringToCopy);
|
||||||
|
|
||||||
_ownedString.Add(stringValue);
|
//_ownedString.Add(stringValue);
|
||||||
|
valueView = _betterOwnedStrings.Add(stringToCopy);
|
||||||
valueView = stringValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.StringView = valueView;
|
data.ListStringView = valueView;
|
||||||
case .EngineObjectReference:
|
case .EngineObjectReference:
|
||||||
String typeName = null;
|
Profiler.ProfileScope!("EngineObject");
|
||||||
|
ListStringView typeNameView = .();
|
||||||
|
|
||||||
if (!fullTypeName.IsEmpty)
|
if (!fullTypeName.IsEmpty)
|
||||||
{
|
{
|
||||||
_ownedString.Add(new String(fullTypeName));
|
typeNameView = _betterOwnedStrings.Add(fullTypeName);
|
||||||
|
//_ownedString.Add(new String(fullTypeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
data.EngineObject = (FullTypeName: typeName, ID: *(UUID*)value);
|
data.ListEngineObject = (FullTypeName: typeNameView, ID: *(UUID*)value);
|
||||||
default:
|
default:
|
||||||
SetDataSimple(primitiveType, value, ref data);
|
SetDataSimple(primitiveType, value, ref data);
|
||||||
}
|
}
|
||||||
@@ -158,9 +172,11 @@ class SerializedObject
|
|||||||
|
|
||||||
public void GetField(StringView fieldName, SerializationType expectedType, uint8* target, out SerializationType actualType)
|
public void GetField(StringView fieldName, SerializationType expectedType, uint8* target, out SerializationType actualType)
|
||||||
{
|
{
|
||||||
|
// Profiler.ProfileFunction!();
|
||||||
|
|
||||||
actualType = .None;
|
actualType = .None;
|
||||||
|
|
||||||
if (!Fields.TryGetValue(fieldName, let field))
|
if (!Fields.TryGetValueAlt(fieldName, let field))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
actualType = field.PrimitiveType;
|
actualType = field.PrimitiveType;
|
||||||
@@ -178,13 +194,20 @@ class SerializedObject
|
|||||||
switch (field.PrimitiveType)
|
switch (field.PrimitiveType)
|
||||||
{
|
{
|
||||||
case .String, .Enum:
|
case .String, .Enum:
|
||||||
*(StringView*)target = field.Data.StringView;
|
*(StringView*)target = (StringView)field.Data.ListStringView;
|
||||||
case .EngineObjectReference:
|
case .EngineObjectReference:
|
||||||
let engineObjectData = field.Data.EngineObject;
|
let engineObjectData = field.Data.ListEngineObject;
|
||||||
|
|
||||||
*(char8**)target = engineObjectData.FullTypeName?.CStr();
|
(*(FieldData*)(void*)target).EngineObject.FullTypeName = (StringView)engineObjectData.FullTypeName;
|
||||||
|
(*(FieldData*)(void*)target).EngineObject.ID = engineObjectData.ID;
|
||||||
|
|
||||||
|
/**(char8**)target = engineObjectData.FullTypeName?.CStr();
|
||||||
*(int*)(target + sizeof(char8*)) = engineObjectData.FullTypeName?.Length ?? 0;
|
*(int*)(target + sizeof(char8*)) = engineObjectData.FullTypeName?.Length ?? 0;
|
||||||
*(UUID*)(target + sizeof(char8*) + sizeof(int)) = engineObjectData.ID;
|
*(UUID*)(target + sizeof(char8*) + sizeof(int)) = engineObjectData.ID;*/
|
||||||
|
|
||||||
|
/**(char8**)target = engineObjectData.FullTypeName?.CStr();
|
||||||
|
*(int*)(target + sizeof(char8*)) = engineObjectData.FullTypeName?.Length ?? 0;
|
||||||
|
*(UUID*)(target + sizeof(char8*) + sizeof(int)) = engineObjectData.ID;*/
|
||||||
default:
|
default:
|
||||||
// Most values can simply be copied, the conversion will be done in C#
|
// Most values can simply be copied, the conversion will be done in C#
|
||||||
#unwarn
|
#unwarn
|
||||||
@@ -194,21 +217,25 @@ class SerializedObject
|
|||||||
|
|
||||||
public void Serialize(NewScriptInstance scriptInstance)
|
public void Serialize(NewScriptInstance scriptInstance)
|
||||||
{
|
{
|
||||||
|
Profiler.ProfileFunction!();
|
||||||
ScriptEngine.Classes.EntitySerializer.Serialize(scriptInstance, this);
|
ScriptEngine.Classes.EntitySerializer.Serialize(scriptInstance, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deserialize(NewScriptInstance scriptInstance)
|
public void Deserialize(NewScriptInstance scriptInstance)
|
||||||
{
|
{
|
||||||
|
// Profiler.ProfileFunction!();
|
||||||
ScriptEngine.Classes.EntitySerializer.Deserialize(scriptInstance, this);
|
ScriptEngine.Classes.EntitySerializer.Deserialize(scriptInstance, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SerializeStaticFields(NewScriptClass scriptClass)
|
public void SerializeStaticFields(NewScriptClass scriptClass)
|
||||||
{
|
{
|
||||||
|
Profiler.ProfileFunction!();
|
||||||
ScriptEngine.Classes.EntitySerializer.SerializeStatic(scriptClass, this);
|
ScriptEngine.Classes.EntitySerializer.SerializeStatic(scriptClass, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeserializeStaticFields(NewScriptClass scriptClass)
|
public void DeserializeStaticFields(NewScriptClass scriptClass)
|
||||||
{
|
{
|
||||||
|
// Profiler.ProfileFunction!();
|
||||||
ScriptEngine.Classes.EntitySerializer.DeserializeStatic(scriptClass, this);
|
ScriptEngine.Classes.EntitySerializer.DeserializeStatic(scriptClass, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +252,7 @@ class SerializedObject
|
|||||||
|
|
||||||
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
|
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
|
||||||
{
|
{
|
||||||
|
// Profiler.ProfileFunction!();
|
||||||
Log.EngineLogger.Assert(value.type == typeof(Self));
|
Log.EngineLogger.Assert(value.type == typeof(Self));
|
||||||
|
|
||||||
SerializedObject object = value.Get<Self>();
|
SerializedObject object = value.Get<Self>();
|
||||||
@@ -237,7 +265,7 @@ class SerializedObject
|
|||||||
|
|
||||||
for (let (fieldName, field) in object.Fields)
|
for (let (fieldName, field) in object.Fields)
|
||||||
{
|
{
|
||||||
writer.Identifier(fieldName);
|
writer.Identifier((StringView)fieldName);
|
||||||
switch (field.PrimitiveType)
|
switch (field.PrimitiveType)
|
||||||
{
|
{
|
||||||
case .Bool:
|
case .Bool:
|
||||||
@@ -250,7 +278,8 @@ class SerializedObject
|
|||||||
writer.Type("string");
|
writer.Type("string");
|
||||||
}
|
}
|
||||||
#unwarn
|
#unwarn
|
||||||
Serialize.Value(writer, ValueView(typeof(StringView), &field.Data.StringView), environment);
|
StringView dataView = (StringView)field.Data.ListStringView;
|
||||||
|
Serialize.Value(writer, ValueView(typeof(StringView), &dataView), environment);
|
||||||
|
|
||||||
case .Int8:
|
case .Int8:
|
||||||
writer.Type("int8");
|
writer.Type("int8");
|
||||||
@@ -290,11 +319,12 @@ class SerializedObject
|
|||||||
case .Enum:
|
case .Enum:
|
||||||
writer.Type("Enum");
|
writer.Type("Enum");
|
||||||
#unwarn
|
#unwarn
|
||||||
Serialize.Value(writer, ValueView(typeof(StringView), &field.Data.StringView), environment);
|
StringView dataView = (StringView)field.Data.ListStringView;
|
||||||
|
Serialize.Value(writer, ValueView(typeof(StringView), &dataView), environment);
|
||||||
case .EngineObjectReference:
|
case .EngineObjectReference:
|
||||||
writer.Type("EngineObject");
|
writer.Type("EngineObject");
|
||||||
if (field.Data.EngineObject.FullTypeName != null)
|
if (field.Data.EngineObject.FullTypeName != null)
|
||||||
writer.Type(field.Data.EngineObject.FullTypeName);
|
writer.Type((StringView)field.Data.ListEngineObject.FullTypeName);
|
||||||
Serialize.Value(writer, field.Data.EngineObject.ID, environment);
|
Serialize.Value(writer, field.Data.EngineObject.ID, environment);
|
||||||
case .ObjectReference:
|
case .ObjectReference:
|
||||||
writer.outStr.Append('&');
|
writer.outStr.Append('&');
|
||||||
@@ -476,26 +506,45 @@ class SerializedObject
|
|||||||
}
|
}
|
||||||
else if (fieldTypeName == "Enum")
|
else if (fieldTypeName == "Enum")
|
||||||
{
|
{
|
||||||
String enumValue = new .();
|
Result<void> result = .Ok;
|
||||||
Deserialize.String!(reader, ref enumValue, environment);
|
|
||||||
|
Result<void> GetEnum(String outBuffer)
|
||||||
|
{
|
||||||
|
var outBuffer;
|
||||||
|
Deserialize.String!(reader, ref outBuffer, environment);
|
||||||
|
return .Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldData.ListStringView = object._betterOwnedStrings.Add(scope [&](s) =>
|
||||||
|
{
|
||||||
|
result = GetEnum(s);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*String enumValue = new .();
|
||||||
|
Deserialize.String!(reader, ref enumValue, environment);*/
|
||||||
|
|
||||||
object._ownedString.Add(enumValue);
|
//object._ownedString.Add(enumValue);
|
||||||
fieldData.StringView = enumValue;
|
//fieldData.ListStringView = object._betterOwnedStrings.Add(enumValue);
|
||||||
|
//fieldData.StringView = enumValue;
|
||||||
fieldType = .Enum;
|
fieldType = .Enum;
|
||||||
|
|
||||||
|
Try!(result);
|
||||||
|
|
||||||
break HandleField;
|
break HandleField;
|
||||||
}
|
}
|
||||||
else if (fieldTypeName == "EngineObject")
|
else if (fieldTypeName == "EngineObject")
|
||||||
{
|
{
|
||||||
String entityTypeName = null;
|
ListStringView entityTypeName = .();
|
||||||
|
|
||||||
if (reader.IsTyped())
|
if (reader.IsTyped())
|
||||||
{
|
{
|
||||||
StringView entityTypeNameView = Try!(reader.Type());
|
StringView entityTypeNameView = Try!(reader.Type());
|
||||||
|
|
||||||
entityTypeName = new String(entityTypeNameView);
|
//entityTypeName = new String(entityTypeNameView);
|
||||||
|
|
||||||
object._ownedString.Add(entityTypeName);
|
//object._ownedString.Add(entityTypeName);
|
||||||
|
|
||||||
|
entityTypeName = object._betterOwnedStrings.Add(entityTypeNameView);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object Reference
|
// Object Reference
|
||||||
@@ -505,7 +554,7 @@ class SerializedObject
|
|||||||
|
|
||||||
UUID reference = UUID(id);
|
UUID reference = UUID(id);
|
||||||
fieldType = .EngineObjectReference;
|
fieldType = .EngineObjectReference;
|
||||||
fieldData.EngineObject = (FullTypeName: entityTypeName, ID: reference);
|
fieldData.ListEngineObject = (FullTypeName: entityTypeName, ID: reference);
|
||||||
|
|
||||||
break HandleField;
|
break HandleField;
|
||||||
}
|
}
|
||||||
@@ -534,12 +583,30 @@ class SerializedObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String target = new .();
|
Result<void> result = .Ok;
|
||||||
|
|
||||||
|
Result<void> GetStringValue(String outBuffer)
|
||||||
|
{
|
||||||
|
var outBuffer;
|
||||||
|
Deserialize.String!(reader, ref outBuffer, environment);
|
||||||
|
return .Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldData.ListStringView = object._betterOwnedStrings.Add(scope [&](s) =>
|
||||||
|
{
|
||||||
|
result = GetStringValue(s);
|
||||||
|
});
|
||||||
|
|
||||||
|
fieldType = .String;
|
||||||
|
|
||||||
|
Try!(result);
|
||||||
|
|
||||||
|
/*String target = new .();
|
||||||
Deserialize.String!(reader, ref target, environment);
|
Deserialize.String!(reader, ref target, environment);
|
||||||
|
|
||||||
object._ownedString.Add(target);
|
object._ownedString.Add(target);
|
||||||
fieldData.StringView = target;
|
fieldData.StringView = target;
|
||||||
fieldType = .String;
|
fieldType = .String;*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (Deserialize.IsNumber(reader, let numberType))
|
// else if (Deserialize.IsNumber(reader, let numberType))
|
||||||
|
|||||||
Vendored
+1
-1
Submodule GlitchyEngine/vendor/freetype updated: 6567746ffd...9168ee0f2c
@@ -6,3 +6,6 @@ TargetType = "CustomBuild"
|
|||||||
|
|
||||||
[Configs.Debug.Win64]
|
[Configs.Debug.Win64]
|
||||||
PostBuildCmds = ["dotnet build \"$(WorkspaceDir)/ScriptCore/ScriptCore.csproj\" -c Debug"]
|
PostBuildCmds = ["dotnet build \"$(WorkspaceDir)/ScriptCore/ScriptCore.csproj\" -c Debug"]
|
||||||
|
|
||||||
|
[Configs.Release.Win64]
|
||||||
|
PostBuildCmds = ["dotnet build \"$(WorkspaceDir)/ScriptCore/ScriptCore.csproj\" -c Release"]
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<BaseOutputPath></BaseOutputPath>
|
<BaseOutputPath></BaseOutputPath>
|
||||||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
|
|
||||||
<RootNamespace>GlitchyEngine</RootNamespace>
|
<RootNamespace>GlitchyEngine</RootNamespace>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
@@ -25,7 +24,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" PrivateAssets="all" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
|
||||||
<PackageReference Include="System.Memory" Version="4.6.3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ScriptCoreGenerator\ScriptCoreGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
<ProjectReference Include="..\ScriptCoreGenerator\ScriptCoreGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||||
|
|||||||
+87
-18
@@ -1,6 +1,8 @@
|
|||||||
using GlitchyEngine.Core;
|
using GlitchyEngine.Core;
|
||||||
using GlitchyEngine.Editor;
|
using GlitchyEngine.Editor;
|
||||||
using GlitchyEngine.Extensions;
|
using GlitchyEngine.Extensions;
|
||||||
|
using GlitchyEngine.Native;
|
||||||
|
using GlitchyEngine.Physics;
|
||||||
using GlitchyEngine.Serialization;
|
using GlitchyEngine.Serialization;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using System;
|
using System;
|
||||||
@@ -11,8 +13,7 @@ using System.Reflection;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using GlitchyEngine.Native;
|
using System.Text;
|
||||||
using GlitchyEngine.Physics;
|
|
||||||
|
|
||||||
namespace GlitchyEngine;
|
namespace GlitchyEngine;
|
||||||
|
|
||||||
@@ -552,43 +553,111 @@ internal static unsafe partial class ScriptGlue
|
|||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Serialization_SerializeField(IntPtr serializationContext, SerializationType type, string fieldName, object? valueObject, string fullTypeName)
|
public static void Serialization_SerializeField(IntPtr serializationContext, SerializationType type, string fieldName, object? valueObject, string? fullTypeName)
|
||||||
{
|
{
|
||||||
StringView fieldNameConverted = StringView.FromManagedString(fieldName);
|
StringView fieldNameConverted;
|
||||||
StringView fullTypeNameConverted = StringView.FromManagedString(fullTypeName);
|
{
|
||||||
|
int maxByteCount = Encoding.UTF8.GetMaxByteCount(fieldName.Length);
|
||||||
|
byte* pointer = stackalloc byte[checked(maxByteCount + 1)];
|
||||||
|
int bytes = Encoding.UTF8.GetBytes((ReadOnlySpan<char>)fieldName, new Span<byte>(pointer, maxByteCount));
|
||||||
|
pointer[bytes] = 0;
|
||||||
|
fieldNameConverted = new StringView(pointer, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
void* valueObjectConverted = null;
|
StringView fullTypeNameConverted = new StringView();
|
||||||
bool deleteValueObject = false;
|
if (fullTypeName != null)
|
||||||
|
{
|
||||||
|
int maxByteCount = Encoding.UTF8.GetMaxByteCount(fullTypeName.Length);
|
||||||
|
byte* pointer = stackalloc byte[checked(maxByteCount + 1)];
|
||||||
|
int bytes = Encoding.UTF8.GetBytes((ReadOnlySpan<char>)fullTypeName, new Span<byte>(pointer, maxByteCount));
|
||||||
|
pointer[bytes] = 0;
|
||||||
|
fullTypeNameConverted = new StringView(pointer, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case SerializationType.String:
|
case SerializationType.String:
|
||||||
case SerializationType.Enum:
|
case SerializationType.Enum:
|
||||||
|
bool onHeap = false;
|
||||||
|
StringView nativeString = new StringView();
|
||||||
|
|
||||||
if (valueObject is string stringValue)
|
if (valueObject is string stringValue)
|
||||||
{
|
{
|
||||||
StringView nativeString = StringView.FromManagedString(stringValue);
|
int maxByteCount = Encoding.UTF8.GetMaxByteCount(stringValue.Length);
|
||||||
valueObjectConverted = nativeString.Utf8Ptr;
|
int actualByteCount = checked(maxByteCount + 1);
|
||||||
deleteValueObject = true;
|
|
||||||
|
onHeap = actualByteCount > 256;
|
||||||
|
|
||||||
|
byte* pointer;
|
||||||
|
if (!onHeap)
|
||||||
|
{
|
||||||
|
byte* pointer2 = stackalloc byte[actualByteCount];
|
||||||
|
pointer = pointer2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pointer = (byte*)NativeMemory.Alloc((nuint)actualByteCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bytes = Encoding.UTF8.GetBytes((ReadOnlySpan<char>)stringValue, new Span<byte>(pointer, maxByteCount));
|
||||||
|
pointer[bytes] = 0;
|
||||||
|
nativeString = new StringView(pointer, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, &nativeString, fullTypeNameConverted);
|
||||||
|
|
||||||
|
if (onHeap)
|
||||||
|
StringView.FreeNativeMemory(nativeString);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (valueObject is not null)
|
if (valueObject is not null)
|
||||||
{
|
{
|
||||||
|
// This is probably the dirtiest piece of C# Code, that I have ever seen.
|
||||||
|
// We first take a pointer the Object (which itself is a reference type -> object* is a double pointer!)
|
||||||
|
// We then dereference this double pointer, which gives us a pointer to the objects internals.
|
||||||
|
// These are Header (64bit), Method Table (64bit), and the objects content (at least another 64bit)
|
||||||
|
// I believe, that the actual reference points to the method table however and not the header (compare gcenv.object.h)
|
||||||
|
// Below we calculate a pointer to the objects contents by adding the size of a pointer.
|
||||||
|
|
||||||
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||||
object?* objectRef = &valueObject;
|
object?* objectRef = &valueObject;
|
||||||
// Skip Object Header (IntPtr) + Method Table (IntPtr)
|
// Skip Object Header (IntPtr) + Method Table (IntPtr)
|
||||||
valueObjectConverted = (byte*)*(IntPtr*)objectRef + sizeof(IntPtr);
|
byte* valueRef = (byte*)*(IntPtr*)objectRef + sizeof(IntPtr);
|
||||||
|
float* fRef = (float*)(void*)valueRef;
|
||||||
|
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valueRef, fullTypeNameConverted);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valueObjectConverted, fullTypeNameConverted);
|
|
||||||
|
|
||||||
NativeMemory.Free(fieldNameConverted.Utf8Ptr);
|
|
||||||
NativeMemory.Free(fullTypeNameConverted.Utf8Ptr);
|
|
||||||
|
|
||||||
if (deleteValueObject)
|
//StringView.FreeNativeMemory(fieldNameConverted);
|
||||||
NativeMemory.Free(valueObjectConverted);
|
//StringView.FreeNativeMemory(fullTypeNameConverted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Serialization_SerializeValueType<T>(IntPtr serializationContext, SerializationType type, string fieldName, in T value, string? fullTypeName) where T : unmanaged
|
||||||
|
{
|
||||||
|
StringView fieldNameConverted;
|
||||||
|
{
|
||||||
|
int maxByteCount = Encoding.UTF8.GetMaxByteCount(fieldName.Length);
|
||||||
|
byte* pointer = stackalloc byte[checked(maxByteCount + 1)];
|
||||||
|
int bytes = Encoding.UTF8.GetBytes((ReadOnlySpan<char>)fieldName, new Span<byte>(pointer, maxByteCount));
|
||||||
|
pointer[bytes] = 0;
|
||||||
|
fieldNameConverted = new StringView(pointer, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView fullTypeNameConverted = new StringView();
|
||||||
|
if (fullTypeName != null)
|
||||||
|
{
|
||||||
|
int maxByteCount = Encoding.UTF8.GetMaxByteCount(fullTypeName.Length);
|
||||||
|
byte* pointer = stackalloc byte[checked(maxByteCount + 1)];
|
||||||
|
int bytes = Encoding.UTF8.GetBytes((ReadOnlySpan<char>)fullTypeName, new Span<byte>(pointer, maxByteCount));
|
||||||
|
pointer[bytes] = 0;
|
||||||
|
fullTypeNameConverted = new StringView(pointer, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
fixed (T* valuePtr = &value)
|
||||||
|
{
|
||||||
|
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valuePtr, fullTypeNameConverted);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Custom engine call implementations
|
#endregion Custom engine call implementations
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public static class DictionarySerializer
|
|||||||
if (fieldValue == null)
|
if (fieldValue == null)
|
||||||
{
|
{
|
||||||
// Write a null pointer early out
|
// Write a null pointer early out
|
||||||
container.AddField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
container.AddValueTypeField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public static class DictionarySerializer
|
|||||||
IDictionary dictionary = (IDictionary)fieldValue;
|
IDictionary dictionary = (IDictionary)fieldValue;
|
||||||
ICollection collection = (ICollection)fieldValue;
|
ICollection collection = (ICollection)fieldValue;
|
||||||
|
|
||||||
context.AddField("Count", SerializationType.Int32, collection.Count);
|
context.AddValueTypeField("Count", SerializationType.Int32, collection.Count);
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public static class DictionarySerializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the reference to our dictionary into the field of the parent.
|
// Write the reference to our dictionary into the field of the parent.
|
||||||
container.AddField(fieldName, SerializationType.ObjectReference, context.Id);
|
container.AddValueTypeField(fieldName, SerializationType.ObjectReference, context.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -97,6 +97,13 @@ public class SerializedObject
|
|||||||
|
|
||||||
ScriptGlue.Serialization_SerializeField(_internalContext, serializationType, completeFieldName, value, fullTypeName);
|
ScriptGlue.Serialization_SerializeField(_internalContext, serializationType, completeFieldName, value, fullTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddValueTypeField<T>(string fieldName, SerializationType serializationType, in T value, string? fullTypeName = null) where T : unmanaged
|
||||||
|
{
|
||||||
|
string completeFieldName = $"{_structScopeName}{fieldName}";
|
||||||
|
|
||||||
|
ScriptGlue.Serialization_SerializeValueType(_internalContext, serializationType, completeFieldName, value, fullTypeName);
|
||||||
|
}
|
||||||
|
|
||||||
public void Serialize(Entity entity)
|
public void Serialize(Entity entity)
|
||||||
{
|
{
|
||||||
@@ -236,7 +243,7 @@ public class SerializedObject
|
|||||||
{
|
{
|
||||||
if (listObject == null)
|
if (listObject == null)
|
||||||
{
|
{
|
||||||
AddField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
AddValueTypeField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -248,7 +255,7 @@ public class SerializedObject
|
|||||||
{
|
{
|
||||||
IList list = (IList)listObject;
|
IList list = (IList)listObject;
|
||||||
|
|
||||||
context.AddField("Count", SerializationType.Int32, list.Count);
|
context.AddValueTypeField("Count", SerializationType.Int32, list.Count);
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i++)
|
for (int i = 0; i < list.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -257,47 +264,43 @@ public class SerializedObject
|
|||||||
context.SerializeField($"{i}", element, element?.GetType() ?? elementType);
|
context.SerializeField($"{i}", element, element?.GetType() ?? elementType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddField(fieldName, SerializationType.ObjectReference, context._id);
|
AddValueTypeField(fieldName, SerializationType.ObjectReference, context._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SerializePrimitive(string fieldName, object fieldValue, Type fieldType)
|
public void SerializePrimitive(string fieldName, object fieldValue, Type fieldType)
|
||||||
{
|
{
|
||||||
SerializationType type = SerializationType.None;
|
|
||||||
|
|
||||||
if (fieldType == typeof(bool))
|
if (fieldType == typeof(bool))
|
||||||
type = SerializationType.Bool;
|
AddValueTypeField(fieldName, SerializationType.Bool, (bool)fieldValue);
|
||||||
else if (fieldType == typeof(char))
|
else if (fieldType == typeof(char))
|
||||||
type = SerializationType.Char;
|
AddValueTypeField(fieldName, SerializationType.Char, (char)fieldValue);
|
||||||
else if (fieldType == typeof(byte))
|
else if (fieldType == typeof(byte))
|
||||||
type = SerializationType.UInt8;
|
AddValueTypeField(fieldName, SerializationType.UInt8, (byte)fieldValue);
|
||||||
else if (fieldType == typeof(sbyte))
|
else if (fieldType == typeof(sbyte))
|
||||||
type = SerializationType.Int8;
|
AddValueTypeField(fieldName, SerializationType.Int8, (sbyte)fieldValue);
|
||||||
else if (fieldType == typeof(ushort))
|
else if (fieldType == typeof(ushort))
|
||||||
type = SerializationType.UInt16;
|
AddValueTypeField(fieldName, SerializationType.UInt16, (ushort)fieldValue);
|
||||||
else if (fieldType == typeof(short))
|
else if (fieldType == typeof(short))
|
||||||
type = SerializationType.Int16;
|
AddValueTypeField(fieldName, SerializationType.Int16, (short)fieldValue);
|
||||||
else if (fieldType == typeof(uint))
|
else if (fieldType == typeof(uint))
|
||||||
type = SerializationType.UInt32;
|
AddValueTypeField(fieldName, SerializationType.UInt32, (uint)fieldValue);
|
||||||
else if (fieldType == typeof(int))
|
else if (fieldType == typeof(int))
|
||||||
type = SerializationType.Int32;
|
AddValueTypeField(fieldName, SerializationType.Int32, (int)fieldValue);
|
||||||
else if (fieldType == typeof(ulong))
|
else if (fieldType == typeof(ulong))
|
||||||
type = SerializationType.UInt64;
|
AddValueTypeField(fieldName, SerializationType.UInt64, (ulong)fieldValue);
|
||||||
else if (fieldType == typeof(long))
|
else if (fieldType == typeof(long))
|
||||||
type = SerializationType.Int64;
|
AddValueTypeField(fieldName, SerializationType.Int64, (long)fieldValue);
|
||||||
else if (fieldType == typeof(float))
|
else if (fieldType == typeof(float))
|
||||||
type = SerializationType.Float;
|
AddValueTypeField(fieldName, SerializationType.Float, (float)fieldValue);
|
||||||
else if (fieldType == typeof(double))
|
else if (fieldType == typeof(double))
|
||||||
type = SerializationType.Double;
|
AddValueTypeField(fieldName, SerializationType.Double, (double)fieldValue);
|
||||||
else if (fieldType == typeof(decimal))
|
else if (fieldType == typeof(decimal))
|
||||||
type = SerializationType.Decimal;
|
AddValueTypeField(fieldName, SerializationType.Decimal, (decimal)fieldValue);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Error($"The primitive {fieldType} is not implemented.");
|
Log.Error($"The primitive {fieldType} is not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
AddField(fieldName, type, fieldValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SerializeEnum(string fieldName, object? fieldValue, Type fieldType)
|
public void SerializeEnum(string fieldName, object? fieldValue, Type fieldType)
|
||||||
@@ -318,13 +321,13 @@ public class SerializedObject
|
|||||||
{
|
{
|
||||||
if (fieldType.IsSubclassOf(typeof(EngineObject)))
|
if (fieldType.IsSubclassOf(typeof(EngineObject)))
|
||||||
{
|
{
|
||||||
AddField(fieldName, SerializationType.EngineObjectReference, ((EngineObject?)fieldValue)?.UUID ?? UUID.Zero, fieldValue?.GetType().FullName);
|
AddValueTypeField(fieldName, SerializationType.ObjectReference, ((EngineObject?)fieldValue)?.UUID ?? UUID.Zero, fieldValue?.GetType().FullName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fieldValue == null)
|
if (fieldValue == null)
|
||||||
{
|
{
|
||||||
AddField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
AddValueTypeField(fieldName, SerializationType.ObjectReference, UUID.Zero);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -335,7 +338,7 @@ public class SerializedObject
|
|||||||
context.SerializeInstanceFields(fieldValue);
|
context.SerializeInstanceFields(fieldValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddField(fieldName, SerializationType.ObjectReference, context._id);
|
AddValueTypeField(fieldName, SerializationType.ObjectReference, context._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
Submodule vendor/NetHostBeef updated: aeb099576d...8a3c8fe257
Reference in New Issue
Block a user