Improve ecs query performance;

This commit is contained in:
2025-10-12 19:49:05 +09:00
parent 682200cbf1
commit 6d1b510ac1
27 changed files with 1546 additions and 992 deletions

View File

@@ -1,6 +1,7 @@
using Ghost.Entities.Components;
using Ghost.Entities.Query;
using Ghost.Entities.Systems;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -51,6 +52,8 @@ public partial class World : IDisposable, IEquatable<World>
private readonly ComponentStorage _componentStorage;
private readonly SystemStorage _systemStorage;
private bool _isDisposed = false;
internal ComponentStorage ComponentStorage => _componentStorage;
public WorldID ID => _id;
@@ -67,6 +70,11 @@ public partial class World : IDisposable, IEquatable<World>
_systemStorage = new SystemStorage(this);
}
~World()
{
Dispose();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CompRef<T> GetSingleton<T>()
where T : unmanaged, IComponentData
@@ -87,29 +95,20 @@ public partial class World : IDisposable, IEquatable<World>
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("GHOST_EDITOR")]
public void NotifyComponentChanged(Entity entity, Type type)
{
//#if GHOST_EDITOR
ComponentChanged?.Invoke(this, entity, type);
//#endif
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("GHOST_EDITOR")]
public void NotifyComponentChanged<T>(Entity entity)
where T : unmanaged, IComponentData
{
NotifyComponentChanged(entity, typeof(T));
}
public void Dispose()
{
_entityManager.Dispose();
_componentStorage.Dispose();
_systemStorage.Dispose();
s_freeWorldSlots.Enqueue(_id);
}
public bool Equals(World? other)
{
if (other is null)
@@ -144,4 +143,22 @@ public partial class World : IDisposable, IEquatable<World>
{
return !(left == right);
}
public void Dispose()
{
if (_isDisposed)
{
return;
}
_entityManager.Dispose();
_componentStorage.Dispose();
_systemStorage.Dispose();
s_freeWorldSlots.Enqueue(_id);
_isDisposed = true;
GC.SuppressFinalize(this);
}
}