Update DelEntBuffer

This commit is contained in:
Mikhail 2023-12-31 22:41:48 +08:00
parent 770c8c5522
commit 16b273d5e4

View File

@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS
private int _delEntBufferCount; private int _delEntBufferCount;
private int _delEntBufferMinCount; private int _delEntBufferMinCount;
private int _freeSpace; private int _freeSpace;
//private bool _isEnableReleaseDelEntBuffer = true; private bool _isEnableReleaseDelEntBuffer = true;
private List<WeakReference<EcsGroup>> _groups = new List<WeakReference<EcsGroup>>(); private List<WeakReference<EcsGroup>> _groups = new List<WeakReference<EcsGroup>>();
private Stack<EcsGroup> _groupsPool = new Stack<EcsGroup>(64); private Stack<EcsGroup> _groupsPool = new Stack<EcsGroup>(64);
@ -41,6 +41,7 @@ namespace DCFApixels.DragonECS
public int Capacity => _entitesCapacity; //_denseEntities.Length; public int Capacity => _entitesCapacity; //_denseEntities.Length;
public int DelEntBufferCount => _delEntBufferCount; public int DelEntBufferCount => _delEntBufferCount;
public bool IsEnableReleaseDelEntBuffer => _isEnableReleaseDelEntBuffer;
public EcsReadonlyGroup Entities => _allEntites.Readonly; public EcsReadonlyGroup Entities => _allEntites.Readonly;
public ReadOnlySpan<IEcsPoolImplementation> AllPools => _pools;// new ReadOnlySpan<IEcsPoolImplementation>(pools, 0, _poolsCount); public ReadOnlySpan<IEcsPoolImplementation> AllPools => _pools;// new ReadOnlySpan<IEcsPoolImplementation>(pools, 0, _poolsCount);
@ -135,52 +136,76 @@ namespace DCFApixels.DragonECS
#region Where Query #region Where Query
public EcsReadonlyGroup WhereToGroupFor<TAspect>(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect public EcsReadonlyGroup WhereToGroupFor<TAspect>(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect
{
if(_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
var executor = GetExecutor<EcsWhereExecutor<TAspect>>(); var executor = GetExecutor<EcsWhereExecutor<TAspect>>();
aspect = executor.Aspect; aspect = executor.Aspect;
return executor.ExecuteFor(span); return executor.ExecuteFor(span);
} }
public EcsReadonlyGroup WhereToGroupFor<TAspect>(EcsSpan span) where TAspect : EcsAspect public EcsReadonlyGroup WhereToGroupFor<TAspect>(EcsSpan span) where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
return GetExecutor<EcsWhereExecutor<TAspect>>().ExecuteFor(span); return GetExecutor<EcsWhereExecutor<TAspect>>().ExecuteFor(span);
} }
public EcsReadonlyGroup WhereToGroup<TAspect>(out TAspect aspect) where TAspect : EcsAspect public EcsReadonlyGroup WhereToGroup<TAspect>(out TAspect aspect) where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
var executor = GetExecutor<EcsWhereExecutor<TAspect>>(); var executor = GetExecutor<EcsWhereExecutor<TAspect>>();
aspect = executor.Aspect; aspect = executor.Aspect;
return executor.Execute(); return executor.Execute();
} }
public EcsReadonlyGroup WhereToGroup<TAspect>() where TAspect : EcsAspect public EcsReadonlyGroup WhereToGroup<TAspect>() where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
return GetExecutor<EcsWhereExecutor<TAspect>>().Execute(); return GetExecutor<EcsWhereExecutor<TAspect>>().Execute();
} }
public EcsSpan WhereFor<TAspect>(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect public EcsSpan WhereFor<TAspect>(EcsSpan span, out TAspect aspect) where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
var executor = GetExecutor<EcsWhereSpanExecutor<TAspect>>(); var executor = GetExecutor<EcsWhereSpanExecutor<TAspect>>();
aspect = executor.Aspect; aspect = executor.Aspect;
return executor.ExecuteFor(span); return executor.ExecuteFor(span);
} }
public EcsSpan WhereFor<TAspect>(EcsSpan span) where TAspect : EcsAspect public EcsSpan WhereFor<TAspect>(EcsSpan span) where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
return GetExecutor<EcsWhereSpanExecutor<TAspect>>().ExecuteFor(span); return GetExecutor<EcsWhereSpanExecutor<TAspect>>().ExecuteFor(span);
} }
public EcsSpan Where<TAspect>(out TAspect aspect) where TAspect : EcsAspect public EcsSpan Where<TAspect>(out TAspect aspect) where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
var executor = GetExecutor<EcsWhereSpanExecutor<TAspect>>(); var executor = GetExecutor<EcsWhereSpanExecutor<TAspect>>();
aspect = executor.Aspect; aspect = executor.Aspect;
return executor.Execute(); return executor.Execute();
} }
public EcsSpan Where<TAspect>() where TAspect : EcsAspect public EcsSpan Where<TAspect>() where TAspect : EcsAspect
{
if (_isEnableReleaseDelEntBuffer)
{ {
ReleaseDelEntityBufferAll(); ReleaseDelEntityBufferAll();
}
return GetExecutor<EcsWhereSpanExecutor<TAspect>>().Execute(); return GetExecutor<EcsWhereSpanExecutor<TAspect>>().Execute();
} }
#endregion #endregion
@ -333,27 +358,27 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region DelEntBuffer #region DelEntBuffer
//public AutoReleaseDelEntBufferLonkUnloker DisableAutoReleaseDelEntBuffer() public AutoReleaseDelEntBufferLonkUnloker DisableAutoReleaseDelEntBuffer()
//{ {
// _isEnableReleaseDelEntBuffer = false; _isEnableReleaseDelEntBuffer = false;
// return new AutoReleaseDelEntBufferLonkUnloker(this); return new AutoReleaseDelEntBufferLonkUnloker(this);
//} }
//public void EnableAutoReleaseDelEntBuffer() public void EnableAutoReleaseDelEntBuffer()
//{ {
// _isEnableReleaseDelEntBuffer = true; _isEnableReleaseDelEntBuffer = true;
//} }
//public readonly struct AutoReleaseDelEntBufferLonkUnloker : IDisposable public readonly struct AutoReleaseDelEntBufferLonkUnloker : IDisposable
//{ {
// private readonly EcsWorld _source; private readonly EcsWorld _source;
// public AutoReleaseDelEntBufferLonkUnloker(EcsWorld source) public AutoReleaseDelEntBufferLonkUnloker(EcsWorld source)
// { {
// _source = source; _source = source;
// } }
// public void Dispose() public void Dispose()
// { {
// _source.EnableAutoReleaseDelEntBuffer(); _source.EnableAutoReleaseDelEntBuffer();
// } }
//} }
public void ReleaseDelEntityBufferAll() public void ReleaseDelEntityBufferAll()
{ {
ReleaseDelEntityBuffer(-1); ReleaseDelEntityBuffer(-1);