mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 18:14:35 +08:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
![]() |
using System;
|
|||
|
using System.Runtime.CompilerServices;
|
|||
|
|
|||
|
namespace DCFApixels.DragonECS.Editors
|
|||
|
{
|
|||
|
internal class BitMask
|
|||
|
{
|
|||
|
private const int OFFSET = 5;
|
|||
|
private const int MOD_MASK = 31;
|
|||
|
private const int DATA_BITS = 32;
|
|||
|
private int[] _data;
|
|||
|
|
|||
|
private int _size;
|
|||
|
|
|||
|
public BitMask(int size)
|
|||
|
{
|
|||
|
_data = Array.Empty<int>();
|
|||
|
Resize(size);
|
|||
|
}
|
|||
|
|
|||
|
public bool this[int index]
|
|||
|
{
|
|||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|||
|
get => (_data[index >> OFFSET] & (1 << (index & MOD_MASK))) != 0;
|
|||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|||
|
set
|
|||
|
{
|
|||
|
if(value)
|
|||
|
_data[index >> OFFSET] |= (1 << (index & MOD_MASK));
|
|||
|
else
|
|||
|
_data[index >> OFFSET] &= ~(1 << (index & MOD_MASK));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Resize(int newSize)
|
|||
|
{
|
|||
|
if (newSize <= _size)
|
|||
|
return;
|
|||
|
|
|||
|
_size = newSize / DATA_BITS + 1;
|
|||
|
Array.Resize(ref _data, _size);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|