tmp update

This commit is contained in:
Mikhail 2023-12-31 17:58:20 +08:00
parent 43d8489157
commit b5300f7b43
2 changed files with 10 additions and 10 deletions

View File

@ -83,17 +83,17 @@ namespace DCFApixels.DragonECS
{ {
public abstract void Inject(object obj); public abstract void Inject(object obj);
} }
internal class EcsBaseTypeInjectRunner<T> : EcsBaseTypeInjectRunner internal sealed class EcsBaseTypeInjectRunner<T> : EcsBaseTypeInjectRunner
{ {
private IEcsInject<T> _runner; private IEcsInject<T> _runner;
public EcsBaseTypeInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsInject<T>>(); public EcsBaseTypeInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsInject<T>>();
public override void Inject(object obj) => _runner.Inject((T)obj); public sealed override void Inject(object obj) => _runner.Inject((T)obj);
} }
internal class EcsObjectTypePreInjectRunner : EcsBaseTypeInjectRunner internal sealed class EcsObjectTypePreInjectRunner : EcsBaseTypeInjectRunner
{ {
private IEcsPreInject _runner; private IEcsPreInject _runner;
public EcsObjectTypePreInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsPreInject>(); public EcsObjectTypePreInjectRunner(EcsPipeline pipeline) => _runner = pipeline.GetRunner<IEcsPreInject>();
public override void Inject(object obj) => _runner.PreInject(obj); public sealed override void Inject(object obj) => _runner.PreInject(obj);
} }
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]

View File

@ -20,13 +20,13 @@ namespace DCFApixels.DragonECS.Utils
internal static unsafe class UnmanagedArrayUtility internal static unsafe class UnmanagedArrayUtility
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* New<T>(int capacity) where T : struct public static T* New<T>(int capacity) where T : unmanaged
{ {
return Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)) * capacity).ToPointer(); return (T*)Marshal.AllocHGlobal(Marshal.SizeOf<T>() * capacity).ToPointer();
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* NewAndInit<T>(int capacity) where T : struct public static T* NewAndInit<T>(int capacity) where T : unmanaged
{ {
int newSize = Marshal.SizeOf(typeof(T)) * capacity; int newSize = Marshal.SizeOf(typeof(T)) * capacity;
byte* newPointer = (byte*)Marshal.AllocHGlobal(newSize).ToPointer(); byte* newPointer = (byte*)Marshal.AllocHGlobal(newSize).ToPointer();
@ -34,7 +34,7 @@ namespace DCFApixels.DragonECS.Utils
for (int i = 0; i < newSize; i++) for (int i = 0; i < newSize; i++)
*(newPointer + i) = 0; *(newPointer + i) = 0;
return newPointer; return (T*)newPointer;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -44,9 +44,9 @@ namespace DCFApixels.DragonECS.Utils
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* Resize<T>(void* oldPointer, int newCount) where T : struct public static T* Resize<T>(void* oldPointer, int newCount) where T : unmanaged
{ {
return (Marshal.ReAllocHGlobal( return (T*)(Marshal.ReAllocHGlobal(
new IntPtr(oldPointer), new IntPtr(oldPointer),
new IntPtr(Marshal.SizeOf(typeof(T)) * newCount))).ToPointer(); new IntPtr(Marshal.SizeOf(typeof(T)) * newCount))).ToPointer();
} }