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