2023-05-27 15:59:46 +08:00
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-06-22 14:31:13 +08:00
|
|
|
|
public sealed class EcsWhereExecutor<TAspect> : EcsQueryExecutor where TAspect : EcsAspect
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-06-22 14:31:13 +08:00
|
|
|
|
private TAspect _aspect;
|
2023-05-27 15:59:46 +08:00
|
|
|
|
private EcsGroup _filteredGroup;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
|
|
|
|
|
private long _executeVersion;
|
|
|
|
|
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2023-05-27 15:59:46 +08:00
|
|
|
|
private EcsProfilerMarker _executeWhere = new EcsProfilerMarker("Where");
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#endif
|
2023-05-07 00:50:02 +08:00
|
|
|
|
|
|
|
|
|
#region Properties
|
2023-06-22 14:31:13 +08:00
|
|
|
|
public TAspect Aspect => _aspect;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
internal long ExecuteVersion => _executeVersion;
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-05-27 15:59:46 +08:00
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
|
|
|
|
{
|
2023-06-22 14:31:13 +08:00
|
|
|
|
_aspect = World.GetAspect<TAspect>();
|
2023-05-27 15:59:46 +08:00
|
|
|
|
_filteredGroup = EcsGroup.New(World);
|
|
|
|
|
}
|
|
|
|
|
protected sealed override void OnDestroy()
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-06-10 00:55:00 +08:00
|
|
|
|
_filteredGroup.Dispose();
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2023-06-22 14:31:13 +08:00
|
|
|
|
public EcsReadonlyGroup Execute() => ExecuteFor(_aspect.World.Entities);
|
2023-06-02 03:33:33 +08:00
|
|
|
|
public EcsReadonlyGroup ExecuteFor(EcsReadonlyGroup sourceGroup)
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2023-06-12 21:59:27 +08:00
|
|
|
|
_executeWhere.Begin();
|
|
|
|
|
if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения.
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#endif
|
2023-06-22 14:31:13 +08:00
|
|
|
|
_aspect.GetIteratorFor(sourceGroup).CopyTo(_filteredGroup);
|
2023-06-02 01:20:46 +08:00
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2023-06-12 21:59:27 +08:00
|
|
|
|
_executeWhere.End();
|
2023-05-07 00:50:02 +08:00
|
|
|
|
#endif
|
2023-06-12 21:59:27 +08:00
|
|
|
|
return _filteredGroup.Readonly;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
2023-06-22 14:39:12 +08:00
|
|
|
|
#endregion
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|