aiecsjs 0.2.0 → 0.2.1
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 +15 -0
- package/README.md +6 -6
- package/README_ZHTW.md +6 -6
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/serialize.cjs +1 -1
- package/dist/serialize.cjs.map +1 -1
- package/dist/serialize.js +1 -1
- package/dist/serialize.js.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/llms-full.txt +21 -6
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
15
15
|
- Doc-test harness so README code blocks are mechanically verified.
|
|
16
16
|
- Promote `aiecsjs/relations` and `aiecsjs/worker` (true SAB-shared columns) to `stable`.
|
|
17
17
|
|
|
18
|
+
## [0.2.1] - 2026-05-28
|
|
19
|
+
|
|
20
|
+
### Security
|
|
21
|
+
|
|
22
|
+
- **Resolve two Dependabot moderate advisories** on the transitive dev-only graph by upgrading `vitest` 1.6.0 → 4.1.7. Adds `vite` 8.0.14 as a direct devDependency to satisfy vitest 4's peer range (`^6 || ^7 || ^8`). These are dev-only — runtime surface unchanged.
|
|
23
|
+
- [GHSA-67mh-4wv8-2f99](https://github.com/advisories/GHSA-67mh-4wv8-2f99) `esbuild <=0.24.2` CORS development server data leak (fixed in 0.25.0).
|
|
24
|
+
- [GHSA-4w7w-66w2-5vf9](https://github.com/advisories/GHSA-4w7w-66w2-5vf9) `vite <=6.4.1` path traversal in optimized deps `.map` handling (fixed in 6.4.2 / 7.3.2 / 8.0.5).
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **README opening unified across the ai*js family**: five-badge shields row (npm + CI + License + AI Generated + 繁體中文/English), one-line tagline as blockquote, ecosystem footer linking to the other two packages. Replaces the previous mixed style (text language switcher + 5 ad-hoc badges).
|
|
29
|
+
- **`VERSION` constant bumped to 0.2.1** ([src/version.ts](src/version.ts)) so `world.version` and snapshot meta reflect this release.
|
|
30
|
+
|
|
31
|
+
Runtime surface unchanged. Production bundles are byte-identical to 0.2.0.
|
|
32
|
+
|
|
18
33
|
## [0.2.0] - 2026-05-28
|
|
19
34
|
|
|
20
35
|
### Fixed (correctness + security)
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# aiecsjs
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/aiecsjs)
|
|
4
|
+
[](https://github.com/yshengliao/aiecsjs/actions/workflows/ci.yml)
|
|
5
5
|
[](LICENSE)
|
|
6
|
-

|
|
7
|
-

|
|
9
|
-

|
|
6
|
+
[](https://www.anthropic.com/claude-code)
|
|
7
|
+
[](README_ZHTW.md)
|
|
10
8
|
|
|
11
9
|
> A TypeScript-first archetype ECS for browser and Node, with SAB-ready snapshot transport and AI-readable documentation.
|
|
12
10
|
|
|
11
|
+
Part of the [ai\*js micro-runtime ecosystem](https://github.com/yshengliao) — see also [aifsmjs](https://github.com/yshengliao/aifsmjs) (FSM) and [aibridgejs](https://github.com/yshengliao/aibridgejs) (cross-context RPC).
|
|
12
|
+
|
|
13
13
|
aiecsjs uses **archetype tables with TypedArray columns** and **bitmask queries** — the same architecture that powers piecs and wolf-ecs at the top of public benchmarks. Its API is **functional and tree-shakable**, composed with `pipe()`. Components support both Structure-of-Arrays (SoA) and Array-of-Structures (AoS) layouts. Entity IDs in 0.x are bare slot indices; internal generation tracks slot reuse but is not encoded in the ID. ABA-safe `EntityRef` is targeted for **0.3+** (deferred from the 0.2 roadmap once the v0.2.0 scope froze on API stability + safety).
|
|
14
14
|
|
|
15
15
|
```ts
|
package/README_ZHTW.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# aiecsjs
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/aiecsjs)
|
|
4
|
+
[](https://github.com/yshengliao/aiecsjs/actions/workflows/ci.yml)
|
|
5
5
|
[](LICENSE)
|
|
6
|
-

|
|
7
|
-

|
|
9
|
-

|
|
6
|
+
[](https://www.anthropic.com/claude-code)
|
|
7
|
+
[](README.md)
|
|
10
8
|
|
|
11
9
|
> 為 TypeScript 而設計的原型式 ECS,支援瀏覽器與 Node,內建 SAB 快照傳輸(snapshot transport)與 AI 可讀文件。
|
|
12
10
|
|
|
11
|
+
隸屬 [ai\*js micro-runtime 生態系](https://github.com/yshengliao) ─ 另見 [aifsmjs](https://github.com/yshengliao/aifsmjs)(FSM)與 [aibridgejs](https://github.com/yshengliao/aibridgejs)(cross-context RPC)。
|
|
12
|
+
|
|
13
13
|
aiecsjs 採用 **原型表格搭配 TypedArray 欄位** 與 **位元遮罩查詢**,這正是 piecs 與 wolf-ecs 在公開效能評測中名列前茅所採用的架構。API 為 **函式式且可 tree-shake**,以 `pipe()` 組合。元件(Component)同時支援 SoA(結構陣列)與 AoS(結構物件)兩種佈局。0.x 的實體 ID 為純索引值;世代計數在內部追蹤槽位重用,但不編入 ID。具 ABA 安全的 `EntityRef` 預計 **0.3+** 推出(0.2 為求 API 穩定與安全性收尾而延後)。
|
|
14
14
|
|
|
15
15
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
1
|
+
'use strict';var U="0.2.1";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
|