mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24: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.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
@ -189,7 +188,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Entity
|
||||
|
||||
|
||||
#region New/Del
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int NewEntity()
|
||||
|
@ -1,5 +1,4 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
@ -3,11 +3,11 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
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 int BYTE_BITS = 8;
|
@ -8,22 +8,26 @@ namespace DCFApixels.DragonECS.Internal
|
||||
public static class EcsTypeCode
|
||||
{
|
||||
private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>();
|
||||
private static int _incremetn = 1;
|
||||
public static int Count => _codes.Count;
|
||||
private static int _increment = 1;
|
||||
public static int Count
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _codes.Count; }
|
||||
}
|
||||
public static int Get(Type type)
|
||||
{
|
||||
if (!_codes.TryGetValue(type, out int code))
|
||||
{
|
||||
code = _incremetn++;
|
||||
code = _increment++;
|
||||
_codes.Add(type, code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Get<T>() => EcsTypeCodeCache<T>.code;
|
||||
public static bool Has(Type type) => _codes.ContainsKey(type);
|
||||
public static bool Has<T>() => _codes.ContainsKey(typeof(T));
|
||||
public static IEnumerable<TypeCodeInfo> GetDeclared() => _codes.Select(o => new TypeCodeInfo(o.Key, o.Value));
|
||||
public static int Get<T>() { return EcsTypeCodeCache<T>.code; }
|
||||
public static bool Has(Type type) { return _codes.ContainsKey(type); }
|
||||
public static bool Has<T>() { return _codes.ContainsKey(typeof(T)); }
|
||||
public static IEnumerable<TypeCodeInfo> GetDeclaredTypes() { return _codes.Select(o => new TypeCodeInfo(o.Key, o.Value)); }
|
||||
}
|
||||
public static class EcsTypeCodeCache<T>
|
||||
{
|
||||
@ -38,10 +42,9 @@ namespace DCFApixels.DragonECS.Internal
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
@ -1,11 +1,10 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Utils
|
||||
namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
[Serializable]
|
||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||
@ -164,7 +163,7 @@ namespace DCFApixels.DragonECS.Utils
|
||||
int freeIndex = _usedCount;
|
||||
for (int i = 0; i < _size; i++)
|
||||
{
|
||||
if(_sparse[i] > 0)
|
||||
if (_sparse[i] > 0)
|
||||
{
|
||||
_sparse[i] = usedIndex;
|
||||
_dense[usedIndex++] = i;
|
@ -6,7 +6,7 @@ using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Utils
|
||||
namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
public class SparseArray<TValue>
|
||||
{
|
@ -6,7 +6,7 @@ using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Utils
|
||||
namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
internal class SparseArray64<TValue>
|
||||
{
|
@ -1,8 +1,23 @@
|
||||
using System;
|
||||
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
|
||||
{
|
||||
@ -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