mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-12 16:45:55 +08:00
update queries cashe
This commit is contained in:
parent
07c122d406
commit
89ebd5d1ba
@ -2,7 +2,6 @@
|
||||
using DCFApixels.DragonECS.PoolsCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static DCFApixels.DragonECS.EcsAspect;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
|
||||
@ -222,7 +222,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Other
|
||||
public EcsMaskIterator GetIterator()
|
||||
{
|
||||
if(_iterator == null)
|
||||
if (_iterator == null)
|
||||
{
|
||||
_iterator = new EcsMaskIterator(EcsWorld.GetWorld(_worldID), this);
|
||||
}
|
||||
@ -748,7 +748,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Enumerable
|
||||
public Enumerable Iterate(EcsSpan span)
|
||||
{
|
||||
return new Enumerable();
|
||||
return new Enumerable(this, span);
|
||||
}
|
||||
public readonly ref struct Enumerable
|
||||
{
|
||||
|
||||
@ -202,6 +202,11 @@ namespace DCFApixels.DragonECS
|
||||
_isDestroyed = true;
|
||||
_poolTypeCode_2_CmpTypeIDs = null;
|
||||
_cmpTypeCode_2_CmpTypeIDs = null;
|
||||
|
||||
foreach (var item in _executorCoures)
|
||||
{
|
||||
item.Value.Destroy();
|
||||
}
|
||||
//_entities - не обнуляется для работы entlong.IsAlive
|
||||
}
|
||||
//public void Clear() { }
|
||||
|
||||
@ -6,7 +6,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
public partial class EcsWorld
|
||||
{
|
||||
private readonly Dictionary<(Type, Type), EcsQueryExecutorCore> _executorCoures = new Dictionary<(Type, Type), EcsQueryExecutorCore>();
|
||||
private readonly Dictionary<(Type, EcsMask), EcsQueryExecutorCore> _executorCoures = new Dictionary<(Type, EcsMask), EcsQueryExecutorCore>();
|
||||
private readonly ExecutorMediator _executorsMediator;
|
||||
public readonly struct ExecutorMediator
|
||||
{
|
||||
@ -19,15 +19,15 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
World = world;
|
||||
}
|
||||
public TExecutorCore GetCore<TExecutorCore>(Type aspectType)
|
||||
public TExecutorCore GetCore<TExecutorCore>(EcsMask mask)
|
||||
where TExecutorCore : EcsQueryExecutorCore, new()
|
||||
{
|
||||
var coreType = typeof(EcsQueryExecutorCore);
|
||||
if(World._executorCoures.TryGetValue((aspectType, coreType), out EcsQueryExecutorCore core))
|
||||
var coreType = typeof(TExecutorCore);
|
||||
if (World._executorCoures.TryGetValue((coreType, mask), out EcsQueryExecutorCore core) == false)
|
||||
{
|
||||
core = new TExecutorCore();
|
||||
core.Initialize(World);
|
||||
World._executorCoures.Add((aspectType, coreType), core);
|
||||
core.Initialize(World, mask);
|
||||
World._executorCoures.Add((coreType, mask), core);
|
||||
}
|
||||
return (TExecutorCore)core;
|
||||
}
|
||||
@ -36,6 +36,7 @@ namespace DCFApixels.DragonECS
|
||||
public abstract class EcsQueryExecutorCore
|
||||
{
|
||||
private EcsWorld _source;
|
||||
private EcsMask _mask;
|
||||
public short WorldID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -46,9 +47,15 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _source; }
|
||||
}
|
||||
internal void Initialize(EcsWorld world)
|
||||
protected EcsMask Mask
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _mask; }
|
||||
}
|
||||
internal void Initialize(EcsWorld world, EcsMask mask)
|
||||
{
|
||||
_source = world;
|
||||
_mask = mask;
|
||||
OnInitialize();
|
||||
}
|
||||
internal void Destroy()
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
@ -11,31 +10,8 @@ namespace DCFApixels.DragonECS.Internal
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
internal readonly struct EcsWhereExecutorCoreList : IEcsWorldComponent<EcsWhereExecutorCoreList>
|
||||
internal class EcsWhereExecutorCore : EcsQueryExecutorCore
|
||||
{
|
||||
internal readonly EcsWhereExecutorCore[] _cores;
|
||||
public EcsWhereExecutorCoreList(EcsWhereExecutorCore[] cores)
|
||||
{
|
||||
_cores = cores;
|
||||
}
|
||||
public void Init(ref EcsWhereExecutorCoreList component, EcsWorld world)
|
||||
{
|
||||
component = new EcsWhereExecutorCoreList(new EcsWhereExecutorCore[64]);
|
||||
}
|
||||
public void OnDestroy(ref EcsWhereExecutorCoreList component, EcsWorld world)
|
||||
{
|
||||
component = default;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
internal class EcsWhereExecutorCore
|
||||
{
|
||||
private EcsWorld _source;
|
||||
|
||||
private EcsMaskIterator _iterator;
|
||||
private int[] _filteredEntities = new int[32];
|
||||
private int _filteredEntitiesCount = 0;
|
||||
@ -51,12 +27,13 @@ namespace DCFApixels.DragonECS.Internal
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public EcsWhereExecutorCore(EcsWorld source, EcsAspect aspect)
|
||||
#region OnInitialize/OnDestroy
|
||||
protected sealed override void OnInitialize()
|
||||
{
|
||||
_source = source;
|
||||
_versionsChecker = new PoolVersionsChecker(aspect.Mask);
|
||||
_versionsChecker = new PoolVersionsChecker(Mask);
|
||||
_iterator = Mask.GetIterator();
|
||||
}
|
||||
protected sealed override void OnDestroy() { }
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
@ -64,26 +41,26 @@ namespace DCFApixels.DragonECS.Internal
|
||||
private void Filter(EcsSpan span)
|
||||
{
|
||||
_filteredEntitiesCount = _iterator.Iterate(span).CopyTo(ref _filteredEntities);
|
||||
_lastWorldVersion = _source.Version;
|
||||
_lastWorldVersion = World.Version;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan Execute()
|
||||
{
|
||||
return ExecuteFor(_source.Entities);
|
||||
return ExecuteFor(World.Entities);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ExecuteFor(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
||||
if (span.WorldID != _source.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
_source.ReleaseDelEntityBufferAllAuto();
|
||||
if (_lastWorldVersion != _source.Version || _versionsChecker.NextEquals() == false)
|
||||
World.ReleaseDelEntityBufferAllAuto();
|
||||
if (_lastWorldVersion != World.Version || _versionsChecker.NextEquals() == false)
|
||||
{
|
||||
Filter(span);
|
||||
}
|
||||
return new EcsSpan(_source.id, _filteredEntities, _filteredEntitiesCount);
|
||||
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
||||
}
|
||||
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -137,20 +114,7 @@ namespace DCFApixels.DragonECS
|
||||
protected sealed override void OnInitialize()
|
||||
{
|
||||
_aspect = World.GetAspect<TAspect>();
|
||||
int maskID = _aspect.Mask.ID;
|
||||
ref var list = ref World.Get<EcsWhereExecutorCoreList>();
|
||||
var cores = list._cores;
|
||||
if (maskID >= list._cores.Length)
|
||||
{
|
||||
Array.Resize(ref cores, cores.Length << 1);
|
||||
list = new EcsWhereExecutorCoreList(cores);
|
||||
}
|
||||
ref var coreRef = ref cores[maskID];
|
||||
if (coreRef == null)
|
||||
{
|
||||
coreRef = new EcsWhereExecutorCore(World, _aspect);
|
||||
}
|
||||
_core = coreRef;
|
||||
_core = Mediator.GetCore<EcsWhereExecutorCore>(_aspect.Mask);
|
||||
}
|
||||
protected sealed override void OnDestroy() { }
|
||||
#endregion
|
||||
|
||||
@ -10,31 +10,8 @@ namespace DCFApixels.DragonECS.Internal
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
internal readonly struct EcsWhereToGroupExecutorCoreList : IEcsWorldComponent<EcsWhereToGroupExecutorCoreList>
|
||||
internal class EcsWhereToGroupExecutorCore : EcsQueryExecutorCore
|
||||
{
|
||||
internal readonly EcsWhereToGroupExecutorCore[] _cores;
|
||||
public EcsWhereToGroupExecutorCoreList(EcsWhereToGroupExecutorCore[] cores)
|
||||
{
|
||||
_cores = cores;
|
||||
}
|
||||
public void Init(ref EcsWhereToGroupExecutorCoreList component, EcsWorld world)
|
||||
{
|
||||
component = new EcsWhereToGroupExecutorCoreList(new EcsWhereToGroupExecutorCore[64]);
|
||||
}
|
||||
public void OnDestroy(ref EcsWhereToGroupExecutorCoreList component, EcsWorld world)
|
||||
{
|
||||
component = default;
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
internal class EcsWhereToGroupExecutorCore
|
||||
{
|
||||
private EcsWorld _source;
|
||||
|
||||
private EcsMaskIterator _iterator;
|
||||
private EcsGroup _filteredGroup;
|
||||
|
||||
@ -49,13 +26,14 @@ namespace DCFApixels.DragonECS.Internal
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors/Destroy
|
||||
public EcsWhereToGroupExecutorCore(EcsWorld source, EcsAspect aspect)
|
||||
#region OnInitialize/OnDestroy
|
||||
protected sealed override void OnInitialize()
|
||||
{
|
||||
_source = source;
|
||||
_versionsChecker = new PoolVersionsChecker(aspect.Mask);
|
||||
_versionsChecker = new PoolVersionsChecker(Mask);
|
||||
_filteredGroup = EcsGroup.New(World);
|
||||
_iterator = Mask.GetIterator();
|
||||
}
|
||||
public void Destroy()
|
||||
protected sealed override void OnDestroy()
|
||||
{
|
||||
_filteredGroup.Dispose();
|
||||
}
|
||||
@ -66,22 +44,22 @@ namespace DCFApixels.DragonECS.Internal
|
||||
private void Filter(EcsSpan span)
|
||||
{
|
||||
_iterator.Iterate(span).CopyTo(_filteredGroup);
|
||||
_lastWorldVersion = _source.Version;
|
||||
_lastWorldVersion = World.Version;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan Execute()
|
||||
public EcsReadonlyGroup Execute()
|
||||
{
|
||||
return ExecuteFor(_source.Entities);
|
||||
return ExecuteFor(World.Entities);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ExecuteFor(EcsSpan span)
|
||||
public EcsReadonlyGroup ExecuteFor(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
||||
if (span.WorldID != _source.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
_source.ReleaseDelEntityBufferAllAuto();
|
||||
if (_lastWorldVersion != _source.Version || _versionsChecker.NextEquals() == false)
|
||||
World.ReleaseDelEntityBufferAllAuto();
|
||||
if (_lastWorldVersion != World.Version || _versionsChecker.NextEquals() == false)
|
||||
{
|
||||
Filter(span);
|
||||
}
|
||||
@ -119,8 +97,7 @@ namespace DCFApixels.DragonECS
|
||||
protected sealed override void OnInitialize()
|
||||
{
|
||||
_aspect = World.GetAspect<TAspect>();
|
||||
_filteredGroup = EcsGroup.New(World);
|
||||
_versionsChecker = new PoolVersionsChecker(_aspect._mask);
|
||||
_core = Mediator.GetCore<EcsWhereToGroupExecutorCore>(_aspect.Mask);
|
||||
}
|
||||
protected sealed override void OnDestroy()
|
||||
{
|
||||
@ -130,12 +107,12 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region Methods
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan Execute()
|
||||
public EcsReadonlyGroup Execute()
|
||||
{
|
||||
return _core.Execute();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ExecuteFor(EcsSpan span)
|
||||
public EcsReadonlyGroup ExecuteFor(EcsSpan span)
|
||||
{
|
||||
return _core.ExecuteFor(span);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user