mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
fix changes
This commit is contained in:
parent
eeb1620c22
commit
d7988166dd
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Unity.Profiling;
|
||||||
using static UnityEngine.Networking.UnityWebRequest;
|
using static UnityEngine.Networking.UnityWebRequest;
|
||||||
using delayedOp = System.Int32;
|
using delayedOp = System.Int32;
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ namespace DCFApixels.DragonECS
|
|||||||
// _delayedOps это int[] для отложенных операций, хранятся отложенные операции в виде int значения, если старший бит = 0 то это опреация добавленияб если = 1 то это операция вычитания
|
// _delayedOps это int[] для отложенных операций, хранятся отложенные операции в виде int значения, если старший бит = 0 то это опреация добавленияб если = 1 то это операция вычитания
|
||||||
|
|
||||||
// this collection can only store numbers greater than 0
|
// this collection can only store numbers greater than 0
|
||||||
public class EcsGroup
|
public unsafe class EcsGroup
|
||||||
{
|
{
|
||||||
private const int DEALAYED_ADD = 0;
|
private const int DEALAYED_ADD = 0;
|
||||||
private const int DEALAYED_REMOVE = int.MinValue;
|
private const int DEALAYED_REMOVE = int.MinValue;
|
||||||
@ -155,10 +156,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Contains(int entityID)
|
public bool Contains(int entityID)
|
||||||
{
|
{
|
||||||
//TODO добавить проверку на больше 0 в #if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
return _sparse[entityID] > 0;
|
||||||
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
|
||||||
#endif
|
|
||||||
return /*entityID > 0 && entityID < _sparse.Length && */ _sparse[entityID] > 0;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -180,11 +178,11 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal void AddInternal(int entityID)
|
internal void AddInternal(int entityID)
|
||||||
{
|
{
|
||||||
if (_lockCount > 0)
|
//if (_lockCount > 0)
|
||||||
{
|
//{
|
||||||
AddDelayedOp(entityID, DEALAYED_ADD);
|
// AddDelayedOp(entityID, DEALAYED_ADD);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
AggressiveAdd(entityID);
|
AggressiveAdd(entityID);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -205,11 +203,11 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal void RemoveInternal(int entityID)
|
internal void RemoveInternal(int entityID)
|
||||||
{
|
{
|
||||||
if (_lockCount > 0)
|
//if (_lockCount > 0)
|
||||||
{
|
//{
|
||||||
AddDelayedOp(entityID, DEALAYED_REMOVE);
|
// AddDelayedOp(entityID, DEALAYED_REMOVE);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
AggressiveRemove(entityID);
|
AggressiveRemove(entityID);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -298,8 +296,8 @@ namespace DCFApixels.DragonECS
|
|||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (_source != group.World) throw new ArgumentException("World != groupFilter.World");
|
if (_source != group.World) throw new ArgumentException("World != groupFilter.World");
|
||||||
#endif
|
#endif
|
||||||
foreach (var item in group)
|
foreach (var item in this)
|
||||||
if (Contains(item.id))
|
if (group.Contains(item.id))
|
||||||
AggressiveRemove(item.id);
|
AggressiveRemove(item.id);
|
||||||
}
|
}
|
||||||
/// <summary>as Except sets</summary>
|
/// <summary>as Except sets</summary>
|
||||||
@ -358,6 +356,35 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Static Set operations
|
||||||
|
/// <summary>as Except sets</summary>
|
||||||
|
public static EcsReadonlyGroup Remove(EcsGroup a, EcsGroup b)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
|
if (a._source != b._source) throw new ArgumentException("a.World != b.World");
|
||||||
|
#endif
|
||||||
|
EcsGroup result = a._source.GetGroupFromPool();
|
||||||
|
foreach (var item in a)
|
||||||
|
if (!b.Contains(item.id))
|
||||||
|
result.AggressiveAdd(item.id);
|
||||||
|
a._source.ReleaseGroup(a);
|
||||||
|
return result.Readonly;
|
||||||
|
}
|
||||||
|
/// <summary>as Intersect sets</summary>
|
||||||
|
public static EcsReadonlyGroup And(EcsGroup a, EcsGroup b)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
|
if (a._source != b._source) throw new ArgumentException("a.World != b.World");
|
||||||
|
#endif
|
||||||
|
EcsGroup result = a._source.GetGroupFromPool();
|
||||||
|
foreach (var item in a)
|
||||||
|
if (b.Contains(item.id))
|
||||||
|
result.AggressiveAdd(item.id);
|
||||||
|
a._source.ReleaseGroup(a);
|
||||||
|
return result.Readonly;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region GetEnumerator
|
#region GetEnumerator
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void Unlock()
|
private void Unlock()
|
||||||
@ -380,27 +407,28 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private ProfilerMarker _getEnumeratorReturn = new ProfilerMarker("EcsGroup.GetEnumerator");
|
||||||
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
Sort();
|
// _lockCount++;
|
||||||
_lockCount++;
|
|
||||||
return new Enumerator(this);
|
return new Enumerator(this);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Enumerator
|
#region Enumerator
|
||||||
public struct Enumerator : IDisposable
|
public ref struct Enumerator// : IDisposable
|
||||||
{
|
{
|
||||||
private readonly EcsGroup _source;
|
// private readonly EcsGroup _source;
|
||||||
private readonly int[] _dense;
|
private readonly int[] _dense;
|
||||||
private readonly int _count;
|
private readonly int _count;
|
||||||
private int _index;
|
private int _index;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator(EcsGroup group)
|
public Enumerator(EcsGroup group)
|
||||||
{
|
{
|
||||||
_source = group;
|
// _source = group;
|
||||||
_dense = group._dense;
|
_dense = group._dense;
|
||||||
_count = group.Count;
|
_count = group.Count;
|
||||||
_index = 0;
|
_index = 0;
|
||||||
@ -408,12 +436,12 @@ namespace DCFApixels.DragonECS
|
|||||||
public ent Current
|
public ent Current
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => new ent(_dense[_index]);
|
get => (ent)_dense[_index];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool MoveNext() => ++_index <= _count && _count<_dense.Length; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны
|
public bool MoveNext() => ++_index <= _count && _count<_dense.Length; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Dispose() => _source.Unlock();
|
//public void Dispose() => _source.Unlock();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
272
src/EcsMask.cs
272
src/EcsMask.cs
@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,8 +33,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +44,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,10 +56,10 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,11 +69,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,12 +83,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,13 +98,13 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,14 +114,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T7>.uniqueID,
|
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,15 +131,15 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T7>.uniqueID,
|
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T8>.uniqueID,
|
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,16 +149,16 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T7>.uniqueID,
|
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T8>.uniqueID,
|
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T9>.uniqueID,
|
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,17 +168,17 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T7>.uniqueID,
|
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T8>.uniqueID,
|
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T9>.uniqueID,
|
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T10>.uniqueID,
|
ComponentIndexer.GetComponentId<T10>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,18 +188,18 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T6>.uniqueID,
|
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T7>.uniqueID,
|
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T8>.uniqueID,
|
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T9>.uniqueID,
|
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T10>.uniqueID,
|
ComponentIndexer.GetComponentId<T10>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T11>.uniqueID,
|
ComponentIndexer.GetComponentId<T11>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,8 +227,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,9 +238,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,10 +250,10 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,11 +263,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,12 +277,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T0>.uniqueID,
|
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T1>.uniqueID,
|
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T2>.uniqueID,
|
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T3>.uniqueID,
|
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T4>.uniqueID,
|
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
EcsWorld<TWorldArchetype>.ComponentType<T5>.uniqueID,
|
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,43 +357,43 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
static Activator()
|
static Activator()
|
||||||
{
|
{
|
||||||
var inc = new TInc().GetComponentsIDs<TWorldArchetype>();
|
// var inc = new TInc().GetComponentsIDs<TWorldArchetype>();
|
||||||
var exc = new TExc().GetComponentsIDs<TWorldArchetype>();
|
// var exc = new TExc().GetComponentsIDs<TWorldArchetype>();
|
||||||
Array.Sort(inc);
|
// Array.Sort(inc);
|
||||||
Array.Sort(exc);
|
// Array.Sort(exc);
|
||||||
|
//
|
||||||
Type thisType = typeof(Activator<TInc, TExc>);
|
// Type thisType = typeof(Activator<TInc, TExc>);
|
||||||
|
//
|
||||||
Type sortedIncType = typeof(TInc);
|
// Type sortedIncType = typeof(TInc);
|
||||||
if (sortedIncType.IsGenericType)
|
// if (sortedIncType.IsGenericType)
|
||||||
{
|
// {
|
||||||
Type[] sortedInc = new Type[inc.Length];
|
// Type[] sortedInc = new Type[inc.Length];
|
||||||
for (int i = 0; i < sortedInc.Length; i++)
|
// for (int i = 0; i < sortedInc.Length; i++)
|
||||||
sortedInc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[inc[i]];
|
// sortedInc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[inc[i]];
|
||||||
sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc);
|
// sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc);
|
||||||
}
|
// }
|
||||||
Type sortedExcType = typeof(TExc);
|
// Type sortedExcType = typeof(TExc);
|
||||||
if (sortedExcType.IsGenericType)
|
// if (sortedExcType.IsGenericType)
|
||||||
{
|
// {
|
||||||
Type[] sortedExc = new Type[exc.Length];
|
// Type[] sortedExc = new Type[exc.Length];
|
||||||
for (int i = 0; i < sortedExc.Length; i++)
|
// for (int i = 0; i < sortedExc.Length; i++)
|
||||||
sortedExc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[exc[i]];
|
// sortedExc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[exc[i]];
|
||||||
sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc);
|
// sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType);
|
// Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType);
|
||||||
|
//
|
||||||
if (targetType != thisType)
|
// if (targetType != thisType)
|
||||||
{
|
// {
|
||||||
instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null);
|
// instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
var id = _count++;
|
// var id = _count++;
|
||||||
if (_count >= _capacity)
|
// if (_count >= _capacity)
|
||||||
_capacity <<= 1;
|
// _capacity <<= 1;
|
||||||
|
//
|
||||||
instance = new EcsMask(typeof(TWorldArchetype), id, inc, exc);
|
// instance = new EcsMask(typeof(TWorldArchetype), id, inc, exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly static EcsMask instance;
|
public readonly static EcsMask instance;
|
||||||
|
@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public interface IEcsPool<T> : IEcsPool where T : struct
|
public interface IEcsPool<T> : IEcsPool where T : struct
|
||||||
{
|
{
|
||||||
public ref readonly T Read(int entity);
|
public ref T Read(int entity);
|
||||||
public new ref T Write(int entity);
|
public new ref T Write(int entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public sealed class EcsNullPool : EcsPool, IEcsPool<NullComponent>
|
public sealed class EcsNullPool : EcsPool, IEcsPool<NullComponent>
|
||||||
{
|
{
|
||||||
public static EcsNullPool instance => new EcsNullPool(null);
|
public static EcsNullPool instance => new EcsNullPool(null);
|
||||||
private readonly IEcsWorld _source;
|
private IEcsWorld _source;
|
||||||
private EcsNullPool(IEcsWorld source) => _source = source;
|
private EcsNullPool(IEcsWorld source) => _source = source;
|
||||||
private NullComponent fakeComponent;
|
private NullComponent fakeComponent;
|
||||||
public Type ComponentType => typeof(NullComponent);
|
public Type ComponentType => typeof(NullComponent);
|
||||||
@ -40,7 +40,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public void Del(int index) { }
|
public void Del(int index) { }
|
||||||
public override bool Has(int index) => false;
|
public override bool Has(int index) => false;
|
||||||
void IEcsPool.Write(int entityID) { }
|
void IEcsPool.Write(int entityID) { }
|
||||||
public ref readonly NullComponent Read(int entity) => ref fakeComponent;
|
public ref NullComponent Read(int entity) => ref fakeComponent;
|
||||||
public ref NullComponent Write(int entity) => ref fakeComponent;
|
public ref NullComponent Write(int entity) => ref fakeComponent;
|
||||||
void IEcsPool.OnWorldResize(int newSize) { }
|
void IEcsPool.OnWorldResize(int newSize) { }
|
||||||
internal override void OnWorldResize(int newSize) { }
|
internal override void OnWorldResize(int newSize) { }
|
||||||
@ -100,8 +100,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private ProfilerMarker _delMark = new ProfilerMarker("EcsPoo.Del");
|
private ProfilerMarker _delMark = new ProfilerMarker("EcsPoo.Del");
|
||||||
public ref T Add(int entityID)
|
public ref T Add(int entityID)
|
||||||
{
|
{
|
||||||
using (_addMark.Auto())
|
// using (_addMark.Auto())
|
||||||
{
|
// {
|
||||||
ref int itemIndex = ref _mapping[entityID];
|
ref int itemIndex = ref _mapping[entityID];
|
||||||
if (itemIndex <= 0)
|
if (itemIndex <= 0)
|
||||||
{
|
{
|
||||||
@ -124,29 +124,29 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
_poolRunnres.write.OnComponentWrite<T>(entityID);
|
_poolRunnres.write.OnComponentWrite<T>(entityID);
|
||||||
return ref _items[itemIndex];
|
return ref _items[itemIndex];
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
public ref T Write(int entityID)
|
public ref T Write(int entityID)
|
||||||
{
|
{
|
||||||
using (_writeMark.Auto())
|
// using (_writeMark.Auto())
|
||||||
return ref _items[_mapping[entityID]];
|
return ref _items[_mapping[entityID]];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref readonly T Read(int entityID)
|
public ref T Read(int entityID)
|
||||||
{
|
{
|
||||||
using (_readMark.Auto())
|
// using (_readMark.Auto())
|
||||||
return ref _items[_mapping[entityID]];
|
return ref _items[_mapping[entityID]];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public sealed override bool Has(int entityID)
|
public sealed override bool Has(int entityID)
|
||||||
{
|
{
|
||||||
using (_hasMark.Auto())
|
// using (_hasMark.Auto())
|
||||||
return _mapping[entityID] > 0;
|
return _mapping[entityID] > 0;
|
||||||
}
|
}
|
||||||
public void Del(int entityID)
|
public void Del(int entityID)
|
||||||
{
|
{
|
||||||
using (_delMark.Auto())
|
// using (_delMark.Auto())
|
||||||
{
|
// {
|
||||||
entities.Remove(entityID);
|
entities.Remove(entityID);
|
||||||
|
|
||||||
if (_recycledItemsCount >= _recycledItems.Length)
|
if (_recycledItemsCount >= _recycledItems.Length)
|
||||||
@ -155,7 +155,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_mapping[entityID] = 0;
|
_mapping[entityID] = 0;
|
||||||
_itemsCount--;
|
_itemsCount--;
|
||||||
_poolRunnres.del.OnComponentDel<T>(entityID);
|
_poolRunnres.del.OnComponentDel<T>(entityID);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -18,35 +18,48 @@ namespace DCFApixels.DragonECS
|
|||||||
public abstract class EcsQuery<TWorldArchetype> : EcsQueryBase
|
public abstract class EcsQuery<TWorldArchetype> : EcsQueryBase
|
||||||
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||||
{
|
{
|
||||||
private int _id;
|
|
||||||
public int ID => _id;
|
|
||||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.GetEnumerator");
|
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.GetEnumerator");
|
||||||
|
|
||||||
public EcsGroup.Enumerator GetEnumerator()
|
public EcsGroup.Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
using (_getEnumerator.Auto())
|
using (_getEnumerator.Auto())
|
||||||
{
|
{
|
||||||
groupFilter.Clear();
|
// groupFilter.Clear();
|
||||||
var pools = World.GetAllPools();
|
var pools = World.GetAllPools();
|
||||||
|
//
|
||||||
if (mask.Inc.Length > 0)
|
// if (mask.Inc.Length > 0)
|
||||||
|
// {
|
||||||
|
// groupFilter.CopyFrom(pools[mask.Inc[0]].entities);
|
||||||
|
// for (int i = 1; i < mask.Inc.Length; i++)
|
||||||
|
// {
|
||||||
|
// groupFilter.AndWith(pools[mask.Inc[i]].entities);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// groupFilter.CopyFrom(World.Entities);
|
||||||
|
// }
|
||||||
|
// for (int i = 0; i < mask.Exc.Length; i++)
|
||||||
|
// {
|
||||||
|
// groupFilter.RemoveGroup(pools[mask.Exc[i]].entities);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// groupFilter.Sort();
|
||||||
|
// return groupFilter.GetEnumerator();
|
||||||
|
//
|
||||||
|
EcsReadonlyGroup sum = World.Entities;
|
||||||
|
for (int i = 0; i < mask.Inc.Length; i++)
|
||||||
{
|
{
|
||||||
groupFilter.CopyFrom(pools[mask.Inc[0]].entities);
|
sum = EcsGroup.And(sum.GetGroupInternal(), pools[mask.Inc[i]].entities);
|
||||||
for (int i = 1; i < mask.Inc.Length; i++)
|
// Debug.Log("inc " + sum.ToString());
|
||||||
{
|
|
||||||
groupFilter.AndWith(pools[mask.Inc[i]].entities);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
groupFilter.CopyFrom(World.Entities);
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < mask.Exc.Length; i++)
|
for (int i = 0; i < mask.Exc.Length; i++)
|
||||||
{
|
{
|
||||||
groupFilter.RemoveGroup(pools[mask.Exc[i]].entities);
|
sum = EcsGroup.Remove(sum.GetGroupInternal(), pools[mask.Exc[i]].entities);
|
||||||
|
// Debug.Log("exc " + sum.ToString());
|
||||||
}
|
}
|
||||||
groupFilter.Sort();
|
//sum.GetGroupInternal().Sort();
|
||||||
return groupFilter.GetEnumerator();
|
return sum.GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected virtual void Init(Builder b) { }
|
protected virtual void Init(Builder b) { }
|
||||||
|
@ -10,7 +10,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
public ref TComponent Add(ent entityID);
|
public ref TComponent Add(ent entityID);
|
||||||
public ref TComponent Write(ent entityID);
|
public ref TComponent Write(ent entityID);
|
||||||
public ref readonly TComponent Read(ent entityID);
|
public ref TComponent Read(ent entityID);
|
||||||
public bool Has(ent entityID);
|
public bool Has(ent entityID);
|
||||||
public void Del(ent entityID);
|
public void Del(ent entityID);
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
public ref TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -51,7 +51,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
public ref TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -75,7 +75,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
public ref TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -82,6 +82,8 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public IEcsRealationTable[] _relationTables;
|
public IEcsRealationTable[] _relationTables;
|
||||||
|
|
||||||
|
private readonly int _worldArchetypeID = ComponentIndexer.GetWorldId<TWorldArchetype>();
|
||||||
|
|
||||||
#region RelationTables
|
#region RelationTables
|
||||||
public IEcsRealationTable GetRelationTalbe<TWorldArhetype>(TWorldArhetype targetWorld)
|
public IEcsRealationTable GetRelationTalbe<TWorldArhetype>(TWorldArhetype targetWorld)
|
||||||
where TWorldArhetype : EcsWorld<TWorldArhetype>
|
where TWorldArhetype : EcsWorld<TWorldArhetype>
|
||||||
@ -110,7 +112,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region GetterMethods
|
#region GetterMethods
|
||||||
public ReadOnlySpan<EcsPool> GetAllPools() => new ReadOnlySpan<EcsPool>(_pools);
|
public ReadOnlySpan<EcsPool> GetAllPools() => new ReadOnlySpan<EcsPool>(_pools);
|
||||||
public int GetComponentID<T>() => ComponentType<T>.uniqueID;
|
public int GetComponentID<T>() => ComponentIndexer.GetComponentId<T>(_worldArchetypeID);////ComponentType<T>.uniqueID;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -159,18 +161,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#region GetPool
|
#region GetPool
|
||||||
public EcsPool<T> GetPool<T>() where T : struct
|
public EcsPool<T> GetPool<T>() where T : struct
|
||||||
{
|
{
|
||||||
int uniqueID = ComponentType<T>.uniqueID;
|
//int uniqueID = ComponentType<T>.uniqueID;
|
||||||
|
int uniqueID = ComponentIndexer.GetComponentId<T>(_worldArchetypeID);
|
||||||
|
|
||||||
if (uniqueID >= _pools.Length)
|
if (uniqueID >= _pools.Length)
|
||||||
{
|
{
|
||||||
int oldCapacity = _pools.Length;
|
int oldCapacity = _pools.Length;
|
||||||
Array.Resize(ref _pools, ComponentType.Capacity);
|
Array.Resize(ref _pools, _pools.Length << 1);
|
||||||
ArrayUtility.Fill(_pools, _nullPool, oldCapacity, oldCapacity - _pools.Length);
|
ArrayUtility.Fill(_pools, _nullPool, oldCapacity, oldCapacity - _pools.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pools[uniqueID] == _nullPool)
|
if (_pools[uniqueID] == _nullPool)
|
||||||
{
|
{
|
||||||
_pools[uniqueID] = new EcsPool<T>(this, ComponentType<T>.uniqueID, 512, _poolRunnres);
|
_pools[uniqueID] = new EcsPool<T>(this, uniqueID, 512, _poolRunnres);
|
||||||
}
|
}
|
||||||
return (EcsPool<T>)_pools[uniqueID];
|
return (EcsPool<T>)_pools[uniqueID];
|
||||||
}
|
}
|
||||||
@ -330,7 +333,7 @@ namespace DCFApixels.DragonECS
|
|||||||
QueryType.capacity <<= 1;
|
QueryType.capacity <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal static class ComponentType
|
/* internal static class ComponentType
|
||||||
{
|
{
|
||||||
internal static int increment = 1;
|
internal static int increment = 1;
|
||||||
internal static int Capacity
|
internal static int Capacity
|
||||||
@ -358,7 +361,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
ComponentType.types[uniqueID] = typeof(T);
|
ComponentType.types[uniqueID] = typeof(T);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GroupsPool
|
#region GroupsPool
|
||||||
@ -397,4 +400,56 @@ namespace DCFApixels.DragonECS
|
|||||||
del = pipeline.GetRunner<IEcsComponentDel>();
|
del = pipeline.GetRunner<IEcsComponentDel>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class ComponentIndexer
|
||||||
|
{
|
||||||
|
private static List<Resizer> resizer = new List<Resizer>();
|
||||||
|
private static int tokenCount = 0;
|
||||||
|
private static int[] componentCounts = new int[0];
|
||||||
|
private static class World<TWorldArchetype>
|
||||||
|
{
|
||||||
|
public static int id = GetToken();
|
||||||
|
}
|
||||||
|
private static int GetToken()
|
||||||
|
{
|
||||||
|
tokenCount++;
|
||||||
|
Array.Resize(ref componentCounts, tokenCount);
|
||||||
|
foreach (var item in resizer)
|
||||||
|
item.Resize(tokenCount);
|
||||||
|
return tokenCount - 1;
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static int GetWorldId<TWorldArchetype>() => World<TWorldArchetype>.id;
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static int GetComponentId<TComponent>(int worldID) => Component<TComponent>.Get(worldID);
|
||||||
|
private abstract class Resizer
|
||||||
|
{
|
||||||
|
public abstract void Resize(int size);
|
||||||
|
}
|
||||||
|
private sealed class Resizer<T> : Resizer
|
||||||
|
{
|
||||||
|
public override void Resize(int size) => Array.Resize(ref Component<T>.ids, size);
|
||||||
|
}
|
||||||
|
private static class Component<TComponent>
|
||||||
|
{
|
||||||
|
public static int[] ids;
|
||||||
|
static Component()
|
||||||
|
{
|
||||||
|
ids = new int[tokenCount];
|
||||||
|
for (int i = 0; i < ids.Length; i++)
|
||||||
|
ids[i] = -1;
|
||||||
|
resizer.Add(new Resizer<TComponent>());
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static int Get(int token)
|
||||||
|
{
|
||||||
|
ref int id = ref ids[token];
|
||||||
|
if (id < 0)
|
||||||
|
id = componentCounts[token]++;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
namespace DCFApixels.DragonECS
|
using System.Runtime.InteropServices;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
internal static class ArrayUtility
|
internal static class ArrayUtility
|
||||||
{
|
{
|
||||||
@ -18,4 +21,37 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static unsafe class UnmanagedArray
|
||||||
|
{
|
||||||
|
public static void* New<T>(int elementCount)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
return Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)) * elementCount).ToPointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void* NewAndInit<T>(int elementCount)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
int newSizeInBytes = Marshal.SizeOf(typeof(T)) * elementCount;
|
||||||
|
byte* newArrayPointer = (byte*)Marshal.AllocHGlobal(newSizeInBytes).ToPointer();
|
||||||
|
|
||||||
|
for (int i = 0; i < newSizeInBytes; i++)
|
||||||
|
*(newArrayPointer + i) = 0;
|
||||||
|
|
||||||
|
return (void*)newArrayPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Free(void* pointerToUnmanagedMemory)
|
||||||
|
{
|
||||||
|
Marshal.FreeHGlobal(new IntPtr(pointerToUnmanagedMemory));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void* Resize<T>(void* oldPointer, int newElementCount)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
return (Marshal.ReAllocHGlobal(new IntPtr(oldPointer),
|
||||||
|
new IntPtr(Marshal.SizeOf(typeof(T)) * newElementCount))).ToPointer();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user