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
13dfbe9e31
commit
0813a68e04
@ -11,8 +11,8 @@
|
|||||||
{
|
{
|
||||||
public EcsDefaultWrold(EcsPipeline pipeline = null) : base(pipeline) { }
|
public EcsDefaultWrold(EcsPipeline pipeline = null) : base(pipeline) { }
|
||||||
}
|
}
|
||||||
public sealed class EcsEventWrold : EcsWorld<EcsDefaultWrold>
|
public sealed class EcsEventWrold : EcsEdgeWorld<EcsEventWrold>
|
||||||
{
|
{
|
||||||
public EcsEventWrold(EcsPipeline pipeline = null) : base(pipeline) { }
|
public EcsEventWrold(IEcsWorld firstTarget, IEcsWorld secondTarget, EcsPipeline pipeline = null) : base(firstTarget, secondTarget, pipeline) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
src/EcsEdgeWorld.cs
Normal file
23
src/EcsEdgeWorld.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public class EcsEdgeWorld<TWorldArchetype> : EcsWorld<TWorldArchetype> where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||||
|
{
|
||||||
|
private IEcsWorld _firstTarget;
|
||||||
|
private IEcsWorld _secondTarget;
|
||||||
|
public EcsEdgeWorld(IEcsWorld firstTarget, IEcsWorld secondTarget, EcsPipeline pipeline) : base(pipeline)
|
||||||
|
{
|
||||||
|
_firstTarget = firstTarget;
|
||||||
|
_secondTarget = secondTarget;
|
||||||
|
}
|
||||||
|
public EcsEdgeWorld(IEcsWorld firstTarget, EcsPipeline pipeline) : base(pipeline)
|
||||||
|
{
|
||||||
|
_firstTarget = firstTarget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -135,6 +135,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public ref T Write(int entityID)
|
public ref T Write(int entityID)
|
||||||
{
|
{
|
||||||
// using (_writeMark.Auto())
|
// using (_writeMark.Auto())
|
||||||
|
_poolRunnres.write.OnComponentWrite<T>(entityID);
|
||||||
return ref _items[_mapping[entityID]];
|
return ref _items[_mapping[entityID]];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private EcsPool<Edge> attachPool;
|
private EcsPool<Edge> attachPool;
|
||||||
|
|
||||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where");
|
||||||
protected sealed override void OnBuildAfter()
|
protected sealed override void OnBuildAfter()
|
||||||
{
|
{
|
||||||
attachPool = World.GetPool<Edge>();
|
attachPool = World.GetPool<Edge>();
|
||||||
@ -102,7 +102,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.Where");
|
||||||
protected sealed override void OnBuildAfter() { }
|
protected sealed override void OnBuildAfter() { }
|
||||||
public sealed override void Execute()
|
public sealed override void Execute()
|
||||||
{
|
{
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
using DCFApixels.DragonECS;
|
|
||||||
using DCFApixels.DragonECS.Internal;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public interface IEcsRealationTable
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal class EcsRelationWorld<TRelationTableArhetype> : EcsWorld<EcsRelationWorld<TRelationTableArhetype>>
|
|
||||||
where TRelationTableArhetype : EcsRelationTableArchetypeBase { }
|
|
||||||
public sealed class EcsRelationTable<TTableArhetype> : IEcsRealationTable
|
|
||||||
where TTableArhetype : EcsRelationTableArchetypeBase
|
|
||||||
{
|
|
||||||
public readonly IEcsWorld leftWorld;
|
|
||||||
public readonly IEcsWorld rightWorld;
|
|
||||||
|
|
||||||
private int[] _relations; //dense
|
|
||||||
private int[] _leftMapping;
|
|
||||||
private int[] _rgihtMapping;
|
|
||||||
|
|
||||||
private EcsRelationWorld<TTableArhetype> _relationWorld;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using UnityEditor.Search;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Properties
|
#region Properties
|
||||||
public int UniqueID { get; }
|
public int UniqueID { get; }
|
||||||
public EcsPipeline Pipeline { get; }
|
public EcsPipeline Pipeline { get; }
|
||||||
public EcsReadonlyGroup Entities => default;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Entities
|
#region Entities
|
||||||
@ -19,12 +18,6 @@ namespace DCFApixels.DragonECS
|
|||||||
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 GetEcsEntity(int entityID);
|
public EcsEntity GetEcsEntity(int entityID);
|
||||||
public void Destroy();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Group
|
|
||||||
internal EcsGroup GetGroupFromPool();
|
|
||||||
internal void ReleaseGroup(EcsGroup group);
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,9 +25,7 @@ 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 uniqueID;
|
public readonly short uniqueID;
|
||||||
|
|
||||||
protected EcsWorld()
|
protected EcsWorld()
|
||||||
{
|
{
|
||||||
uniqueID = (short)_worldIdDispenser.GetFree();
|
uniqueID = (short)_worldIdDispenser.GetFree();
|
||||||
@ -42,7 +33,6 @@ namespace DCFApixels.DragonECS
|
|||||||
Array.Resize(ref Worlds, Worlds.Length << 1);
|
Array.Resize(ref Worlds, Worlds.Length << 1);
|
||||||
Worlds[uniqueID] = (IEcsWorld)this;
|
Worlds[uniqueID] = (IEcsWorld)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Realeze()
|
protected void Realeze()
|
||||||
{
|
{
|
||||||
Worlds[uniqueID] = null;
|
Worlds[uniqueID] = null;
|
||||||
@ -92,7 +82,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public EcsWorld(EcsPipeline pipline = null)
|
public EcsWorld(EcsPipeline pipline)
|
||||||
{
|
{
|
||||||
_pipeline = pipline ?? EcsPipeline.Empty;
|
_pipeline = pipline ?? EcsPipeline.Empty;
|
||||||
if (!_pipeline.IsInit) pipline.Init();
|
if (!_pipeline.IsInit) pipline.Init();
|
||||||
@ -104,8 +94,10 @@ namespace DCFApixels.DragonECS
|
|||||||
_gens = new short[512];
|
_gens = new short[512];
|
||||||
_entitesCapacity = _gens.Length;
|
_entitesCapacity = _gens.Length;
|
||||||
|
|
||||||
_queries = new EcsQuery[QueryType.capacity];
|
|
||||||
_groups = new List<WeakReference<EcsGroup>>();
|
_groups = new List<WeakReference<EcsGroup>>();
|
||||||
|
_allEntites = GetGroupFromPool();
|
||||||
|
|
||||||
|
_queries = new EcsQuery[QueryType.capacity];
|
||||||
|
|
||||||
_poolRunnres = new PoolRunnres(_pipeline);
|
_poolRunnres = new PoolRunnres(_pipeline);
|
||||||
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
||||||
@ -113,8 +105,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
|
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
|
||||||
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
|
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
|
||||||
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
|
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
|
||||||
|
|
||||||
_allEntites = GetGroupFromPool();
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -139,16 +129,28 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Query
|
#region Query
|
||||||
public TQuery Query<TQuery>(out TQuery query) where TQuery : EcsQueryBase
|
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQueryBase
|
||||||
|
{
|
||||||
|
//int uniqueID = QueryType<TQuery>.uniqueID;
|
||||||
|
//if (_queries.Length < QueryType.capacity)
|
||||||
|
// Array.Resize(ref _queries, QueryType.capacity);
|
||||||
|
//if (_queries[uniqueID] == null)
|
||||||
|
// _queries[uniqueID] = EcsQueryBase.Builder.Build<TQuery>(this);
|
||||||
|
//query = (TQuery)_queries[uniqueID];
|
||||||
|
//query.Where();
|
||||||
|
//return query;
|
||||||
|
query = Select<TQuery>();
|
||||||
|
query.Execute();
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
public TQuery Select<TQuery>() where TQuery : EcsQueryBase
|
||||||
{
|
{
|
||||||
int uniqueID = QueryType<TQuery>.uniqueID;
|
int uniqueID = QueryType<TQuery>.uniqueID;
|
||||||
if (_queries.Length < QueryType.capacity)
|
if (_queries.Length < QueryType.capacity)
|
||||||
Array.Resize(ref _queries, QueryType.capacity);
|
Array.Resize(ref _queries, QueryType.capacity);
|
||||||
if (_queries[uniqueID] == null)
|
if (_queries[uniqueID] == null)
|
||||||
_queries[uniqueID] = EcsQueryBase.Builder.Build<TQuery>(this);
|
_queries[uniqueID] = EcsQueryBase.Builder.Build<TQuery>(this);
|
||||||
query = (TQuery)_queries[uniqueID];
|
return (TQuery)_queries[uniqueID];
|
||||||
query.Execute();
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -254,14 +256,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
_groups.Add(new WeakReference<EcsGroup>(group));
|
_groups.Add(new WeakReference<EcsGroup>(group));
|
||||||
}
|
}
|
||||||
EcsGroup IEcsWorld.GetGroupFromPool() => GetGroupFromPool();
|
EcsGroup IEcsTable.GetGroupFromPool() => GetGroupFromPool();
|
||||||
internal EcsGroup GetGroupFromPool()
|
internal EcsGroup GetGroupFromPool()
|
||||||
{
|
{
|
||||||
if (_groupsPool.Count <= 0)
|
if (_groupsPool.Count <= 0)
|
||||||
return new EcsGroup(this);
|
return new EcsGroup(this);
|
||||||
return _groupsPool.Pop();
|
return _groupsPool.Pop();
|
||||||
}
|
}
|
||||||
void IEcsWorld.ReleaseGroup(EcsGroup group)
|
void IEcsTable.ReleaseGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (group.World != this)
|
if (group.World != this)
|
||||||
|
@ -10,26 +10,31 @@ namespace DCFApixels.DragonECS
|
|||||||
public Type ArchetypeType { get; }
|
public Type ArchetypeType { get; }
|
||||||
public int Count { get; }
|
public int Count { get; }
|
||||||
public int Capacity { get; }
|
public int Capacity { get; }
|
||||||
|
public EcsReadonlyGroup Entities => default;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
public int GetComponentID<T>();
|
||||||
public EcsPool<T> GetPool<T>() where T : struct;
|
public EcsPool<T> GetPool<T>() where T : struct;
|
||||||
public ReadOnlySpan<EcsPool> GetAllPools();
|
public ReadOnlySpan<EcsPool> GetAllPools();
|
||||||
public TQuery Query<TQuery>(out TQuery query) where TQuery : EcsQueryBase;
|
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQueryBase;
|
||||||
|
public TQuery Select<TQuery>() where TQuery : EcsQueryBase;
|
||||||
|
|
||||||
public int GetComponentID<T>();
|
|
||||||
public bool IsMaskCompatible<TInc, TExc>(int entityID) where TInc : struct, IInc where TExc : struct, IExc;
|
public bool IsMaskCompatible<TInc, TExc>(int entityID) where TInc : struct, IInc where TExc : struct, IExc;
|
||||||
public bool IsMaskCompatible(EcsComponentMask mask, int entityID);
|
public bool IsMaskCompatible(EcsComponentMask mask, int entityID);
|
||||||
|
|
||||||
|
public void Destroy();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
internal void RegisterGroup(EcsGroup group);
|
internal void RegisterGroup(EcsGroup group);
|
||||||
|
internal EcsGroup GetGroupFromPool();
|
||||||
|
internal void ReleaseGroup(EcsGroup group);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IEcsReadonlyTableExtensions
|
public static class IEcsReadonlyTableExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool IsMaskCompatible<TInc>(this IEcsTable 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