mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
fix changes
This commit is contained in:
parent
e7835a39d3
commit
13dfbe9e31
@ -7,18 +7,18 @@ namespace DCFApixels.DragonECS
|
|||||||
/// Используется для реализации отношений. traget - это сущьность к которой крепится эта сущьность. other - это сущьность с которой traget образует связь
|
/// Используется для реализации отношений. traget - это сущьность к которой крепится эта сущьность. other - это сущьность с которой traget образует связь
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 8, Size = 16)]
|
[StructLayout(LayoutKind.Explicit, Pack = 8, Size = 16)]
|
||||||
public readonly struct Attach
|
public readonly struct Edge
|
||||||
{
|
{
|
||||||
[FieldOffset(0), MarshalAs(UnmanagedType.U8)]
|
[FieldOffset(0), MarshalAs(UnmanagedType.U8)]
|
||||||
public readonly EcsEntity target;
|
public readonly EcsEntity origin;
|
||||||
[FieldOffset(1), MarshalAs(UnmanagedType.U8)]
|
[FieldOffset(1), MarshalAs(UnmanagedType.U8)]
|
||||||
public readonly EcsEntity other;
|
public readonly EcsEntity other;
|
||||||
|
|
||||||
/// <summary>alias for "target"</summary>
|
/// <summary>alias for "origin"</summary>
|
||||||
public EcsEntity left
|
public EcsEntity left
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => target;
|
get => origin;
|
||||||
}
|
}
|
||||||
/// <summary>alias for "other"</summary>
|
/// <summary>alias for "other"</summary>
|
||||||
public EcsEntity right
|
public EcsEntity right
|
||||||
|
@ -141,7 +141,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_source = world;
|
_source = world;
|
||||||
_source.RegisterGroup(this);
|
_source.RegisterGroup(this);
|
||||||
_dense = new int[denseCapacity];
|
_dense = new int[denseCapacity];
|
||||||
_sparse = new int[world.EntitesCapacity];
|
_sparse = new int[world.Capacity];
|
||||||
|
|
||||||
_delayedOps = new delayedOp[delayedOpsCapacity];
|
_delayedOps = new delayedOp[delayedOpsCapacity];
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public ent Current
|
public ent Current
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => (ent)_dense[_index];
|
get => new 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 дает среде понять что проверки на выход за границы не нужны
|
||||||
|
@ -389,11 +389,11 @@ namespace DCFApixels.DragonECS
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// var id = _count++;
|
// var uniqueID = _count++;
|
||||||
// if (_count >= _capacity)
|
// if (_count >= _capacity)
|
||||||
// _capacity <<= 1;
|
// _capacity <<= 1;
|
||||||
//
|
//
|
||||||
// instance = new EcsMask(typeof(TWorldArchetype), id, inc_, exc_);
|
// instance = new EcsMask(typeof(TWorldArchetype), uniqueID, inc_, exc_);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly static EcsMask instance;
|
public readonly static EcsMask instance;
|
||||||
|
@ -87,7 +87,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_source = source;
|
_source = source;
|
||||||
_componentID = id;
|
_componentID = id;
|
||||||
|
|
||||||
_mapping = new int[source.EntitesCapacity];
|
_mapping = new int[source.Capacity];
|
||||||
_recycledItems = new int[128];
|
_recycledItems = new int[128];
|
||||||
_recycledItemsCount = 0;
|
_recycledItemsCount = 0;
|
||||||
_items = new T[capacity];
|
_items = new T[capacity];
|
||||||
|
@ -14,7 +14,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region Builder
|
#region Builder
|
||||||
protected virtual void Init(Builder b) { }
|
protected virtual void Init(Builder b) { }
|
||||||
protected abstract void OnBuilt();
|
protected abstract void OnBuildAfter();
|
||||||
public abstract void Execute();
|
public abstract void Execute();
|
||||||
public sealed class Builder : EcsQueryBuilderBase
|
public sealed class Builder : EcsQueryBuilderBase
|
||||||
{
|
{
|
||||||
@ -46,7 +46,7 @@ namespace DCFApixels.DragonECS
|
|||||||
newQuery.groupFilter = EcsGroup.New(world);
|
newQuery.groupFilter = EcsGroup.New(world);
|
||||||
newQuery.source = world;
|
newQuery.source = world;
|
||||||
builder.End(out newQuery.mask);
|
builder.End(out newQuery.mask);
|
||||||
newQuery.OnBuilt();
|
newQuery.OnBuildAfter();
|
||||||
return (TQuery)(object)newQuery;
|
return (TQuery)(object)newQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public abstract class EcsJoinQuery : EcsQueryBase
|
public abstract class EcsJoinQuery : EcsQueryBase
|
||||||
{
|
{
|
||||||
private EcsPool<Attach> attachPool;
|
private EcsPool<Edge> attachPool;
|
||||||
|
|
||||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
||||||
protected sealed override void OnBuilt()
|
protected sealed override void OnBuildAfter()
|
||||||
{
|
{
|
||||||
attachPool = World.GetPool<Attach>();
|
attachPool = World.GetPool<Edge>();
|
||||||
}
|
}
|
||||||
public sealed override void Execute()
|
public sealed override void Execute()
|
||||||
{
|
{
|
||||||
@ -103,7 +103,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public abstract class EcsQuery : EcsQueryBase
|
public abstract class EcsQuery : EcsQueryBase
|
||||||
{
|
{
|
||||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
||||||
protected sealed override void OnBuilt() { }
|
protected sealed override void OnBuildAfter() { }
|
||||||
public sealed override void Execute()
|
public sealed override void Execute()
|
||||||
{
|
{
|
||||||
using (_getEnumerator.Auto())
|
using (_getEnumerator.Auto())
|
||||||
|
@ -91,9 +91,9 @@ namespace DCFApixels.DragonECS
|
|||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// internal inc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
// internal inc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.id);
|
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public bool Has(ent entityID) => pool.Has(entityID.id);
|
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//
|
//
|
||||||
// public static implicit operator inc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Include<TComponent>();
|
// public static implicit operator inc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Include<TComponent>();
|
||||||
@ -108,9 +108,9 @@ namespace DCFApixels.DragonECS
|
|||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// internal exc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
// internal exc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.id);
|
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public bool Has(ent entityID) => pool.Has(entityID.id);
|
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//
|
//
|
||||||
// public static implicit operator exc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Exclude<TComponent>();
|
// public static implicit operator exc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Exclude<TComponent>();
|
||||||
@ -125,9 +125,9 @@ namespace DCFApixels.DragonECS
|
|||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// internal opt_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
// internal opt_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.id);
|
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public bool Has(ent entityID) => pool.Has(entityID.id);
|
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//
|
//
|
||||||
// public static implicit operator opt_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Optional<TComponent>();
|
// public static implicit operator opt_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Optional<TComponent>();
|
||||||
@ -137,24 +137,24 @@ namespace DCFApixels.DragonECS
|
|||||||
//
|
//
|
||||||
// #region join
|
// #region join
|
||||||
// [StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
// [StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
||||||
// public readonly struct attach : IEcsQueryField<Attach>
|
// public readonly struct attach : IEcsQueryField<Edge>
|
||||||
// {
|
// {
|
||||||
// internal readonly EcsPool<Attach> pool;
|
// internal readonly EcsPool<Edge> pool;
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// internal attach(EcsPool<Attach> pool) => this.pool = pool;
|
// internal attach(EcsPool<Edge> pool) => this.pool = pool;
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref Attach Add(ent entityID) => ref pool.Add(entityID.id);
|
// public ref Edge Add(ent entityID) => ref pool.Add(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref Attach Write(ent entityID) => ref pool.Write(entityID.id);
|
// public ref Edge Write(ent entityID) => ref pool.Write(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public ref Attach Read(ent entityID) => ref pool.Read(entityID.id);
|
// public ref Edge Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public bool Has(ent entityID) => pool.Has(entityID.id);
|
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public void Del(ent entityID) => pool.Del(entityID.id);
|
// public void Del(ent entityID) => pool.Del(entityID.uniqueID);
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
// public static implicit operator attach(EcsQueryBuilderBase buider) => buider.Include<Attach>();
|
// public static implicit operator attach(EcsQueryBuilderBase buider) => buider.Include<Edge>();
|
||||||
// public static implicit operator attach(inc_<Attach> o) => new attach(o.pool);
|
// public static implicit operator attach(inc_<Edge> o) => new attach(o.pool);
|
||||||
// }
|
// }
|
||||||
// #endregion
|
// #endregion
|
||||||
}
|
}
|
||||||
|
172
src/EcsWorld.cs
172
src/EcsWorld.cs
@ -6,14 +6,11 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public interface IEcsWorld : IEcsReadonlyTable
|
public interface IEcsWorld : IEcsTable
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
//private float _timeScale;//TODO реализовать собсвенныйтайм склей для разных миров
|
public int UniqueID { get; }
|
||||||
public int ID { get; }
|
|
||||||
public EcsPipeline Pipeline { get; }
|
public EcsPipeline Pipeline { get; }
|
||||||
public int EntitesCount { get; }
|
|
||||||
public int EntitesCapacity { get; }
|
|
||||||
public EcsReadonlyGroup Entities => default;
|
public EcsReadonlyGroup Entities => default;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -21,7 +18,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsEntity NewEntity();
|
public EcsEntity NewEntity();
|
||||||
public void DelEntity(EcsEntity entity);
|
public void DelEntity(EcsEntity entity);
|
||||||
public bool EntityIsAlive(int entityID, short gen);
|
public bool EntityIsAlive(int entityID, short gen);
|
||||||
public EcsEntity GetEntity(int entityID);
|
public EcsEntity GetEcsEntity(int entityID);
|
||||||
public void Destroy();
|
public void Destroy();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -36,41 +33,35 @@ namespace DCFApixels.DragonECS
|
|||||||
public static IEcsWorld[] Worlds = new IEcsWorld[8];
|
public static IEcsWorld[] Worlds = new IEcsWorld[8];
|
||||||
private static IntDispenser _worldIdDispenser = new IntDispenser(0);
|
private static IntDispenser _worldIdDispenser = new IntDispenser(0);
|
||||||
|
|
||||||
public readonly short id;
|
public readonly short uniqueID;
|
||||||
|
|
||||||
protected EcsWorld(bool isIndexable)
|
protected EcsWorld()
|
||||||
{
|
{
|
||||||
if(isIndexable == true)
|
uniqueID = (short)_worldIdDispenser.GetFree();
|
||||||
{
|
if (uniqueID >= Worlds.Length)
|
||||||
id = (short)_worldIdDispenser.GetFree();
|
|
||||||
if (id >= Worlds.Length)
|
|
||||||
Array.Resize(ref Worlds, Worlds.Length << 1);
|
Array.Resize(ref Worlds, Worlds.Length << 1);
|
||||||
Worlds[id] = (IEcsWorld)this;
|
Worlds[uniqueID] = (IEcsWorld)this;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
id = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Realeze()
|
protected void Realeze()
|
||||||
{
|
{
|
||||||
Worlds[id] = null;
|
Worlds[uniqueID] = null;
|
||||||
_worldIdDispenser.Release(id);
|
_worldIdDispenser.Release(uniqueID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class EcsWorld<TWorldArchetype> : EcsWorld, IEcsWorld
|
public abstract class EcsWorld<TWorldArchetype> : EcsWorld, IEcsWorld
|
||||||
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||||
{
|
{
|
||||||
|
private readonly int _worldArchetypeID = ComponentIndexer.GetWorldId<TWorldArchetype>();
|
||||||
|
|
||||||
private IntDispenser _entityDispenser;
|
private IntDispenser _entityDispenser;
|
||||||
private int[] _denseEntities;
|
|
||||||
private int _entitiesCount;
|
private int _entitiesCount;
|
||||||
|
private int _entitesCapacity;
|
||||||
private short[] _gens; //старший бит указывает на то жива ли сущьность.
|
private short[] _gens; //старший бит указывает на то жива ли сущьность.
|
||||||
|
|
||||||
private EcsGroup _allEntites;
|
private EcsGroup _allEntites;
|
||||||
|
|
||||||
//private short[] _componentCounts; //TODO
|
//private short[] _componentCounts; //TODO
|
||||||
|
|
||||||
private EcsPool[] _pools;
|
private EcsPool[] _pools;
|
||||||
private EcsNullPool _nullPool;
|
private EcsNullPool _nullPool;
|
||||||
|
|
||||||
@ -79,36 +70,11 @@ namespace DCFApixels.DragonECS
|
|||||||
private EcsPipeline _pipeline;
|
private EcsPipeline _pipeline;
|
||||||
|
|
||||||
private List<WeakReference<EcsGroup>> _groups;
|
private List<WeakReference<EcsGroup>> _groups;
|
||||||
|
private Stack<EcsGroup> _groupsPool = new Stack<EcsGroup>(64);
|
||||||
|
|
||||||
public IEcsRealationTable[] _relationTables;
|
|
||||||
|
|
||||||
private readonly int _worldArchetypeID = ComponentIndexer.GetWorldId<TWorldArchetype>();
|
|
||||||
|
|
||||||
#region RelationTables
|
|
||||||
public IEcsRealationTable GetRelationTalbe<TWorldArhetype>(TWorldArhetype targetWorld)
|
|
||||||
where TWorldArhetype : EcsWorld<TWorldArhetype>
|
|
||||||
{
|
|
||||||
int targetID = targetWorld.ID;
|
|
||||||
if (targetID <= 0)
|
|
||||||
throw new ArgumentException("targetWorld.ID <= 0");
|
|
||||||
|
|
||||||
if(_relationTables.Length <= targetID)
|
|
||||||
Array.Resize(ref _relationTables, targetID + 8);
|
|
||||||
|
|
||||||
if (_relationTables[targetID] == null)
|
|
||||||
{
|
|
||||||
// _relationTables[targetID]= new EcsRelationTable
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region RunnersCache
|
|
||||||
private PoolRunnres _poolRunnres;
|
private PoolRunnres _poolRunnres;
|
||||||
private IEcsEntityCreate _entityCreate;
|
private IEcsEntityCreate _entityCreate;
|
||||||
private IEcsEntityDestroy _entityDestry;
|
private IEcsEntityDestroy _entityDestry;
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetterMethods
|
#region GetterMethods
|
||||||
public ReadOnlySpan<EcsPool> GetAllPools() => new ReadOnlySpan<EcsPool>(_pools);
|
public ReadOnlySpan<EcsPool> GetAllPools() => new ReadOnlySpan<EcsPool>(_pools);
|
||||||
@ -116,24 +82,17 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Properties
|
|
||||||
int IEcsReadonlyTable.Count => _entitiesCount;
|
|
||||||
int IEcsReadonlyTable.Capacity => _denseEntities.Length;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public Type ArchetypeType => typeof(TWorldArchetype);
|
public Type ArchetypeType => typeof(TWorldArchetype);
|
||||||
public int ID => id;
|
public int UniqueID => uniqueID;
|
||||||
|
public int Count => _entitiesCount;
|
||||||
|
public int Capacity => _entitesCapacity; //_denseEntities.Length;
|
||||||
public EcsPipeline Pipeline => _pipeline;
|
public EcsPipeline Pipeline => _pipeline;
|
||||||
|
|
||||||
public int EntitesCount => _entitiesCount;
|
|
||||||
public int EntitesCapacity => _denseEntities.Length;
|
|
||||||
public EcsReadonlyGroup Entities => _allEntites.Readonly;
|
public EcsReadonlyGroup Entities => _allEntites.Readonly;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public EcsWorld(EcsPipeline pipline = null) : this(pipline, true) { }
|
public EcsWorld(EcsPipeline pipline = null)
|
||||||
internal EcsWorld(EcsPipeline pipline, bool isIndexable) : base(isIndexable)
|
|
||||||
{
|
{
|
||||||
_pipeline = pipline ?? EcsPipeline.Empty;
|
_pipeline = pipline ?? EcsPipeline.Empty;
|
||||||
if (!_pipeline.IsInit) pipline.Init();
|
if (!_pipeline.IsInit) pipline.Init();
|
||||||
@ -143,11 +102,11 @@ namespace DCFApixels.DragonECS
|
|||||||
ArrayUtility.Fill(_pools, _nullPool);
|
ArrayUtility.Fill(_pools, _nullPool);
|
||||||
|
|
||||||
_gens = new short[512];
|
_gens = new short[512];
|
||||||
|
_entitesCapacity = _gens.Length;
|
||||||
|
|
||||||
_queries = new EcsQuery[QueryType.capacity];
|
_queries = new EcsQuery[QueryType.capacity];
|
||||||
_groups = new List<WeakReference<EcsGroup>>();
|
_groups = new List<WeakReference<EcsGroup>>();
|
||||||
|
|
||||||
_denseEntities = new int[512];
|
|
||||||
|
|
||||||
_poolRunnres = new PoolRunnres(_pipeline);
|
_poolRunnres = new PoolRunnres(_pipeline);
|
||||||
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
||||||
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
|
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
|
||||||
@ -162,7 +121,6 @@ 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 = ComponentIndexer.GetComponentId<T>(_worldArchetypeID);
|
int uniqueID = ComponentIndexer.GetComponentId<T>(_worldArchetypeID);
|
||||||
|
|
||||||
if (uniqueID >= _pools.Length)
|
if (uniqueID >= _pools.Length)
|
||||||
@ -178,7 +136,6 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
return (EcsPool<T>)_pools[uniqueID];
|
return (EcsPool<T>)_pools[uniqueID];
|
||||||
}
|
}
|
||||||
//public EcsPool<T> UncheckedGetPool<T>() where T : struct => (EcsPool<T>)_pools[ComponentType<T>.uniqueID];
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Query
|
#region Query
|
||||||
@ -225,13 +182,12 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsEntity NewEntity()
|
public EcsEntity NewEntity()
|
||||||
{
|
{
|
||||||
int entityID = _entityDispenser.GetFree();
|
int entityID = _entityDispenser.GetFree();
|
||||||
if (_entityDispenser.LastInt >= _denseEntities.Length)
|
_entitiesCount++;
|
||||||
Array.Resize(ref _denseEntities, _denseEntities.Length << 1);
|
|
||||||
_denseEntities[_entitiesCount++] = entityID;
|
|
||||||
|
|
||||||
if (_gens.Length <= entityID)
|
if (_gens.Length <= entityID)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _gens, _gens.Length << 1);
|
Array.Resize(ref _gens, _gens.Length << 1);
|
||||||
|
_entitesCapacity = _gens.Length;
|
||||||
for (int i = 0; i < _groups.Count; i++)
|
for (int i = 0; i < _groups.Count; i++)
|
||||||
{
|
{
|
||||||
if (_groups[i].TryGetTarget(out EcsGroup group))
|
if (_groups[i].TryGetTarget(out EcsGroup group))
|
||||||
@ -249,7 +205,7 @@ namespace DCFApixels.DragonECS
|
|||||||
item.OnWorldResize(_gens.Length);
|
item.OnWorldResize(_gens.Length);
|
||||||
}
|
}
|
||||||
_gens[entityID] |= short.MinValue;
|
_gens[entityID] |= short.MinValue;
|
||||||
EcsEntity entity = new EcsEntity(entityID, _gens[entityID]++, id);
|
EcsEntity entity = new EcsEntity(entityID, _gens[entityID]++, uniqueID);
|
||||||
_entityCreate.OnEntityCreate(entity);
|
_entityCreate.OnEntityCreate(entity);
|
||||||
_allEntites.Add(entityID);
|
_allEntites.Add(entityID);
|
||||||
return entity;
|
return entity;
|
||||||
@ -264,9 +220,9 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsEntity GetEntity(int entityID)
|
public EcsEntity GetEcsEntity(int entityID)
|
||||||
{
|
{
|
||||||
return new EcsEntity(entityID, _gens[entityID], id);
|
return new EcsEntity(entityID, _gens[entityID], uniqueID);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool EntityIsAlive(int entityID, short gen)
|
public bool EntityIsAlive(int entityID, short gen)
|
||||||
@ -279,7 +235,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public void Destroy()
|
public void Destroy()
|
||||||
{
|
{
|
||||||
_entityDispenser = null;
|
_entityDispenser = null;
|
||||||
_denseEntities = null;
|
//_denseEntities = null;
|
||||||
_gens = null;
|
_gens = null;
|
||||||
_pools = null;
|
_pools = null;
|
||||||
_nullPool = null;
|
_nullPool = null;
|
||||||
@ -293,11 +249,27 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Other
|
#region Groups
|
||||||
void IEcsReadonlyTable.RegisterGroup(EcsGroup group)
|
void IEcsTable.RegisterGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
_groups.Add(new WeakReference<EcsGroup>(group));
|
_groups.Add(new WeakReference<EcsGroup>(group));
|
||||||
}
|
}
|
||||||
|
EcsGroup IEcsWorld.GetGroupFromPool() => GetGroupFromPool();
|
||||||
|
internal EcsGroup GetGroupFromPool()
|
||||||
|
{
|
||||||
|
if (_groupsPool.Count <= 0)
|
||||||
|
return new EcsGroup(this);
|
||||||
|
return _groupsPool.Pop();
|
||||||
|
}
|
||||||
|
void IEcsWorld.ReleaseGroup(EcsGroup group)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
|
if (group.World != this)
|
||||||
|
throw new ArgumentException("groupFilter.World != this");
|
||||||
|
#endif
|
||||||
|
group.Clear();
|
||||||
|
_groupsPool.Push(group);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Utils
|
#region Utils
|
||||||
@ -316,58 +288,10 @@ namespace DCFApixels.DragonECS
|
|||||||
QueryType.capacity <<= 1;
|
QueryType.capacity <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* internal static class ComponentType
|
|
||||||
{
|
|
||||||
internal static int increment = 1;
|
|
||||||
internal static int Capacity
|
|
||||||
{
|
|
||||||
get => types.Length;
|
|
||||||
}
|
|
||||||
internal static Type[] types = new Type[64];
|
|
||||||
}
|
|
||||||
internal static class ComponentType<T>
|
|
||||||
{
|
|
||||||
internal static int uniqueID;
|
|
||||||
|
|
||||||
static ComponentType()
|
|
||||||
{
|
|
||||||
uniqueID = ComponentType.increment++;
|
|
||||||
#if (DEBUG && !DISABLE_DRAGONECS_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
|
||||||
if (ComponentType.increment + 1 > ushort.MaxValue)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"No more room for new component for this {typeof(TWorldArchetype).FullName} IWorldArchetype");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (uniqueID >= ComponentType.types.Length)
|
|
||||||
{
|
|
||||||
Array.Resize(ref ComponentType.types, ComponentType.types.Length << 1);
|
|
||||||
}
|
|
||||||
ComponentType.types[uniqueID] = typeof(T);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GroupsPool
|
|
||||||
private Stack<EcsGroup> _pool = new Stack<EcsGroup>(64);
|
|
||||||
EcsGroup IEcsWorld.GetGroupFromPool() => GetGroupFromPool();
|
|
||||||
internal EcsGroup GetGroupFromPool()
|
|
||||||
{
|
|
||||||
if (_pool.Count <= 0)
|
|
||||||
return new EcsGroup(this);
|
|
||||||
return _pool.Pop();
|
|
||||||
}
|
|
||||||
void IEcsWorld.ReleaseGroup(EcsGroup group)
|
|
||||||
{
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
|
||||||
if (group.World != this)
|
|
||||||
throw new ArgumentException("groupFilter.World != this");
|
|
||||||
#endif
|
|
||||||
group.Clear();
|
|
||||||
_pool.Push(group);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Utils
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 24)]
|
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 24)]
|
||||||
internal readonly struct PoolRunnres
|
internal readonly struct PoolRunnres
|
||||||
{
|
{
|
||||||
@ -382,9 +306,6 @@ namespace DCFApixels.DragonECS
|
|||||||
del = pipeline.GetRunner<IEcsComponentDel>();
|
del = pipeline.GetRunner<IEcsComponentDel>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static class ComponentIndexer
|
public static class ComponentIndexer
|
||||||
{
|
{
|
||||||
private static List<Resizer> resizer = new List<Resizer>();
|
private static List<Resizer> resizer = new List<Resizer>();
|
||||||
@ -434,4 +355,5 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,14 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
// uniqueID - 32 bits
|
||||||
|
// gen - 16 bits
|
||||||
|
// world - 16 bits
|
||||||
/// <summary>Strong identifier/Permanent entity identifier</summary>
|
/// <summary>Strong identifier/Permanent entity identifier</summary>
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)]
|
[StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)]
|
||||||
public readonly partial struct EcsEntity : IEquatable<long>, IEquatable<EcsEntity>
|
public readonly partial struct EcsEntity : IEquatable<long>, IEquatable<EcsEntity>
|
||||||
{
|
{
|
||||||
public static readonly EcsEntity NULL = default;
|
public static readonly EcsEntity NULL = default;
|
||||||
// uniqueID - 32 bits
|
|
||||||
// gen - 16 bits
|
|
||||||
// world - 16 bits
|
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
internal readonly long full; //Union
|
internal readonly long full; //Union
|
||||||
[FieldOffset(3)]
|
[FieldOffset(3)]
|
||||||
@ -21,11 +21,8 @@ namespace DCFApixels.DragonECS
|
|||||||
[FieldOffset(0)]
|
[FieldOffset(0)]
|
||||||
public readonly short world;
|
public readonly short world;
|
||||||
|
|
||||||
public ent Ent
|
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => new ent(id);
|
public ent ToEnt() => EcsWorld.Worlds[world].EntityIsAlive(id, gen) ? new ent(id) : default;
|
||||||
}
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -53,7 +50,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override int GetHashCode() => unchecked((int)full) ^ (int)(full >> 32);
|
public override int GetHashCode() => unchecked((int)full) ^ (int)(full >> 32);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override string ToString() => $"Entity(id:{id} gen:{gen} world:{world})";
|
public override string ToString() => $"Entity(uniqueID:{id} gen:{gen} world:{world})";
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override bool Equals(object obj) => obj is EcsEntity other && full == other.full;
|
public override bool Equals(object obj) => obj is EcsEntity other && full == other.full;
|
||||||
#endregion
|
#endregion
|
||||||
@ -66,7 +63,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static explicit operator long(in EcsEntity a) => a.full;
|
public static explicit operator long(in EcsEntity a) => a.full;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static explicit operator ent(in EcsEntity a) => a.Ent;
|
public static explicit operator ent(in EcsEntity a) => a.ToEnt();
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static explicit operator EcsEntity(in long a) => new EcsEntity(a);
|
public static explicit operator EcsEntity(in long a) => new EcsEntity(a);
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -13,7 +13,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal ent(int id) => this.id = id;
|
internal ent(int id) => this.id = id;
|
||||||
|
|
||||||
public static explicit operator ent(int id) => new ent(id);
|
//public static explicit operator ent(int uniqueID) => new ent(uniqueID);
|
||||||
public static explicit operator int(ent entityID) => entityID.id;
|
public static explicit operator int(ent entityID) => entityID.id;
|
||||||
|
|
||||||
public static bool operator ==(ent a, ent b) => a.id == b.id;
|
public static bool operator ==(ent a, ent b) => a.id == b.id;
|
||||||
@ -27,6 +27,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public struct Null { }
|
public struct Null { }
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsEntity ToStrong(IEcsWorld world) => world.GetEntity(id);
|
public EcsEntity ToStrong(IEcsWorld world) => world.GetEcsEntity(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public interface IEcsReadonlyTable
|
public interface IEcsTable
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
/// <summary>Table Archetype</summary>
|
/// <summary>Table Archetype</summary>
|
||||||
@ -30,7 +30,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public static class IEcsReadonlyTableExtensions
|
public static class IEcsReadonlyTableExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool IsMaskCompatible<TInc>(this IEcsReadonlyTable self, int entityID) where TInc : struct, IInc
|
public static bool IsMaskCompatible<TInc>(this IEcsTable self, int entityID) where TInc : struct, IInc
|
||||||
{
|
{
|
||||||
return self.IsMaskCompatible<TInc, Exc>(entityID);
|
return self.IsMaskCompatible<TInc, Exc>(entityID);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user