-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change implementation of CloneEntity() - replaced JSON serialization …
…by static CopyValue(source, target) methods
- Loading branch information
Showing
11 changed files
with
233 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Friflo.Engine.ECS; | ||
|
||
internal delegate void CopyScript<in TScript>(TScript value, TScript target); | ||
|
||
|
||
internal static class CopyScriptUtils | ||
{ | ||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2090", Justification = "TODO")] // TODO | ||
internal static CopyScript<TScript> CreateCopyScript<TScript>() | ||
{ | ||
const BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod; | ||
var method = typeof(TScript).GetMethod("CopyScript", flags); | ||
if (method is null) { | ||
return null; | ||
} | ||
var genericDelegate = Delegate.CreateDelegate(typeof(CopyScript<TScript>), method); | ||
return (CopyScript<TScript>)genericDelegate; | ||
} | ||
} | ||
|
||
internal static class CopyScriptUtils<TValue> | ||
{ | ||
internal static readonly CopyScript<TValue> CopyScript = CopyScriptUtils.CreateCopyScript<TValue>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Friflo.Engine.ECS; | ||
|
||
public readonly struct CopyContext | ||
{ | ||
public readonly Entity source; | ||
public readonly Entity target; | ||
|
||
internal CopyContext(Entity source, Entity target) { | ||
this.source = source; | ||
this.target = target; | ||
} | ||
} | ||
|
||
internal delegate void CopyValue<TValue>(in TValue value, ref TValue target, in CopyContext context); | ||
|
||
|
||
internal static class CopyValueUtils | ||
{ | ||
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2090", Justification = "TODO")] // TODO | ||
internal static CopyValue<TComponent> CreateCopyValue<TComponent>() | ||
{ | ||
const BindingFlags flags = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod; | ||
var method = typeof(TComponent).GetMethod("CopyValue", flags); | ||
if (method is null) { | ||
var schema = EntityStore.Static.EntitySchema; | ||
var componentType = schema.ComponentTypeByType[typeof(TComponent)]; | ||
if (componentType.IsBlittable) { | ||
return null; | ||
} | ||
return MissingCopyValue; | ||
} | ||
var genericDelegate = Delegate.CreateDelegate(typeof(CopyValue<TComponent>), method); | ||
return (CopyValue<TComponent>)genericDelegate; | ||
} | ||
|
||
private static void MissingCopyValue<TValue>(in TValue value, ref TValue target, in CopyContext context) { | ||
var name = typeof(TValue).Name; | ||
var msg = $"at {typeof(TValue).Namespace}.{name} - expect: static void CopyValue(in {name} source, ref {name} target, in CopyContext context)"; | ||
throw new MissingMethodException(msg); | ||
} | ||
} | ||
|
||
internal static class CopyValueUtils<TValue> | ||
{ | ||
internal static readonly CopyValue<TValue> CopyValue = CopyValueUtils.CreateCopyValue<TValue>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.