mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
fixes
This commit is contained in:
parent
d81ee5f1e5
commit
9805f0c709
@ -104,7 +104,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public static Action<DebugService> OnServiceChanged = delegate { };
|
public static Action<DebugService> OnServiceChanged = delegate { };
|
||||||
|
|
||||||
private IntDispenser _idDispenser = new IntDispenser(0);
|
private IntDispenser _idDispenser = new IntDispenser(-1);
|
||||||
private Dictionary<string, int> _nameIdTable = new Dictionary<string, int>();
|
private Dictionary<string, int> _nameIdTable = new Dictionary<string, int>();
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -248,7 +248,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
Sort();
|
// Sort();
|
||||||
_lockCount++;
|
_lockCount++;
|
||||||
return new Enumerator(this);
|
return new Enumerator(this);
|
||||||
}
|
}
|
||||||
|
@ -289,12 +289,11 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region EcsMask
|
#region EcsMask
|
||||||
public sealed class EcsMask
|
public class EcsMaskBase
|
||||||
{
|
{
|
||||||
internal readonly Type WorldArchetypeType;
|
internal Type WorldArchetypeType;
|
||||||
internal readonly int UniqueID;
|
internal int[] Inc;
|
||||||
internal readonly int[] Inc;
|
internal int[] Exc;
|
||||||
internal readonly int[] Exc;
|
|
||||||
|
|
||||||
internal int IncCount
|
internal int IncCount
|
||||||
{
|
{
|
||||||
@ -306,6 +305,26 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => Exc.Length;
|
get => Exc.Length;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public sealed class EcsMask : EcsMaskBase
|
||||||
|
{
|
||||||
|
// internal readonly Type WorldArchetypeType;
|
||||||
|
internal readonly int UniqueID;
|
||||||
|
//internal readonly int[] Inc;
|
||||||
|
//internal readonly int[] Exc;
|
||||||
|
|
||||||
|
//internal int IncCount
|
||||||
|
//{
|
||||||
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
// get => Inc.Length;
|
||||||
|
//}
|
||||||
|
//internal int ExcCount
|
||||||
|
//{
|
||||||
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
// get => Exc.Length;
|
||||||
|
//}
|
||||||
internal EcsMask(Type worldArchetypeType, int uniqueID, int[] inc, int[] exc)
|
internal EcsMask(Type worldArchetypeType, int uniqueID, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
WorldArchetypeType = worldArchetypeType;
|
WorldArchetypeType = worldArchetypeType;
|
||||||
|
@ -19,11 +19,25 @@ namespace DCFApixels.DragonECS
|
|||||||
internal void AddEntity(int entityID);
|
internal void AddEntity(int entityID);
|
||||||
internal void RemoveEntity(int entityID);
|
internal void RemoveEntity(int entityID);
|
||||||
}
|
}
|
||||||
public class EcsQuery<TWorldArchetype> : IEcsQuery
|
public abstract class EcsQueryBase : IEcsQuery
|
||||||
|
{
|
||||||
|
internal EcsGroup group;
|
||||||
|
internal EcsQueryMask mask;
|
||||||
|
|
||||||
|
|
||||||
|
public void AddEntity(int entityID) => group.Add(entityID);
|
||||||
|
public void RemoveEntity(int entityID) => group.Remove(entityID);
|
||||||
|
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
void IEcsQuery.AddEntity(int entityID) => group.Add(entityID);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
void IEcsQuery.RemoveEntity(int entityID) => group.Remove(entityID);
|
||||||
|
}
|
||||||
|
public abstract class EcsQuery<TWorldArchetype> : EcsQueryBase
|
||||||
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||||
{
|
{
|
||||||
private int _id;
|
private int _id;
|
||||||
internal EcsGroup group;
|
|
||||||
|
|
||||||
public int ID => _id;
|
public int ID => _id;
|
||||||
public EcsReadonlyGroup entities
|
public EcsReadonlyGroup entities
|
||||||
@ -39,10 +53,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsGroup.Enumerator GetEnumerator() => group.GetEnumerator();
|
public EcsGroup.Enumerator GetEnumerator() => group.GetEnumerator();
|
||||||
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
void IEcsQuery.AddEntity(int entityID) => group.Add(entityID);
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
void IEcsQuery.RemoveEntity(int entityID) => group.Remove(entityID);
|
|
||||||
|
|
||||||
#region Builder
|
#region Builder
|
||||||
public sealed class Builder : EcsQueryBuilder
|
public sealed class Builder : EcsQueryBuilder
|
||||||
@ -89,14 +99,14 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EcsQueryMask
|
public class EcsQueryMask : EcsMaskBase
|
||||||
{
|
{
|
||||||
internal readonly Type WorldArchetypeType;
|
// internal readonly Type WorldArchetypeType;
|
||||||
internal readonly int[] Inc;
|
// internal readonly int[] Inc;
|
||||||
internal readonly int[] Exc;
|
// internal readonly int[] Exc;
|
||||||
|
//
|
||||||
public int IncCount => Inc.Length;
|
// public int IncCount => Inc.Length;
|
||||||
public int ExcCount => Exc.Length;
|
// public int ExcCount => Exc.Length;
|
||||||
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
|
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
WorldArchetypeType = worldArchetypeType;
|
WorldArchetypeType = worldArchetypeType;
|
||||||
|
116
src/EcsWorld.cs
116
src/EcsWorld.cs
@ -30,7 +30,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public abstract class EcsWorld
|
public abstract class EcsWorld
|
||||||
{
|
{
|
||||||
internal static IEcsWorld[] Worlds = new IEcsWorld[8];
|
internal static IEcsWorld[] Worlds = new IEcsWorld[8];
|
||||||
private static IntDispenser _worldIdDispenser = new IntDispenser(1);
|
private static IntDispenser _worldIdDispenser = new IntDispenser(0);
|
||||||
|
|
||||||
public readonly short id;
|
public readonly short id;
|
||||||
|
|
||||||
@ -69,8 +69,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private IEcsPool[] _pools;
|
private IEcsPool[] _pools;
|
||||||
private EcsNullPool _nullPool;
|
private EcsNullPool _nullPool;
|
||||||
|
|
||||||
private List<EcsGroup>[] _filtersByIncludedComponents;
|
private List<EcsQueryBase>[] _filtersByIncludedComponents;
|
||||||
private List<EcsGroup>[] _filtersByExcludedComponents;
|
private List<EcsQueryBase>[] _filtersByExcludedComponents;
|
||||||
|
|
||||||
private IEcsQuery[] _archetypes;
|
private IEcsQuery[] _archetypes;
|
||||||
|
|
||||||
@ -78,6 +78,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private List<EcsGroup> _groups;
|
private List<EcsGroup> _groups;
|
||||||
|
|
||||||
|
|
||||||
#region RunnersCache
|
#region RunnersCache
|
||||||
private PoolRunnres _poolRunnres;
|
private PoolRunnres _poolRunnres;
|
||||||
private IEcsEntityCreate _entityCreate;
|
private IEcsEntityCreate _entityCreate;
|
||||||
@ -109,7 +110,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
_pipeline = pipline ?? EcsPipeline.Empty;
|
_pipeline = pipline ?? EcsPipeline.Empty;
|
||||||
if (!_pipeline.IsInit) pipline.Init();
|
if (!_pipeline.IsInit) pipline.Init();
|
||||||
_entityDispenser = new IntDispenser(1);
|
_entityDispenser = new IntDispenser(0);
|
||||||
_nullPool = EcsNullPool.instance;
|
_nullPool = EcsNullPool.instance;
|
||||||
_pools = new IEcsPool[512];
|
_pools = new IEcsPool[512];
|
||||||
FillArray(_pools, _nullPool);
|
FillArray(_pools, _nullPool);
|
||||||
@ -120,8 +121,8 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
_denseEntities = new int[512];
|
_denseEntities = new int[512];
|
||||||
|
|
||||||
_filtersByIncludedComponents = new List<EcsGroup>[16];
|
_filtersByIncludedComponents = new List<EcsQueryBase>[16];
|
||||||
_filtersByExcludedComponents = new List<EcsGroup>[16];
|
_filtersByExcludedComponents = new List<EcsQueryBase>[16];
|
||||||
|
|
||||||
_poolRunnres = new PoolRunnres(_pipeline);
|
_poolRunnres = new PoolRunnres(_pipeline);
|
||||||
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
||||||
@ -172,9 +173,10 @@ namespace DCFApixels.DragonECS
|
|||||||
_archetypes[uniqueID] = (TEntityArhetype)Activator.CreateInstance(typeof(TEntityArhetype), builder);
|
_archetypes[uniqueID] = (TEntityArhetype)Activator.CreateInstance(typeof(TEntityArhetype), builder);
|
||||||
builder.End(out EcsQueryMask mask);
|
builder.End(out EcsQueryMask mask);
|
||||||
|
|
||||||
var filter = new EcsGroup(this);
|
var filter = (EcsQueryBase)_archetypes[uniqueID];
|
||||||
|
|
||||||
((EcsQuery<TWorldArchetype>)_archetypes[uniqueID]).group = filter;
|
((EcsQuery<TWorldArchetype>)_archetypes[uniqueID]).group = new EcsGroup(this);
|
||||||
|
((EcsQuery<TWorldArchetype>)_archetypes[uniqueID]).mask = mask;
|
||||||
|
|
||||||
for (int i = 0; i < mask.IncCount; i++)
|
for (int i = 0; i < mask.IncCount; i++)
|
||||||
{
|
{
|
||||||
@ -182,7 +184,7 @@ namespace DCFApixels.DragonECS
|
|||||||
var list = _filtersByIncludedComponents[componentID];
|
var list = _filtersByIncludedComponents[componentID];
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
list = new List<EcsGroup>(8);
|
list = new List<EcsQueryBase>(8);
|
||||||
_filtersByIncludedComponents[componentID] = list;
|
_filtersByIncludedComponents[componentID] = list;
|
||||||
}
|
}
|
||||||
list.Add(filter);
|
list.Add(filter);
|
||||||
@ -194,7 +196,7 @@ namespace DCFApixels.DragonECS
|
|||||||
var list = _filtersByExcludedComponents[componentID];
|
var list = _filtersByExcludedComponents[componentID];
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
list = new List<EcsGroup>(8);
|
list = new List<EcsQueryBase>(8);
|
||||||
_filtersByExcludedComponents[componentID] = list;
|
_filtersByExcludedComponents[componentID] = list;
|
||||||
}
|
}
|
||||||
list.Add(filter);
|
list.Add(filter);
|
||||||
@ -204,7 +206,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
int entity = _denseEntities[i];
|
int entity = _denseEntities[i];
|
||||||
if (IsMaskCompatible(mask.Inc, mask.Exc, entity))
|
if (IsMaskCompatible(mask.Inc, mask.Exc, entity))
|
||||||
filter.Add(entity);
|
filter.AddEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entities = (TEntityArhetype)_archetypes[uniqueID];
|
entities = (TEntityArhetype)_archetypes[uniqueID];
|
||||||
@ -238,7 +240,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return IsMaskCompatible(EcsMaskMap<TWorldArchetype>.GetMask<TInc, TExc>(), entityID);
|
return IsMaskCompatible(EcsMaskMap<TWorldArchetype>.GetMask<TInc, TExc>(), entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsMaskCompatible(EcsMask mask, int entity)
|
public bool IsMaskCompatible(EcsMaskBase mask, int entity)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (mask.WorldArchetypeType != typeof(TWorldArchetype))
|
if (mask.WorldArchetypeType != typeof(TWorldArchetype))
|
||||||
@ -257,7 +259,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsMaskCompatibleWithout(EcsMask mask, int entity, int otherComponentID)
|
public bool IsMaskCompatibleWithout(EcsMaskBase mask, int entity, int otherComponentID)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (mask.WorldArchetypeType != typeof(TWorldArchetype))
|
if (mask.WorldArchetypeType != typeof(TWorldArchetype))
|
||||||
@ -286,30 +288,30 @@ namespace DCFApixels.DragonECS
|
|||||||
var includeList = _filtersByIncludedComponents[componentID];
|
var includeList = _filtersByIncludedComponents[componentID];
|
||||||
var excludeList = _filtersByExcludedComponents[componentID];
|
var excludeList = _filtersByExcludedComponents[componentID];
|
||||||
|
|
||||||
// if (includeList != null)
|
if (includeList != null)
|
||||||
// {
|
{
|
||||||
// foreach (var filter in includeList)
|
foreach (var filter in includeList)
|
||||||
// {
|
{
|
||||||
// if (IsMaskCompatible(filter.Mask, entityID))
|
if (IsMaskCompatible(filter.mask, entityID))
|
||||||
// {
|
{
|
||||||
// filter.entities.UncheckedAdd(entityID);
|
filter.AddEntity(entityID);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if (excludeList != null)
|
if (excludeList != null)
|
||||||
// {
|
{
|
||||||
// foreach (var filter in excludeList)
|
foreach (var filter in excludeList)
|
||||||
// {
|
{
|
||||||
// if (IsMaskCompatibleWithout(filter.Mask, entityID, componentID))
|
if (IsMaskCompatibleWithout(filter.mask, entityID, componentID))
|
||||||
// {
|
{
|
||||||
// filter.entities.UncheckedRemove(entityID);
|
filter.RemoveEntity(entityID);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//TODO провести стресс тест для варианта выши и закоментированного ниже
|
//TODO провести стресс тест для варианта выши и закоментированного ниже
|
||||||
|
|
||||||
if (includeList != null) foreach (var filter in includeList) filter.Add(entityID);
|
// if (includeList != null) foreach (var filter in includeList) filter.Add(entityID);
|
||||||
if (excludeList != null) foreach (var filter in excludeList) filter.Remove(entityID);
|
// if (excludeList != null) foreach (var filter in excludeList) filter.Remove(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IEcsReadonlyTable.OnEntityComponentRemoved(int entityID, int componentID)
|
void IEcsReadonlyTable.OnEntityComponentRemoved(int entityID, int componentID)
|
||||||
@ -317,30 +319,30 @@ namespace DCFApixels.DragonECS
|
|||||||
var includeList = _filtersByIncludedComponents[componentID];
|
var includeList = _filtersByIncludedComponents[componentID];
|
||||||
var excludeList = _filtersByExcludedComponents[componentID];
|
var excludeList = _filtersByExcludedComponents[componentID];
|
||||||
|
|
||||||
// if (includeList != null)
|
if (includeList != null)
|
||||||
// {
|
{
|
||||||
// foreach (var filter in includeList)
|
foreach (var filter in includeList)
|
||||||
// {
|
{
|
||||||
// if (IsMaskCompatible(filter.Mask, entityID))
|
if (IsMaskCompatible(filter.mask, entityID))
|
||||||
// {
|
{
|
||||||
// filter.entities.UncheckedRemove(entityID);
|
filter.RemoveEntity(entityID);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if (excludeList != null)
|
if (excludeList != null)
|
||||||
// {
|
{
|
||||||
// foreach (var filter in excludeList)
|
foreach (var filter in excludeList)
|
||||||
// {
|
{
|
||||||
// if (IsMaskCompatibleWithout(filter.Mask, entityID, componentID))
|
if (IsMaskCompatibleWithout(filter.mask, entityID, componentID))
|
||||||
// {
|
{
|
||||||
// filter.entities.UncheckedAdd(entityID);
|
filter.AddEntity(entityID);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//TODO провести стресс тест для варианта выши и закоментированного ниже
|
//TODO провести стресс тест для варианта выши и закоментированного ниже
|
||||||
|
|
||||||
if (includeList != null) foreach (var filter in includeList) filter.Remove(entityID);
|
// if (includeList != null) foreach (var filter in includeList) filter.Remove(entityID);
|
||||||
if (excludeList != null) foreach (var filter in excludeList) filter.Add(entityID);
|
// if (excludeList != null) foreach (var filter in excludeList) filter.Add(entityID);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public bool IsMaskCompatible<TInc>(int entity) where TInc : struct, IInc;
|
public bool IsMaskCompatible<TInc>(int entity) where TInc : struct, IInc;
|
||||||
public bool IsMaskCompatible<TInc, TExc>(int entity) where TInc : struct, IInc where TExc : struct, IExc;
|
public bool IsMaskCompatible<TInc, TExc>(int entity) where TInc : struct, IInc where TExc : struct, IExc;
|
||||||
public bool IsMaskCompatible(EcsMask mask, int entity);
|
public bool IsMaskCompatible(EcsMaskBase mask, int entity);
|
||||||
public bool IsMaskCompatibleWithout(EcsMask mask, int entity, int otherPoolID);
|
public bool IsMaskCompatibleWithout(EcsMaskBase mask, int entity, int otherPoolID);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
Loading…
Reference in New Issue
Block a user