From 5c805ba555cc0a0f57e84a6f401074b78c38e18d Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 27 May 2023 23:02:32 +0800 Subject: [PATCH] refactoring/add DebuggerProxy to entlong --- src/Builtin/BaseRunners.cs | 8 +++----- src/EcsRunner.cs | 7 +++---- src/EcsSubject.cs | 21 ++++++++++++--------- src/entlong.cs | 38 +++++++++++++++++++++++++++++++++----- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/Builtin/BaseRunners.cs b/src/Builtin/BaseRunners.cs index 539a849..76ac5db 100644 --- a/src/Builtin/BaseRunners.cs +++ b/src/Builtin/BaseRunners.cs @@ -2,6 +2,7 @@ namespace DCFApixels.DragonECS { + #region Interfaces public interface IEcsPreInitProcess : IEcsSystem { void PreInit(EcsPipeline pipeline); @@ -18,7 +19,8 @@ namespace DCFApixels.DragonECS { void Destroy(EcsPipeline pipeline); } - public interface IEcsBaseSystem : IEcsInitProcess, IEcsRunProcess, IEcsDestroyProcess { } + + #endregion namespace Internal { @@ -40,7 +42,6 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.PreInit(pipeline); #endif } - #if DEBUG && !DISABLE_DEBUG protected override void OnSetup() { @@ -70,7 +71,6 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.Init(pipeline); #endif } - #if DEBUG && !DISABLE_DEBUG protected override void OnSetup() { @@ -101,7 +101,6 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.Run(pipeline); #endif } - #if DEBUG && !DISABLE_DEBUG protected override void OnSetup() { @@ -131,7 +130,6 @@ namespace DCFApixels.DragonECS foreach (var item in targets) item.Destroy(pipeline); #endif } - #if DEBUG && !DISABLE_DEBUG protected override void OnSetup() { diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 7fe8745..910e4f3 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -1,7 +1,9 @@ -using System; +using DCFApixels.DragonECS.RunnersCore; +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -9,9 +11,6 @@ using static DCFApixels.DragonECS.EcsDebugUtility; namespace DCFApixels.DragonECS { - using RunnersCore; - using System.ComponentModel; - [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] sealed class EcsRunnerFilterAttribute : Attribute { diff --git a/src/EcsSubject.cs b/src/EcsSubject.cs index 1dfcd45..af1e44f 100644 --- a/src/EcsSubject.cs +++ b/src/EcsSubject.cs @@ -148,7 +148,10 @@ namespace DCFApixels.DragonECS _inc = inc; _exc = exc; } + public override string ToString() => CreateLogString(_worldType, _inc, _exc); + + #region Debug utils private static string CreateLogString(Type worldType, int[] inc, int[] exc) { #if DEBUG @@ -159,7 +162,6 @@ namespace DCFApixels.DragonECS return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization #endif } - internal class DebuggerProxy { public readonly Type worldType; @@ -179,6 +181,7 @@ namespace DCFApixels.DragonECS } public override string ToString() => CreateLogString(worldType, inc, exc); } + #endregion } #endregion @@ -186,25 +189,25 @@ namespace DCFApixels.DragonECS public ref struct EcsSubjectIterator where TSubject : EcsSubject { public readonly TSubject s; - private EcsReadonlyGroup sourceGroup; - private Enumerator enumerator; + private EcsReadonlyGroup _sourceGroup; + private Enumerator _enumerator; public EcsSubjectIterator(TSubject s, EcsReadonlyGroup sourceGroup) { this.s = s; - this.sourceGroup = sourceGroup; - enumerator = default; + this._sourceGroup = sourceGroup; + _enumerator = default; } public int Entity { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => enumerator.Current; + get => _enumerator.Current; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Begin() => enumerator = GetEnumerator(); + public void Begin() => _enumerator = GetEnumerator(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Next() => enumerator.MoveNext(); + public bool Next() => _enumerator.MoveNext(); public void CopyTo(EcsGroup group) { group.Clear(); @@ -213,7 +216,7 @@ namespace DCFApixels.DragonECS group.AddInternal(enumerator.Current); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() => new Enumerator(sourceGroup, s); + public Enumerator GetEnumerator() => new Enumerator(_sourceGroup, s); public override string ToString() { diff --git a/src/entlong.cs b/src/entlong.cs index 52841b1..bdbca2f 100644 --- a/src/entlong.cs +++ b/src/entlong.cs @@ -1,15 +1,18 @@ #pragma warning disable IDE1006 using System; -using System.ComponentModel; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using static DCFApixels.DragonECS.entlong.ThrowHalper; namespace DCFApixels.DragonECS { - using static entlong.ThrowHalper; // [ id 32 | gen 16 | world 16 ] /// Strong identifier/Permanent entity identifier [StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)] + [DebuggerTypeProxy(typeof(DebuggerProxy))] public readonly struct entlong : IEquatable, IEquatable { public static readonly entlong NULL = default; @@ -34,7 +37,6 @@ namespace DCFApixels.DragonECS get => this == NULL; } - [EditorBrowsable(EditorBrowsableState.Never)] public int ID { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -46,7 +48,6 @@ namespace DCFApixels.DragonECS return id; } } - [EditorBrowsable(EditorBrowsableState.Never)] public short Gen { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -69,7 +70,6 @@ namespace DCFApixels.DragonECS return EcsWorld.Worlds[world]; } } - [EditorBrowsable(EditorBrowsableState.Never)] public short WorldID { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -158,5 +158,33 @@ namespace DCFApixels.DragonECS } } #endregion + + #region DebuggerProxy + internal class DebuggerProxy + { + private List _componentsList; + private entlong _value; + public long full => _value.full; + public int id => _value.id; + public int gen => _value.gen; + public int world => _value.world; + public EntState State => _value.IsNull ? EntState.Null : _value.IsAlive ? EntState.Alive : EntState.Dead; + public EcsWorld EcsWorld => _value.World; + public IEnumerable components + { + get + { + _value.World.GetComponents(_value.ID, _componentsList); + return _componentsList; + } + } + public DebuggerProxy(entlong value) + { + _value = value; + _componentsList = new List(); + } + public enum EntState { Null, Dead, Alive, } + } + #endregion } }