MCPcopy Create free account
hub / github.com/esengine/esengine / getBit

Method getBit

packages/core/src/ECS/Utils/BigIntCompatibility.ts:205–217  ·  view source on GitHub ↗

* 获取掩码中指定位,如果位超出当前掩码的区段长度,则直接返回0 * @param mask 掩码 * @param bitIndex 位索引,不小于零

(mask: BitMask64Data, bitIndex: number)

Source from the content-addressed store, hash-verified

203 * @param bitIndex 位索引,不小于零
204 */
205 public static getBit(mask: BitMask64Data, bitIndex: number): boolean {
206 if (bitIndex < 0) {
207 return false;
208 }
209 const targetSeg = BitMask64Utils.getSegmentByBitIndex(mask, bitIndex, false);
210 if(!targetSeg) return false;
211 const mod = bitIndex & 63; // bitIndex % 64 优化方案
212 if(mod < 32){
213 return (targetSeg[SegmentPart.LOW] & (1 << mod)) !== 0;
214 } else {
215 return (targetSeg[SegmentPart.HIGH] & (1 << (mod - 32))) !== 0;
216 }
217 }
218 /**
219 * 清除掩码中指定位为0,如果位超出当前掩码的区段长度,则什么也不做
220 * @param mask 要修改的掩码(原地修改)

Callers 4

getMethod · 0.80

Calls 1

getSegmentByBitIndexMethod · 0.80

Tested by

no test coverage detected