aiecsjs 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -2
- package/README.md +20 -11
- package/README_ZHTW.md +17 -9
- package/STABILITY.md +11 -9
- package/STABILITY_ZHTW.md +3 -3
- package/api.json +52 -24
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +1 -1
- package/dist/commands.d.ts +1 -1
- package/dist/commands.js +1 -1
- package/dist/commands.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/observers.cjs +1 -1
- package/dist/observers.cjs.map +1 -1
- package/dist/observers.d.cts +23 -6
- package/dist/observers.d.ts +23 -6
- package/dist/observers.js +1 -1
- package/dist/observers.js.map +1 -1
- package/dist/relations.cjs.map +1 -1
- package/dist/relations.d.cts +1 -1
- package/dist/relations.d.ts +1 -1
- package/dist/relations.js.map +1 -1
- package/dist/serialize.cjs +1 -1
- package/dist/serialize.cjs.map +1 -1
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +1 -1
- package/dist/serialize.js.map +1 -1
- package/dist/{types-B3YUJZEg.d.cts → types-BGEeHad-.d.cts} +1 -1
- package/dist/{types-B3YUJZEg.d.ts → types-BGEeHad-.d.ts} +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +23 -1
- package/dist/worker.d.ts +23 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/llms-full.txt +1148 -373
- package/package.json +8 -2
package/dist/commands.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/bitmask.ts","../src/internal/world.ts","../src/internal/entity.ts","../src/internal/component.ts","../src/commands.ts"],"names":["setBit","mask","bit","w","clearBit","testBit","cloneMask","src","out","i","maskHash","m","parts","forEachSetBit","base","words","fn","wi","word","ctz32","v","worldRegistry","getWorldState","world","state","ensureCapacity","needed","newCap","growEntityArrays","genCtor","newGen","newArch","wordCount","newMask","storage","info","growSoAColumns","soa","fields","f","old","newLen","next","findOrCreateArchetype","key","existing","id","arch","collectBits","ensureArchetypeCapacity","bits","lsb","getOrRegisterComponentBit","readEntityMask","eid","writeEntityMask","tryGetComponentBit","createEntity","row","destroyEntity","isAliveInternal","clearAllEntityStorages","archId","lastRow","moved","idx","componentInfoById","getComponentInfo","component","addComponent","initial","prevMask","writeInitial","migrateEntity","removeComponent","clearSoAEntity","obj","col","val","arr","factory","inst","srcArchId","srcArch","destArchId","destArch","newRow","createCommandBuffer","buf","makeApi","flush","cb","stateOf","lookupWorld","placeholders","op","resolve","num","real","withCommandBuffer","result","cbStateMap","api","ph","s","worldId","lookupState"],"mappings":"AAMO,SAASA,CAAAA,CAAOC,CAAAA,CAAmBC,CAAAA,CAAmB,CAC3D,IAAMC,CAAAA,CAAID,CAAAA,GAAQ,CAAA,CAClBD,CAAAA,CAAKE,CAAC,CAAA,CAAA,CAAKF,CAAAA,CAAKE,CAAC,CAAA,EAAK,CAAA,EAAM,CAAA,GAAMD,CAAAA,CAAM,EAAA,EAC1C,CAEO,SAASE,CAAAA,CAASH,CAAAA,CAAmBC,CAAAA,CAAmB,CAC7D,IAAMC,CAAAA,CAAID,CAAAA,GAAQ,CAAA,CAClBD,EAAKE,CAAC,CAAA,CAAA,CAAKF,CAAAA,CAAKE,CAAC,CAAA,EAAK,CAAA,EAAK,EAAE,CAAA,GAAMD,CAAAA,CAAM,EAAA,CAAA,EAC3C,CAEO,SAASG,CAAAA,CAAQJ,CAAAA,CAAmBC,CAAAA,CAAsB,CAC/D,IAAMC,CAAAA,CAAID,CAAAA,GAAQ,CAAA,CAClB,OAAA,CAAA,CAASD,CAAAA,CAAKE,C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 bitmask helpers.\n\nexport function createMask(wordCount: number): Uint32Array {\n return new Uint32Array(wordCount)\n}\n\nexport function setBit(mask: Uint32Array, bit: number): void {\n const w = bit >>> 5\n mask[w] = (mask[w] ?? 0) | (1 << (bit & 31))\n}\n\nexport function clearBit(mask: Uint32Array, bit: number): void {\n const w = bit >>> 5\n mask[w] = (mask[w] ?? 0) & ~(1 << (bit & 31))\n}\n\nexport function testBit(mask: Uint32Array, bit: number): boolean {\n const w = bit >>> 5\n return ((mask[w] ?? 0) & (1 << (bit & 31))) !== 0\n}\n\nexport function copyMask(dst: Uint32Array, src: Uint32Array): void {\n const n = src.length\n for (let i = 0; i < n; i++) dst[i] = src[i] ?? 0\n}\n\nexport function cloneMask(src: Uint32Array): Uint32Array {\n const out = new Uint32Array(src.length)\n for (let i = 0; i < src.length; i++) out[i] = src[i] ?? 0\n return out\n}\n\nexport function maskEquals(a: Uint32Array, b: Uint32Array): boolean {\n const n = a.length\n if (b.length !== n) return false\n for (let i = 0; i < n; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return false\n return true\n}\n\nexport function maskHash(m: Uint32Array): string {\n // Stable string key for Map lookups. Hex-joined.\n const parts: string[] = []\n for (let i = 0; i < m.length; i++) {\n parts.push((m[i] ?? 0).toString(16))\n }\n return parts.join(',')\n}\n\nexport function isMaskZero(m: Uint32Array): boolean {\n for (let i = 0; i < m.length; i++) if ((m[i] ?? 0) !== 0) return false\n return true\n}\n\nexport function unionMask(a: Uint32Array, b: Uint32Array): Uint32Array {\n const out = new Uint32Array(a.length)\n for (let i = 0; i < a.length; i++) out[i] = (a[i] ?? 0) | (b[i] ?? 0)\n return out\n}\n\n/**\n * Test whether an archetype's mask matches a query.\n * - withMask: all of these bits must be present\n * - anyMask: if anyHasBits, at least one of these bits must be present\n * - noneMask: none of these bits may be present\n */\nexport function matches(\n mask: Uint32Array,\n withMask: Uint32Array,\n anyMask: Uint32Array,\n noneMask: Uint32Array,\n anyHasBits: boolean,\n words: number,\n): boolean {\n let anyHit = !anyHasBits\n for (let w = 0; w < words; w++) {\n const m = mask[w] ?? 0\n const wm = withMask[w] ?? 0\n const am = anyMask[w] ?? 0\n const nm = noneMask[w] ?? 0\n if ((m & wm) !== wm) return false\n if ((m & nm) !== 0) return false\n if (!anyHit && (m & am) !== 0) anyHit = true\n }\n return anyHit\n}\n\nexport function listBits(mask: Uint32Array): number[] {\n const out: number[] = []\n for (let w = 0; w < mask.length; w++) {\n let word = mask[w] ?? 0\n while (word !== 0) {\n const bit = (w << 5) + ctz32(word)\n out.push(bit)\n word &= word - 1\n }\n }\n return out\n}\n\n// Iterate set bits in a slice of a larger Uint32Array starting at `base`.\n// Shared by destroy paths and storage cleanup so the bit-extraction maths\n// lives in exactly one place.\nexport function forEachSetBit(\n mask: Uint32Array,\n base: number,\n words: number,\n fn: (bit: number) => void,\n): void {\n for (let wi = 0; wi < words; wi++) {\n let word = mask[base + wi] ?? 0\n while (word !== 0) {\n const bit = (wi << 5) + ctz32(word)\n fn(bit)\n word &= word - 1\n }\n }\n}\n\n// Match a query against an entity's mask stored as a slice inside a larger\n// Uint32Array. Reading directly from the parent array avoids the temporary\n// Uint32Array allocation on every observer dispatch.\nexport function matchesEntityMask(\n entityMask: Uint32Array,\n base: number,\n words: number,\n withMask: Uint32Array,\n anyMask: Uint32Array,\n noneMask: Uint32Array,\n anyHasBits: boolean,\n): boolean {\n let anyHit = !anyHasBits\n for (let i = 0; i < words; i++) {\n const m = entityMask[base + i] ?? 0\n const wm = withMask[i] ?? 0\n const am = anyMask[i] ?? 0\n const nm = noneMask[i] ?? 0\n if ((m & wm) !== wm) return false\n if ((m & nm) !== 0) return false\n if (!anyHit && (m & am) !== 0) anyHit = true\n }\n return anyHit\n}\n\nfunction ctz32(v: number): number {\n // Count trailing zeros in a 32-bit integer (assumes v !== 0)\n return 31 - Math.clz32(v & -v)\n}\n","import { VERSION } from '../version.js'\nimport {\n type World,\n type WorldOptions,\n type ResolvedWorldOptions,\n type WorldState,\n type ArchetypeState,\n type ComponentInfo,\n type WorldComponentStorage,\n type FieldInfo,\n} from './types.js'\nimport { cloneMask, copyMask, createMask, maskHash } from './bitmask.js'\n\nexport const WORLD_BRAND = Symbol.for('aiecsjs.world')\n\nconst DEFAULT_OPTIONS: Required<Omit<WorldOptions, 'buffer' | 'bufferByteOffset'>> = {\n initialCapacity: 1024,\n maxEntities: 1_000_000,\n indexBits: 24,\n generationBits: 8,\n}\n\nconst DEFAULT_MAX_COMPONENTS = 256\n\nlet nextWorldId = 1\nconst worldRegistry = new Map<number, WorldState>()\n\nexport function getWorldState(world: World): WorldState {\n const state = worldRegistry.get(world.id)\n if (!state) throw new Error(`aiecsjs: world ${world.id} is destroyed or unknown`)\n if (state.destroyed) throw new Error(`aiecsjs: world ${world.id} is destroyed`)\n return state\n}\n\nexport function registerWorld(state: WorldState): void {\n worldRegistry.set(state.id, state)\n}\n\nexport function unregisterWorld(id: number): void {\n worldRegistry.delete(id)\n}\n\nexport function isWorldRegistered(id: number): boolean {\n return worldRegistry.has(id)\n}\n\nfunction resolveOptions(opts: WorldOptions | undefined): ResolvedWorldOptions {\n const o = opts ?? {}\n const indexBits = o.indexBits ?? DEFAULT_OPTIONS.indexBits\n const generationBits = o.generationBits ?? DEFAULT_OPTIONS.generationBits\n const maxComponents = DEFAULT_MAX_COMPONENTS\n if (indexBits < 1 || indexBits > 24) {\n throw new Error('aiecsjs: indexBits must be in [1, 24]')\n }\n if (generationBits < 0 || generationBits > 16) {\n throw new Error('aiecsjs: generationBits must be in [0, 16]')\n }\n const maxByIndex = 1 << indexBits\n const initialCapacity = Math.max(1, Math.min(o.initialCapacity ?? DEFAULT_OPTIONS.initialCapacity, maxByIndex))\n const maxEntities = Math.max(initialCapacity, Math.min(o.maxEntities ?? DEFAULT_OPTIONS.maxEntities, maxByIndex))\n return {\n initialCapacity,\n maxEntities,\n indexBits,\n generationBits,\n maxComponents,\n maskWordCount: Math.ceil(maxComponents / 32),\n buffer: o.buffer ?? null,\n bufferByteOffset: o.bufferByteOffset ?? 0,\n }\n}\n\nexport function createEmptyArchetype(maskWordCount: number, maxComponents: number): ArchetypeState {\n return {\n id: 0,\n mask: createMask(maskWordCount),\n size: 0,\n capacity: 16,\n entities: new Uint32Array(16),\n entityRow: new Map<number, number>(),\n componentBits: [],\n edgeAdd: new Int32Array(maxComponents).fill(-1),\n edgeRemove: new Int32Array(maxComponents).fill(-1),\n }\n}\n\nexport function createWorld(options?: WorldOptions): World {\n const resolved = resolveOptions(options)\n const id = nextWorldId++\n\n const generationCtor = resolved.generationBits > 8 ? Uint16Array : Uint8Array\n const generations = new generationCtor(resolved.initialCapacity)\n\n const state: WorldState = {\n id,\n capacity: resolved.initialCapacity,\n version: VERSION,\n options: resolved,\n size: 0,\n nextFreshIndex: 1, // 0 reserved\n freeList: [],\n generations,\n destroyed: false,\n componentBitFor: new Map<number, number>(),\n componentInfoByBit: new Array(resolved.maxComponents).fill(null),\n componentStorageByBit: new Array(resolved.maxComponents).fill(null),\n nextComponentBit: 0,\n entityArchetype: new Uint32Array(resolved.initialCapacity),\n entityMask: new Uint32Array(resolved.initialCapacity * resolved.maskWordCount),\n archetypes: [],\n archetypeByMaskHash: new Map<string, number>(),\n queryVersion: 0,\n queries: [],\n queryMasks: new Map(),\n queryArchetypeCache: [],\n queryArchetypeStamp: [],\n bitToQueries: new Map<number, Set<number>>(),\n reactiveBuffers: new Map(),\n observers: [],\n relationStorage: new Map(),\n sab: resolved.buffer,\n readOnly: false,\n }\n\n // Seed archetype 0 (the empty mask)\n const empty = createEmptyArchetype(resolved.maskWordCount, resolved.maxComponents)\n empty.id = 0\n state.archetypes.push(empty)\n state.archetypeByMaskHash.set(maskHash(empty.mask), 0)\n\n registerWorld(state)\n return makePublicWorld(state)\n}\n\nexport function makePublicWorld(state: WorldState): World {\n return {\n id: state.id,\n get capacity() { return state.capacity },\n version: state.version,\n } as World\n}\n\nexport function destroyWorld(world: World): void {\n const state = worldRegistry.get(world.id)\n if (!state || state.destroyed) return\n state.destroyed = true\n // Clear large buffers to help GC\n state.archetypes = []\n state.archetypeByMaskHash.clear()\n state.componentInfoByBit = []\n state.componentStorageByBit = []\n state.queries = []\n state.queryMasks.clear()\n state.queryArchetypeCache = []\n state.observers = []\n state.relationStorage.clear()\n state.reactiveBuffers.clear()\n unregisterWorld(world.id)\n}\n\nexport function resetWorld(world: World): void {\n const state = getWorldState(world)\n // Keep capacity and registered components; clear entities and per-entity state.\n state.size = 0\n state.nextFreshIndex = 1\n state.freeList = []\n state.generations.fill(0)\n state.entityArchetype.fill(0)\n state.entityMask.fill(0)\n // Wipe archetype memberships but keep archetype graph for stability.\n for (const arch of state.archetypes) {\n arch.size = 0\n arch.entityRow.clear()\n }\n // Clear SoA columns and AoS instances; storage allocation is preserved.\n for (const storage of state.componentStorageByBit) {\n if (!storage) continue\n if (storage.kind === 'soa' && storage.soa) {\n for (const k of Object.keys(storage.soa)) {\n storage.soa[k]?.fill(0)\n }\n } else if (storage.kind === 'aos' && storage.aos) {\n storage.aos.fill(undefined as unknown as never)\n }\n }\n state.queryVersion++\n for (const buf of state.reactiveBuffers.values()) {\n buf.entered.length = 0\n buf.exited.length = 0\n }\n}\n\nexport function getWorldSize(world: World): number {\n return getWorldState(world).size\n}\n\nexport function getWorldCapacity(world: World): number {\n return getWorldState(world).capacity\n}\n\n// --- Capacity growth ---\n\nexport function ensureCapacity(state: WorldState, needed: number): void {\n if (needed <= state.capacity) return\n if (needed > state.options.maxEntities) {\n throw new Error(`aiecsjs: requested capacity ${needed} exceeds maxEntities ${state.options.maxEntities}`)\n }\n let newCap = state.capacity\n while (newCap < needed) newCap = Math.min(newCap * 2, state.options.maxEntities)\n growEntityArrays(state, newCap)\n}\n\nfunction growEntityArrays(state: WorldState, newCap: number): void {\n // generations\n const genCtor: any = state.generations.constructor\n const newGen = new genCtor(newCap) as Uint8Array | Uint16Array\n ;(newGen as Uint8Array).set(state.generations as Uint8Array)\n state.generations = newGen\n\n // entityArchetype\n const newArch = new Uint32Array(newCap)\n newArch.set(state.entityArchetype)\n state.entityArchetype = newArch\n\n // entityMask\n const wordCount = state.options.maskWordCount\n const newMask = new Uint32Array(newCap * wordCount)\n newMask.set(state.entityMask)\n state.entityMask = newMask\n\n // Component storages (SoA columns + AoS arrays)\n for (const storage of state.componentStorageByBit) {\n if (!storage) continue\n if (storage.kind === 'soa' && storage.soa) {\n const info = state.componentInfoByBit[storage.bit]\n if (info) growSoAColumns(storage.soa, info.fields, newCap)\n } else if (storage.kind === 'aos' && storage.aos) {\n storage.aos.length = newCap\n }\n }\n\n state.capacity = newCap\n}\n\nfunction growSoAColumns(soa: Record<string, any>, fields: FieldInfo[], newCap: number): void {\n for (const f of fields) {\n const old = soa[f.name]\n if (!old) continue\n const newLen = newCap * f.vectorLen\n if (old.length >= newLen) continue\n const next = new f.ctor(newLen)\n next.set(old)\n soa[f.name] = next\n }\n}\n\n// --- Archetype management ---\n\nexport function findOrCreateArchetype(state: WorldState, mask: Uint32Array): { archId: number; created: boolean } {\n const key = maskHash(mask)\n const existing = state.archetypeByMaskHash.get(key)\n if (existing !== undefined) return { archId: existing, created: false }\n\n const id = state.archetypes.length\n const arch: ArchetypeState = {\n id,\n mask: cloneMask(mask),\n size: 0,\n capacity: 16,\n entities: new Uint32Array(16),\n entityRow: new Map<number, number>(),\n componentBits: collectBits(mask),\n edgeAdd: new Int32Array(state.options.maxComponents).fill(-1),\n edgeRemove: new Int32Array(state.options.maxComponents).fill(-1),\n }\n state.archetypes.push(arch)\n state.archetypeByMaskHash.set(key, id)\n state.queryVersion++\n return { archId: id, created: true }\n}\n\nexport function ensureArchetypeCapacity(arch: ArchetypeState, needed: number): void {\n if (needed <= arch.capacity) return\n let newCap = arch.capacity\n while (newCap < needed) newCap *= 2\n const next = new Uint32Array(newCap)\n next.set(arch.entities)\n arch.entities = next\n arch.capacity = newCap\n}\n\nfunction collectBits(mask: Uint32Array): number[] {\n const bits: number[] = []\n for (let w = 0; w < mask.length; w++) {\n let word = mask[w] ?? 0\n while (word !== 0) {\n const lsb = word & -word\n const bit = (w << 5) + (31 - Math.clz32(lsb))\n bits.push(bit)\n word &= word - 1\n }\n }\n return bits\n}\n\n// --- Component registration in a world ---\n\nexport function getOrRegisterComponentBit(state: WorldState, info: ComponentInfo): number {\n const existing = state.componentBitFor.get(info.id)\n if (existing !== undefined) return existing\n\n if (state.nextComponentBit >= state.options.maxComponents) {\n throw new Error(`aiecsjs: world reached maxComponents=${state.options.maxComponents}`)\n }\n const bit = state.nextComponentBit++\n state.componentBitFor.set(info.id, bit)\n state.componentInfoByBit[bit] = info\n\n // Create storage\n let storage: WorldComponentStorage\n if (info.kind === 'soa') {\n const soa: Record<string, any> = {}\n for (const f of info.fields) {\n soa[f.name] = new f.ctor(state.capacity * f.vectorLen)\n }\n storage = { kind: 'soa', componentId: info.id, bit, soa }\n } else if (info.kind === 'aos') {\n storage = { kind: 'aos', componentId: info.id, bit, aos: new Array(state.capacity) }\n } else {\n storage = { kind: 'tag', componentId: info.id, bit }\n }\n state.componentStorageByBit[bit] = storage\n return bit\n}\n\n// Read a bitmask out of state.entityMask[] into a fresh Uint32Array.\nexport function readEntityMask(state: WorldState, eid: number): Uint32Array {\n const w = state.options.maskWordCount\n const out = new Uint32Array(w)\n const base = eid * w\n for (let i = 0; i < w; i++) out[i] = state.entityMask[base + i] ?? 0\n return out\n}\n\nexport function writeEntityMask(state: WorldState, eid: number, mask: Uint32Array): void {\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = mask[i] ?? 0\n}\n\n// Get the bit of a component within a world without registering.\nexport function tryGetComponentBit(state: WorldState, info: ComponentInfo): number | undefined {\n return state.componentBitFor.get(info.id)\n}\n\nexport function isWorld(x: unknown): x is World {\n if (!x || typeof x !== 'object') return false\n const obj = x as { id?: unknown; version?: unknown }\n if (typeof obj.id !== 'number') return false\n if (typeof obj.version !== 'string') return false\n return worldRegistry.has(obj.id)\n}\n","import type { EntityId, World, WorldState } from './types.js'\nimport {\n ensureArchetypeCapacity,\n ensureCapacity,\n getWorldState,\n} from './world.js'\nimport { clearAllEntityStorages } from './component.js'\n\nexport function createEntity(world: World): EntityId {\n const state = getWorldState(world)\n if (state.readOnly) {\n throw new Error('aiecsjs: cannot createEntity on a read-only world (worker-attached)')\n }\n\n let eid: number\n if (state.freeList.length > 0) {\n eid = state.freeList.pop()!\n } else {\n if (state.nextFreshIndex >= state.options.maxEntities) {\n throw new Error(`aiecsjs: reached maxEntities ${state.options.maxEntities}`)\n }\n if (state.nextFreshIndex >= state.capacity) {\n ensureCapacity(state, state.nextFreshIndex + 1)\n }\n eid = state.nextFreshIndex++\n }\n\n // Move into the empty archetype (0)\n const arch = state.archetypes[0]\n if (!arch) throw new Error('aiecsjs: missing empty archetype')\n ensureArchetypeCapacity(arch, arch.size + 1)\n const row = arch.size\n arch.entities[row] = eid\n arch.entityRow.set(eid, row)\n arch.size++\n\n state.entityArchetype[eid] = 0\n // Reset entityMask row for this eid\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = 0\n\n state.size++\n return eid as EntityId\n}\n\nexport function destroyEntity(world: World, eid: EntityId): void {\n const state = getWorldState(world)\n if (state.readOnly) {\n throw new Error('aiecsjs: cannot destroyEntity on a read-only world')\n }\n if (!isAliveInternal(state, eid)) return\n\n // Fire onRemove for every component the entity has, plus reactive exit\n // (Late-bound to avoid circular imports — done via observers module.)\n const { dispatchDestroyObservers } = lazyObservers()\n dispatchDestroyObservers(state, eid)\n\n // Clean up relations referring to this entity\n cleanupRelationsOnDestroy(state, eid)\n\n // Zero the SoA columns / undefine the AoS slots the entity owned, before\n // the mask is cleared. Without this, destroyed entities leave stale data\n // visible to snapshots and serialisation.\n clearAllEntityStorages(state, eid)\n\n // Swap-pop from its archetype\n const archId = state.entityArchetype[eid] ?? 0\n const arch = state.archetypes[archId]\n if (arch) {\n const row = arch.entityRow.get(eid)\n if (row !== undefined) {\n const lastRow = arch.size - 1\n if (row !== lastRow) {\n const moved = arch.entities[lastRow] ?? 0\n arch.entities[row] = moved\n arch.entityRow.set(moved, row)\n }\n arch.entities[lastRow] = 0\n arch.entityRow.delete(eid)\n arch.size--\n }\n }\n\n // Wipe state\n state.entityArchetype[eid] = 0\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = 0\n // bump generation (Uint8Array wraps to 8 bits naturally; Uint16Array to 16)\n const idx = eid as number\n state.generations[idx] = ((state.generations[idx] ?? 0) + 1) & 0xFFFF\n\n state.freeList.push(eid)\n state.size--\n}\n\nexport function entityExists(world: World, eid: EntityId): boolean {\n const state = getWorldState(world)\n return isAliveInternal(state, eid)\n}\n\nexport function isAliveInternal(state: WorldState, eid: number): boolean {\n if (eid <= 0) return false\n if (eid >= state.capacity) return false\n // An entity is alive iff it is in some archetype (its row map points somewhere).\n const archId = state.entityArchetype[eid] ?? 0\n const arch = state.archetypes[archId]\n if (!arch) return false\n return arch.entityRow.has(eid)\n}\n\nexport function getEntityIndex(eid: EntityId): number {\n return eid as number\n}\n\nexport function getEntityGeneration(_eid: EntityId): number {\n // Unversioned in 0.1: generation not encoded in EntityId.\n return 0\n}\n\nexport function packEntity(index: number, _generation: number): EntityId {\n // Identity in 0.1.\n return index as EntityId\n}\n\nexport function isEntity(world: World, x: unknown): x is EntityId {\n if (typeof x !== 'number') return false\n return entityExists(world, x as EntityId)\n}\n\n// --- Lazy loaders to break import cycles ---\n\ninterface ObserversAPI {\n dispatchDestroyObservers(state: WorldState, eid: EntityId): void\n}\nlet _observersAPI: ObserversAPI | null = null\nexport function registerObserversAPI(api: ObserversAPI): void {\n _observersAPI = api\n}\nfunction lazyObservers(): ObserversAPI {\n if (!_observersAPI) {\n return { dispatchDestroyObservers: () => {} }\n }\n return _observersAPI\n}\n\nlet _relationsCleanup: ((state: WorldState, eid: EntityId) => void) | null = null\nexport function registerRelationsCleanup(fn: (state: WorldState, eid: EntityId) => void): void {\n _relationsCleanup = fn\n}\nfunction cleanupRelationsOnDestroy(state: WorldState, eid: EntityId): void {\n if (_relationsCleanup) _relationsCleanup(state, eid)\n}\n","import type {\n AoSComponent,\n ComponentInfo,\n ComponentInit,\n ComponentLike,\n EntityId,\n FieldInfo,\n SoAComponent,\n SoASchema,\n TagComponent,\n TypedArrayConstructor,\n World,\n WorldState,\n WorldComponentStorage,\n SoAColumns,\n} from './types.js'\nimport { setBit, clearBit, testBit, cloneMask, forEachSetBit } from './bitmask.js'\nimport {\n ensureArchetypeCapacity,\n findOrCreateArchetype,\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n writeEntityMask,\n} from './world.js'\nimport { isAliveInternal } from './entity.js'\n\n// --- Component factories ---\n\nlet nextComponentId = 1\n\nconst TYPE_CTOR: Record<string, TypedArrayConstructor> = {\n i8: Int8Array,\n u8: Uint8Array,\n i16: Int16Array,\n u16: Uint16Array,\n i32: Int32Array,\n u32: Uint32Array,\n f32: Float32Array,\n f64: Float64Array,\n eid: Uint32Array,\n bool: Uint8Array,\n}\n\nconst componentInfoById = new Map<number, ComponentInfo>()\n\nexport function defineComponent<S extends SoASchema>(schema: S): SoAComponent<S> {\n const fields: FieldInfo[] = []\n for (const [name, decl] of Object.entries(schema)) {\n let type: keyof typeof TYPE_CTOR\n let vectorLen = 1\n if (typeof decl === 'string') {\n type = decl\n } else if (Array.isArray(decl)) {\n const [t, len] = decl\n type = t\n vectorLen = len\n } else {\n throw new TypeError(`aiecsjs: invalid field declaration for \"${name}\"`)\n }\n const ctor = TYPE_CTOR[type]\n if (!ctor) throw new TypeError(`aiecsjs: unknown field type \"${type}\" for field \"${name}\"`)\n fields.push({\n name,\n type: type as any,\n vectorLen,\n ctor,\n bytesPerElement: (ctor as any).BYTES_PER_ELEMENT,\n })\n }\n const id = nextComponentId++\n const info: ComponentInfo = { id, kind: 'soa', schema, fields, factory: null }\n componentInfoById.set(id, info)\n const handle: SoAComponent<S> = {\n __kind: 'soa',\n __id: id,\n __schema: schema,\n }\n return handle\n}\n\nexport function defineTag(): TagComponent {\n const id = nextComponentId++\n const info: ComponentInfo = { id, kind: 'tag', schema: null, fields: [], factory: null }\n componentInfoById.set(id, info)\n return { __kind: 'tag', __id: id }\n}\n\nexport function defineObjectComponent<T>(factory?: () => T): AoSComponent<T> {\n const id = nextComponentId++\n const fac = factory ?? (() => ({} as T))\n const info: ComponentInfo = { id, kind: 'aos', schema: null, fields: [], factory: fac as any }\n componentInfoById.set(id, info)\n return { __kind: 'aos', __id: id, __factory: fac }\n}\n\nexport function getComponentInfo(component: ComponentLike): ComponentInfo {\n const info = componentInfoById.get(component.__id)\n if (!info) throw new Error('aiecsjs: component is not registered (call defineComponent/defineTag/defineObjectComponent)')\n return info\n}\n\n// --- Component ops on entities ---\n\nexport function addComponent<C extends ComponentLike>(\n world: World,\n eid: EntityId,\n component: C,\n initial?: ComponentInit<C>,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) {\n throw new Error(`aiecsjs: addComponent on dead entity ${eid}`)\n }\n const info = getComponentInfo(component)\n const bit = getOrRegisterComponentBit(state, info)\n\n const prevMask = readEntityMask(state, eid)\n if (testBit(prevMask, bit)) {\n if (initial !== undefined) writeInitial(state, eid, component, initial)\n return\n }\n const newMask = cloneMask(prevMask)\n setBit(newMask, bit)\n migrateEntity(state, eid, newMask)\n\n writeInitial(state, eid, component, initial)\n\n fireAddObservers(state, eid, bit)\n notifyMaskChange(state, eid, bit, prevMask, newMask)\n}\n\nexport function removeComponent<C extends ComponentLike>(world: World, eid: EntityId, component: C): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) return\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return\n const prevMask = readEntityMask(state, eid)\n if (!testBit(prevMask, bit)) return\n\n fireRemoveObservers(state, eid, bit)\n\n const newMask = cloneMask(prevMask)\n clearBit(newMask, bit)\n migrateEntity(state, eid, newMask)\n\n const storage = state.componentStorageByBit[bit]\n if (storage?.kind === 'soa' && storage.soa) {\n clearSoAEntity(storage.soa, info.fields, eid)\n } else if (storage?.kind === 'aos' && storage.aos) {\n storage.aos[eid] = undefined\n }\n\n notifyMaskChange(state, eid, bit, prevMask, newMask)\n}\n\nexport function hasComponent<C extends ComponentLike>(world: World, eid: EntityId, component: C): boolean {\n const state = getWorldState(world)\n if (!isAliveInternal(state, eid)) return false\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return false\n const mask = readEntityMask(state, eid)\n return testBit(mask, bit)\n}\n\nexport function getComponent<C extends ComponentLike>(world: World, eid: EntityId, component: C): unknown {\n const state = getWorldState(world)\n if (!isAliveInternal(state, eid)) return undefined\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return undefined\n const mask = readEntityMask(state, eid)\n if (!testBit(mask, bit)) return undefined\n const storage = state.componentStorageByBit[bit]\n if (!storage) return undefined\n if (storage.kind === 'soa') return storage.soa\n if (storage.kind === 'aos') return storage.aos?.[eid]\n return true // tag\n}\n\nexport function setComponent<C extends ComponentLike, V>(\n world: World,\n eid: EntityId,\n component: C,\n value: V,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) throw new Error(`aiecsjs: setComponent on dead entity ${eid}`)\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) {\n // Adding via set\n addComponent(world, eid, component, value as any)\n return\n }\n const mask = readEntityMask(state, eid)\n if (!testBit(mask, bit)) {\n addComponent(world, eid, component, value as any)\n return\n }\n writeInitial(state, eid, component, value as any)\n fireSetObservers(state, eid, bit, value)\n}\n\n// --- Internals ---\n\nfunction writeInitial(state: WorldState, eid: number, component: ComponentLike, initial: unknown): void {\n const info = getComponentInfo(component)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) return\n const storage = state.componentStorageByBit[bit]\n if (!storage) return\n if (info.kind === 'soa' && storage.soa) {\n if (initial == null) return\n const obj = initial as Record<string, unknown>\n for (const f of info.fields) {\n if (!(f.name in obj)) continue\n const col = storage.soa[f.name]\n if (!col) continue\n const val = obj[f.name]\n if (f.vectorLen === 1) {\n col[eid] = typeof val === 'boolean' ? (val ? 1 : 0) : Number(val)\n } else if (Array.isArray(val) || ArrayBuffer.isView(val)) {\n const base = eid * f.vectorLen\n const arr = val as ArrayLike<number>\n for (let i = 0; i < f.vectorLen; i++) col[base + i] = Number(arr[i] ?? 0)\n }\n }\n } else if (info.kind === 'aos' && storage.aos) {\n const factory = info.factory ?? (() => ({}))\n let inst = storage.aos[eid]\n if (inst === undefined) {\n inst = factory()\n storage.aos[eid] = inst\n }\n if (initial && typeof initial === 'object') {\n Object.assign(inst as object, initial as object)\n }\n }\n // tag: nothing\n}\n\nfunction clearSoAEntity(soa: SoAColumns, fields: FieldInfo[], eid: number): void {\n for (const f of fields) {\n const col = soa[f.name]\n if (!col) continue\n if (f.vectorLen === 1) {\n col[eid] = 0\n } else {\n const base = eid * f.vectorLen\n for (let i = 0; i < f.vectorLen; i++) col[base + i] = 0\n }\n }\n}\n\n// Clear every component-storage slot that the entity currently owns.\n// Walks the entity's mask; for each set bit, zeroes the SoA columns or\n// undefines the AoS slot at the entity index. Tag storages are bit-only.\n// Caller (e.g. destroyEntity) is expected to clear the mask separately.\nexport function clearAllEntityStorages(state: WorldState, eid: EntityId): void {\n const wordCount = state.options.maskWordCount\n const idx = eid as number\n const base = idx * wordCount\n forEachSetBit(state.entityMask, base, wordCount, (bit) => {\n const storage = state.componentStorageByBit[bit]\n const info = state.componentInfoByBit[bit]\n if (storage?.kind === 'soa' && storage.soa && info) {\n clearSoAEntity(storage.soa, info.fields, idx)\n } else if (storage?.kind === 'aos' && storage.aos) {\n storage.aos[idx] = undefined\n }\n })\n}\n\nfunction migrateEntity(state: WorldState, eid: number, newMask: Uint32Array): void {\n const srcArchId = state.entityArchetype[eid] ?? 0\n const srcArch = state.archetypes[srcArchId]\n if (!srcArch) return\n\n const found = findOrCreateArchetype(state, newMask)\n const destArchId = found.archId\n const destArch = state.archetypes[destArchId]\n if (!destArch) return\n\n if (destArchId !== srcArchId) {\n // Swap-pop from src\n const row = srcArch.entityRow.get(eid)\n if (row !== undefined) {\n const lastRow = srcArch.size - 1\n if (row !== lastRow) {\n const moved = srcArch.entities[lastRow] ?? 0\n srcArch.entities[row] = moved\n srcArch.entityRow.set(moved, row)\n }\n srcArch.entities[lastRow] = 0\n srcArch.entityRow.delete(eid)\n srcArch.size--\n }\n\n // Append to dest\n ensureArchetypeCapacity(destArch, destArch.size + 1)\n const newRow = destArch.size\n destArch.entities[newRow] = eid\n destArch.entityRow.set(eid, newRow)\n destArch.size++\n\n state.entityArchetype[eid] = destArchId\n }\n\n writeEntityMask(state, eid, newMask)\n}\n\n// --- Observer dispatch (lazy-bound) ---\n\ninterface ObserversDispatchAPI {\n fireAdd(state: WorldState, eid: EntityId, bit: number): void\n fireRemove(state: WorldState, eid: EntityId, bit: number): void\n fireSet(state: WorldState, eid: EntityId, bit: number, value: unknown): void\n}\nlet _dispatch: ObserversDispatchAPI = {\n fireAdd: () => {},\n fireRemove: () => {},\n fireSet: () => {},\n}\n\ntype MaskChangeFn = (state: WorldState, eid: EntityId, bit: number, prev: Uint32Array, next: Uint32Array) => void\nlet _maskChange: MaskChangeFn = () => {}\nexport function registerMaskChangeDispatch(fn: MaskChangeFn): void {\n _maskChange = fn\n}\nfunction notifyMaskChange(state: WorldState, eid: number, bit: number, prev: Uint32Array, next: Uint32Array): void {\n _maskChange(state, eid as EntityId, bit, prev, next)\n}\nexport function registerObserverDispatch(api: ObserversDispatchAPI): void {\n _dispatch = api\n}\nfunction fireAddObservers(state: WorldState, eid: number, bit: number): void {\n _dispatch.fireAdd(state, eid as EntityId, bit)\n}\nfunction fireRemoveObservers(state: WorldState, eid: number, bit: number): void {\n _dispatch.fireRemove(state, eid as EntityId, bit)\n}\nfunction fireSetObservers(state: WorldState, eid: number, bit: number, value: unknown): void {\n _dispatch.fireSet(state, eid as EntityId, bit, value)\n}\n\n// --- Helper for serialize/worker ---\n\nexport function getComponentByInternalId(id: number): ComponentInfo | undefined {\n return componentInfoById.get(id)\n}\n\nexport function listAllComponents(): ComponentInfo[] {\n return Array.from(componentInfoById.values())\n}\n\nexport function _resetComponentRegistry_FOR_TESTS_ONLY(): void {\n componentInfoById.clear()\n nextComponentId = 1\n}\n","// aiecsjs/commands — deferred structural mutations during iteration.\n\nimport type {\n CommandBuffer,\n CommandBufferState,\n CommandOp,\n ComponentInit,\n ComponentLike,\n EntityId,\n World,\n} from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\nimport {\n addComponent,\n removeComponent,\n} from './internal/component.js'\nimport { createEntity, destroyEntity } from './internal/entity.js'\n\nexport function createCommandBuffer(world: World): CommandBuffer {\n const state = getWorldState(world)\n const buf: CommandBufferState = {\n worldId: state.id,\n ops: [],\n nextPlaceholder: -1,\n flushing: false,\n }\n attachState(buf)\n return makeApi(buf)\n}\n\nexport function flush(cb: CommandBuffer): void {\n const state = stateOf(cb)\n if (state.flushing) return\n state.flushing = true\n try {\n const world = lookupWorld(state.worldId)\n\n // Phase 1: resolve placeholders by creating real entities first\n const placeholders = new Map<number, EntityId>()\n for (const op of state.ops) {\n if (op.kind === 'create') {\n placeholders.set(op.placeholder, createEntity(world))\n }\n }\n\n const resolve = (eid: EntityId): EntityId => {\n const num = eid as number\n if (num < 0) {\n const real = placeholders.get(num)\n if (real === undefined) throw new Error(`aiecsjs: unresolved placeholder ${num}`)\n return real\n }\n return eid\n }\n\n // Phase 2: add/remove in queue order\n for (const op of state.ops) {\n if (op.kind === 'add') {\n addComponent(world, resolve(op.eid), op.component, op.initial as ComponentInit<ComponentLike>)\n } else if (op.kind === 'remove') {\n removeComponent(world, resolve(op.eid), op.component)\n }\n }\n\n // Phase 3: destroy last\n for (const op of state.ops) {\n if (op.kind === 'destroy') {\n destroyEntity(world, resolve(op.eid))\n }\n }\n\n state.ops.length = 0\n state.nextPlaceholder = -1\n } finally {\n state.flushing = false\n }\n}\n\nexport function withCommandBuffer<R>(world: World, fn: (cb: CommandBuffer) => R): R {\n const cb = createCommandBuffer(world)\n const result = fn(cb)\n flush(cb)\n return result\n}\n\n// --- Internals ---\n\nconst cbStateMap = new WeakMap<object, CommandBufferState>()\n\nfunction attachState(state: CommandBufferState): void {\n // The CommandBuffer API object is created in makeApi; we link them via WeakMap there.\n void state\n}\n\nfunction makeApi(state: CommandBufferState): CommandBuffer {\n const api: CommandBuffer = {\n add(eid, component, initial) {\n state.ops.push({ kind: 'add', eid, component, initial })\n },\n remove(eid, component) {\n state.ops.push({ kind: 'remove', eid, component })\n },\n destroy(eid) {\n state.ops.push({ kind: 'destroy', eid })\n },\n create() {\n const ph = state.nextPlaceholder--\n state.ops.push({ kind: 'create', placeholder: ph })\n return ph as EntityId\n },\n }\n cbStateMap.set(api, state)\n return api\n}\n\nfunction stateOf(cb: CommandBuffer): CommandBufferState {\n const s = cbStateMap.get(cb)\n if (!s) throw new Error('aiecsjs: unknown CommandBuffer')\n return s\n}\n\n// Look up a public World from its state id. We need a registry — re-import lazily.\nfunction lookupWorld(worldId: number): World {\n // The world registry is in internal/world.ts. We need to construct a public reference.\n // Since destroy clears state, we look up afresh by id via the worldRegistry.\n const state = lookupState(worldId)\n return { id: state.id, capacity: state.capacity, version: state.version } as World\n}\n\nfunction lookupState(worldId: number): import('./internal/types.js').WorldState {\n // Access worldRegistry indirectly via getWorldState requires a World object.\n // Use a small workaround: construct a minimal World-like and call getWorldState.\n return getWorldState({ id: worldId, capacity: 0, version: '0.0.0' } as World)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/internal/bitmask.ts","../src/internal/world.ts","../src/internal/entity.ts","../src/internal/component.ts","../src/commands.ts"],"names":["setBit","mask","bit","w","clearBit","testBit","cloneMask","src","out","i","maskHash","m","parts","forEachSetBit","base","words","fn","wi","word","ctz32","v","worldRegistry","getWorldState","world","state","ensureCapacity","needed","newCap","growEntityArrays","genCtor","newGen","newArch","wordCount","newMask","storage","info","growSoAColumns","soa","fields","f","old","newLen","next","findOrCreateArchetype","key","existing","id","arch","collectBits","ensureArchetypeCapacity","bits","lsb","getOrRegisterComponentBit","readEntityMask","eid","writeEntityMask","tryGetComponentBit","createEntity","row","destroyEntity","isAliveInternal","clearAllEntityStorages","archId","lastRow","moved","idx","componentInfoById","getComponentInfo","component","addComponent","initial","prevMask","writeInitial","migrateEntity","removeComponent","clearSoAEntity","obj","col","val","arr","factory","inst","target","srcArchId","srcArch","destArchId","destArch","newRow","createCommandBuffer","buf","makeApi","flush","cb","stateOf","lookupWorld","placeholders","op","resolve","num","real","withCommandBuffer","result","cbStateMap","api","ph","s","worldId","lookupState"],"mappings":"AAMO,SAASA,CAAAA,CAAOC,CAAAA,CAAmBC,CAAAA,CAAmB,CAC3D,IAAMC,CAAAA,CAAID,CAAAA,GAAQ,CAAA,CAClBD,CAAAA,CAAKE,CAAC,CAAA,CAAA,CAAKF,CAAAA,CAAKE,CAAC,CAAA,EAAK,CAAA,EAAM,CAAA,GAAMD,CAAAA,CAAM,EAAA,EAC1C,CAEO,SAASE,CAAAA,CAASH,CAAAA,CAAmBC,CAAAA,CAAmB,CAC7D,IAAMC,CAAAA,CAAID,CAAAA,GAAQ,CAAA,CAClBD,CAAAA,CAAKE,CAAC,CAAA,CAAA,CAAKF,CAAAA,CAAKE,CAAC,CAAA,EAAK,CAAA,EAAK,EAAE,CAAA,GAAMD,CAAAA,CAAM,EAAA,CAAA,EAC3C,CAEO,SAASG,CAAAA,CAAQJ,CAAAA,CAAmBC,CAAAA,CAAsB,CAC/D,IAAMC,EAAID,CAAAA,GAAQ,CAAA,CAClB,OAAA,CAAA,CAASD,CAAAA,CAAKE,CAAC,CAAA,EAAK,CAAA,EAAM,CAAA,GAAMD,CAAAA,CAAM,EAAA,CAAA,IAAU,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AA2D,CAG9E,OAAOpF,CAAAA,CAAc,CAAE,EAAA,CAAIoF,CAAuC,CAAU,CAC9E","file":"commands.js","sourcesContent":["// Multi-word Uint32 bitmask helpers.\n\nexport function createMask(wordCount: number): Uint32Array {\n return new Uint32Array(wordCount)\n}\n\nexport function setBit(mask: Uint32Array, bit: number): void {\n const w = bit >>> 5\n mask[w] = (mask[w] ?? 0) | (1 << (bit & 31))\n}\n\nexport function clearBit(mask: Uint32Array, bit: number): void {\n const w = bit >>> 5\n mask[w] = (mask[w] ?? 0) & ~(1 << (bit & 31))\n}\n\nexport function testBit(mask: Uint32Array, bit: number): boolean {\n const w = bit >>> 5\n return ((mask[w] ?? 0) & (1 << (bit & 31))) !== 0\n}\n\nexport function copyMask(dst: Uint32Array, src: Uint32Array): void {\n const n = src.length\n for (let i = 0; i < n; i++) dst[i] = src[i] ?? 0\n}\n\nexport function cloneMask(src: Uint32Array): Uint32Array {\n const out = new Uint32Array(src.length)\n for (let i = 0; i < src.length; i++) out[i] = src[i] ?? 0\n return out\n}\n\nexport function maskEquals(a: Uint32Array, b: Uint32Array): boolean {\n const n = a.length\n if (b.length !== n) return false\n for (let i = 0; i < n; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return false\n return true\n}\n\nexport function maskHash(m: Uint32Array): string {\n // Stable string key for Map lookups. Hex-joined.\n const parts: string[] = []\n for (let i = 0; i < m.length; i++) {\n parts.push((m[i] ?? 0).toString(16))\n }\n return parts.join(',')\n}\n\nexport function isMaskZero(m: Uint32Array): boolean {\n for (let i = 0; i < m.length; i++) if ((m[i] ?? 0) !== 0) return false\n return true\n}\n\nexport function unionMask(a: Uint32Array, b: Uint32Array): Uint32Array {\n const out = new Uint32Array(a.length)\n for (let i = 0; i < a.length; i++) out[i] = (a[i] ?? 0) | (b[i] ?? 0)\n return out\n}\n\n/**\n * Test whether an archetype's mask matches a query.\n * - withMask: all of these bits must be present\n * - anyMask: if anyHasBits, at least one of these bits must be present\n * - noneMask: none of these bits may be present\n */\nexport function matches(\n mask: Uint32Array,\n withMask: Uint32Array,\n anyMask: Uint32Array,\n noneMask: Uint32Array,\n anyHasBits: boolean,\n words: number,\n): boolean {\n let anyHit = !anyHasBits\n for (let w = 0; w < words; w++) {\n const m = mask[w] ?? 0\n const wm = withMask[w] ?? 0\n const am = anyMask[w] ?? 0\n const nm = noneMask[w] ?? 0\n if ((m & wm) !== wm) return false\n if ((m & nm) !== 0) return false\n if (!anyHit && (m & am) !== 0) anyHit = true\n }\n return anyHit\n}\n\nexport function listBits(mask: Uint32Array): number[] {\n const out: number[] = []\n for (let w = 0; w < mask.length; w++) {\n let word = mask[w] ?? 0\n while (word !== 0) {\n const bit = (w << 5) + ctz32(word)\n out.push(bit)\n word &= word - 1\n }\n }\n return out\n}\n\n// Iterate set bits in a slice of a larger Uint32Array starting at `base`.\n// Shared by destroy paths and storage cleanup so the bit-extraction maths\n// lives in exactly one place.\nexport function forEachSetBit(\n mask: Uint32Array,\n base: number,\n words: number,\n fn: (bit: number) => void,\n): void {\n for (let wi = 0; wi < words; wi++) {\n let word = mask[base + wi] ?? 0\n while (word !== 0) {\n const bit = (wi << 5) + ctz32(word)\n fn(bit)\n word &= word - 1\n }\n }\n}\n\n// Match a query against an entity's mask stored as a slice inside a larger\n// Uint32Array. Reading directly from the parent array avoids the temporary\n// Uint32Array allocation on every observer dispatch.\nexport function matchesEntityMask(\n entityMask: Uint32Array,\n base: number,\n words: number,\n withMask: Uint32Array,\n anyMask: Uint32Array,\n noneMask: Uint32Array,\n anyHasBits: boolean,\n): boolean {\n let anyHit = !anyHasBits\n for (let i = 0; i < words; i++) {\n const m = entityMask[base + i] ?? 0\n const wm = withMask[i] ?? 0\n const am = anyMask[i] ?? 0\n const nm = noneMask[i] ?? 0\n if ((m & wm) !== wm) return false\n if ((m & nm) !== 0) return false\n if (!anyHit && (m & am) !== 0) anyHit = true\n }\n return anyHit\n}\n\nfunction ctz32(v: number): number {\n // Count trailing zeros in a 32-bit integer (assumes v !== 0)\n return 31 - Math.clz32(v & -v)\n}\n","import { VERSION } from '../version.js'\nimport { cloneMask, copyMask, createMask, maskHash } from './bitmask.js'\nimport type {\n ArchetypeState,\n ComponentInfo,\n FieldInfo,\n ResolvedWorldOptions,\n World,\n WorldComponentStorage,\n WorldOptions,\n WorldState,\n} from './types.js'\n\nexport const WORLD_BRAND = Symbol.for('aiecsjs.world')\n\nconst DEFAULT_OPTIONS: Required<Omit<WorldOptions, 'buffer' | 'bufferByteOffset'>> = {\n initialCapacity: 1024,\n maxEntities: 1_000_000,\n indexBits: 24,\n generationBits: 8,\n}\n\nconst DEFAULT_MAX_COMPONENTS = 256\n\nlet nextWorldId = 1\nconst worldRegistry = new Map<number, WorldState>()\n\nexport function getWorldState(world: World): WorldState {\n const state = worldRegistry.get(world.id)\n if (!state) throw new Error(`aiecsjs: world ${world.id} is destroyed or unknown`)\n if (state.destroyed) throw new Error(`aiecsjs: world ${world.id} is destroyed`)\n return state\n}\n\nexport function registerWorld(state: WorldState): void {\n worldRegistry.set(state.id, state)\n}\n\nexport function unregisterWorld(id: number): void {\n worldRegistry.delete(id)\n}\n\nexport function isWorldRegistered(id: number): boolean {\n return worldRegistry.has(id)\n}\n\nfunction resolveOptions(opts: WorldOptions | undefined): ResolvedWorldOptions {\n const o = opts ?? {}\n const indexBits = o.indexBits ?? DEFAULT_OPTIONS.indexBits\n const generationBits = o.generationBits ?? DEFAULT_OPTIONS.generationBits\n const maxComponents = DEFAULT_MAX_COMPONENTS\n if (indexBits < 1 || indexBits > 24) {\n throw new Error('aiecsjs: indexBits must be in [1, 24]')\n }\n if (generationBits < 0 || generationBits > 16) {\n throw new Error('aiecsjs: generationBits must be in [0, 16]')\n }\n const maxByIndex = 1 << indexBits\n const initialCapacity = Math.max(\n 1,\n Math.min(o.initialCapacity ?? DEFAULT_OPTIONS.initialCapacity, maxByIndex),\n )\n const maxEntities = Math.max(\n initialCapacity,\n Math.min(o.maxEntities ?? DEFAULT_OPTIONS.maxEntities, maxByIndex),\n )\n return {\n initialCapacity,\n maxEntities,\n indexBits,\n generationBits,\n maxComponents,\n maskWordCount: Math.ceil(maxComponents / 32),\n buffer: o.buffer ?? null,\n bufferByteOffset: o.bufferByteOffset ?? 0,\n }\n}\n\nexport function createEmptyArchetype(maskWordCount: number, maxComponents: number): ArchetypeState {\n return {\n id: 0,\n mask: createMask(maskWordCount),\n size: 0,\n capacity: 16,\n entities: new Uint32Array(16),\n entityRow: new Map<number, number>(),\n componentBits: [],\n edgeAdd: new Int32Array(maxComponents).fill(-1),\n edgeRemove: new Int32Array(maxComponents).fill(-1),\n }\n}\n\nexport function createWorld(options?: WorldOptions): World {\n const resolved = resolveOptions(options)\n const id = nextWorldId++\n\n const generationCtor = resolved.generationBits > 8 ? Uint16Array : Uint8Array\n const generations = new generationCtor(resolved.initialCapacity)\n\n const state: WorldState = {\n id,\n capacity: resolved.initialCapacity,\n version: VERSION,\n options: resolved,\n size: 0,\n nextFreshIndex: 1, // 0 reserved\n freeList: [],\n generations,\n destroyed: false,\n componentBitFor: new Map<number, number>(),\n componentInfoByBit: new Array(resolved.maxComponents).fill(null),\n componentStorageByBit: new Array(resolved.maxComponents).fill(null),\n nextComponentBit: 0,\n entityArchetype: new Uint32Array(resolved.initialCapacity),\n entityMask: new Uint32Array(resolved.initialCapacity * resolved.maskWordCount),\n archetypes: [],\n archetypeByMaskHash: new Map<string, number>(),\n queryVersion: 0,\n queries: [],\n queryMasks: new Map(),\n queryArchetypeCache: [],\n queryArchetypeStamp: [],\n bitToQueries: new Map<number, Set<number>>(),\n reactiveBuffers: new Map(),\n observers: [],\n relationStorage: new Map(),\n sab: resolved.buffer,\n readOnly: false,\n }\n\n // Seed archetype 0 (the empty mask)\n const empty = createEmptyArchetype(resolved.maskWordCount, resolved.maxComponents)\n empty.id = 0\n state.archetypes.push(empty)\n state.archetypeByMaskHash.set(maskHash(empty.mask), 0)\n\n registerWorld(state)\n return makePublicWorld(state)\n}\n\nexport function makePublicWorld(state: WorldState): World {\n return {\n id: state.id,\n get capacity() {\n return state.capacity\n },\n version: state.version,\n } as World\n}\n\nexport function destroyWorld(world: World): void {\n const state = worldRegistry.get(world.id)\n if (!state || state.destroyed) return\n state.destroyed = true\n // Clear large buffers to help GC\n state.archetypes = []\n state.archetypeByMaskHash.clear()\n state.componentInfoByBit = []\n state.componentStorageByBit = []\n state.queries = []\n state.queryMasks.clear()\n state.queryArchetypeCache = []\n state.observers = []\n state.relationStorage.clear()\n state.reactiveBuffers.clear()\n unregisterWorld(world.id)\n}\n\nexport function resetWorld(world: World): void {\n const state = getWorldState(world)\n // Keep capacity and registered components; clear entities and per-entity state.\n state.size = 0\n state.nextFreshIndex = 1\n state.freeList = []\n state.generations.fill(0)\n state.entityArchetype.fill(0)\n state.entityMask.fill(0)\n // Wipe archetype memberships but keep archetype graph for stability.\n for (const arch of state.archetypes) {\n arch.size = 0\n arch.entityRow.clear()\n }\n // Clear SoA columns and AoS instances; storage allocation is preserved.\n for (const storage of state.componentStorageByBit) {\n if (!storage) continue\n if (storage.kind === 'soa' && storage.soa) {\n for (const k of Object.keys(storage.soa)) {\n storage.soa[k]?.fill(0)\n }\n } else if (storage.kind === 'aos' && storage.aos) {\n storage.aos.fill(undefined as unknown as never)\n }\n }\n state.queryVersion++\n for (const buf of state.reactiveBuffers.values()) {\n buf.entered.length = 0\n buf.exited.length = 0\n }\n}\n\nexport function getWorldSize(world: World): number {\n return getWorldState(world).size\n}\n\nexport function getWorldCapacity(world: World): number {\n return getWorldState(world).capacity\n}\n\n// --- Capacity growth ---\n\nexport function ensureCapacity(state: WorldState, needed: number): void {\n if (needed <= state.capacity) return\n if (needed > state.options.maxEntities) {\n throw new Error(\n `aiecsjs: requested capacity ${needed} exceeds maxEntities ${state.options.maxEntities}`,\n )\n }\n let newCap = state.capacity\n while (newCap < needed) newCap = Math.min(newCap * 2, state.options.maxEntities)\n growEntityArrays(state, newCap)\n}\n\nfunction growEntityArrays(state: WorldState, newCap: number): void {\n // generations\n const genCtor: any = state.generations.constructor\n const newGen = new genCtor(newCap) as Uint8Array | Uint16Array\n ;(newGen as Uint8Array).set(state.generations as Uint8Array)\n state.generations = newGen\n\n // entityArchetype\n const newArch = new Uint32Array(newCap)\n newArch.set(state.entityArchetype)\n state.entityArchetype = newArch\n\n // entityMask\n const wordCount = state.options.maskWordCount\n const newMask = new Uint32Array(newCap * wordCount)\n newMask.set(state.entityMask)\n state.entityMask = newMask\n\n // Component storages (SoA columns + AoS arrays)\n for (const storage of state.componentStorageByBit) {\n if (!storage) continue\n if (storage.kind === 'soa' && storage.soa) {\n const info = state.componentInfoByBit[storage.bit]\n if (info) growSoAColumns(storage.soa, info.fields, newCap)\n } else if (storage.kind === 'aos' && storage.aos) {\n storage.aos.length = newCap\n }\n }\n\n state.capacity = newCap\n}\n\nfunction growSoAColumns(soa: Record<string, any>, fields: FieldInfo[], newCap: number): void {\n for (const f of fields) {\n const old = soa[f.name]\n if (!old) continue\n const newLen = newCap * f.vectorLen\n if (old.length >= newLen) continue\n const next = new f.ctor(newLen)\n next.set(old)\n soa[f.name] = next\n }\n}\n\n// --- Archetype management ---\n\nexport function findOrCreateArchetype(\n state: WorldState,\n mask: Uint32Array,\n): { archId: number; created: boolean } {\n const key = maskHash(mask)\n const existing = state.archetypeByMaskHash.get(key)\n if (existing !== undefined) return { archId: existing, created: false }\n\n const id = state.archetypes.length\n const arch: ArchetypeState = {\n id,\n mask: cloneMask(mask),\n size: 0,\n capacity: 16,\n entities: new Uint32Array(16),\n entityRow: new Map<number, number>(),\n componentBits: collectBits(mask),\n edgeAdd: new Int32Array(state.options.maxComponents).fill(-1),\n edgeRemove: new Int32Array(state.options.maxComponents).fill(-1),\n }\n state.archetypes.push(arch)\n state.archetypeByMaskHash.set(key, id)\n state.queryVersion++\n return { archId: id, created: true }\n}\n\nexport function ensureArchetypeCapacity(arch: ArchetypeState, needed: number): void {\n if (needed <= arch.capacity) return\n let newCap = arch.capacity\n while (newCap < needed) newCap *= 2\n const next = new Uint32Array(newCap)\n next.set(arch.entities)\n arch.entities = next\n arch.capacity = newCap\n}\n\nfunction collectBits(mask: Uint32Array): number[] {\n const bits: number[] = []\n for (let w = 0; w < mask.length; w++) {\n let word = mask[w] ?? 0\n while (word !== 0) {\n const lsb = word & -word\n const bit = (w << 5) + (31 - Math.clz32(lsb))\n bits.push(bit)\n word &= word - 1\n }\n }\n return bits\n}\n\n// --- Component registration in a world ---\n\nexport function getOrRegisterComponentBit(state: WorldState, info: ComponentInfo): number {\n const existing = state.componentBitFor.get(info.id)\n if (existing !== undefined) return existing\n\n if (state.nextComponentBit >= state.options.maxComponents) {\n throw new Error(`aiecsjs: world reached maxComponents=${state.options.maxComponents}`)\n }\n const bit = state.nextComponentBit++\n state.componentBitFor.set(info.id, bit)\n state.componentInfoByBit[bit] = info\n\n // Create storage\n let storage: WorldComponentStorage\n if (info.kind === 'soa') {\n const soa: Record<string, any> = {}\n for (const f of info.fields) {\n soa[f.name] = new f.ctor(state.capacity * f.vectorLen)\n }\n storage = { kind: 'soa', componentId: info.id, bit, soa }\n } else if (info.kind === 'aos') {\n storage = { kind: 'aos', componentId: info.id, bit, aos: new Array(state.capacity) }\n } else {\n storage = { kind: 'tag', componentId: info.id, bit }\n }\n state.componentStorageByBit[bit] = storage\n return bit\n}\n\n// Read a bitmask out of state.entityMask[] into a fresh Uint32Array.\nexport function readEntityMask(state: WorldState, eid: number): Uint32Array {\n const w = state.options.maskWordCount\n const out = new Uint32Array(w)\n const base = eid * w\n for (let i = 0; i < w; i++) out[i] = state.entityMask[base + i] ?? 0\n return out\n}\n\nexport function writeEntityMask(state: WorldState, eid: number, mask: Uint32Array): void {\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = mask[i] ?? 0\n}\n\n// Get the bit of a component within a world without registering.\nexport function tryGetComponentBit(state: WorldState, info: ComponentInfo): number | undefined {\n return state.componentBitFor.get(info.id)\n}\n\nexport function isWorld(x: unknown): x is World {\n if (!x || typeof x !== 'object') return false\n const obj = x as { id?: unknown; version?: unknown }\n if (typeof obj.id !== 'number') return false\n if (typeof obj.version !== 'string') return false\n return worldRegistry.has(obj.id)\n}\n","import { clearAllEntityStorages } from './component.js'\nimport type { EntityId, World, WorldState } from './types.js'\nimport { ensureArchetypeCapacity, ensureCapacity, getWorldState } from './world.js'\n\nexport function createEntity(world: World): EntityId {\n const state = getWorldState(world)\n if (state.readOnly) {\n throw new Error('aiecsjs: cannot createEntity on a read-only world (worker-attached)')\n }\n\n let eid: number\n if (state.freeList.length > 0) {\n eid = state.freeList.pop()!\n } else {\n if (state.nextFreshIndex >= state.options.maxEntities) {\n throw new Error(`aiecsjs: reached maxEntities ${state.options.maxEntities}`)\n }\n if (state.nextFreshIndex >= state.capacity) {\n ensureCapacity(state, state.nextFreshIndex + 1)\n }\n eid = state.nextFreshIndex++\n }\n\n // Move into the empty archetype (0)\n const arch = state.archetypes[0]\n if (!arch) throw new Error('aiecsjs: missing empty archetype')\n ensureArchetypeCapacity(arch, arch.size + 1)\n const row = arch.size\n arch.entities[row] = eid\n arch.entityRow.set(eid, row)\n arch.size++\n\n state.entityArchetype[eid] = 0\n // Reset entityMask row for this eid\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = 0\n\n state.size++\n return eid as EntityId\n}\n\nexport function destroyEntity(world: World, eid: EntityId): void {\n const state = getWorldState(world)\n if (state.readOnly) {\n throw new Error('aiecsjs: cannot destroyEntity on a read-only world')\n }\n if (!isAliveInternal(state, eid)) return\n\n // Fire onRemove for every component the entity has, plus reactive exit\n // (Late-bound to avoid circular imports — done via observers module.)\n const { dispatchDestroyObservers } = lazyObservers()\n dispatchDestroyObservers(state, eid)\n\n // Clean up relations referring to this entity\n cleanupRelationsOnDestroy(state, eid)\n\n // Zero the SoA columns / undefine the AoS slots the entity owned, before\n // the mask is cleared. Without this, destroyed entities leave stale data\n // visible to snapshots and serialisation.\n clearAllEntityStorages(state, eid)\n\n // Swap-pop from its archetype\n const archId = state.entityArchetype[eid] ?? 0\n const arch = state.archetypes[archId]\n if (arch) {\n const row = arch.entityRow.get(eid)\n if (row !== undefined) {\n const lastRow = arch.size - 1\n if (row !== lastRow) {\n const moved = arch.entities[lastRow] ?? 0\n arch.entities[row] = moved\n arch.entityRow.set(moved, row)\n }\n arch.entities[lastRow] = 0\n arch.entityRow.delete(eid)\n arch.size--\n }\n }\n\n // Wipe state\n state.entityArchetype[eid] = 0\n const w = state.options.maskWordCount\n const base = eid * w\n for (let i = 0; i < w; i++) state.entityMask[base + i] = 0\n // bump generation (Uint8Array wraps to 8 bits naturally; Uint16Array to 16)\n const idx = eid as number\n state.generations[idx] = ((state.generations[idx] ?? 0) + 1) & 0xffff\n\n state.freeList.push(eid)\n state.size--\n}\n\nexport function entityExists(world: World, eid: EntityId): boolean {\n const state = getWorldState(world)\n return isAliveInternal(state, eid)\n}\n\nexport function isAliveInternal(state: WorldState, eid: number): boolean {\n if (eid <= 0) return false\n if (eid >= state.capacity) return false\n // An entity is alive iff it is in some archetype (its row map points somewhere).\n const archId = state.entityArchetype[eid] ?? 0\n const arch = state.archetypes[archId]\n if (!arch) return false\n return arch.entityRow.has(eid)\n}\n\nexport function getEntityIndex(eid: EntityId): number {\n return eid as number\n}\n\nexport function getEntityGeneration(_eid: EntityId): number {\n // Unversioned in 0.1: generation not encoded in EntityId.\n return 0\n}\n\nexport function packEntity(index: number, _generation: number): EntityId {\n // Identity in 0.1.\n return index as EntityId\n}\n\nexport function isEntity(world: World, x: unknown): x is EntityId {\n if (typeof x !== 'number') return false\n return entityExists(world, x as EntityId)\n}\n\n// --- Lazy loaders to break import cycles ---\n\ninterface ObserversAPI {\n dispatchDestroyObservers(state: WorldState, eid: EntityId): void\n}\nlet _observersAPI: ObserversAPI | null = null\nexport function registerObserversAPI(api: ObserversAPI): void {\n _observersAPI = api\n}\nfunction lazyObservers(): ObserversAPI {\n if (!_observersAPI) {\n return { dispatchDestroyObservers: () => {} }\n }\n return _observersAPI\n}\n\nlet _relationsCleanup: ((state: WorldState, eid: EntityId) => void) | null = null\nexport function registerRelationsCleanup(fn: (state: WorldState, eid: EntityId) => void): void {\n _relationsCleanup = fn\n}\nfunction cleanupRelationsOnDestroy(state: WorldState, eid: EntityId): void {\n if (_relationsCleanup) _relationsCleanup(state, eid)\n}\n","import { clearBit, cloneMask, forEachSetBit, setBit, testBit } from './bitmask.js'\nimport { isAliveInternal } from './entity.js'\nimport type {\n AoSComponent,\n ComponentInfo,\n ComponentInit,\n ComponentLike,\n EntityId,\n FieldInfo,\n SoAColumns,\n SoAComponent,\n SoASchema,\n TagComponent,\n TypedArrayConstructor,\n World,\n WorldComponentStorage,\n WorldState,\n} from './types.js'\nimport {\n ensureArchetypeCapacity,\n findOrCreateArchetype,\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n writeEntityMask,\n} from './world.js'\n\n// --- Component factories ---\n\nlet nextComponentId = 1\n\nconst TYPE_CTOR: Record<string, TypedArrayConstructor> = {\n i8: Int8Array,\n u8: Uint8Array,\n i16: Int16Array,\n u16: Uint16Array,\n i32: Int32Array,\n u32: Uint32Array,\n f32: Float32Array,\n f64: Float64Array,\n eid: Uint32Array,\n bool: Uint8Array,\n}\n\nconst componentInfoById = new Map<number, ComponentInfo>()\n\nexport function defineComponent<S extends SoASchema>(schema: S): SoAComponent<S> {\n const fields: FieldInfo[] = []\n for (const [name, decl] of Object.entries(schema)) {\n let type: keyof typeof TYPE_CTOR\n let vectorLen = 1\n if (typeof decl === 'string') {\n type = decl\n } else if (Array.isArray(decl)) {\n const [t, len] = decl\n type = t\n vectorLen = len\n } else {\n throw new TypeError(`aiecsjs: invalid field declaration for \"${name}\"`)\n }\n const ctor = TYPE_CTOR[type]\n if (!ctor) throw new TypeError(`aiecsjs: unknown field type \"${type}\" for field \"${name}\"`)\n fields.push({\n name,\n type: type as any,\n vectorLen,\n ctor,\n bytesPerElement: (ctor as any).BYTES_PER_ELEMENT,\n })\n }\n const id = nextComponentId++\n const info: ComponentInfo = { id, kind: 'soa', schema, fields, factory: null }\n componentInfoById.set(id, info)\n const handle: SoAComponent<S> = {\n __kind: 'soa',\n __id: id,\n __schema: schema,\n }\n return handle\n}\n\nexport function defineTag(): TagComponent {\n const id = nextComponentId++\n const info: ComponentInfo = { id, kind: 'tag', schema: null, fields: [], factory: null }\n componentInfoById.set(id, info)\n return { __kind: 'tag', __id: id }\n}\n\nexport function defineObjectComponent<T>(factory?: () => T): AoSComponent<T> {\n const id = nextComponentId++\n const fac = factory ?? (() => ({}) as T)\n const info: ComponentInfo = { id, kind: 'aos', schema: null, fields: [], factory: fac as any }\n componentInfoById.set(id, info)\n return { __kind: 'aos', __id: id, __factory: fac }\n}\n\nexport function getComponentInfo(component: ComponentLike): ComponentInfo {\n const info = componentInfoById.get(component.__id)\n if (!info)\n throw new Error(\n 'aiecsjs: component is not registered (call defineComponent/defineTag/defineObjectComponent)',\n )\n return info\n}\n\n// --- Component ops on entities ---\n\nexport function addComponent<C extends ComponentLike>(\n world: World,\n eid: EntityId,\n component: C,\n initial?: ComponentInit<C>,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) {\n throw new Error(`aiecsjs: addComponent on dead entity ${eid}`)\n }\n const info = getComponentInfo(component)\n const bit = getOrRegisterComponentBit(state, info)\n\n const prevMask = readEntityMask(state, eid)\n if (testBit(prevMask, bit)) {\n if (initial !== undefined) writeInitial(state, eid, component, initial)\n return\n }\n const newMask = cloneMask(prevMask)\n setBit(newMask, bit)\n migrateEntity(state, eid, newMask)\n\n writeInitial(state, eid, component, initial)\n\n fireAddObservers(state, eid, bit)\n notifyMaskChange(state, eid, bit, prevMask, newMask)\n}\n\nexport function removeComponent<C extends ComponentLike>(\n world: World,\n eid: EntityId,\n component: C,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) return\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return\n const prevMask = readEntityMask(state, eid)\n if (!testBit(prevMask, bit)) return\n\n // Write the new mask BEFORE firing observers so query-targeted observers\n // reading `state.entityMask` see the post-removal state (and thus correctly\n // detect \"entity left this query\"). Without this reorder, a query that\n // requires the removed component would still match during dispatch and the\n // remove observer would never fire. Component-targeted observers receive the\n // bit directly and don't depend on mask timing. addComponent already follows\n // this \"mutate then fire\" order; keeping removeComponent consistent.\n const newMask = cloneMask(prevMask)\n clearBit(newMask, bit)\n migrateEntity(state, eid, newMask)\n\n fireRemoveObservers(state, eid, bit)\n\n const storage = state.componentStorageByBit[bit]\n if (storage?.kind === 'soa' && storage.soa) {\n clearSoAEntity(storage.soa, info.fields, eid)\n } else if (storage?.kind === 'aos' && storage.aos) {\n storage.aos[eid] = undefined\n }\n\n notifyMaskChange(state, eid, bit, prevMask, newMask)\n}\n\nexport function hasComponent<C extends ComponentLike>(\n world: World,\n eid: EntityId,\n component: C,\n): boolean {\n const state = getWorldState(world)\n if (!isAliveInternal(state, eid)) return false\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return false\n const mask = readEntityMask(state, eid)\n return testBit(mask, bit)\n}\n\nexport function getComponent<C extends ComponentLike>(\n world: World,\n eid: EntityId,\n component: C,\n): unknown {\n const state = getWorldState(world)\n if (!isAliveInternal(state, eid)) return undefined\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) return undefined\n const mask = readEntityMask(state, eid)\n if (!testBit(mask, bit)) return undefined\n const storage = state.componentStorageByBit[bit]\n if (!storage) return undefined\n if (storage.kind === 'soa') return storage.soa\n if (storage.kind === 'aos') return storage.aos?.[eid]\n return true // tag\n}\n\nexport function setComponent<C extends ComponentLike, V>(\n world: World,\n eid: EntityId,\n component: C,\n value: V,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n if (!isAliveInternal(state, eid)) throw new Error(`aiecsjs: setComponent on dead entity ${eid}`)\n const info = getComponentInfo(component)\n const bit = tryGetComponentBit(state, info)\n if (bit === undefined) {\n // Adding via set\n addComponent(world, eid, component, value as any)\n return\n }\n const mask = readEntityMask(state, eid)\n if (!testBit(mask, bit)) {\n addComponent(world, eid, component, value as any)\n return\n }\n writeInitial(state, eid, component, value as any)\n fireSetObservers(state, eid, bit, value)\n}\n\n// --- Internals ---\n\nfunction writeInitial(\n state: WorldState,\n eid: number,\n component: ComponentLike,\n initial: unknown,\n): void {\n const info = getComponentInfo(component)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) return\n const storage = state.componentStorageByBit[bit]\n if (!storage) return\n if (info.kind === 'soa' && storage.soa) {\n if (initial == null) return\n const obj = initial as Record<string, unknown>\n for (const f of info.fields) {\n if (!(f.name in obj)) continue\n const col = storage.soa[f.name]\n if (!col) continue\n const val = obj[f.name]\n if (f.vectorLen === 1) {\n col[eid] = typeof val === 'boolean' ? (val ? 1 : 0) : Number(val)\n } else if (Array.isArray(val) || ArrayBuffer.isView(val)) {\n const base = eid * f.vectorLen\n const arr = val as ArrayLike<number>\n for (let i = 0; i < f.vectorLen; i++) col[base + i] = Number(arr[i] ?? 0)\n }\n }\n } else if (info.kind === 'aos' && storage.aos) {\n const factory = info.factory ?? (() => ({}))\n let inst = storage.aos[eid]\n if (inst === undefined) {\n inst = factory()\n storage.aos[eid] = inst\n }\n if (initial && typeof initial === 'object') {\n // SECURITY: do NOT use `Object.assign(inst, initial)` here. When `initial`\n // comes from `JSON.parse(untrustedBytes)` — e.g. via `fromJSON`,\n // `deserializeWorld`, or app code piping a bridge payload — the parsed\n // object can carry an OWN `__proto__` property, and `Object.assign` uses\n // [[Set]] semantics which would trigger the proto setter and clobber the\n // instance's prototype chain. Explicit own-key copy with a deny-list\n // closes the prototype-pollution path.\n const src = initial as Record<string, unknown>\n const target = inst as Record<string, unknown>\n for (const key of Object.keys(src)) {\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue\n target[key] = src[key]\n }\n }\n }\n // tag: nothing\n}\n\nfunction clearSoAEntity(soa: SoAColumns, fields: FieldInfo[], eid: number): void {\n for (const f of fields) {\n const col = soa[f.name]\n if (!col) continue\n if (f.vectorLen === 1) {\n col[eid] = 0\n } else {\n const base = eid * f.vectorLen\n for (let i = 0; i < f.vectorLen; i++) col[base + i] = 0\n }\n }\n}\n\n// Clear every component-storage slot that the entity currently owns.\n// Walks the entity's mask; for each set bit, zeroes the SoA columns or\n// undefines the AoS slot at the entity index. Tag storages are bit-only.\n// Caller (e.g. destroyEntity) is expected to clear the mask separately.\nexport function clearAllEntityStorages(state: WorldState, eid: EntityId): void {\n const wordCount = state.options.maskWordCount\n const idx = eid as number\n const base = idx * wordCount\n forEachSetBit(state.entityMask, base, wordCount, (bit) => {\n const storage = state.componentStorageByBit[bit]\n const info = state.componentInfoByBit[bit]\n if (storage?.kind === 'soa' && storage.soa && info) {\n clearSoAEntity(storage.soa, info.fields, idx)\n } else if (storage?.kind === 'aos' && storage.aos) {\n storage.aos[idx] = undefined\n }\n })\n}\n\nfunction migrateEntity(state: WorldState, eid: number, newMask: Uint32Array): void {\n const srcArchId = state.entityArchetype[eid] ?? 0\n const srcArch = state.archetypes[srcArchId]\n if (!srcArch) return\n\n const found = findOrCreateArchetype(state, newMask)\n const destArchId = found.archId\n const destArch = state.archetypes[destArchId]\n if (!destArch) return\n\n if (destArchId !== srcArchId) {\n // Swap-pop from src\n const row = srcArch.entityRow.get(eid)\n if (row !== undefined) {\n const lastRow = srcArch.size - 1\n if (row !== lastRow) {\n const moved = srcArch.entities[lastRow] ?? 0\n srcArch.entities[row] = moved\n srcArch.entityRow.set(moved, row)\n }\n srcArch.entities[lastRow] = 0\n srcArch.entityRow.delete(eid)\n srcArch.size--\n }\n\n // Append to dest\n ensureArchetypeCapacity(destArch, destArch.size + 1)\n const newRow = destArch.size\n destArch.entities[newRow] = eid\n destArch.entityRow.set(eid, newRow)\n destArch.size++\n\n state.entityArchetype[eid] = destArchId\n }\n\n writeEntityMask(state, eid, newMask)\n}\n\n// --- Observer dispatch (lazy-bound) ---\n\ninterface ObserversDispatchAPI {\n fireAdd(state: WorldState, eid: EntityId, bit: number): void\n fireRemove(state: WorldState, eid: EntityId, bit: number): void\n fireSet(state: WorldState, eid: EntityId, bit: number, value: unknown): void\n}\nlet _dispatch: ObserversDispatchAPI = {\n fireAdd: () => {},\n fireRemove: () => {},\n fireSet: () => {},\n}\n\ntype MaskChangeFn = (\n state: WorldState,\n eid: EntityId,\n bit: number,\n prev: Uint32Array,\n next: Uint32Array,\n) => void\nlet _maskChange: MaskChangeFn = () => {}\nexport function registerMaskChangeDispatch(fn: MaskChangeFn): void {\n _maskChange = fn\n}\nfunction notifyMaskChange(\n state: WorldState,\n eid: number,\n bit: number,\n prev: Uint32Array,\n next: Uint32Array,\n): void {\n _maskChange(state, eid as EntityId, bit, prev, next)\n}\nexport function registerObserverDispatch(api: ObserversDispatchAPI): void {\n _dispatch = api\n}\nfunction fireAddObservers(state: WorldState, eid: number, bit: number): void {\n _dispatch.fireAdd(state, eid as EntityId, bit)\n}\nfunction fireRemoveObservers(state: WorldState, eid: number, bit: number): void {\n _dispatch.fireRemove(state, eid as EntityId, bit)\n}\nfunction fireSetObservers(state: WorldState, eid: number, bit: number, value: unknown): void {\n _dispatch.fireSet(state, eid as EntityId, bit, value)\n}\n\n// --- Helper for serialize/worker ---\n\nexport function getComponentByInternalId(id: number): ComponentInfo | undefined {\n return componentInfoById.get(id)\n}\n\nexport function listAllComponents(): ComponentInfo[] {\n return Array.from(componentInfoById.values())\n}\n\nexport function _resetComponentRegistry_FOR_TESTS_ONLY(): void {\n componentInfoById.clear()\n nextComponentId = 1\n}\n","// aiecsjs/commands — deferred structural mutations during iteration.\n\nimport { addComponent, removeComponent } from './internal/component.js'\nimport { createEntity, destroyEntity } from './internal/entity.js'\nimport type {\n CommandBuffer,\n CommandBufferState,\n CommandOp,\n ComponentInit,\n ComponentLike,\n EntityId,\n World,\n} from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\n\nexport function createCommandBuffer(world: World): CommandBuffer {\n const state = getWorldState(world)\n const buf: CommandBufferState = {\n worldId: state.id,\n ops: [],\n nextPlaceholder: -1,\n flushing: false,\n }\n attachState(buf)\n return makeApi(buf)\n}\n\nexport function flush(cb: CommandBuffer): void {\n const state = stateOf(cb)\n if (state.flushing) return\n state.flushing = true\n try {\n const world = lookupWorld(state.worldId)\n\n // Phase 1: resolve placeholders by creating real entities first\n const placeholders = new Map<number, EntityId>()\n for (const op of state.ops) {\n if (op.kind === 'create') {\n placeholders.set(op.placeholder, createEntity(world))\n }\n }\n\n const resolve = (eid: EntityId): EntityId => {\n const num = eid as number\n if (num < 0) {\n const real = placeholders.get(num)\n if (real === undefined) throw new Error(`aiecsjs: unresolved placeholder ${num}`)\n return real\n }\n return eid\n }\n\n // Phase 2: add/remove in queue order\n for (const op of state.ops) {\n if (op.kind === 'add') {\n addComponent(\n world,\n resolve(op.eid),\n op.component,\n op.initial as ComponentInit<ComponentLike>,\n )\n } else if (op.kind === 'remove') {\n removeComponent(world, resolve(op.eid), op.component)\n }\n }\n\n // Phase 3: destroy last\n for (const op of state.ops) {\n if (op.kind === 'destroy') {\n destroyEntity(world, resolve(op.eid))\n }\n }\n\n state.ops.length = 0\n state.nextPlaceholder = -1\n } finally {\n state.flushing = false\n }\n}\n\nexport function withCommandBuffer<R>(world: World, fn: (cb: CommandBuffer) => R): R {\n const cb = createCommandBuffer(world)\n const result = fn(cb)\n flush(cb)\n return result\n}\n\n// --- Internals ---\n\nconst cbStateMap = new WeakMap<object, CommandBufferState>()\n\nfunction attachState(state: CommandBufferState): void {\n // The CommandBuffer API object is created in makeApi; we link them via WeakMap there.\n void state\n}\n\nfunction makeApi(state: CommandBufferState): CommandBuffer {\n const api: CommandBuffer = {\n add(eid, component, initial) {\n state.ops.push({ kind: 'add', eid, component, initial })\n },\n remove(eid, component) {\n state.ops.push({ kind: 'remove', eid, component })\n },\n destroy(eid) {\n state.ops.push({ kind: 'destroy', eid })\n },\n create() {\n const ph = state.nextPlaceholder--\n state.ops.push({ kind: 'create', placeholder: ph })\n return ph as EntityId\n },\n }\n cbStateMap.set(api, state)\n return api\n}\n\nfunction stateOf(cb: CommandBuffer): CommandBufferState {\n const s = cbStateMap.get(cb)\n if (!s) throw new Error('aiecsjs: unknown CommandBuffer')\n return s\n}\n\n// Look up a public World from its state id. We need a registry — re-import lazily.\nfunction lookupWorld(worldId: number): World {\n // The world registry is in internal/world.ts. We need to construct a public reference.\n // Since destroy clears state, we look up afresh by id via the worldRegistry.\n const state = lookupState(worldId)\n return { id: state.id, capacity: state.capacity, version: state.version } as World\n}\n\nfunction lookupState(worldId: number): import('./internal/types.js').WorldState {\n // Access worldRegistry indirectly via getWorldState requires a World object.\n // Use a small workaround: construct a minimal World-like and call getWorldState.\n return getWorldState({ id: worldId, capacity: 0, version: '0.0.0' } as World)\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var U="0.1.4";function b(n){return new Uint32Array(n)}function h(n,e){let t=e>>>5;n[t]=(n[t]??0)|1<<(e&31);}function D(n,e){let t=e>>>5;n[t]=(n[t]??0)&~(1<<(e&31));}function C(n,e){let t=e>>>5;return ((n[t]??0)&1<<(e&31))!==0}function g(n){let e=new Uint32Array(n.length);for(let t=0;t<n.length;t++)e[t]=n[t]??0;return e}function O(n){let e=[];for(let t=0;t<n.length;t++)e.push((n[t]??0).toString(16));return e.join(",")}function q(n){for(let e=0;e<n.length;e++)if((n[e]??0)!==0)return false;return true}function E(n,e,t,r,o,i){let a=!o;for(let s=0;s<i;s++){let c=n[s]??0,u=e[s]??0,d=t[s]??0,y=r[s]??0;if((c&u)!==u||(c&y)!==0)return false;!a&&(c&d)!==0&&(a=true);}return a}function B(n){let e=[];for(let t=0;t<n.length;t++){let r=n[t]??0;for(;r!==0;){let o=(t<<5)+P(r);e.push(o),r&=r-1;}}return e}function V(n,e,t,r){for(let o=0;o<t;o++){let i=n[e+o]??0;for(;i!==0;){let a=(o<<5)+P(i);r(a),i&=i-1;}}}function P(n){return 31-Math.clz32(n&-n)}var W={initialCapacity:1024,maxEntities:1e6,indexBits:24,generationBits:8},de=256,ye=1,k=new Map;function f(n){let e=k.get(n.id);if(!e)throw new Error(`aiecsjs: world ${n.id} is destroyed or unknown`);if(e.destroyed)throw new Error(`aiecsjs: world ${n.id} is destroyed`);return e}function fe(n){k.set(n.id,n);}function pe(n){k.delete(n);}function le(n){let e=n??{},t=e.indexBits??W.indexBits,r=e.generationBits??W.generationBits,o=de;if(t<1||t>24)throw new Error("aiecsjs: indexBits must be in [1, 24]");if(r<0||r>16)throw new Error("aiecsjs: generationBits must be in [0, 16]");let i=1<<t,a=Math.max(1,Math.min(e.initialCapacity??W.initialCapacity,i)),s=Math.max(a,Math.min(e.maxEntities??W.maxEntities,i));return {initialCapacity:a,maxEntities:s,indexBits:t,generationBits:r,maxComponents:o,maskWordCount:Math.ceil(o/32),buffer:e.buffer??null,bufferByteOffset:e.bufferByteOffset??0}}function me(n,e){return {id:0,mask:b(n),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:[],edgeAdd:new Int32Array(e).fill(-1),edgeRemove:new Int32Array(e).fill(-1)}}function be(n){let e=le(n),t=ye++,r=e.generationBits>8?Uint16Array:Uint8Array,o=new r(e.initialCapacity),i={id:t,capacity:e.initialCapacity,version:U,options:e,size:0,nextFreshIndex:1,freeList:[],generations:o,destroyed:false,componentBitFor:new Map,componentInfoByBit:new Array(e.maxComponents).fill(null),componentStorageByBit:new Array(e.maxComponents).fill(null),nextComponentBit:0,entityArchetype:new Uint32Array(e.initialCapacity),entityMask:new Uint32Array(e.initialCapacity*e.maskWordCount),archetypes:[],archetypeByMaskHash:new Map,queryVersion:0,queries:[],queryMasks:new Map,queryArchetypeCache:[],queryArchetypeStamp:[],bitToQueries:new Map,reactiveBuffers:new Map,observers:[],relationStorage:new Map,sab:e.buffer,readOnly:false},a=me(e.maskWordCount,e.maxComponents);return a.id=0,i.archetypes.push(a),i.archetypeByMaskHash.set(O(a.mask),0),fe(i),he(i)}function he(n){return {id:n.id,get capacity(){return n.capacity},version:n.version}}function Ce(n){let e=k.get(n.id);!e||e.destroyed||(e.destroyed=true,e.archetypes=[],e.archetypeByMaskHash.clear(),e.componentInfoByBit=[],e.componentStorageByBit=[],e.queries=[],e.queryMasks.clear(),e.queryArchetypeCache=[],e.observers=[],e.relationStorage.clear(),e.reactiveBuffers.clear(),pe(n.id));}function Ae(n){let e=f(n);e.size=0,e.nextFreshIndex=1,e.freeList=[],e.generations.fill(0),e.entityArchetype.fill(0),e.entityMask.fill(0);for(let t of e.archetypes)t.size=0,t.entityRow.clear();for(let t of e.componentStorageByBit)if(t)if(t.kind==="soa"&&t.soa)for(let r of Object.keys(t.soa))t.soa[r]?.fill(0);else t.kind==="aos"&&t.aos&&t.aos.fill(void 0);e.queryVersion++;for(let t of e.reactiveBuffers.values())t.entered.length=0,t.exited.length=0;}function xe(n){return f(n).size}function ge(n){return f(n).capacity}function $(n,e){if(e<=n.capacity)return;if(e>n.options.maxEntities)throw new Error(`aiecsjs: requested capacity ${e} exceeds maxEntities ${n.options.maxEntities}`);let t=n.capacity;for(;t<e;)t=Math.min(t*2,n.options.maxEntities);ke(n,t);}function ke(n,e){let t=n.generations.constructor,r=new t(e);r.set(n.generations),n.generations=r;let o=new Uint32Array(e);o.set(n.entityArchetype),n.entityArchetype=o;let i=n.options.maskWordCount,a=new Uint32Array(e*i);a.set(n.entityMask),n.entityMask=a;for(let s of n.componentStorageByBit)if(s)if(s.kind==="soa"&&s.soa){let c=n.componentInfoByBit[s.bit];c&&Ie(s.soa,c.fields,e);}else s.kind==="aos"&&s.aos&&(s.aos.length=e);n.capacity=e;}function Ie(n,e,t){for(let r of e){let o=n[r.name];if(!o)continue;let i=t*r.vectorLen;if(o.length>=i)continue;let a=new r.ctor(i);a.set(o),n[r.name]=a;}}function H(n,e){let t=O(e),r=n.archetypeByMaskHash.get(t);if(r!==void 0)return {archId:r,created:false};let o=n.archetypes.length,i={id:o,mask:g(e),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:we(e),edgeAdd:new Int32Array(n.options.maxComponents).fill(-1),edgeRemove:new Int32Array(n.options.maxComponents).fill(-1)};return n.archetypes.push(i),n.archetypeByMaskHash.set(t,o),n.queryVersion++,{archId:o,created:true}}function M(n,e){if(e<=n.capacity)return;let t=n.capacity;for(;t<e;)t*=2;let r=new Uint32Array(t);r.set(n.entities),n.entities=r,n.capacity=t;}function we(n){let e=[];for(let t=0;t<n.length;t++){let r=n[t]??0;for(;r!==0;){let o=r&-r,i=(t<<5)+(31-Math.clz32(o));e.push(i),r&=r-1;}}return e}function A(n,e){let t=n.componentBitFor.get(e.id);if(t!==void 0)return t;if(n.nextComponentBit>=n.options.maxComponents)throw new Error(`aiecsjs: world reached maxComponents=${n.options.maxComponents}`);let r=n.nextComponentBit++;n.componentBitFor.set(e.id,r),n.componentInfoByBit[r]=e;let o;if(e.kind==="soa"){let i={};for(let a of e.fields)i[a.name]=new a.ctor(n.capacity*a.vectorLen);o={kind:"soa",componentId:e.id,bit:r,soa:i};}else e.kind==="aos"?o={kind:"aos",componentId:e.id,bit:r,aos:new Array(n.capacity)}:o={kind:"tag",componentId:e.id,bit:r};return n.componentStorageByBit[r]=o,r}function x(n,e){let t=n.options.maskWordCount,r=new Uint32Array(t),o=e*t;for(let i=0;i<t;i++)r[i]=n.entityMask[o+i]??0;return r}function K(n,e,t){let r=n.options.maskWordCount,o=e*r;for(let i=0;i<r;i++)n.entityMask[o+i]=t[i]??0;}function I(n,e){return n.componentBitFor.get(e.id)}function ve(n){if(!n||typeof n!="object")return false;let e=n;return typeof e.id!="number"||typeof e.version!="string"?false:k.has(e.id)}function Se(n){let e=f(n);if(e.readOnly)throw new Error("aiecsjs: cannot createEntity on a read-only world (worker-attached)");let t;if(e.freeList.length>0)t=e.freeList.pop();else {if(e.nextFreshIndex>=e.options.maxEntities)throw new Error(`aiecsjs: reached maxEntities ${e.options.maxEntities}`);e.nextFreshIndex>=e.capacity&&$(e,e.nextFreshIndex+1),t=e.nextFreshIndex++;}let r=e.archetypes[0];if(!r)throw new Error("aiecsjs: missing empty archetype");M(r,r.size+1);let o=r.size;r.entities[o]=t,r.entityRow.set(t,o),r.size++,e.entityArchetype[t]=0;let i=e.options.maskWordCount,a=t*i;for(let s=0;s<i;s++)e.entityMask[a+s]=0;return e.size++,t}function Ee(n,e){let t=f(n);if(t.readOnly)throw new Error("aiecsjs: cannot destroyEntity on a read-only world");if(!p(t,e))return;Z(t,e);let o=t.entityArchetype[e]??0,i=t.archetypes[o];if(i){let u=i.entityRow.get(e);if(u!==void 0){let d=i.size-1;if(u!==d){let y=i.entities[d]??0;i.entities[u]=y,i.entityRow.set(y,u);}i.entities[d]=0,i.entityRow.delete(e),i.size--;}}t.entityArchetype[e]=0;let a=t.options.maskWordCount,s=e*a;for(let u=0;u<a;u++)t.entityMask[s+u]=0;let c=e;t.generations[c]=(t.generations[c]??0)+1&65535,t.freeList.push(e),t.size--;}function Y(n,e){let t=f(n);return p(t,e)}function p(n,e){if(e<=0||e>=n.capacity)return false;let t=n.entityArchetype[e]??0,r=n.archetypes[t];return r?r.entityRow.has(e):false}function Be(n){return n}function We(n){return 0}function Me(n,e){return n}function _e(n,e){return typeof e!="number"?false:Y(n,e)}var T=1,Qe={i8:Int8Array,u8:Uint8Array,i16:Int16Array,u16:Uint16Array,i32:Int32Array,u32:Uint32Array,f32:Float32Array,f64:Float64Array,eid:Uint32Array,bool:Uint8Array},w=new Map;function Re(n){let e=[];for(let[i,a]of Object.entries(n)){let s,c=1;if(typeof a=="string")s=a;else if(Array.isArray(a)){let[d,y]=a;s=d,c=y;}else throw new TypeError(`aiecsjs: invalid field declaration for "${i}"`);let u=Qe[s];if(!u)throw new TypeError(`aiecsjs: unknown field type "${s}" for field "${i}"`);e.push({name:i,type:s,vectorLen:c,ctor:u,bytesPerElement:u.BYTES_PER_ELEMENT});}let t=T++,r={id:t,kind:"soa",schema:n,fields:e,factory:null};return w.set(t,r),{__kind:"soa",__id:t,__schema:n}}function Te(){let n=T++,e={id:n,kind:"tag",schema:null,fields:[],factory:null};return w.set(n,e),{__kind:"tag",__id:n}}function Le(n){let e=T++,t=n??(()=>({})),r={id:e,kind:"aos",schema:null,fields:[],factory:t};return w.set(e,r),{__kind:"aos",__id:e,__factory:t}}function l(n){let e=w.get(n.__id);if(!e)throw new Error("aiecsjs: component is not registered (call defineComponent/defineTag/defineObjectComponent)");return e}function Q(n,e,t,r){let o=f(n);if(o.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(o,e))throw new Error(`aiecsjs: addComponent on dead entity ${e}`);let i=l(t),a=A(o,i),s=x(o,e);if(C(s,a)){r!==void 0&&R(o,e,t,r);return}let c=g(s);h(c,a),J(o,e,c),R(o,e,t,r),te(o,e,a,s,c);}function Fe(n,e,t){let r=f(n);if(r.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(r,e))return;let o=l(t),i=I(r,o);if(i===void 0)return;let a=x(r,e);if(!C(a,i))return;let s=g(a);D(s,i),J(r,e,s);let c=r.componentStorageByBit[i];c?.kind==="soa"&&c.soa?X(c.soa,o.fields,e):c?.kind==="aos"&&c.aos&&(c.aos[e]=void 0),te(r,e,i,a,s);}function je(n,e,t){let r=f(n);if(!p(r,e))return false;let o=l(t),i=I(r,o);if(i===void 0)return false;let a=x(r,e);return C(a,i)}function ze(n,e,t){let r=f(n);if(!p(r,e))return;let o=l(t),i=I(r,o);if(i===void 0)return;let a=x(r,e);if(!C(a,i))return;let s=r.componentStorageByBit[i];if(s)return s.kind==="soa"?s.soa:s.kind==="aos"?s.aos?.[e]:true}function De(n,e,t,r){let o=f(n);if(o.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(o,e))throw new Error(`aiecsjs: setComponent on dead entity ${e}`);let i=l(t),a=I(o,i);if(a===void 0){Q(n,e,t,r);return}let s=x(o,e);if(!C(s,a)){Q(n,e,t,r);return}R(o,e,t,r);}function R(n,e,t,r){let o=l(t),i=n.componentBitFor.get(o.id);if(i===void 0)return;let a=n.componentStorageByBit[i];if(a){if(o.kind==="soa"&&a.soa){if(r==null)return;let s=r;for(let c of o.fields){if(!(c.name in s))continue;let u=a.soa[c.name];if(!u)continue;let d=s[c.name];if(c.vectorLen===1)u[e]=typeof d=="boolean"?d?1:0:Number(d);else if(Array.isArray(d)||ArrayBuffer.isView(d)){let y=e*c.vectorLen,ue=d;for(let S=0;S<c.vectorLen;S++)u[y+S]=Number(ue[S]??0);}}}else if(o.kind==="aos"&&a.aos){let s=o.factory??(()=>({})),c=a.aos[e];c===void 0&&(c=s(),a.aos[e]=c),r&&typeof r=="object"&&Object.assign(c,r);}}}function X(n,e,t){for(let r of e){let o=n[r.name];if(o)if(r.vectorLen===1)o[t]=0;else {let i=t*r.vectorLen;for(let a=0;a<r.vectorLen;a++)o[i+a]=0;}}}function Z(n,e){let t=n.options.maskWordCount,r=e,o=r*t;V(n.entityMask,o,t,i=>{let a=n.componentStorageByBit[i],s=n.componentInfoByBit[i];a?.kind==="soa"&&a.soa&&s?X(a.soa,s.fields,r):a?.kind==="aos"&&a.aos&&(a.aos[r]=void 0);});}function J(n,e,t){let r=n.entityArchetype[e]??0,o=n.archetypes[r];if(!o)return;let a=H(n,t).archId,s=n.archetypes[a];if(s){if(a!==r){let c=o.entityRow.get(e);if(c!==void 0){let d=o.size-1;if(c!==d){let y=o.entities[d]??0;o.entities[c]=y,o.entityRow.set(y,c);}o.entities[d]=0,o.entityRow.delete(e),o.size--;}M(s,s.size+1);let u=s.size;s.entities[u]=e,s.entityRow.set(e,u),s.size++,n.entityArchetype[e]=a;}K(n,e,t);}}var ee=()=>{};function ne(n){ee=n;}function te(n,e,t,r,o){ee(n,e,t,r,o);}function re(n){return w.get(n)}var z=1,m=new Map;function $e(n){let e=(n.all??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-"),t=(n.any??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-"),r=(n.none??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-");return `A${e}|Y${t}|N${r}`}function He(n){let e=Array.isArray(n)?{all:n}:n;for(let i of [...e.all??[],...e.any??[],...e.none??[]])if(!i||typeof i!="object"||typeof i.__id!="number")throw new TypeError("aiecsjs: defineQuery received a non-component value");let t=$e(e),r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:(e.all??[]).map(i=>i.__id),any:(e.any??[]).map(i=>i.__id),none:(e.none??[]).map(i=>i.__id),columnViewCache:[...e.all??[],...e.any??[]],reactiveKind:"normal",sourceQueryId:-1,sourceQuery:null};return m.set(t,o),o}function Ke(n){let e=n,t=`enter:${e.id}`,r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"enter",sourceQueryId:e.id,sourceQuery:e};return m.set(t,o),o}function Ne(n){let e=n,t=`exit:${e.id}`,r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"exit",sourceQueryId:e.id,sourceQuery:e};return m.set(t,o),o}function v(n,e){if(n.queries[e.id]===e&&n.queryMasks.has(e.id))return;let t=n.options.maskWordCount,r=b(t),o=b(t),i=b(t);for(let c of e.all){let u=F(c),d=A(n,u);h(r,d);}for(let c of e.any){let u=F(c),d=A(n,u);h(o,d);}for(let c of e.none){let u=F(c),d=A(n,u);h(i,d);}let a={withMask:r,anyMask:o,noneMask:i,anyHasBits:!q(o)};n.queryMasks.set(e.id,a),n.queries[e.id]=e,n.queryArchetypeCache[e.id]=null,n.queryArchetypeStamp[e.id]=-1;let s=[...B(r),...B(o),...B(i)];for(let c of s){let u=n.bitToQueries.get(c);u||(u=new Set,n.bitToQueries.set(c,u)),u.add(e.id);}e.reactiveKind!=="normal"&&(n.reactiveBuffers.has(e.id)||n.reactiveBuffers.set(e.id,{entered:[],exited:[]}),e.sourceQuery&&v(n,e.sourceQuery));}function _(n,e){if(v(n,e),n.queryArchetypeCache[e.id]&&n.queryArchetypeStamp[e.id]===n.queryVersion)return n.queryArchetypeCache[e.id];let t=n.queryMasks.get(e.id),r=n.options.maskWordCount,o=[];for(let i=0;i<n.archetypes.length;i++){let a=n.archetypes[i];E(a.mask,t.withMask,t.anyMask,t.noneMask,t.anyHasBits,r)&&o.push(i);}return n.queryArchetypeCache[e.id]=o,n.queryArchetypeStamp[e.id]=n.queryVersion,o}function Ge(n,e){let t=f(n),o=_(t,e),i=[];for(let a of o){let s=t.archetypes[a];i.push({id:s.id,mask:Array.from(s.mask),size:s.size});}return i}function Ye(n,e){let t=f(n),r=e,o=[];if(r.reactiveKind==="enter"){let a=t.reactiveBuffers.get(r.id);if(a){for(let s of a.entered)o.push(s);a.entered.length=0;}return o}if(r.reactiveKind==="exit"){let a=t.reactiveBuffers.get(r.id);if(a){for(let s of a.exited)o.push(s);a.exited.length=0;}return o}let i=_(t,r);for(let a of i){let s=t.archetypes[a];for(let c=0;c<s.size;c++)o.push(s.entities[c]);}return o}function*Ze(n,e){let t=f(n),r=e;if(r.reactiveKind!=="normal"){let i=t.reactiveBuffers.get(r.id);if(!i)return;let a=r.reactiveKind==="enter"?i.entered:i.exited;for(let s of a)yield s;a.length=0;return}let o=_(t,r);for(let i of o){let a=t.archetypes[i];for(let s=0;s<a.size;s++)yield a.entities[s];}}function Xe(n,e,t){let r=f(n),o=e;if(o.reactiveKind!=="normal"){let s=r.reactiveBuffers.get(o.id);if(!s)return;let c=o.reactiveKind==="enter"?s.entered:s.exited;if(c.length===0)return;let u=ie(r,o);for(let d=0;d<c.length;d++){let y=c[d];oe(t,y,u);}c.length=0;return}v(r,o);let i=_(r,o),a=ie(r,o);for(let s of i){let c=r.archetypes[s],u=c.entities,d=c.size;for(let y=0;y<d;y++)oe(t,u[y],a);}}function oe(n,e,t){switch(t.length){case 0:n(e);break;case 1:n(e,t[0]);break;case 2:n(e,t[0],t[1]);break;case 3:n(e,t[0],t[1],t[2]);break;case 4:n(e,t[0],t[1],t[2],t[3]);break;case 5:n(e,t[0],t[1],t[2],t[3],t[4]);break;default:n(e,...t);}}function ie(n,e){let t=[];for(let r of e.columnViewCache){let o=l(r),i=n.componentBitFor.get(o.id);if(i===void 0){t.push(void 0);continue}let a=n.componentStorageByBit[i];if(!a){t.push(void 0);continue}a.kind==="soa"?t.push(a.soa):a.kind==="aos"?t.push(a.aos):t.push(true);}return t}function se(n,e,t,r,o){for(let s of m.values())s.reactiveKind!=="normal"&&s.sourceQuery&&n.queries[s.sourceQuery.id]!==s.sourceQuery&&v(n,s.sourceQuery);let i=n.bitToQueries.get(t);if(!i)return;let a=n.options.maskWordCount;for(let s of i){let c=n.queries[s];if(!c||c.reactiveKind!=="normal")continue;let u=n.queryMasks.get(s);if(!u)continue;let d=E(r,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,a),y=E(o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,a);!d&&y?ae(n,s,"enter",e):d&&!y&&ae(n,s,"exit",e);}}function ae(n,e,t,r){for(let o of m.values()){if(o.sourceQueryId!==e||o.reactiveKind!==t)continue;v(n,o);let i=Je(n,o.id);t==="enter"?i.entered.push(r):i.exited.push(r);}}function Je(n,e){let t=n.reactiveBuffers.get(e);return t||(t={entered:[],exited:[]},n.reactiveBuffers.set(e,t)),t}function F(n){let e=en(n);if(!e)throw new Error(`aiecsjs: component id ${n} not registered`);return e}var j=null;function ce(n){j=n;}function en(n){return j?j(n):void 0}var nn={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function tn(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,t)=>{let r=e;for(let o of n)r=o(r,t);return r}}ce(n=>re(n));ne((n,e,t,r,o)=>{se(n,e,t,r,o);});var Bn=typeof SharedArrayBuffer<"u";exports.IS_SAB_SUPPORTED=Bn;exports.Types=nn;exports.VERSION=U;exports.addComponent=Q;exports.createEntity=Se;exports.createWorld=be;exports.defineComponent=Re;exports.defineObjectComponent=Le;exports.defineQuery=He;exports.defineTag=Te;exports.destroyEntity=Ee;exports.destroyWorld=Ce;exports.enterQuery=Ke;exports.entityExists=Y;exports.exitQuery=Ne;exports.forEachEntity=Xe;exports.getComponent=ze;exports.getEntityGeneration=We;exports.getEntityIndex=Be;exports.getWorldCapacity=ge;exports.getWorldSize=xe;exports.hasComponent=je;exports.isEntity=_e;exports.isWorld=ve;exports.iterQuery=Ze;exports.packEntity=Me;exports.pipe=tn;exports.queryArchetypes=Ge;exports.removeComponent=Fe;exports.resetWorld=Ae;exports.runQuery=Ye;exports.setComponent=De;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var U="0.2.0";function b(n){return new Uint32Array(n)}function h(n,e){let t=e>>>5;n[t]=(n[t]??0)|1<<(e&31);}function D(n,e){let t=e>>>5;n[t]=(n[t]??0)&~(1<<(e&31));}function C(n,e){let t=e>>>5;return ((n[t]??0)&1<<(e&31))!==0}function g(n){let e=new Uint32Array(n.length);for(let t=0;t<n.length;t++)e[t]=n[t]??0;return e}function O(n){let e=[];for(let t=0;t<n.length;t++)e.push((n[t]??0).toString(16));return e.join(",")}function q(n){for(let e=0;e<n.length;e++)if((n[e]??0)!==0)return false;return true}function E(n,e,t,r,o,i){let s=!o;for(let a=0;a<i;a++){let c=n[a]??0,u=e[a]??0,d=t[a]??0,y=r[a]??0;if((c&u)!==u||(c&y)!==0)return false;!s&&(c&d)!==0&&(s=true);}return s}function W(n){let e=[];for(let t=0;t<n.length;t++){let r=n[t]??0;for(;r!==0;){let o=(t<<5)+P(r);e.push(o),r&=r-1;}}return e}function V(n,e,t,r){for(let o=0;o<t;o++){let i=n[e+o]??0;for(;i!==0;){let s=(o<<5)+P(i);r(s),i&=i-1;}}}function P(n){return 31-Math.clz32(n&-n)}var B={initialCapacity:1024,maxEntities:1e6,indexBits:24,generationBits:8},ye=256,fe=1,k=new Map;function f(n){let e=k.get(n.id);if(!e)throw new Error(`aiecsjs: world ${n.id} is destroyed or unknown`);if(e.destroyed)throw new Error(`aiecsjs: world ${n.id} is destroyed`);return e}function pe(n){k.set(n.id,n);}function le(n){k.delete(n);}function me(n){let e=n??{},t=e.indexBits??B.indexBits,r=e.generationBits??B.generationBits,o=ye;if(t<1||t>24)throw new Error("aiecsjs: indexBits must be in [1, 24]");if(r<0||r>16)throw new Error("aiecsjs: generationBits must be in [0, 16]");let i=1<<t,s=Math.max(1,Math.min(e.initialCapacity??B.initialCapacity,i)),a=Math.max(s,Math.min(e.maxEntities??B.maxEntities,i));return {initialCapacity:s,maxEntities:a,indexBits:t,generationBits:r,maxComponents:o,maskWordCount:Math.ceil(o/32),buffer:e.buffer??null,bufferByteOffset:e.bufferByteOffset??0}}function be(n,e){return {id:0,mask:b(n),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:[],edgeAdd:new Int32Array(e).fill(-1),edgeRemove:new Int32Array(e).fill(-1)}}function he(n){let e=me(n),t=fe++,r=e.generationBits>8?Uint16Array:Uint8Array,o=new r(e.initialCapacity),i={id:t,capacity:e.initialCapacity,version:U,options:e,size:0,nextFreshIndex:1,freeList:[],generations:o,destroyed:false,componentBitFor:new Map,componentInfoByBit:new Array(e.maxComponents).fill(null),componentStorageByBit:new Array(e.maxComponents).fill(null),nextComponentBit:0,entityArchetype:new Uint32Array(e.initialCapacity),entityMask:new Uint32Array(e.initialCapacity*e.maskWordCount),archetypes:[],archetypeByMaskHash:new Map,queryVersion:0,queries:[],queryMasks:new Map,queryArchetypeCache:[],queryArchetypeStamp:[],bitToQueries:new Map,reactiveBuffers:new Map,observers:[],relationStorage:new Map,sab:e.buffer,readOnly:false},s=be(e.maskWordCount,e.maxComponents);return s.id=0,i.archetypes.push(s),i.archetypeByMaskHash.set(O(s.mask),0),pe(i),Ce(i)}function Ce(n){return {id:n.id,get capacity(){return n.capacity},version:n.version}}function $(n){let e=k.get(n.id);!e||e.destroyed||(e.destroyed=true,e.archetypes=[],e.archetypeByMaskHash.clear(),e.componentInfoByBit=[],e.componentStorageByBit=[],e.queries=[],e.queryMasks.clear(),e.queryArchetypeCache=[],e.observers=[],e.relationStorage.clear(),e.reactiveBuffers.clear(),le(n.id));}function Ae(n){let e=f(n);e.size=0,e.nextFreshIndex=1,e.freeList=[],e.generations.fill(0),e.entityArchetype.fill(0),e.entityMask.fill(0);for(let t of e.archetypes)t.size=0,t.entityRow.clear();for(let t of e.componentStorageByBit)if(t)if(t.kind==="soa"&&t.soa)for(let r of Object.keys(t.soa))t.soa[r]?.fill(0);else t.kind==="aos"&&t.aos&&t.aos.fill(void 0);e.queryVersion++;for(let t of e.reactiveBuffers.values())t.entered.length=0,t.exited.length=0;}function xe(n){return f(n).size}function ge(n){return f(n).capacity}function H(n,e){if(e<=n.capacity)return;if(e>n.options.maxEntities)throw new Error(`aiecsjs: requested capacity ${e} exceeds maxEntities ${n.options.maxEntities}`);let t=n.capacity;for(;t<e;)t=Math.min(t*2,n.options.maxEntities);ke(n,t);}function ke(n,e){let t=n.generations.constructor,r=new t(e);r.set(n.generations),n.generations=r;let o=new Uint32Array(e);o.set(n.entityArchetype),n.entityArchetype=o;let i=n.options.maskWordCount,s=new Uint32Array(e*i);s.set(n.entityMask),n.entityMask=s;for(let a of n.componentStorageByBit)if(a)if(a.kind==="soa"&&a.soa){let c=n.componentInfoByBit[a.bit];c&&Ie(a.soa,c.fields,e);}else a.kind==="aos"&&a.aos&&(a.aos.length=e);n.capacity=e;}function Ie(n,e,t){for(let r of e){let o=n[r.name];if(!o)continue;let i=t*r.vectorLen;if(o.length>=i)continue;let s=new r.ctor(i);s.set(o),n[r.name]=s;}}function K(n,e){let t=O(e),r=n.archetypeByMaskHash.get(t);if(r!==void 0)return {archId:r,created:false};let o=n.archetypes.length,i={id:o,mask:g(e),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:we(e),edgeAdd:new Int32Array(n.options.maxComponents).fill(-1),edgeRemove:new Int32Array(n.options.maxComponents).fill(-1)};return n.archetypes.push(i),n.archetypeByMaskHash.set(t,o),n.queryVersion++,{archId:o,created:true}}function M(n,e){if(e<=n.capacity)return;let t=n.capacity;for(;t<e;)t*=2;let r=new Uint32Array(t);r.set(n.entities),n.entities=r,n.capacity=t;}function we(n){let e=[];for(let t=0;t<n.length;t++){let r=n[t]??0;for(;r!==0;){let o=r&-r,i=(t<<5)+(31-Math.clz32(o));e.push(i),r&=r-1;}}return e}function A(n,e){let t=n.componentBitFor.get(e.id);if(t!==void 0)return t;if(n.nextComponentBit>=n.options.maxComponents)throw new Error(`aiecsjs: world reached maxComponents=${n.options.maxComponents}`);let r=n.nextComponentBit++;n.componentBitFor.set(e.id,r),n.componentInfoByBit[r]=e;let o;if(e.kind==="soa"){let i={};for(let s of e.fields)i[s.name]=new s.ctor(n.capacity*s.vectorLen);o={kind:"soa",componentId:e.id,bit:r,soa:i};}else e.kind==="aos"?o={kind:"aos",componentId:e.id,bit:r,aos:new Array(n.capacity)}:o={kind:"tag",componentId:e.id,bit:r};return n.componentStorageByBit[r]=o,r}function x(n,e){let t=n.options.maskWordCount,r=new Uint32Array(t),o=e*t;for(let i=0;i<t;i++)r[i]=n.entityMask[o+i]??0;return r}function N(n,e,t){let r=n.options.maskWordCount,o=e*r;for(let i=0;i<r;i++)n.entityMask[o+i]=t[i]??0;}function I(n,e){return n.componentBitFor.get(e.id)}function ve(n){if(!n||typeof n!="object")return false;let e=n;return typeof e.id!="number"||typeof e.version!="string"?false:k.has(e.id)}function Se(n){let e=f(n);if(e.readOnly)throw new Error("aiecsjs: cannot createEntity on a read-only world (worker-attached)");let t;if(e.freeList.length>0)t=e.freeList.pop();else {if(e.nextFreshIndex>=e.options.maxEntities)throw new Error(`aiecsjs: reached maxEntities ${e.options.maxEntities}`);e.nextFreshIndex>=e.capacity&&H(e,e.nextFreshIndex+1),t=e.nextFreshIndex++;}let r=e.archetypes[0];if(!r)throw new Error("aiecsjs: missing empty archetype");M(r,r.size+1);let o=r.size;r.entities[o]=t,r.entityRow.set(t,o),r.size++,e.entityArchetype[t]=0;let i=e.options.maskWordCount,s=t*i;for(let a=0;a<i;a++)e.entityMask[s+a]=0;return e.size++,t}function Ee(n,e){let t=f(n);if(t.readOnly)throw new Error("aiecsjs: cannot destroyEntity on a read-only world");if(!p(t,e))return;X(t,e);let o=t.entityArchetype[e]??0,i=t.archetypes[o];if(i){let u=i.entityRow.get(e);if(u!==void 0){let d=i.size-1;if(u!==d){let y=i.entities[d]??0;i.entities[u]=y,i.entityRow.set(y,u);}i.entities[d]=0,i.entityRow.delete(e),i.size--;}}t.entityArchetype[e]=0;let s=t.options.maskWordCount,a=e*s;for(let u=0;u<s;u++)t.entityMask[a+u]=0;let c=e;t.generations[c]=(t.generations[c]??0)+1&65535,t.freeList.push(e),t.size--;}function Z(n,e){let t=f(n);return p(t,e)}function p(n,e){if(e<=0||e>=n.capacity)return false;let t=n.entityArchetype[e]??0,r=n.archetypes[t];return r?r.entityRow.has(e):false}function We(n){return n}function Be(n){return 0}function Me(n,e){return n}function _e(n,e){return typeof e!="number"?false:Z(n,e)}var T=1,Qe={i8:Int8Array,u8:Uint8Array,i16:Int16Array,u16:Uint16Array,i32:Int32Array,u32:Uint32Array,f32:Float32Array,f64:Float64Array,eid:Uint32Array,bool:Uint8Array},w=new Map;function Re(n){let e=[];for(let[i,s]of Object.entries(n)){let a,c=1;if(typeof s=="string")a=s;else if(Array.isArray(s)){let[d,y]=s;a=d,c=y;}else throw new TypeError(`aiecsjs: invalid field declaration for "${i}"`);let u=Qe[a];if(!u)throw new TypeError(`aiecsjs: unknown field type "${a}" for field "${i}"`);e.push({name:i,type:a,vectorLen:c,ctor:u,bytesPerElement:u.BYTES_PER_ELEMENT});}let t=T++,r={id:t,kind:"soa",schema:n,fields:e,factory:null};return w.set(t,r),{__kind:"soa",__id:t,__schema:n}}function Te(){let n=T++,e={id:n,kind:"tag",schema:null,fields:[],factory:null};return w.set(n,e),{__kind:"tag",__id:n}}function Le(n){let e=T++,t=n??(()=>({})),r={id:e,kind:"aos",schema:null,fields:[],factory:t};return w.set(e,r),{__kind:"aos",__id:e,__factory:t}}function l(n){let e=w.get(n.__id);if(!e)throw new Error("aiecsjs: component is not registered (call defineComponent/defineTag/defineObjectComponent)");return e}function Q(n,e,t,r){let o=f(n);if(o.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(o,e))throw new Error(`aiecsjs: addComponent on dead entity ${e}`);let i=l(t),s=A(o,i),a=x(o,e);if(C(a,s)){r!==void 0&&R(o,e,t,r);return}let c=g(a);h(c,s),ee(o,e,c),R(o,e,t,r),re(o,e,s,a,c);}function je(n,e,t){let r=f(n);if(r.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(r,e))return;let o=l(t),i=I(r,o);if(i===void 0)return;let s=x(r,e);if(!C(s,i))return;let a=g(s);D(a,i),ee(r,e,a);let c=r.componentStorageByBit[i];c?.kind==="soa"&&c.soa?J(c.soa,o.fields,e):c?.kind==="aos"&&c.aos&&(c.aos[e]=void 0),re(r,e,i,s,a);}function Fe(n,e,t){let r=f(n);if(!p(r,e))return false;let o=l(t),i=I(r,o);if(i===void 0)return false;let s=x(r,e);return C(s,i)}function ze(n,e,t){let r=f(n);if(!p(r,e))return;let o=l(t),i=I(r,o);if(i===void 0)return;let s=x(r,e);if(!C(s,i))return;let a=r.componentStorageByBit[i];if(a)return a.kind==="soa"?a.soa:a.kind==="aos"?a.aos?.[e]:true}function De(n,e,t,r){let o=f(n);if(o.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!p(o,e))throw new Error(`aiecsjs: setComponent on dead entity ${e}`);let i=l(t),s=I(o,i);if(s===void 0){Q(n,e,t,r);return}let a=x(o,e);if(!C(a,s)){Q(n,e,t,r);return}R(o,e,t,r);}function R(n,e,t,r){let o=l(t),i=n.componentBitFor.get(o.id);if(i===void 0)return;let s=n.componentStorageByBit[i];if(s){if(o.kind==="soa"&&s.soa){if(r==null)return;let a=r;for(let c of o.fields){if(!(c.name in a))continue;let u=s.soa[c.name];if(!u)continue;let d=a[c.name];if(c.vectorLen===1)u[e]=typeof d=="boolean"?d?1:0:Number(d);else if(Array.isArray(d)||ArrayBuffer.isView(d)){let y=e*c.vectorLen,de=d;for(let S=0;S<c.vectorLen;S++)u[y+S]=Number(de[S]??0);}}}else if(o.kind==="aos"&&s.aos){let a=o.factory??(()=>({})),c=s.aos[e];if(c===void 0&&(c=a(),s.aos[e]=c),r&&typeof r=="object"){let u=r,d=c;for(let y of Object.keys(u))y==="__proto__"||y==="constructor"||y==="prototype"||(d[y]=u[y]);}}}}function J(n,e,t){for(let r of e){let o=n[r.name];if(o)if(r.vectorLen===1)o[t]=0;else {let i=t*r.vectorLen;for(let s=0;s<r.vectorLen;s++)o[i+s]=0;}}}function X(n,e){let t=n.options.maskWordCount,r=e,o=r*t;V(n.entityMask,o,t,i=>{let s=n.componentStorageByBit[i],a=n.componentInfoByBit[i];s?.kind==="soa"&&s.soa&&a?J(s.soa,a.fields,r):s?.kind==="aos"&&s.aos&&(s.aos[r]=void 0);});}function ee(n,e,t){let r=n.entityArchetype[e]??0,o=n.archetypes[r];if(!o)return;let s=K(n,t).archId,a=n.archetypes[s];if(a){if(s!==r){let c=o.entityRow.get(e);if(c!==void 0){let d=o.size-1;if(c!==d){let y=o.entities[d]??0;o.entities[c]=y,o.entityRow.set(y,c);}o.entities[d]=0,o.entityRow.delete(e),o.size--;}M(a,a.size+1);let u=a.size;a.entities[u]=e,a.entityRow.set(e,u),a.size++,n.entityArchetype[e]=s;}N(n,e,t);}}var ne=()=>{};function te(n){ne=n;}function re(n,e,t,r,o){ne(n,e,t,r,o);}function oe(n){return w.get(n)}var z=1,m=new Map;function $e(n){let e=(n.all??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-"),t=(n.any??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-"),r=(n.none??[]).map(o=>o.__id).sort((o,i)=>o-i).join("-");return `A${e}|Y${t}|N${r}`}function He(n){let e=Array.isArray(n)?{all:n}:n;for(let i of [...e.all??[],...e.any??[],...e.none??[]])if(!i||typeof i!="object"||typeof i.__id!="number")throw new TypeError("aiecsjs: defineQuery received a non-component value");let t=$e(e),r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:(e.all??[]).map(i=>i.__id),any:(e.any??[]).map(i=>i.__id),none:(e.none??[]).map(i=>i.__id),columnViewCache:[...e.all??[],...e.any??[]],reactiveKind:"normal",sourceQueryId:-1,sourceQuery:null};return m.set(t,o),o}function Ke(n){let e=n,t=`enter:${e.id}`,r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"enter",sourceQueryId:e.id,sourceQuery:e};return m.set(t,o),o}function Ne(n){let e=n,t=`exit:${e.id}`,r=m.get(t);if(r)return r;let o={id:z++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"exit",sourceQueryId:e.id,sourceQuery:e};return m.set(t,o),o}function v(n,e){if(n.queries[e.id]===e&&n.queryMasks.has(e.id))return;let t=n.options.maskWordCount,r=b(t),o=b(t),i=b(t);for(let c of e.all){let u=j(c),d=A(n,u);h(r,d);}for(let c of e.any){let u=j(c),d=A(n,u);h(o,d);}for(let c of e.none){let u=j(c),d=A(n,u);h(i,d);}let s={withMask:r,anyMask:o,noneMask:i,anyHasBits:!q(o)};n.queryMasks.set(e.id,s),n.queries[e.id]=e,n.queryArchetypeCache[e.id]=null,n.queryArchetypeStamp[e.id]=-1;let a=[...W(r),...W(o),...W(i)];for(let c of a){let u=n.bitToQueries.get(c);u||(u=new Set,n.bitToQueries.set(c,u)),u.add(e.id);}e.reactiveKind!=="normal"&&(n.reactiveBuffers.has(e.id)||n.reactiveBuffers.set(e.id,{entered:[],exited:[]}),e.sourceQuery&&v(n,e.sourceQuery));}function _(n,e){if(v(n,e),n.queryArchetypeCache[e.id]&&n.queryArchetypeStamp[e.id]===n.queryVersion)return n.queryArchetypeCache[e.id];let t=n.queryMasks.get(e.id),r=n.options.maskWordCount,o=[];for(let i=0;i<n.archetypes.length;i++){let s=n.archetypes[i];E(s.mask,t.withMask,t.anyMask,t.noneMask,t.anyHasBits,r)&&o.push(i);}return n.queryArchetypeCache[e.id]=o,n.queryArchetypeStamp[e.id]=n.queryVersion,o}function Ge(n,e){let t=f(n),o=_(t,e),i=[];for(let s of o){let a=t.archetypes[s];i.push({id:a.id,mask:Array.from(a.mask),size:a.size});}return i}function Ye(n,e){let t=f(n),r=e,o=[];if(r.reactiveKind==="enter"){let s=t.reactiveBuffers.get(r.id);if(s){for(let a of s.entered)o.push(a);s.entered.length=0;}return o}if(r.reactiveKind==="exit"){let s=t.reactiveBuffers.get(r.id);if(s){for(let a of s.exited)o.push(a);s.exited.length=0;}return o}let i=_(t,r);for(let s of i){let a=t.archetypes[s];for(let c=0;c<a.size;c++)o.push(a.entities[c]);}return o}function*Ze(n,e){let t=f(n),r=e;if(r.reactiveKind!=="normal"){let i=t.reactiveBuffers.get(r.id);if(!i)return;let s=r.reactiveKind==="enter"?i.entered:i.exited;for(let a of s)yield a;s.length=0;return}let o=_(t,r);for(let i of o){let s=t.archetypes[i];for(let a=0;a<s.size;a++)yield s.entities[a];}}function Xe(n,e,t){let r=f(n),o=e;if(o.reactiveKind!=="normal"){let a=r.reactiveBuffers.get(o.id);if(!a)return;let c=o.reactiveKind==="enter"?a.entered:a.exited;if(c.length===0)return;let u=se(r,o);for(let d=0;d<c.length;d++){let y=c[d];ie(t,y,u);}c.length=0;return}v(r,o);let i=_(r,o),s=se(r,o);for(let a of i){let c=r.archetypes[a],u=c.entities,d=c.size;for(let y=0;y<d;y++)ie(t,u[y],s);}}function ie(n,e,t){switch(t.length){case 0:n(e);break;case 1:n(e,t[0]);break;case 2:n(e,t[0],t[1]);break;case 3:n(e,t[0],t[1],t[2]);break;case 4:n(e,t[0],t[1],t[2],t[3]);break;case 5:n(e,t[0],t[1],t[2],t[3],t[4]);break;default:n(e,...t);}}function se(n,e){let t=[];for(let r of e.columnViewCache){let o=l(r),i=n.componentBitFor.get(o.id);if(i===void 0){t.push(void 0);continue}let s=n.componentStorageByBit[i];if(!s){t.push(void 0);continue}s.kind==="soa"?t.push(s.soa):s.kind==="aos"?t.push(s.aos):t.push(true);}return t}function ce(n,e,t,r,o){for(let a of m.values())a.reactiveKind!=="normal"&&a.sourceQuery&&n.queries[a.sourceQuery.id]!==a.sourceQuery&&v(n,a.sourceQuery);let i=n.bitToQueries.get(t);if(!i)return;let s=n.options.maskWordCount;for(let a of i){let c=n.queries[a];if(!c||c.reactiveKind!=="normal")continue;let u=n.queryMasks.get(a);if(!u)continue;let d=E(r,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,s),y=E(o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,s);!d&&y?ae(n,a,"enter",e):d&&!y&&ae(n,a,"exit",e);}}function ae(n,e,t,r){for(let o of m.values()){if(o.sourceQueryId!==e||o.reactiveKind!==t)continue;v(n,o);let i=Je(n,o.id);t==="enter"?i.entered.push(r):i.exited.push(r);}}function Je(n,e){let t=n.reactiveBuffers.get(e);return t||(t={entered:[],exited:[]},n.reactiveBuffers.set(e,t)),t}function j(n){let e=en(n);if(!e)throw new Error(`aiecsjs: component id ${n} not registered`);return e}var F=null;function ue(n){F=n;}function en(n){return F?F(n):void 0}var nn={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function tn(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,t)=>{let r=e;for(let o of n)r=o(r,t);return r}}ue(n=>oe(n));te((n,e,t,r,o)=>{ce(n,e,t,r,o);});var Wn=typeof SharedArrayBuffer<"u";exports.IS_SAB_SUPPORTED=Wn;exports.Types=nn;exports.VERSION=U;exports.addComponent=Q;exports.createEntity=Se;exports.createWorld=he;exports.defineComponent=Re;exports.defineObjectComponent=Le;exports.defineQuery=He;exports.defineTag=Te;exports.destroyEntity=Ee;exports.destroyWorld=$;exports.disposeWorld=$;exports.enterQuery=Ke;exports.entityExists=Z;exports.exitQuery=Ne;exports.forEachEntity=Xe;exports.getComponent=ze;exports.getEntityGeneration=Be;exports.getEntityIndex=We;exports.getWorldCapacity=ge;exports.getWorldSize=xe;exports.hasComponent=Fe;exports.isEntity=_e;exports.isWorld=ve;exports.iterQuery=Ze;exports.packEntity=Me;exports.pipe=tn;exports.queryArchetypes=Ge;exports.removeComponent=je;exports.resetWorld=Ae;exports.runQuery=Ye;exports.setComponent=De;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|