mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
fix leaks/refactoring
This commit is contained in:
parent
cf31891a97
commit
73bb779a5a
@ -196,10 +196,12 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
if (_groupSparsePagePoolCount <= 0)
|
||||
{
|
||||
var x = UnmanagedArrayUtility.NewAndInit<int>(EcsGroup.PAGE_SIZE);
|
||||
return x;
|
||||
var newPage = UnmanagedArrayUtility.NewAndInit<int>(EcsGroup.PAGE_SIZE);
|
||||
return newPage;
|
||||
}
|
||||
return _groupSparsePagePool[--_groupSparsePagePoolCount];
|
||||
var takedPage = _groupSparsePagePool[--_groupSparsePagePoolCount];
|
||||
_groupSparsePagePool[_groupSparsePagePoolCount] = null;
|
||||
return takedPage;
|
||||
}
|
||||
internal void ReturnPage(int* page)
|
||||
{
|
||||
@ -214,6 +216,16 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
_groupSparsePagePool[_groupSparsePagePoolCount++] = page;
|
||||
}
|
||||
private void DisposeGroupPages()
|
||||
{
|
||||
foreach (var page in _groupSparsePagePool)
|
||||
{
|
||||
if (page != null)
|
||||
{
|
||||
UnmanagedArrayUtility.Free(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Groups Pool
|
||||
|
@ -7,13 +7,12 @@ namespace DCFApixels.DragonECS.Core
|
||||
{
|
||||
public abstract class EcsMetaAttribute : Attribute { }
|
||||
|
||||
|
||||
internal unsafe static class EcsMetaAttributeHalper
|
||||
internal static class EcsMetaAttributeHalper
|
||||
{
|
||||
internal const string EMPTY_NO_SENSE_MESSAGE = "With empty parameters, this attribute makes no sense.";
|
||||
[ThreadStatic]
|
||||
private static string[] _splitBuffer;
|
||||
public static string[] Split(char separator, string value)
|
||||
public static unsafe string[] Split(char separator, string value)
|
||||
{
|
||||
if (_splitBuffer == null)
|
||||
{
|
||||
@ -46,7 +45,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
}
|
||||
|
||||
#region SplitStream
|
||||
private ref struct SplitStream
|
||||
private unsafe ref struct SplitStream
|
||||
{
|
||||
public string current;
|
||||
public char* ptr;
|
||||
|
@ -198,7 +198,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Constructors/New
|
||||
private Builder() { }
|
||||
|
||||
internal static unsafe (TAspect aspect, EcsMask mask) New<TAspect>(EcsWorld world) where TAspect : new()
|
||||
internal static (TAspect aspect, EcsMask mask) New<TAspect>(EcsWorld world) where TAspect : new()
|
||||
{
|
||||
//Get Builder
|
||||
if (_constructorBuildersStack == null)
|
||||
|
@ -758,7 +758,7 @@ namespace DCFApixels.DragonECS
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
public unsafe ref struct Enumerator
|
||||
public ref struct Enumerator
|
||||
{
|
||||
private ReadOnlySpan<int>.Enumerator _span;
|
||||
|
||||
@ -784,7 +784,7 @@ namespace DCFApixels.DragonECS
|
||||
get { return _span.Current; }
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool MoveNext()
|
||||
public unsafe bool MoveNext()
|
||||
{
|
||||
while (_span.MoveNext())
|
||||
{
|
||||
|
@ -236,6 +236,7 @@ namespace DCFApixels.DragonECS
|
||||
_isDestroyed = true;
|
||||
_poolTypeCode_2_CmpTypeIDs = null;
|
||||
_cmpTypeCode_2_CmpTypeIDs = null;
|
||||
DisposeGroupPages();
|
||||
|
||||
foreach (var item in _executorCoures)
|
||||
{
|
||||
@ -1054,6 +1055,11 @@ namespace DCFApixels.DragonECS
|
||||
list.Add(_pools[poolIdsPtr[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count >= BUFFER_THRESHOLD)
|
||||
{
|
||||
UnmanagedArrayUtility.Free(poolIdsPtr);
|
||||
}
|
||||
}
|
||||
public ReadOnlySpan<object> GetComponentsFor(int entityID)
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Core
|
||||
{
|
||||
@ -70,7 +71,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
|
||||
|
||||
|
||||
public unsafe class DependencyGraph<T> : IDependencyGraph<T>
|
||||
public class DependencyGraph<T> : IDependencyGraph<T>
|
||||
{
|
||||
private readonly Dictionary<T, VertexID> _vertexIDs = new Dictionary<T, VertexID>(32);
|
||||
private StructList<VertexInfo> _vertexInfos = new StructList<VertexInfo>(32);
|
||||
@ -226,7 +227,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
#endregion
|
||||
|
||||
#region Sort
|
||||
public T[] Sort()
|
||||
public unsafe T[] Sort()
|
||||
{
|
||||
const int BUFFER_THRESHOLD = 256;
|
||||
if (_count <= BUFFER_THRESHOLD)
|
||||
@ -248,7 +249,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
return ConvertIdsToTsArray(buffer);
|
||||
}
|
||||
}
|
||||
private void TopoSorting(UnsafeArray<VertexID> sortingBuffer)
|
||||
private unsafe void TopoSorting(UnsafeArray<VertexID> sortingBuffer)
|
||||
{
|
||||
VertexID[] nodes = new VertexID[_count];
|
||||
var adjacency = new List<(VertexID To, int DependencyIndex)>[GetVertexInfosCount()];
|
||||
@ -336,7 +337,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
throw new InvalidOperationException("Cyclic dependency detected." + details);
|
||||
}
|
||||
}
|
||||
private void ReoderInsertionIndexes(UnsafeArray<VertexID> sortingBuffer)
|
||||
private unsafe void ReoderInsertionIndexes(UnsafeArray<VertexID> sortingBuffer)
|
||||
{
|
||||
for (int i = 0; i < GetVertexInfosCount(); i++)
|
||||
{
|
||||
@ -375,7 +376,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
|
||||
}
|
||||
}
|
||||
private static void MoveElement<TValue>(ref UnsafeArray<TValue> array, int oldIndex, int newIndex) where TValue : unmanaged
|
||||
private static unsafe void MoveElement<TValue>(ref UnsafeArray<TValue> array, int oldIndex, int newIndex) where TValue : unmanaged
|
||||
{
|
||||
if (oldIndex == newIndex) return;
|
||||
|
||||
@ -405,7 +406,7 @@ namespace DCFApixels.DragonECS.Core
|
||||
|
||||
ptr[newIndex] = item;
|
||||
}
|
||||
private T[] ConvertIdsToTsArray(UnsafeArray<VertexID> buffer)
|
||||
private unsafe T[] ConvertIdsToTsArray(UnsafeArray<VertexID> buffer)
|
||||
{
|
||||
T[] result = new T[buffer.Length];
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
|
Loading…
Reference in New Issue
Block a user