< Summary

Information
Class: Lattice.ECS.Core.ComponentFilter
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/ComponentFilter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 133
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Empty()100%210%
With()100%210%
Without()100%210%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/ComponentFilter.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4using System.Runtime.CompilerServices;
 5
 6namespace Lattice.ECS.Core
 7{
 8    /// <summary>
 9    /// 组件过滤器 - 描述查询条件
 10    ///
 11    /// FrameSync 风格:
 12    /// - 必须包含的组件(Required)
 13    /// - 必须排除的组件(Excluded)
 14    /// </summary>
 15    public struct ComponentFilter
 16    {
 17        /// <summary>必须包含的组件位图</summary>
 18        public ComponentMask Required;
 19
 20        /// <summary>必须排除的组件位图</summary>
 21        public ComponentMask Excluded;
 22
 23        /// <summary>创建空过滤器</summary>
 024        public static ComponentFilter Empty => new ComponentFilter
 025        {
 026            Required = ComponentMask.Empty,
 027            Excluded = ComponentMask.Empty
 028        };
 29
 30        /// <summary>添加必须包含的组件</summary>
 31        public ComponentFilter With<T>() where T : unmanaged, IComponent
 32        {
 033            Required.Add(ComponentTypeId<T>.Id);
 034            return this;
 35        }
 36
 37        /// <summary>添加必须排除的组件</summary>
 38        public ComponentFilter Without<T>() where T : unmanaged, IComponent
 39        {
 040            Excluded.Add(ComponentTypeId<T>.Id);
 041            return this;
 42        }
 43    }
 44
 45    /// <summary>
 46    /// 组件位图 - 512位组件集合(8 x ulong)
 47    /// </summary>
 48    public unsafe struct ComponentMask
 49    {
 50        private fixed ulong _bits[8];
 51
 52        /// <summary>最大组件类型数</summary>
 53        public const int MaxComponents = 512;
 54
 55        /// <summary>位图块数</summary>
 56        public const int BlockCount = 8;
 57
 58        /// <summary>空位图</summary>
 59        public static ComponentMask Empty => new ComponentMask();
 60
 61        /// <summary>是否为空</summary>
 62        public bool IsEmpty
 63        {
 64            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65            get
 66            {
 67                for (int i = 0; i < BlockCount; i++)
 68                    if (_bits[i] != 0) return false;
 69                return true;
 70            }
 71        }
 72
 73        /// <summary>获取指定块的位</summary>
 74        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 75        public ulong GetBlock(int index)
 76        {
 77            return _bits[index];
 78        }
 79
 80        /// <summary>添加组件类型</summary>
 81        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 82        public void Add(int typeId)
 83        {
 84            int block = typeId >> 6;
 85            int bit = typeId & 0x3F;
 86            _bits[block] |= (1UL << bit);
 87        }
 88
 89        /// <summary>移除组件类型</summary>
 90        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 91        public void Remove(int typeId)
 92        {
 93            int block = typeId >> 6;
 94            int bit = typeId & 0x3F;
 95            _bits[block] &= ~(1UL << bit);
 96        }
 97
 98        /// <summary>检查是否包含组件类型</summary>
 99        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 100        public bool Contains(int typeId)
 101        {
 102            int block = typeId >> 6;
 103            int bit = typeId & 0x3F;
 104            return (_bits[block] & (1UL << bit)) != 0;
 105        }
 106
 107        /// <summary>检查当前集合是否包含另一个集合的所有组件</summary>
 108        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 109        public bool IsSupersetOf(in ComponentMask other)
 110        {
 111            for (int i = 0; i < BlockCount; i++)
 112                if ((_bits[i] & other._bits[i]) != other._bits[i])
 113                    return false;
 114            return true;
 115        }
 116
 117        /// <summary>并集</summary>
 118        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 119        public void UnionWith(in ComponentMask other)
 120        {
 121            for (int i = 0; i < BlockCount; i++)
 122                _bits[i] |= other._bits[i];
 123        }
 124
 125        /// <summary>交集</summary>
 126        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 127        public void IntersectWith(in ComponentMask other)
 128        {
 129            for (int i = 0; i < BlockCount; i++)
 130                _bits[i] &= other._bits[i];
 131        }
 132    }
 133}

Methods/Properties

get_Empty()
With()
Without()