complete World.Dispose
parent
6136450617
commit
b27875b9a8
|
@ -1,8 +1,8 @@
|
|||
using MoonTools.ECS.Collections;
|
||||
using System;
|
||||
using MoonTools.ECS.Collections;
|
||||
|
||||
namespace MoonTools.ECS;
|
||||
|
||||
// TODO: do we want to get fancy with queries beyond Include and Exclude?
|
||||
public class Filter
|
||||
{
|
||||
private World World;
|
||||
|
@ -10,6 +10,8 @@ public class Filter
|
|||
|
||||
internal IndexableSet<Entity> EntitySet = new IndexableSet<Entity>();
|
||||
|
||||
private bool IsDisposed;
|
||||
|
||||
public ReverseSpanEnumerator<Entity> Entities => EntitySet.GetEnumerator();
|
||||
|
||||
public bool Empty => EntitySet.Count == 0;
|
||||
|
@ -91,4 +93,31 @@ public class Filter
|
|||
public bool MoveNext() => LinearCongruentialEnumerator.MoveNext();
|
||||
public Entity Current => Filter.NthEntity(LinearCongruentialEnumerator.Current);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
EntitySet.Dispose();
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
// ~Filter()
|
||||
// {
|
||||
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
using System;
|
||||
using MoonTools.ECS.Collections;
|
||||
|
||||
namespace MoonTools.ECS;
|
||||
|
||||
internal class IdAssigner
|
||||
internal class IdAssigner : IDisposable
|
||||
{
|
||||
uint Next;
|
||||
NativeArray<uint> AvailableIds = new NativeArray<uint>();
|
||||
|
||||
private bool IsDisposed;
|
||||
|
||||
public uint Assign()
|
||||
{
|
||||
if (AvailableIds.TryPop(out var id))
|
||||
|
@ -29,4 +32,31 @@ internal class IdAssigner
|
|||
AvailableIds.CopyTo(other.AvailableIds);
|
||||
other.Next = Next;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
AvailableIds.Dispose();
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
// ~IdAssigner()
|
||||
// {
|
||||
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
|
26
src/World.cs
26
src/World.cs
|
@ -466,7 +466,6 @@ namespace MoonTools.ECS
|
|||
{
|
||||
if (disposing)
|
||||
{
|
||||
// TODO: dispose managed state (managed objects)
|
||||
foreach (var componentStorage in ComponentIndex.Values)
|
||||
{
|
||||
componentStorage.Dispose();
|
||||
|
@ -476,10 +475,31 @@ namespace MoonTools.ECS
|
|||
{
|
||||
relationStorage.Dispose();
|
||||
}
|
||||
|
||||
foreach (var messageStorage in MessageIndex.Values)
|
||||
{
|
||||
messageStorage.Dispose();
|
||||
}
|
||||
|
||||
foreach (var typeSet in EntityComponentIndex.Values)
|
||||
{
|
||||
typeSet.Dispose();
|
||||
}
|
||||
|
||||
foreach (var typeSet in EntityRelationIndex.Values)
|
||||
{
|
||||
typeSet.Dispose();
|
||||
}
|
||||
|
||||
foreach (var filter in FilterIndex.Values)
|
||||
{
|
||||
filter.Dispose();
|
||||
}
|
||||
|
||||
EntityIdAssigner.Dispose();
|
||||
TypeIdAssigner.Dispose();
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
||||
// TODO: set large fields to null
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue