refactoring/add DebuggerProxy to entlong

This commit is contained in:
Mikhail 2023-05-27 23:02:32 +08:00
parent 77286fc00c
commit 5c805ba555
4 changed files with 51 additions and 23 deletions

View File

@ -2,6 +2,7 @@
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
#region Interfaces
public interface IEcsPreInitProcess : IEcsSystem public interface IEcsPreInitProcess : IEcsSystem
{ {
void PreInit(EcsPipeline pipeline); void PreInit(EcsPipeline pipeline);
@ -18,7 +19,8 @@ namespace DCFApixels.DragonECS
{ {
void Destroy(EcsPipeline pipeline); void Destroy(EcsPipeline pipeline);
} }
public interface IEcsBaseSystem : IEcsInitProcess, IEcsRunProcess, IEcsDestroyProcess { }
#endregion
namespace Internal namespace Internal
{ {
@ -40,7 +42,6 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.PreInit(pipeline); foreach (var item in targets) item.PreInit(pipeline);
#endif #endif
} }
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
protected override void OnSetup() protected override void OnSetup()
{ {
@ -70,7 +71,6 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.Init(pipeline); foreach (var item in targets) item.Init(pipeline);
#endif #endif
} }
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
protected override void OnSetup() protected override void OnSetup()
{ {
@ -101,7 +101,6 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.Run(pipeline); foreach (var item in targets) item.Run(pipeline);
#endif #endif
} }
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
protected override void OnSetup() protected override void OnSetup()
{ {
@ -131,7 +130,6 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.Destroy(pipeline); foreach (var item in targets) item.Destroy(pipeline);
#endif #endif
} }
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
protected override void OnSetup() protected override void OnSetup()
{ {

View File

@ -1,7 +1,9 @@
using System; using DCFApixels.DragonECS.RunnersCore;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -9,9 +11,6 @@ using static DCFApixels.DragonECS.EcsDebugUtility;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
using RunnersCore;
using System.ComponentModel;
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
sealed class EcsRunnerFilterAttribute : Attribute sealed class EcsRunnerFilterAttribute : Attribute
{ {

View File

@ -148,7 +148,10 @@ namespace DCFApixels.DragonECS
_inc = inc; _inc = inc;
_exc = exc; _exc = exc;
} }
public override string ToString() => CreateLogString(_worldType, _inc, _exc); public override string ToString() => CreateLogString(_worldType, _inc, _exc);
#region Debug utils
private static string CreateLogString(Type worldType, int[] inc, int[] exc) private static string CreateLogString(Type worldType, int[] inc, int[] exc)
{ {
#if DEBUG #if DEBUG
@ -159,7 +162,6 @@ namespace DCFApixels.DragonECS
return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization
#endif #endif
} }
internal class DebuggerProxy internal class DebuggerProxy
{ {
public readonly Type worldType; public readonly Type worldType;
@ -179,6 +181,7 @@ namespace DCFApixels.DragonECS
} }
public override string ToString() => CreateLogString(worldType, inc, exc); public override string ToString() => CreateLogString(worldType, inc, exc);
} }
#endregion
} }
#endregion #endregion
@ -186,25 +189,25 @@ namespace DCFApixels.DragonECS
public ref struct EcsSubjectIterator<TSubject> where TSubject : EcsSubject public ref struct EcsSubjectIterator<TSubject> where TSubject : EcsSubject
{ {
public readonly TSubject s; public readonly TSubject s;
private EcsReadonlyGroup sourceGroup; private EcsReadonlyGroup _sourceGroup;
private Enumerator enumerator; private Enumerator _enumerator;
public EcsSubjectIterator(TSubject s, EcsReadonlyGroup sourceGroup) public EcsSubjectIterator(TSubject s, EcsReadonlyGroup sourceGroup)
{ {
this.s = s; this.s = s;
this.sourceGroup = sourceGroup; this._sourceGroup = sourceGroup;
enumerator = default; _enumerator = default;
} }
public int Entity public int Entity
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => enumerator.Current; get => _enumerator.Current;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Begin() => enumerator = GetEnumerator(); public void Begin() => _enumerator = GetEnumerator();
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Next() => enumerator.MoveNext(); public bool Next() => _enumerator.MoveNext();
public void CopyTo(EcsGroup group) public void CopyTo(EcsGroup group)
{ {
group.Clear(); group.Clear();
@ -213,7 +216,7 @@ namespace DCFApixels.DragonECS
group.AddInternal(enumerator.Current); group.AddInternal(enumerator.Current);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Enumerator GetEnumerator() => new Enumerator(sourceGroup, s); public Enumerator GetEnumerator() => new Enumerator(_sourceGroup, s);
public override string ToString() public override string ToString()
{ {

View File

@ -1,15 +1,18 @@
#pragma warning disable IDE1006 #pragma warning disable IDE1006
using System; using System;
using System.ComponentModel; using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using static DCFApixels.DragonECS.entlong.ThrowHalper;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
using static entlong.ThrowHalper;
// [ id 32 | gen 16 | world 16 ] // [ id 32 | gen 16 | world 16 ]
/// <summary>Strong identifier/Permanent entity identifier</summary> /// <summary>Strong identifier/Permanent entity identifier</summary>
[StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)] [StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)]
[DebuggerTypeProxy(typeof(DebuggerProxy))]
public readonly struct entlong : IEquatable<long>, IEquatable<entlong> public readonly struct entlong : IEquatable<long>, IEquatable<entlong>
{ {
public static readonly entlong NULL = default; public static readonly entlong NULL = default;
@ -34,7 +37,6 @@ namespace DCFApixels.DragonECS
get => this == NULL; get => this == NULL;
} }
[EditorBrowsable(EditorBrowsableState.Never)]
public int ID public int ID
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -46,7 +48,6 @@ namespace DCFApixels.DragonECS
return id; return id;
} }
} }
[EditorBrowsable(EditorBrowsableState.Never)]
public short Gen public short Gen
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -69,7 +70,6 @@ namespace DCFApixels.DragonECS
return EcsWorld.Worlds[world]; return EcsWorld.Worlds[world];
} }
} }
[EditorBrowsable(EditorBrowsableState.Never)]
public short WorldID public short WorldID
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -158,5 +158,33 @@ namespace DCFApixels.DragonECS
} }
} }
#endregion #endregion
#region DebuggerProxy
internal class DebuggerProxy
{
private List<object> _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<object> components
{
get
{
_value.World.GetComponents(_value.ID, _componentsList);
return _componentsList;
}
}
public DebuggerProxy(entlong value)
{
_value = value;
_componentsList = new List<object>();
}
public enum EntState { Null, Dead, Alive, }
}
#endregion
} }
} }