From 8b5cdd84f49fd71a20eb67604ea19fa893b03f75 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:52:54 +0800 Subject: [PATCH] fixes for support Unity 2020.1.x --- src/Collections/EcsSpan.cs | 2 +- src/EcsAspect.cs | 17 ++++++++++++++--- src/EcsRunner.cs | 12 ++++++------ src/Utils/ReadOnlySpanDummy.cs | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Collections/EcsSpan.cs b/src/Collections/EcsSpan.cs index d95f773..636703d 100644 --- a/src/Collections/EcsSpan.cs +++ b/src/Collections/EcsSpan.cs @@ -25,7 +25,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _values.Length; } - public readonly int this[int index] + public int this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => _values[index]; diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index 917d000..9eab505 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -142,16 +142,28 @@ namespace DCFApixels.DragonECS foreach (var id in maskInc) { var bit = EcsMaskBit.FromID(id); - if (!r.TryAdd(bit.chankIndex, bit.mask)) + if (r.ContainsKey(bit.chankIndex)) + { r[bit.chankIndex] = r[bit.chankIndex] | bit.mask; + } + else + { + r[bit.chankIndex] = bit.mask; + } } EcsMaskBit[] incMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray(); r.Clear(); foreach (var id in maskExc) { var bit = EcsMaskBit.FromID(id); - if (!r.TryAdd(bit.chankIndex, bit.mask)) + if (r.ContainsKey(bit.chankIndex)) + { r[bit.chankIndex] = r[bit.chankIndex] | bit.mask; + } + else + { + r[bit.chankIndex] = bit.mask; + } } EcsMaskBit[] excMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray(); @@ -230,7 +242,6 @@ namespace DCFApixels.DragonECS } public static EcsMaskBit FromID(int id) { - short x = 10; return new EcsMaskBit(id >> DIV_SHIFT, 1 << (id & MOD_MASK)); //аналогично new EcsMaskBit(id / BITS, 1 << (id % BITS)) но быстрее } public override string ToString() diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index e229c4d..ecb4b15 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -138,12 +138,12 @@ namespace DCFApixels.DragonECS throw new Exception(); } - Type GetRunnerBaseType(Type type) + Type GetRunnerBaseType(Type typeX) { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(EcsRunner<>)) - return type; - if (type.BaseType != null) - return GetRunnerBaseType(type.BaseType); + if (typeX.IsGenericType && typeX.GetGenericTypeDefinition() == typeof(EcsRunner<>)) + return typeX; + if (typeX.BaseType != null) + return GetRunnerBaseType(typeX.BaseType); return null; } Type baseType = GetRunnerBaseType(type); @@ -291,7 +291,7 @@ namespace DCFApixels.DragonECS name = Regex.Replace(name, @"\bEcs|Process\b", ""); if (Regex.IsMatch(name, "`\\w{1,}$")) { - var s = name.Split("`"); + var s = name.Split("`".ToCharArray()); name = s[0] + $"<{s[1]}>"; } _processes.Add(type, new ProcessInterface(type, name)); diff --git a/src/Utils/ReadOnlySpanDummy.cs b/src/Utils/ReadOnlySpanDummy.cs index 508b375..03a291a 100644 --- a/src/Utils/ReadOnlySpanDummy.cs +++ b/src/Utils/ReadOnlySpanDummy.cs @@ -1,5 +1,6 @@ #if ENABLE_DUMMY_SPAN using System; +using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using EditorBrowsableAttribute = System.ComponentModel.EditorBrowsableAttribute; @@ -68,12 +69,14 @@ namespace DCFApixels.DragonECS #endregion #region Object +#pragma warning disable CS0809 // [Obsolete("Equals() on ReadOnlySpan 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 ReadOnlySpan will always throw an exception.")] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => throw new NotSupportedException(); +#pragma warning restore CS0809 // public override string ToString() { //if (typeof(T) == typeof(char)) @@ -155,6 +158,19 @@ namespace DCFApixels.DragonECS // return retVal; //} + public void CopyTo(T[] array) + { + if (_length > array.Length) + { + throw new ArgumentOutOfRangeException(); + } + + for (int i = 0; i < _length; i++) + { + array[i] = _array[i]; + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlySpan Slice(int start) {