< Summary

Information
Class: Lattice.ECS.Framework.FilterOptimized<T>
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Framework/FilterOptimized.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 137
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%620%
GetEnumerator()100%210%
.ctor(...)100%210%
get_Component()100%210%
MoveNext()0%4260%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Framework/FilterOptimized.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4using System;
 5using Lattice.Core;
 6using Lattice.ECS.Core;
 7
 8namespace Lattice.ECS.Framework
 9{
 10    /// <summary>
 11    /// 旧版带裁剪能力的单组件 Filter 兼容层。
 12    /// 新代码建议直接使用 <see cref="Frame.Query{T}()" /> 并在循环中叠加裁剪判断。
 13    /// </summary>
 14    [Obsolete("请改用 Frame.Query<T>() 并在循环中处理裁剪。FilterOptimized 仅保留为兼容层。", false)]
 15    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
 16    public unsafe class FilterOptimized<T1> where T1 : unmanaged, IComponent
 17    {
 18        private readonly Query<T1> _query;
 19        private readonly CullingSystem* _culling;
 20
 021        public FilterOptimized(Frame frame, CullingSystem* culling = null)
 22        {
 023            if (frame == null)
 24            {
 025                throw new ArgumentNullException(nameof(frame));
 26            }
 27
 028            _query = frame.Query<T1>();
 029            _culling = culling;
 030        }
 31
 032        public Enumerator GetEnumerator() => new Enumerator(_query.GetEnumerator(), _culling);
 33
 34        public ref struct Enumerator
 35        {
 36            private Query<T1>.Enumerator _enumerator;
 37            private readonly CullingSystem* _culling;
 38
 39            public Enumerator(Query<T1>.Enumerator enumerator, CullingSystem* culling)
 40            {
 041                _enumerator = enumerator;
 042                _culling = culling;
 043                CurrentEntity = EntityRef.None;
 044                CurrentPtr = null;
 045            }
 46
 47            public EntityRef CurrentEntity;
 48            public T1* CurrentPtr;
 049            public ref T1 Component => ref *CurrentPtr;
 50
 51            public bool MoveNext()
 52            {
 053                while (_enumerator.MoveNext())
 54                {
 055                    EntityRef entity = _enumerator.CurrentEntity;
 056                    if (_culling != null && _culling->IsCulled(entity.Index))
 57                    {
 58                        continue;
 59                    }
 60
 061                    CurrentEntity = entity;
 062                    CurrentPtr = _enumerator.CurrentPtr;
 063                    return true;
 64                }
 65
 066                return false;
 67            }
 68        }
 69    }
 70
 71    /// <summary>
 72    /// 旧版带裁剪能力的双组件 Filter 兼容层。
 73    /// 新代码建议直接使用 <see cref="Frame.Query{T1,T2}()" /> 并在循环中叠加裁剪判断。
 74    /// </summary>
 75    [Obsolete("请改用 Frame.Query<T1, T2>() 并在循环中处理裁剪。FilterOptimized 仅保留为兼容层。", false)]
 76    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
 77    public unsafe class FilterOptimized<T1, T2>
 78        where T1 : unmanaged, IComponent
 79        where T2 : unmanaged, IComponent
 80    {
 81        private readonly Query<T1, T2> _query;
 82        private readonly CullingSystem* _culling;
 83
 84        public FilterOptimized(Frame frame, CullingSystem* culling = null)
 85        {
 86            if (frame == null)
 87            {
 88                throw new ArgumentNullException(nameof(frame));
 89            }
 90
 91            _query = frame.Query<T1, T2>();
 92            _culling = culling;
 93        }
 94
 95        public Enumerator GetEnumerator() => new Enumerator(_query.GetEnumerator(), _culling);
 96
 97        public ref struct Enumerator
 98        {
 99            private Query<T1, T2>.Enumerator _enumerator;
 100            private readonly CullingSystem* _culling;
 101
 102            public Enumerator(Query<T1, T2>.Enumerator enumerator, CullingSystem* culling)
 103            {
 104                _enumerator = enumerator;
 105                _culling = culling;
 106                CurrentEntity = EntityRef.None;
 107                CurrentPtr1 = null;
 108                CurrentPtr2 = null;
 109            }
 110
 111            public EntityRef CurrentEntity;
 112            public T1* CurrentPtr1;
 113            public T2* CurrentPtr2;
 114            public ref T1 Component1 => ref *CurrentPtr1;
 115            public ref T2 Component2 => ref *CurrentPtr2;
 116
 117            public bool MoveNext()
 118            {
 119                while (_enumerator.MoveNext())
 120                {
 121                    EntityRef entity = _enumerator.Entity;
 122                    if (_culling != null && _culling->IsCulled(entity.Index))
 123                    {
 124                        continue;
 125                    }
 126
 127                    CurrentEntity = entity;
 128                    CurrentPtr1 = _enumerator.Component1Ptr;
 129                    CurrentPtr2 = _enumerator.Component2Ptr;
 130                    return true;
 131                }
 132
 133                return false;
 134            }
 135        }
 136    }
 137}