使用BitMask64Data.segments扩展ComponentRegistry

This commit is contained in:
YHH
2025-09-30 23:58:52 +08:00
parent 632864b361
commit 5ea3b72b2b
5 changed files with 345 additions and 29 deletions

View File

@@ -188,10 +188,10 @@ export class Entity {
const components: Component[] = [];
const mask = this._componentMask;
// 遍历位掩码中设置的位
for (let bitIndex = 0; bitIndex < 64; bitIndex++) {
const bitMask = BitMask64Utils.create(bitIndex);
if (BitMask64Utils.hasAny(mask, bitMask)) {
const maxBitIndex = ComponentRegistry.getRegisteredCount();
for (let bitIndex = 0; bitIndex < maxBitIndex; bitIndex++) {
if (BitMask64Utils.getBitExtended(mask, bitIndex)) {
const componentType = ComponentRegistry.getTypeByBitIndex(bitIndex);
if (componentType) {
let component: Component | null = null;
@@ -504,7 +504,7 @@ export class Entity {
this._localComponents.delete(componentType);
// 更新位掩码
BitMask64Utils.clearBit(this._componentMask, bitIndex);
BitMask64Utils.clearBitExtended(this._componentMask, bitIndex);
// 使缓存失效
this._componentCache = null;