fix changes

This commit is contained in:
Mikhail 2023-04-20 10:59:55 +08:00
parent 13dfbe9e31
commit 0813a68e04
7 changed files with 61 additions and 55 deletions

View File

@ -11,8 +11,8 @@
{
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
View 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;
}
}
}

View File

@ -129,12 +129,13 @@ namespace DCFApixels.DragonECS
}
_poolRunnres.write.OnComponentWrite<T>(entityID);
return ref _items[itemIndex];
// }
// }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Write(int entityID)
{
// using (_writeMark.Auto())
_poolRunnres.write.OnComponentWrite<T>(entityID);
return ref _items[_mapping[entityID]];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS
{
private EcsPool<Edge> attachPool;
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where");
protected sealed override void OnBuildAfter()
{
attachPool = World.GetPool<Edge>();
@ -102,7 +102,7 @@ namespace DCFApixels.DragonECS
public abstract class EcsQuery : EcsQueryBase
{
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where");
protected sealed override void OnBuildAfter() { }
public sealed override void Execute()
{

View File

@ -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;
}
}

View File

@ -1,8 +1,8 @@
using DCFApixels.DragonECS.Internal;
using System;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEditor.Search;
namespace DCFApixels.DragonECS
{
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
#region Properties
public int UniqueID { get; }
public EcsPipeline Pipeline { get; }
public EcsReadonlyGroup Entities => default;
#endregion
#region Entities
@ -19,12 +18,6 @@ namespace DCFApixels.DragonECS
public void DelEntity(EcsEntity entity);
public bool EntityIsAlive(int entityID, short gen);
public EcsEntity GetEcsEntity(int entityID);
public void Destroy();
#endregion
#region Group
internal EcsGroup GetGroupFromPool();
internal void ReleaseGroup(EcsGroup group);
#endregion
}
@ -32,9 +25,7 @@ namespace DCFApixels.DragonECS
{
public static IEcsWorld[] Worlds = new IEcsWorld[8];
private static IntDispenser _worldIdDispenser = new IntDispenser(0);
public readonly short uniqueID;
protected EcsWorld()
{
uniqueID = (short)_worldIdDispenser.GetFree();
@ -42,7 +33,6 @@ namespace DCFApixels.DragonECS
Array.Resize(ref Worlds, Worlds.Length << 1);
Worlds[uniqueID] = (IEcsWorld)this;
}
protected void Realeze()
{
Worlds[uniqueID] = null;
@ -92,7 +82,7 @@ namespace DCFApixels.DragonECS
#endregion
#region Constructors
public EcsWorld(EcsPipeline pipline = null)
public EcsWorld(EcsPipeline pipline)
{
_pipeline = pipline ?? EcsPipeline.Empty;
if (!_pipeline.IsInit) pipline.Init();
@ -104,8 +94,10 @@ namespace DCFApixels.DragonECS
_gens = new short[512];
_entitesCapacity = _gens.Length;
_queries = new EcsQuery[QueryType.capacity];
_groups = new List<WeakReference<EcsGroup>>();
_allEntites = GetGroupFromPool();
_queries = new EcsQuery[QueryType.capacity];
_poolRunnres = new PoolRunnres(_pipeline);
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
@ -113,8 +105,6 @@ namespace DCFApixels.DragonECS
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
_pipeline.GetRunner<IEcsInject<IEcsWorld>>().Inject(this);
_pipeline.GetRunner<IEcsWorldCreate>().OnWorldCreate(this);
_allEntites = GetGroupFromPool();
}
#endregion
@ -139,16 +129,28 @@ namespace DCFApixels.DragonECS
#endregion
#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;
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.Execute();
return query;
return (TQuery)_queries[uniqueID];
}
#endregion
@ -254,14 +256,14 @@ namespace DCFApixels.DragonECS
{
_groups.Add(new WeakReference<EcsGroup>(group));
}
EcsGroup IEcsWorld.GetGroupFromPool() => GetGroupFromPool();
EcsGroup IEcsTable.GetGroupFromPool() => GetGroupFromPool();
internal EcsGroup GetGroupFromPool()
{
if (_groupsPool.Count <= 0)
return new EcsGroup(this);
return _groupsPool.Pop();
}
void IEcsWorld.ReleaseGroup(EcsGroup group)
void IEcsTable.ReleaseGroup(EcsGroup group)
{
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
if (group.World != this)

View File

@ -10,26 +10,31 @@ namespace DCFApixels.DragonECS
public Type ArchetypeType { get; }
public int Count { get; }
public int Capacity { get; }
public EcsReadonlyGroup Entities => default;
#endregion
#region Methods
public int GetComponentID<T>();
public EcsPool<T> GetPool<T>() where T : struct;
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(EcsComponentMask mask, int entityID);
public void Destroy();
#endregion
#region Internal Methods
internal void RegisterGroup(EcsGroup group);
internal EcsGroup GetGroupFromPool();
internal void ReleaseGroup(EcsGroup group);
#endregion
}
public static class IEcsReadonlyTableExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsMaskCompatible<TInc>(this IEcsTable self, int entityID) where TInc : struct, IInc
{
return self.IsMaskCompatible<TInc, Exc>(entityID);