mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
update mask, add world.TryFindPoolInstance
This commit is contained in:
parent
8ad85548a2
commit
3986149267
@ -272,13 +272,13 @@ namespace DCFApixels.DragonECS
|
||||
public TPool IncludePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
var pool = CachePool<TPool>();
|
||||
IncludeImplicit(pool.ComponentType);
|
||||
SetMaskInclude(pool.ComponentType);
|
||||
return pool;
|
||||
}
|
||||
public TPool ExcludePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
var pool = CachePool<TPool>();
|
||||
ExcludeImplicit(pool.ComponentType);
|
||||
SetMaskExclude(pool.ComponentType);
|
||||
return pool;
|
||||
}
|
||||
public TPool OptionalPool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
@ -291,14 +291,14 @@ namespace DCFApixels.DragonECS
|
||||
var pool = _world.GetPoolInstance<TPool>();
|
||||
return pool;
|
||||
}
|
||||
private void IncludeImplicit(Type type)
|
||||
public void SetMaskInclude(Type type)
|
||||
{
|
||||
if (_maskBuilder.IsNull == false)
|
||||
{
|
||||
_maskBuilder.Inc(type);
|
||||
}
|
||||
}
|
||||
private void ExcludeImplicit(Type type)
|
||||
public void SetMaskExclude(Type type)
|
||||
{
|
||||
if (_maskBuilder.IsNull == false)
|
||||
{
|
||||
@ -334,8 +334,8 @@ namespace DCFApixels.DragonECS
|
||||
IncludePool<TPool>();
|
||||
ExcludePool<TPool>();
|
||||
OptionalPool<TPool>();
|
||||
IncludeImplicit(null);
|
||||
ExcludeImplicit(null);
|
||||
SetMaskInclude(null);
|
||||
SetMaskExclude(null);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ namespace DCFApixels.DragonECS
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
public class EcsMaskIterator
|
||||
public class EcsMaskIterator : IDisposable
|
||||
{
|
||||
// TODO есть идея перенести эти ChunckBuffer-ы в стек,
|
||||
// для этого нужно проработать дизайн так чтобы память в стеке выделялась за пределами итератора и GetEnumerator,
|
||||
@ -555,6 +555,15 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
unsafe ~EcsMaskIterator()
|
||||
{
|
||||
Cleanup(false);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Cleanup(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
private void Cleanup(bool disposing)
|
||||
{
|
||||
_sortIncBuffer.ReadonlyDispose();
|
||||
//_sortExcBuffer.ReadonlyDispose();// использует общую памяять с _sortIncBuffer;
|
||||
@ -563,7 +572,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SortConstraints
|
||||
#region SortConstraints/TryFindEntityStorage
|
||||
private unsafe int SortConstraints_Internal()
|
||||
{
|
||||
UnsafeArray<int> sortIncBuffer = _sortIncBuffer;
|
||||
@ -611,7 +620,7 @@ namespace DCFApixels.DragonECS
|
||||
// Поэтому исключающее ограничение игнорируется для maxEntites.
|
||||
return maxEntites;
|
||||
}
|
||||
private unsafe bool TryGetEntityStorage(out IEntityStorage storage)
|
||||
private unsafe bool TryFindEntityStorage(out IEntityStorage storage)
|
||||
{
|
||||
if (_isHasAnyEntityStorage)
|
||||
{
|
||||
@ -737,7 +746,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new Enumerator(_span.Slice(0, 0), _iterator);
|
||||
}
|
||||
if (_iterator.TryGetEntityStorage(out IEntityStorage storage))
|
||||
if (_iterator.TryFindEntityStorage(out IEntityStorage storage))
|
||||
{
|
||||
return new Enumerator(storage.ToSpan(), _iterator);
|
||||
}
|
||||
@ -811,6 +820,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Iterate/Enumerable OnlyInc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public OnlyIncEnumerable IterateOnlyInc(EcsSpan span) { return new OnlyIncEnumerable(this, span); }
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
@ -876,7 +886,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new Enumerator(_span.Slice(0, 0), _iterator);
|
||||
}
|
||||
if (_iterator.TryGetEntityStorage(out IEntityStorage storage))
|
||||
if (_iterator.TryFindEntityStorage(out IEntityStorage storage))
|
||||
{
|
||||
return new Enumerator(storage.ToSpan(), _iterator);
|
||||
}
|
||||
|
@ -40,6 +40,17 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return FindPoolInstance_Internal(GetComponentTypeID(componentType));
|
||||
}
|
||||
public bool TryFindPoolInstance(int componentTypeID, out IEcsPool pool)
|
||||
{
|
||||
pool = FindPoolInstance(componentTypeID);
|
||||
return pool.IsNullOrDummy() == false;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryFindPoolInstance(Type componentType, out IEcsPool pool)
|
||||
{
|
||||
pool = FindPoolInstance(componentType);
|
||||
return pool.IsNullOrDummy() == false;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private IEcsPool FindPoolInstance_Internal(int componentTypeID)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user