update collections

This commit is contained in:
Mikhail 2024-01-05 22:16:48 +08:00
parent 4ed102eaf2
commit 3119ea42db
2 changed files with 57 additions and 17 deletions

View File

@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
@ -111,10 +112,6 @@ namespace DCFApixels.DragonECS
public bool IsSupersetOf(EcsGroup group) => _source.IsSupersetOf(group);
#endregion
#region Object
public override string ToString() => _source != null ? _source.ToString() : "NULL";
#endregion
#region Internal
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal EcsGroup GetGroupInternal() => _source;
@ -122,6 +119,19 @@ namespace DCFApixels.DragonECS
#endregion
#region Other
public override string ToString()
{
return _source != null ? _source.ToString() : "NULL";
}
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
[Obsolete("Equals() on EcsGroup will always throw an exception. Use the equality operator instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => throw new NotSupportedException();
[Obsolete("GetHashCode() on EcsGroup will always throw an exception.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => throw new NotSupportedException();
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator EcsSpan(EcsReadonlyGroup a) => a.ToSpan();
internal class DebuggerProxy : EcsGroup.DebuggerProxy
@ -710,7 +720,7 @@ namespace DCFApixels.DragonECS
#region Other
public override string ToString()
{
return $"group{{{string.Join(", ", _dense.Skip(1).Take(_count).OrderBy(o => o))}}}";
return $"group({_count}) {{{string.Join(", ", _dense.Skip(1).Take(_count).OrderBy(o => o))}}}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int First()

View File

@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
namespace DCFApixels.DragonECS
{
[DebuggerTypeProxy(typeof(DebuggerProxy))]
public readonly ref struct EcsSpan
{
private readonly int _worldID;
@ -91,18 +94,6 @@ namespace DCFApixels.DragonECS
}
#endregion
#region Object
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
[Obsolete("Equals() on EcsSpan will always throw an exception. Use the equality operator instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => throw new NotSupportedException();
[Obsolete("GetHashCode() on EcsSpan will always throw an exception.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => throw new NotSupportedException();
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
public override string ToString() => _values.ToString();
#endregion
#region operators
public static bool operator ==(EcsSpan left, EcsSpan right) => left._values == right._values;
public static bool operator !=(EcsSpan left, EcsSpan right) => left._values != right._values;
@ -120,6 +111,45 @@ namespace DCFApixels.DragonECS
public EcsSpan Slice(int start, int length) => new EcsSpan(_worldID, _values.Slice(start, length));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int[] ToArray() => _values.ToArray();
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
[Obsolete("Equals() on EcsSpan will always throw an exception. Use the equality operator instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => throw new NotSupportedException();
[Obsolete("GetHashCode() on EcsSpan will always throw an exception.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => throw new NotSupportedException();
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
public override string ToString()
{
return $"span({_values.Length}) {{{string.Join(", ", _values.ToArray().OrderBy(o => o))}}}";
}
internal class DebuggerProxy
{
private int[] _values;
private int _worldID;
public EcsWorld World => EcsWorld.GetWorld(_worldID);
public entlong[] Entities
{
get
{
entlong[] result = new entlong[_values.Length];
int i = 0;
foreach (var e in _values)
result[i++] = World.GetEntityLong(e);
return result;
}
}
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];
span._values.CopyTo(_values);
_worldID = span._worldID;
}
}
#endregion
}
}