2023-05-27 15:59:46 +08:00
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
|
|
|
|
public sealed class EcsWhereExecutor<TSubject> : EcsQueryExecutor where TSubject : EcsSubject
|
|
|
|
|
{
|
2023-05-27 15:59:46 +08:00
|
|
|
|
private TSubject _subject;
|
|
|
|
|
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
|
|
|
|
|
public TSubject Subject => _subject;
|
|
|
|
|
internal long ExecuteVersion => _executeVersion;
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-05-27 15:59:46 +08:00
|
|
|
|
#region OnInitialize/OnDestroy
|
|
|
|
|
protected sealed override void OnInitialize()
|
|
|
|
|
{
|
|
|
|
|
_subject = World.GetSubject<TSubject>();
|
|
|
|
|
_filteredGroup = EcsGroup.New(World);
|
|
|
|
|
}
|
|
|
|
|
protected sealed override void OnDestroy()
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-05-27 15:59:46 +08:00
|
|
|
|
_filteredGroup.Release();
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
2023-06-02 03:33:33 +08:00
|
|
|
|
public EcsReadonlyGroup Execute() => ExecuteFor(_subject.World.Entities);
|
|
|
|
|
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-05-07 00:50:02 +08:00
|
|
|
|
using (_executeWhere.Auto())
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#endif
|
2023-05-07 00:50:02 +08:00
|
|
|
|
{
|
2023-06-02 01:20:46 +08:00
|
|
|
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
2023-05-30 18:30:10 +08:00
|
|
|
|
if (sourceGroup.IsNull) throw new System.ArgumentNullException();//TODO составить текст исключения.
|
2023-05-07 00:50:02 +08:00
|
|
|
|
#endif
|
2023-05-28 05:53:08 +08:00
|
|
|
|
_subject.GetIteratorFor(sourceGroup).CopyTo(_filteredGroup);
|
2023-06-02 03:33:33 +08:00
|
|
|
|
return _filteredGroup.Readonly;
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-02 03:33:33 +08:00
|
|
|
|
#endregion
|
2023-05-07 00:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|