mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
refactoring
This commit is contained in:
parent
d636d94549
commit
544ef0d40d
@ -1,4 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Utils;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using DCFApixels.DragonECS.Utils;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using DCFApixels.DragonECS.Utils;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Utils;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
@ -3,11 +3,11 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using static DCFApixels.BitsUtility;
|
using static DCFApixels.DragonECS.Internal.BitsUtility;
|
||||||
|
|
||||||
namespace DCFApixels
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
public unsafe static class BitsUtility
|
internal unsafe static class BitsUtility
|
||||||
{
|
{
|
||||||
private const char DEFAULT_SEPARATOR = '_';
|
private const char DEFAULT_SEPARATOR = '_';
|
||||||
private const int BYTE_BITS = 8;
|
private const int BYTE_BITS = 8;
|
@ -8,22 +8,26 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
public static class EcsTypeCode
|
public static class EcsTypeCode
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>();
|
private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>();
|
||||||
private static int _incremetn = 1;
|
private static int _increment = 1;
|
||||||
public static int Count => _codes.Count;
|
public static int Count
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get { return _codes.Count; }
|
||||||
|
}
|
||||||
public static int Get(Type type)
|
public static int Get(Type type)
|
||||||
{
|
{
|
||||||
if (!_codes.TryGetValue(type, out int code))
|
if (!_codes.TryGetValue(type, out int code))
|
||||||
{
|
{
|
||||||
code = _incremetn++;
|
code = _increment++;
|
||||||
_codes.Add(type, code);
|
_codes.Add(type, code);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int Get<T>() => EcsTypeCodeCache<T>.code;
|
public static int Get<T>() { return EcsTypeCodeCache<T>.code; }
|
||||||
public static bool Has(Type type) => _codes.ContainsKey(type);
|
public static bool Has(Type type) { return _codes.ContainsKey(type); }
|
||||||
public static bool Has<T>() => _codes.ContainsKey(typeof(T));
|
public static bool Has<T>() { return _codes.ContainsKey(typeof(T)); }
|
||||||
public static IEnumerable<TypeCodeInfo> GetDeclared() => _codes.Select(o => new TypeCodeInfo(o.Key, o.Value));
|
public static IEnumerable<TypeCodeInfo> GetDeclaredTypes() { return _codes.Select(o => new TypeCodeInfo(o.Key, o.Value)); }
|
||||||
}
|
}
|
||||||
public static class EcsTypeCodeCache<T>
|
public static class EcsTypeCodeCache<T>
|
||||||
{
|
{
|
||||||
@ -38,10 +42,9 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.AutoToString(false) + "\n\r";
|
return this.AutoToString(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS.Internal
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
public readonly struct GenericEnumerable<T, TEnumerator> : IEnumerable<T> where TEnumerator : IEnumerator<T>
|
internal readonly struct GenericEnumerable<T, TEnumerator> : IEnumerable<T> where TEnumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
public readonly TEnumerator _enumerator;
|
public readonly TEnumerator _enumerator;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
@ -1,11 +1,10 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Utils
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
@ -6,7 +6,7 @@ using System.Diagnostics.Contracts;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Utils
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
public class SparseArray<TValue>
|
public class SparseArray<TValue>
|
||||||
{
|
{
|
@ -6,7 +6,7 @@ using System.Diagnostics.Contracts;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Utils
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
internal class SparseArray64<TValue>
|
internal class SparseArray64<TValue>
|
||||||
{
|
{
|
@ -1,8 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using static Leopotam.EcsLite.EcsWorld;
|
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class EcsFrameworkException : Exception
|
||||||
|
{
|
||||||
|
public EcsFrameworkException() { }
|
||||||
|
public EcsFrameworkException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
|
||||||
|
public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
|
||||||
|
}
|
||||||
|
[Serializable]
|
||||||
|
public class EcsRunnerImplementationException : EcsFrameworkException
|
||||||
|
{
|
||||||
|
public EcsRunnerImplementationException() { }
|
||||||
|
public EcsRunnerImplementationException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
|
||||||
|
public EcsRunnerImplementationException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Internal
|
namespace DCFApixels.DragonECS.Internal
|
||||||
{
|
{
|
||||||
@ -105,20 +120,3 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public class EcsFrameworkException : Exception
|
|
||||||
{
|
|
||||||
public EcsFrameworkException() { }
|
|
||||||
public EcsFrameworkException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
|
|
||||||
public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
|
|
||||||
}
|
|
||||||
[Serializable]
|
|
||||||
public class EcsRunnerImplementationException : EcsFrameworkException
|
|
||||||
{
|
|
||||||
public EcsRunnerImplementationException() { }
|
|
||||||
public EcsRunnerImplementationException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
|
|
||||||
public EcsRunnerImplementationException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Utils
|
|
||||||
{
|
|
||||||
internal sealed class IntDispenser
|
|
||||||
{
|
|
||||||
private readonly ConcurrentQueue<int> _freeInts;
|
|
||||||
private int _increment;
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
public int LastInt => _increment;
|
|
||||||
public int FreeConut => _freeInts.Count;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
public IntDispenser(int startIncrement = 0)
|
|
||||||
{
|
|
||||||
_freeInts = new ConcurrentQueue<int>();
|
|
||||||
_increment = startIncrement;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetFree/Release
|
|
||||||
public int GetFree()
|
|
||||||
{
|
|
||||||
if (!_freeInts.TryDequeue(out int result))
|
|
||||||
{
|
|
||||||
result = Interlocked.Increment(ref _increment);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Release(int released)
|
|
||||||
{
|
|
||||||
_freeInts.Enqueue(released);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a20cbd833c35ff3438f9fe003903c0c3
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue
Block a user