entity_component/bitset.rs
1// 2^32 gives 4 billion concurrent entities for 512MB of ram per component
2// 2^24 gives 16 million concurrent entities for 2MB of ram per component
3// 2^20 gives 1 million concurrent entities for 128KB of ram per component
4// 2^16 gives 65536 concurrent entities for 8KB of ram per component
5// 2^12 gives 4096 concurrent entities for 512B of ram per component
6// SIMD processes 256 bits/entities (32 bytes) at once when comparing bitsets.
7#[cfg(feature = "keysize16")]
8const BITSET_EXP: u32 = 16;
9#[cfg(feature = "keysize20")]
10const BITSET_EXP: u32 = 20;
11#[cfg(feature = "keysize24")]
12const BITSET_EXP: u32 = 24;
13#[cfg(feature = "keysize32")]
14const BITSET_EXP: u32 = 32;
15pub(crate) const BITSET_SIZE: usize = 2usize.saturating_pow(BITSET_EXP);
16pub(crate) const BITSET_SLICE_COUNT: usize = BITSET_SIZE / (32 * 8 / 8);
17
18/// The type of bitsets used to track entities in component storages.
19/// Mostly used to create caches.
20pub type BitSetVec = Vec<[u32; 8]>;
21
22/// Creates a bitset big enough to contain the index of each entity.
23/// Mostly used to create caches.
24pub fn create_bitset() -> BitSetVec {
25 vec![[0u32; 8]; BITSET_SLICE_COUNT]
26}