update collectiona

This commit is contained in:
Mikhail 2024-01-05 23:49:29 +08:00
parent 3119ea42db
commit fc167fb28c
3 changed files with 25 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using DCFApixels.DragonECS.Internal;
using DCFApixels.DragonECS.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
@ -13,7 +14,7 @@ namespace DCFApixels.DragonECS
//_dense заполняется с индекса 1
//в операциях изменяющих состояние группы нельзя итерироваться по this, либо осторожно учитывать этот момент
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
[DebuggerTypeProxy(typeof(DebuggerProxy))]
[DebuggerTypeProxy(typeof(EcsGroup.DebuggerProxy))]
public readonly ref struct EcsReadonlyGroup
{
private readonly EcsGroup _source;
@ -134,10 +135,10 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator EcsSpan(EcsReadonlyGroup a) => a.ToSpan();
internal class DebuggerProxy : EcsGroup.DebuggerProxy
{
public DebuggerProxy(EcsReadonlyGroup group) : base(group._source) { }
}
//internal class DebuggerProxy : EcsGroup.DebuggerProxy
//{
// public DebuggerProxy(EcsReadonlyGroup group) : base(group._source) { }
//}
#endregion
}
@ -720,7 +721,8 @@ namespace DCFApixels.DragonECS
#region Other
public override string ToString()
{
return $"group({_count}) {{{string.Join(", ", _dense.Skip(1).Take(_count).OrderBy(o => o))}}}";
return EntitiesCollectionUtility.AutoToString(_dense.Skip(1).Take(_count), "group");
//return $"group({_count}) {{{string.Join(", ", _dense.Skip(1).Take(_count).OrderBy(o => o))}}}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int First()
@ -762,6 +764,7 @@ namespace DCFApixels.DragonECS
public int CapacitySparce => _group.CapacitySparce;
public override string ToString() => _group.ToString();
public DebuggerProxy(EcsGroup group) => _group = group;
public DebuggerProxy(EcsReadonlyGroup group) : this(group.GetGroupInternal()) { }
}
#endregion
}

View File

@ -1,8 +1,8 @@
using System;
using DCFApixels.DragonECS.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
namespace DCFApixels.DragonECS
@ -122,7 +122,8 @@ namespace DCFApixels.DragonECS
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
public override string ToString()
{
return $"span({_values.Length}) {{{string.Join(", ", _values.ToArray().OrderBy(o => o))}}}";
return EntitiesCollectionUtility.AutoToString(_values.ToArray(), "span");
//return $"span({_values.Length}) {{{string.Join(", ", _values.ToArray().OrderBy(o => o))}}}";
}
internal class DebuggerProxy
@ -142,7 +143,6 @@ namespace DCFApixels.DragonECS
}
}
public int Count => _values.Length;
//public override string ToString() => $"span({_values.Length}) {{{string.Join(", ", _values.OrderBy(o => o))}}}";
public DebuggerProxy(EcsSpan span)
{
_values = new int[span.Length];

View File

@ -1,6 +1,8 @@
using System.Runtime.CompilerServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System;
namespace DCFApixels.DragonECS.Utils
{
@ -51,4 +53,12 @@ namespace DCFApixels.DragonECS.Utils
new IntPtr(Marshal.SizeOf(typeof(T)) * newCount))).ToPointer();
}
}
public static class EntitiesCollectionUtility
{
public static string AutoToString(IEnumerable<int> range, string name)
{
return $"{name}({range.Count()}) {{{string.Join(", ", range.OrderBy(o => o))}}})";
}
}
}