using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { #region IEcsWorldComponent public interface IEcsWorldComponent { void Init(ref T component, EcsWorld world); void OnDestroy(ref T component, EcsWorld world); } public static class EcsWorldComponentHandler { public static readonly IEcsWorldComponent instance; public static readonly bool isHasHandler; static EcsWorldComponentHandler() { T def = default; if (def is IEcsWorldComponent intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private class DummyHandler : IEcsWorldComponent { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Init(ref T component, EcsWorld world) { } public void OnDestroy(ref T component, EcsWorld world) { } } } #endregion #region IEcsComponentReset public interface IEcsComponentReset { void Reset(ref T component); } public static class EcsComponentResetHandler { public static readonly IEcsComponentReset instance; public static readonly bool isHasHandler; static EcsComponentResetHandler() { T def = default; if (def is IEcsComponentReset intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private sealed class DummyHandler : IEcsComponentReset { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Reset(ref T component) => component = default; } } #endregion #region IEcsComponentCopy public interface IEcsComponentCopy { void Copy(ref T from, ref T to); } public static class EcsComponentCopyHandler { public static readonly IEcsComponentCopy instance; public static readonly bool isHasHandler; static EcsComponentCopyHandler() { T def = default; if (def is IEcsComponentCopy intrf) { isHasHandler = true; instance = intrf; } else { isHasHandler = false; instance = new DummyHandler(); } } private sealed class DummyHandler : IEcsComponentCopy { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Copy(ref T from, ref T to) => to = from; } } #endregion }