aiecsjs 0.5.8 → 0.5.9
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/README.md +2 -2
- package/README_ZHTW.md +2 -2
- package/dist/{chunk-3FV6UMUS.cjs → chunk-JDV5JZP2.cjs} +2 -2
- package/dist/{chunk-3FV6UMUS.cjs.map → chunk-JDV5JZP2.cjs.map} +1 -1
- package/dist/chunk-OBMQME2P.js +2 -0
- package/dist/chunk-OBMQME2P.js.map +1 -0
- package/dist/chunk-Q2XLL6YG.cjs +2 -0
- package/dist/chunk-Q2XLL6YG.cjs.map +1 -0
- package/dist/chunk-USHKPJQG.cjs +2 -0
- package/dist/chunk-USHKPJQG.cjs.map +1 -0
- package/dist/chunk-XKN3ULCC.js +2 -0
- package/dist/chunk-XKN3ULCC.js.map +1 -0
- package/dist/{chunk-TNZMD7E5.js → chunk-ZZBNE7C5.js} +2 -2
- package/dist/{chunk-TNZMD7E5.js.map → chunk-ZZBNE7C5.js.map} +1 -1
- package/dist/commands.cjs +1 -1
- package/dist/commands.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/observers.cjs +1 -1
- package/dist/observers.js +1 -1
- package/dist/relations.cjs +1 -1
- package/dist/relations.js +1 -1
- package/dist/serialize.cjs +1 -1
- package/dist/serialize.js +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/llms-full.txt +9 -3
- package/package.json +1 -1
- package/dist/chunk-3ZLNR4JX.cjs +0 -2
- package/dist/chunk-3ZLNR4JX.cjs.map +0 -1
- package/dist/chunk-N5OETPTK.js +0 -2
- package/dist/chunk-N5OETPTK.js.map +0 -1
- package/dist/chunk-YFTCD2UG.js +0 -2
- package/dist/chunk-YFTCD2UG.js.map +0 -1
- package/dist/chunk-ZIZSWIHW.cjs +0 -2
- package/dist/chunk-ZIZSWIHW.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkUSHKPJQG_cjs=require('./chunk-USHKPJQG.cjs'),chunkQ2XLL6YG_cjs=require('./chunk-Q2XLL6YG.cjs');var J={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function X(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function Y(n,e){let r=chunkQ2XLL6YG_cjs.j(n);if(!chunkQ2XLL6YG_cjs.z(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=chunkQ2XLL6YG_cjs.j(n);if(e.worldId!==r.id)return null;let t=e.id,o=chunkQ2XLL6YG_cjs.t(t,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=chunkQ2XLL6YG_cjs.u(t,r.options);return C!==A?null:e.id}function Z(n,e){return b(n,e)!==null}chunkUSHKPJQG_cjs.j(n=>chunkQ2XLL6YG_cjs.R(n));chunkQ2XLL6YG_cjs.P((n,e,r,t,o)=>{chunkUSHKPJQG_cjs.i(n,e,r,t,o);});var me=typeof SharedArrayBuffer<"u";Object.defineProperty(exports,"defineQuery",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.a}});Object.defineProperty(exports,"enterQuery",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.b}});Object.defineProperty(exports,"exitQuery",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.c}});Object.defineProperty(exports,"forEachEntity",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.g}});Object.defineProperty(exports,"forEachEntityIndexed",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.h}});Object.defineProperty(exports,"iterQuery",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.f}});Object.defineProperty(exports,"queryArchetypes",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.d}});Object.defineProperty(exports,"runQuery",{enumerable:true,get:function(){return chunkUSHKPJQG_cjs.e}});Object.defineProperty(exports,"EcsError",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.i}});Object.defineProperty(exports,"VERSION",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.a}});Object.defineProperty(exports,"addComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.K}});Object.defineProperty(exports,"createEntity",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.v}});Object.defineProperty(exports,"createWorld",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.l}});Object.defineProperty(exports,"defineComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.G}});Object.defineProperty(exports,"defineObjectComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.I}});Object.defineProperty(exports,"defineTag",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.H}});Object.defineProperty(exports,"destroyEntity",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.x}});Object.defineProperty(exports,"destroyWorld",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.m}});Object.defineProperty(exports,"disposeWorld",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.m}});Object.defineProperty(exports,"entityExists",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.y}});Object.defineProperty(exports,"getComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.N}});Object.defineProperty(exports,"getEntityGeneration",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.B}});Object.defineProperty(exports,"getEntityIndex",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.A}});Object.defineProperty(exports,"getWorldCapacity",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.p}});Object.defineProperty(exports,"getWorldSize",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.o}});Object.defineProperty(exports,"hasComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.M}});Object.defineProperty(exports,"isEntity",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.D}});Object.defineProperty(exports,"isWorld",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.r}});Object.defineProperty(exports,"packEntity",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.C}});Object.defineProperty(exports,"removeComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.L}});Object.defineProperty(exports,"resetWorld",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.n}});Object.defineProperty(exports,"setComponent",{enumerable:true,get:function(){return chunkQ2XLL6YG_cjs.O}});exports.EntityNotAliveError=i;exports.IS_SAB_SUPPORTED=me;exports.Types=J;exports.aliveRef=Z;exports.deref=b;exports.pipe=X;exports.refOf=Y;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as WorldOptions, W as World, E as EntityId, c as ComponentLike, b as ComponentInit, k as SoASchema, h as SoAComponent, A as AoSComponent, T as TagComponent, f as QueryDescriptor, Q as Query, a as Archetype, l as System } from './types-BeVLA7xG.cjs';
|
|
2
2
|
export { d as ComponentView, g as SoAColumns, i as SoAFieldDecl, j as SoAFieldType, n as Types } from './types-BeVLA7xG.cjs';
|
|
3
3
|
|
|
4
|
-
declare const VERSION = "0.5.
|
|
4
|
+
declare const VERSION = "0.5.9";
|
|
5
5
|
|
|
6
6
|
declare function createWorld(options?: WorldOptions): World;
|
|
7
7
|
declare function destroyWorld(world: World): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as WorldOptions, W as World, E as EntityId, c as ComponentLike, b as ComponentInit, k as SoASchema, h as SoAComponent, A as AoSComponent, T as TagComponent, f as QueryDescriptor, Q as Query, a as Archetype, l as System } from './types-BeVLA7xG.js';
|
|
2
2
|
export { d as ComponentView, g as SoAColumns, i as SoAFieldDecl, j as SoAFieldType, n as Types } from './types-BeVLA7xG.js';
|
|
3
3
|
|
|
4
|
-
declare const VERSION = "0.5.
|
|
4
|
+
declare const VERSION = "0.5.9";
|
|
5
5
|
|
|
6
6
|
declare function createWorld(options?: WorldOptions): World;
|
|
7
7
|
declare function destroyWorld(world: World): void;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {j,i as i$1}from'./chunk-
|
|
1
|
+
import {j,i as i$1}from'./chunk-XKN3ULCC.js';export{a as defineQuery,b as enterQuery,c as exitQuery,g as forEachEntity,h as forEachEntityIndexed,f as iterQuery,d as queryArchetypes,e as runQuery}from'./chunk-XKN3ULCC.js';import {R,P,j as j$1,z,t,u}from'./chunk-OBMQME2P.js';export{i as EcsError,a as VERSION,K as addComponent,v as createEntity,l as createWorld,G as defineComponent,I as defineObjectComponent,H as defineTag,x as destroyEntity,m as destroyWorld,m as disposeWorld,y as entityExists,N as getComponent,B as getEntityGeneration,A as getEntityIndex,p as getWorldCapacity,o as getWorldSize,M as hasComponent,D as isEntity,r as isWorld,C as packEntity,L as removeComponent,n as resetWorld,O as setComponent}from'./chunk-OBMQME2P.js';var J={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function X(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function Y(n,e){let r=j$1(n);if(!z(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=j$1(n);if(e.worldId!==r.id)return null;let t$1=e.id,o=t(t$1,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=u(t$1,r.options);return C!==A?null:e.id}function Z(n,e){return b(n,e)!==null}j(n=>R(n));P((n,e,r,t,o)=>{i$1(n,e,r,t,o);});var me=typeof SharedArrayBuffer<"u";export{i as EntityNotAliveError,me as IS_SAB_SUPPORTED,J as Types,Z as aliveRef,b as deref,X as pipe,Y as refOf};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/observers.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkUSHKPJQG_cjs=require('./chunk-USHKPJQG.cjs'),chunkQ2XLL6YG_cjs=require('./chunk-Q2XLL6YG.cjs');function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e,o,t,r){let s=chunkQ2XLL6YG_cjs.j(n);chunkUSHKPJQG_cjs.e(n,e);let i={event:o,componentBit:-1,queryId:e.id,handler:t};return s.observers.push(i),f(()=>{let d=s.observers.indexOf(i);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=chunkQ2XLL6YG_cjs.j(n),s=chunkQ2XLL6YG_cjs.J(e),i=r.componentBitFor.get(s.id);i===void 0&&(i=chunkQ2XLL6YG_cjs.q(r,s));let u={event:o,componentBit:i,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=chunkQ2XLL6YG_cjs.h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}chunkQ2XLL6YG_cjs.Q({fireAdd:E,fireRemove:M,fireSet:g});chunkQ2XLL6YG_cjs.E({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;chunkQ2XLL6YG_cjs.g(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;chunkQ2XLL6YG_cjs.h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});exports.observe=L;exports.onAdd=w;exports.onRemove=x;exports.onSet=C;//# sourceMappingURL=observers.cjs.map
|
|
2
2
|
//# sourceMappingURL=observers.cjs.map
|
package/dist/observers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {e}from'./chunk-
|
|
1
|
+
import {e}from'./chunk-XKN3ULCC.js';import {Q,E as E$1,g as g$1,h,j,J,q}from'./chunk-OBMQME2P.js';function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e$1,o,t,r){let s=j(n);e(n,e$1);let i={event:o,componentBit:-1,queryId:e$1.id,handler:t};return s.observers.push(i),f(()=>{let d=s.observers.indexOf(i);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=j(n),s=J(e),i=r.componentBitFor.get(s.id);i===void 0&&(i=q(r,s));let u={event:o,componentBit:i,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}Q({fireAdd:E,fireRemove:M,fireSet:g});E$1({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;g$1(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});export{L as observe,w as onAdd,x as onRemove,C as onSet};//# sourceMappingURL=observers.js.map
|
|
2
2
|
//# sourceMappingURL=observers.js.map
|
package/dist/relations.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkQ2XLL6YG_cjs=require('./chunk-Q2XLL6YG.cjs');var m=1;function v(a){return {__kind:"relation",__id:m++,__exclusive:a?.exclusive??false,__hasData:false}}var y=v({exclusive:true});function p(a,l){let o=a.relationStorage.get(l.__id);return o||(o={rel:l,exclusive:l.__exclusive?new Int32Array(a.capacity).fill(-1):null,incoming:l.__exclusive?new Map:null,outgoing:new Map,data:new Map},a.relationStorage.set(l.__id,o),o)}function _(a,l,o){let e=a.incoming;if(!e)return;let n=e.get(o);n||(n=new Set,e.set(o,n)),n.add(l);}function f(a,l,o){let e=a.incoming;if(!e)return;let n=e.get(o);n&&(n.delete(l),n.size===0&&e.delete(o));}function S(a,l,o,e,n){let t=chunkQ2XLL6YG_cjs.j(a);if(t.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let i=p(t,o),s=l&t.options.indexMask,c=e&t.options.indexMask;if(i.exclusive){if(s>=i.exclusive.length){let u=new Int32Array(Math.max(s+1,i.exclusive.length*2)).fill(-1);u.set(i.exclusive),i.exclusive=u;}let r=i.exclusive[s]??-1;if(r>=0&&r!==c){let u=i.data.get(s);u?.delete(r),u&&u.size===0&&i.data.delete(s),f(i,s,r);}i.exclusive[s]=c,r!==c&&_(i,s,c);}else {let r=i.outgoing.get(s);r||(r=[],i.outgoing.set(s,r)),r.includes(c)||r.push(c);}if(n!==void 0){let r=i.data.get(s);r||(r=new Map,i.data.set(s,r)),r.set(c,n);}}function w(a,l,o,e){let n=chunkQ2XLL6YG_cjs.j(a);if(n.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=n.relationStorage.get(o.__id);if(!t)return;let i=l&n.options.indexMask,s=e&n.options.indexMask;if(t.exclusive)i<t.exclusive.length&&t.exclusive[i]===s&&(t.exclusive[i]=-1,f(t,i,s));else {let r=t.outgoing.get(i);if(r){let u=r.indexOf(s);u>=0&&r.splice(u,1),r.length===0&&t.outgoing.delete(i);}}let c=t.data.get(i);c&&(c.delete(s),c.size===0&&t.data.delete(i));}function k(a,l,o){let e=chunkQ2XLL6YG_cjs.j(a),n=e.relationStorage.get(o.__id);if(!n)return [];let t=l&e.options.indexMask;if(n.exclusive){if(t<n.exclusive.length){let s=n.exclusive[t]??-1;if(s>=0){let c=e.generations[s]??0;return [chunkQ2XLL6YG_cjs.s(s,c,e.options)]}}return []}let i=n.outgoing.get(t);return i?i.map(s=>{let c=e.generations[s]??0;return chunkQ2XLL6YG_cjs.s(s,c,e.options)}):[]}function I(a,l,o,e){let n=chunkQ2XLL6YG_cjs.j(a),t=n.relationStorage.get(o.__id);if(!t)return;let i=l&n.options.indexMask,s=e&n.options.indexMask;return t.data.get(i)?.get(s)}chunkQ2XLL6YG_cjs.F((a,l)=>{let o=l&a.options.indexMask;for(let e of a.relationStorage.values()){if(e.exclusive){if(o<e.exclusive.length){let t=e.exclusive[o]??-1;t>=0&&f(e,o,t),e.exclusive[o]=-1;}let n=e.incoming?.get(o);if(n){for(let t of n)t<e.exclusive.length&&(e.exclusive[t]=-1);e.incoming?.delete(o);}}e.outgoing.delete(o);for(let[n,t]of e.outgoing){let i=t.indexOf(o);i>=0&&(t.splice(i,1),t.length===0&&e.outgoing.delete(n));}e.data.delete(o);for(let[n,t]of e.data)t.delete(o),t.size===0&&e.data.delete(n);}});exports.ChildOf=y;exports.addRelation=S;exports.defineRelation=v;exports.getRelationData=I;exports.getRelationTargets=k;exports.removeRelation=w;//# sourceMappingURL=relations.cjs.map
|
|
2
2
|
//# sourceMappingURL=relations.cjs.map
|
package/dist/relations.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {F,j,s}from'./chunk-
|
|
1
|
+
import {F,j,s}from'./chunk-OBMQME2P.js';var m=1;function v(a){return {__kind:"relation",__id:m++,__exclusive:a?.exclusive??false,__hasData:false}}var y=v({exclusive:true});function p(a,l){let o=a.relationStorage.get(l.__id);return o||(o={rel:l,exclusive:l.__exclusive?new Int32Array(a.capacity).fill(-1):null,incoming:l.__exclusive?new Map:null,outgoing:new Map,data:new Map},a.relationStorage.set(l.__id,o),o)}function _(a,l,o){let e=a.incoming;if(!e)return;let n=e.get(o);n||(n=new Set,e.set(o,n)),n.add(l);}function f(a,l,o){let e=a.incoming;if(!e)return;let n=e.get(o);n&&(n.delete(l),n.size===0&&e.delete(o));}function S(a,l,o,e,n){let t=j(a);if(t.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let i=p(t,o),s=l&t.options.indexMask,c=e&t.options.indexMask;if(i.exclusive){if(s>=i.exclusive.length){let u=new Int32Array(Math.max(s+1,i.exclusive.length*2)).fill(-1);u.set(i.exclusive),i.exclusive=u;}let r=i.exclusive[s]??-1;if(r>=0&&r!==c){let u=i.data.get(s);u?.delete(r),u&&u.size===0&&i.data.delete(s),f(i,s,r);}i.exclusive[s]=c,r!==c&&_(i,s,c);}else {let r=i.outgoing.get(s);r||(r=[],i.outgoing.set(s,r)),r.includes(c)||r.push(c);}if(n!==void 0){let r=i.data.get(s);r||(r=new Map,i.data.set(s,r)),r.set(c,n);}}function w(a,l,o,e){let n=j(a);if(n.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=n.relationStorage.get(o.__id);if(!t)return;let i=l&n.options.indexMask,s=e&n.options.indexMask;if(t.exclusive)i<t.exclusive.length&&t.exclusive[i]===s&&(t.exclusive[i]=-1,f(t,i,s));else {let r=t.outgoing.get(i);if(r){let u=r.indexOf(s);u>=0&&r.splice(u,1),r.length===0&&t.outgoing.delete(i);}}let c=t.data.get(i);c&&(c.delete(s),c.size===0&&t.data.delete(i));}function k(a,l,o){let e=j(a),n=e.relationStorage.get(o.__id);if(!n)return [];let t=l&e.options.indexMask;if(n.exclusive){if(t<n.exclusive.length){let s$1=n.exclusive[t]??-1;if(s$1>=0){let c=e.generations[s$1]??0;return [s(s$1,c,e.options)]}}return []}let i=n.outgoing.get(t);return i?i.map(s$1=>{let c=e.generations[s$1]??0;return s(s$1,c,e.options)}):[]}function I(a,l,o,e){let n=j(a),t=n.relationStorage.get(o.__id);if(!t)return;let i=l&n.options.indexMask,s=e&n.options.indexMask;return t.data.get(i)?.get(s)}F((a,l)=>{let o=l&a.options.indexMask;for(let e of a.relationStorage.values()){if(e.exclusive){if(o<e.exclusive.length){let t=e.exclusive[o]??-1;t>=0&&f(e,o,t),e.exclusive[o]=-1;}let n=e.incoming?.get(o);if(n){for(let t of n)t<e.exclusive.length&&(e.exclusive[t]=-1);e.incoming?.delete(o);}}e.outgoing.delete(o);for(let[n,t]of e.outgoing){let i=t.indexOf(o);i>=0&&(t.splice(i,1),t.length===0&&e.outgoing.delete(n));}e.data.delete(o);for(let[n,t]of e.data)t.delete(o),t.size===0&&e.data.delete(n);}});export{y as ChildOf,S as addRelation,v as defineRelation,I as getRelationData,k as getRelationTargets,w as removeRelation};//# sourceMappingURL=relations.js.map
|
|
2
2
|
//# sourceMappingURL=relations.js.map
|
package/dist/serialize.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkJDV5JZP2_cjs=require('./chunk-JDV5JZP2.cjs');require('./chunk-Q2XLL6YG.cjs');Object.defineProperty(exports,"createDeltaSerializer",{enumerable:true,get:function(){return chunkJDV5JZP2_cjs.e}});Object.defineProperty(exports,"deserializeWorld",{enumerable:true,get:function(){return chunkJDV5JZP2_cjs.b}});Object.defineProperty(exports,"fromJSON",{enumerable:true,get:function(){return chunkJDV5JZP2_cjs.d}});Object.defineProperty(exports,"serializeWorld",{enumerable:true,get:function(){return chunkJDV5JZP2_cjs.a}});Object.defineProperty(exports,"toJSON",{enumerable:true,get:function(){return chunkJDV5JZP2_cjs.c}});//# sourceMappingURL=serialize.cjs.map
|
|
2
2
|
//# sourceMappingURL=serialize.cjs.map
|
package/dist/serialize.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{e as createDeltaSerializer,b as deserializeWorld,d as fromJSON,a as serializeWorld,c as toJSON}from'./chunk-
|
|
1
|
+
export{e as createDeltaSerializer,b as deserializeWorld,d as fromJSON,a as serializeWorld,c as toJSON}from'./chunk-ZZBNE7C5.js';import'./chunk-OBMQME2P.js';//# sourceMappingURL=serialize.js.map
|
|
2
2
|
//# sourceMappingURL=serialize.js.map
|
package/dist/worker.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkJDV5JZP2_cjs=require('./chunk-JDV5JZP2.cjs'),chunkQ2XLL6YG_cjs=require('./chunk-Q2XLL6YG.cjs');var l=1095320899;function W(r){let e=chunkQ2XLL6YG_cjs.j(r),o=chunkJDV5JZP2_cjs.a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return chunkJDV5JZP2_cjs.b(e)}function S(r,e){let o=new Uint8Array(r),t=chunkJDV5JZP2_cjs.b(o);if(e?.readOnly){let n=chunkQ2XLL6YG_cjs.j(t);n.readOnly=true;}return t}function B(r){chunkQ2XLL6YG_cjs.k(r.id)&&chunkQ2XLL6YG_cjs.m(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:chunkQ2XLL6YG_cjs.a,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}exports.adoptSnapshot=b;exports.attachWorld=S;exports.detachWorld=B;exports.transferableSnapshot=W;//# sourceMappingURL=worker.cjs.map
|
|
2
2
|
//# sourceMappingURL=worker.cjs.map
|
package/dist/worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,b as b$1}from'./chunk-
|
|
1
|
+
import {a,b as b$1}from'./chunk-ZZBNE7C5.js';import {j,k,m as m$1,a as a$1}from'./chunk-OBMQME2P.js';var l=1095320899;function W(r){let e=j(r),o=a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return b$1(e)}function S(r,e){let o=new Uint8Array(r),t=b$1(o);if(e?.readOnly){let n=j(t);n.readOnly=true;}return t}function B(r){k(r.id)&&m$1(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:a$1,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}export{b as adoptSnapshot,S as attachWorld,B as detachWorld,W as transferableSnapshot};//# sourceMappingURL=worker.js.map
|
|
2
2
|
//# sourceMappingURL=worker.js.map
|
package/llms-full.txt
CHANGED
|
@@ -14,7 +14,7 @@ The short index lives at `llms.txt` (see https://llmstxt.org/).
|
|
|
14
14
|
|
|
15
15
|
TypeScript-first archetype ECS with TypedArray SoA components, command buffers, relations, serialization, and SAB-ready snapshot transport.
|
|
16
16
|
|
|
17
|
-
> **Status: 0.5.
|
|
17
|
+
> **Status: 0.5.9 - stable 1.0-track core.** Root ECS APIs are stable; worker transport remains adapter-shaped and environment-dependent.
|
|
18
18
|
|
|
19
19
|
## Install
|
|
20
20
|
|
|
@@ -72,7 +72,7 @@ Use `defineTag()` for marker components and `defineObjectComponent()` when you n
|
|
|
72
72
|
- Structural mutation during a query loop is allowed by the library, but app systems should prefer `withCommandBuffer()` when adding/removing/destroying entities from inside iteration.
|
|
73
73
|
- Reactive query buffers are unbounded until drained. Poll and clear them every frame or event tick.
|
|
74
74
|
- Query registration currently uses a global module cache; many worlds/components can make structural changes scan more query metadata than expected.
|
|
75
|
-
- Exclusive relation cleanup
|
|
75
|
+
- Exclusive relation cleanup is `O(incoming)` on destroy — a reverse index touches only the edges pointing at the destroyed entity, not the whole relation capacity.
|
|
76
76
|
- Serialization restores capacity with safety clamps, but snapshots from untrusted sources should still be treated as hostile input.
|
|
77
77
|
- Worker/SAB helpers depend on the runtime environment. Feature-detect `SharedArrayBuffer` and cross-origin isolation in browsers.
|
|
78
78
|
- `pnpm lint` currently reports many `noExplicitAny` warnings. They are not release-blocking, but they add AI-review noise.
|
|
@@ -100,6 +100,12 @@ All notable changes to aiecsjs are summarized here. Detailed historical review n
|
|
|
100
100
|
|
|
101
101
|
## [Unreleased]
|
|
102
102
|
|
|
103
|
+
## [0.5.9] - 2026-06-29
|
|
104
|
+
|
|
105
|
+
- Fixed: `forEachEntity` / `forEachEntityIndexed` no longer cache the archetype's entity array, so an in-loop `createEntity`/`addComponent` that reallocates the iterated archetype can no longer yield `undefined` EntityIds or a bogus index `0`.
|
|
106
|
+
- Fixed: `resetWorld` now clears relation storage, so recycled entity slots no longer inherit stale relation edges/data.
|
|
107
|
+
- Docs: relation destroy is documented as `O(incoming)` (was stale `O(capacity)`).
|
|
108
|
+
|
|
103
109
|
## [0.5.8] - 2026-06-14
|
|
104
110
|
|
|
105
111
|
- Changed: exclusive-relation destroy cleanup now clears incoming edges in O(incoming) via a reverse index instead of scanning the full relation capacity per destroy. Behaviour is unchanged; large sparse relation tables no longer pay a per-destroy capacity scan.
|
|
@@ -155,7 +161,7 @@ aiecsjs keeps the root ECS surface stable and treats subpaths as explicit public
|
|
|
155
161
|
## Current Caveats
|
|
156
162
|
|
|
157
163
|
- Reactive query registration scans a module-level query cache on structural changes.
|
|
158
|
-
- Exclusive relation cleanup
|
|
164
|
+
- Exclusive relation cleanup touches only the incoming edges (`O(incoming)`) when an entity is destroyed, via a reverse index — no full relation-capacity scan.
|
|
159
165
|
- Lint has many `noExplicitAny` warnings pending cleanup.
|
|
160
166
|
|
|
161
167
|
---
|
package/package.json
CHANGED
package/dist/chunk-3ZLNR4JX.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkZIZSWIHW_cjs=require('./chunk-ZIZSWIHW.cjs');var E=1,f=new Map;function A(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 T(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=A(e),r=f.get(t);if(r)return r;let o={id:E++,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 f.set(t,o),o}function $(n){let e=n,t=`enter:${e.id}`,r=f.get(t);if(r)return r;let o={id:E++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"enter",sourceQueryId:e.id,sourceQuery:e};return f.set(t,o),o}function D(n){let e=n,t=`exit:${e.id}`,r=f.get(t);if(r)return r;let o={id:E++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"exit",sourceQueryId:e.id,sourceQuery:e};return f.set(t,o),o}function p(n,e){if(n.queries[e.id]===e&&n.queryMasks.has(e.id))return;let t=n.options.maskWordCount,r=chunkZIZSWIHW_cjs.b(t),o=chunkZIZSWIHW_cjs.b(t),i=chunkZIZSWIHW_cjs.b(t);for(let a of e.all){let u=C(a),d=chunkZIZSWIHW_cjs.q(n,u);chunkZIZSWIHW_cjs.c(r,d);}for(let a of e.any){let u=C(a),d=chunkZIZSWIHW_cjs.q(n,u);chunkZIZSWIHW_cjs.c(o,d);}for(let a of e.none){let u=C(a),d=chunkZIZSWIHW_cjs.q(n,u);chunkZIZSWIHW_cjs.c(i,d);}let c={withMask:r,anyMask:o,noneMask:i,anyHasBits:!chunkZIZSWIHW_cjs.d(o)};n.queryMasks.set(e.id,c),n.queries[e.id]=e,n.queryArchetypeCache[e.id]=null,n.queryArchetypeStamp[e.id]=-1;let s=[...chunkZIZSWIHW_cjs.f(r),...chunkZIZSWIHW_cjs.f(o),...chunkZIZSWIHW_cjs.f(i)];for(let a of s){let u=n.bitToQueries.get(a);u||(u=new Set,n.bitToQueries.set(a,u)),u.add(e.id);}e.reactiveKind!=="normal"&&(n.reactiveBuffers.has(e.id)||n.reactiveBuffers.set(e.id,{entered:[],exited:[]}),e.sourceQuery&&p(n,e.sourceQuery));}function m(n,e){if(p(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 c=n.archetypes[i];chunkZIZSWIHW_cjs.e(c.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 H(n,e){let t=chunkZIZSWIHW_cjs.j(n),o=m(t,e),i=[];for(let c of o){let s=t.archetypes[c];i.push({id:s.id,mask:Array.from(s.mask),size:s.size});}return i}function L(n,e){let t=chunkZIZSWIHW_cjs.j(n),r=e,o=[];if(r.reactiveKind==="enter"){let c=t.reactiveBuffers.get(r.id);if(c){for(let s of c.entered)o.push(s);c.entered.length=0;}return o}if(r.reactiveKind==="exit"){let c=t.reactiveBuffers.get(r.id);if(c){for(let s of c.exited)o.push(s);c.exited.length=0;}return o}let i=m(t,r);for(let c of i){let s=t.archetypes[c];for(let a=0;a<s.size;a++)o.push(s.entities[a]);}return o}function*F(n,e){let t=chunkZIZSWIHW_cjs.j(n),r=e;if(r.reactiveKind!=="normal"){let i=t.reactiveBuffers.get(r.id);if(!i)return;let c=r.reactiveKind==="enter"?i.entered:i.exited;for(let s of c)yield s;c.length=0;return}let o=m(t,r);for(let i of o){let c=t.archetypes[i];for(let s=0;s<c.size;s++)yield c.entities[s];}}function O(n,e,t){let r=chunkZIZSWIHW_cjs.j(n),o=e;if(o.reactiveKind!=="normal"){let s=r.reactiveBuffers.get(o.id);if(!s)return;let a=o.reactiveKind==="enter"?s.entered:s.exited;if(a.length===0)return;let u=g(r,o);for(let d=0;d<a.length;d++){let y=a[d];w(t,y,u);}a.length=0;return}p(r,o);let i=m(r,o),c=g(r,o);for(let s of i){let a=r.archetypes[s],u=a.entities;for(let d=0;d<a.size;d++)w(t,u[d],c);}}function w(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 G(n,e,t){let r=chunkZIZSWIHW_cjs.j(n),o=e,i=r.options.indexMask;if(o.reactiveKind!=="normal"){let a=r.reactiveBuffers.get(o.id);if(!a)return;let u=o.reactiveKind==="enter"?a.entered:a.exited;if(u.length===0)return;let d=g(r,o);for(let y=0;y<u.length;y++){let h=u[y];W(t,h,h&i,d);}u.length=0;return}p(r,o);let c=m(r,o),s=g(r,o);for(let a of c){let u=r.archetypes[a],d=u.entities;for(let y=0;y<u.size;y++){let h=d[y];W(t,h,h&i,s);}}}function W(n,e,t,r){switch(r.length){case 0:n(e,t);break;case 1:n(e,t,r[0]);break;case 2:n(e,t,r[0],r[1]);break;case 3:n(e,t,r[0],r[1],r[2]);break;case 4:n(e,t,r[0],r[1],r[2],r[3]);break;case 5:n(e,t,r[0],r[1],r[2],r[3],r[4]);break;default:n(e,t,...r);}}function g(n,e){let t=[];for(let r of e.columnViewCache){let o=chunkZIZSWIHW_cjs.J(r),i=n.componentBitFor.get(o.id);if(i===void 0){t.push(void 0);continue}let c=n.componentStorageByBit[i];if(!c){t.push(void 0);continue}c.kind==="soa"?t.push(c.soa):c.kind==="aos"?t.push(c.aos):t.push(true);}return t}function N(n,e,t,r,o){for(let s of f.values())s.reactiveKind!=="normal"&&s.sourceQuery&&n.queries[s.sourceQuery.id]!==s.sourceQuery&&p(n,s.sourceQuery);let i=n.bitToQueries.get(t);if(!i)return;let c=n.options.maskWordCount;for(let s of i){let a=n.queries[s];if(!a||a.reactiveKind!=="normal")continue;let u=n.queryMasks.get(s);if(!u)continue;let d=chunkZIZSWIHW_cjs.e(r,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,c),y=chunkZIZSWIHW_cjs.e(o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,c);!d&&y?_(n,s,"enter",e):d&&!y&&_(n,s,"exit",e);}}function _(n,e,t,r){for(let o of f.values()){if(o.sourceQueryId!==e||o.reactiveKind!==t)continue;p(n,o);let i=K(n,o.id);t==="enter"?i.entered.push(r):i.exited.push(r);}}function K(n,e){let t=n.reactiveBuffers.get(e);return t||(t={entered:[],exited:[]},n.reactiveBuffers.set(e,t)),t}function C(n){let e=S(n);if(!e)throw new Error(`aiecsjs: component id ${n} not registered`);return e}var x=null;function U(n){x=n;}function S(n){return x?x(n):void 0}exports.a=T;exports.b=$;exports.c=D;exports.d=H;exports.e=L;exports.f=F;exports.g=O;exports.h=G;exports.i=N;exports.j=U;//# sourceMappingURL=chunk-3ZLNR4JX.cjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-3ZLNR4JX.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/query.ts"],"names":["nextQueryId","moduleQueryCache","descKey","d","all","c","a","b","any","none","defineQuery","arg","desc","key","cached","q","enterQuery","query","reactive","exitQuery","ensureQueryRegistered","state","ww","withMask","createMask","anyMask","noneMask","compId","info","getComponentInfoById","bit","getOrRegisterComponentBit","setBit","bundle","isMaskZero","involvedBits","listBits","s","getQueryArchetypes","words","list","arch","matches","queryArchetypes","world","getWorldState","ids","out","id","runQuery","buf","e","archIds","r","iterQuery","src","forEachEntity","fn","cols","buildColumnViews","i","callWithCols","ents","eid","forEachEntityIndexed","indexMask","callWithColsIndexed","comp","getComponentInfo","storage","recordEntityMaskChange","changedBit","prevMask","nextMask","involved","qid","wasMatch","isMatch","pushReactive","queryId","kind","ensureReactiveBuffer","componentId","lazyGetComponentInfo","_getComponentInfoFn","registerComponentLookup"],"mappings":"mEAsBA,IAAIA,CAAAA,CAAc,EACZC,CAAAA,CAAmB,IAAI,IAE7B,SAASC,CAAAA,CAAQC,EAA4B,CAC3C,IAAMC,GAAOD,CAAAA,CAAE,GAAA,EAAO,EAAC,EACpB,GAAA,CAAKE,GAAMA,CAAAA,CAAE,IAAI,CAAA,CACjB,IAAA,CAAK,CA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AAA,CAAwB5B,CAAAA,CAAqD,CAC3F2B,CAAAA,CAAsB3B,EACxB,CACA,SAAS0B,EAAqBnC,CAAAA,CAAuC,CACnE,OAAOoC,CAAAA,CAAsBA,CAAAA,CAAoBpC,CAAE,CAAA,CAAI,MACzD","file":"chunk-3ZLNR4JX.cjs","sourcesContent":["import { createMask, isMaskZero, listBits, matches, setBit } from './bitmask.js'\nimport { getComponentInfo } from './component.js'\nimport type {\n Archetype,\n ComponentInfo,\n ComponentLike,\n EntityId,\n Query,\n QueryDescriptor,\n QueryInternal,\n QueryMaskBundle,\n ReactiveBuffer,\n World,\n WorldState,\n} from './types.js'\nimport {\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n} from './world.js'\n\nlet nextQueryId = 1\nconst moduleQueryCache = new Map<string, QueryInternal>()\n\nfunction descKey(d: QueryDescriptor): string {\n const all = (d.all ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const any = (d.any ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const none = (d.none ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n return `A${all}|Y${any}|N${none}`\n}\n\nexport function defineQuery(arg: ComponentLike[] | QueryDescriptor): Query {\n const desc: QueryDescriptor = Array.isArray(arg) ? { all: arg } : arg\n\n // Validate all members are components\n for (const c of [...(desc.all ?? []), ...(desc.any ?? []), ...(desc.none ?? [])]) {\n if (!c || typeof c !== 'object' || typeof (c as any).__id !== 'number') {\n throw new TypeError('aiecsjs: defineQuery received a non-component value')\n }\n }\n\n const key = descKey(desc)\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n\n const q: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: (desc.all ?? []).map((c) => c.__id),\n any: (desc.any ?? []).map((c) => c.__id),\n none: (desc.none ?? []).map((c) => c.__id),\n columnViewCache: [...(desc.all ?? []), ...(desc.any ?? [])],\n reactiveKind: 'normal',\n sourceQueryId: -1,\n sourceQuery: null,\n }\n moduleQueryCache.set(key, q)\n return q\n}\n\n/**\n * Reactive \"entered\" view of `query`: each read drains the entities that began\n * matching since the last read (via `runQuery` / `iterQuery` / `forEachEntity`).\n *\n * **MUST-DRAIN CONTRACT (unbounded buffer).** The enter buffer has **no cap**.\n * Every structural change that makes an entity newly match pushes one id; the\n * buffer only shrinks when you read the reactive view. A view that is created\n * but never read — e.g. a disabled system, or reading only the {@link exitQuery}\n * twin — accumulates one number per event **forever**, an unbounded memory leak\n * at churn rates (e.g. ~1k spawns/frame). Read every enter view you create, once\n * per frame. Dropping ids silently would corrupt enter/exit symmetry, so capping\n * is intentionally not done — draining is the caller's responsibility.\n */\nexport function enterQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `enter:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'enter',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n/**\n * Reactive \"exited\" view of `query`: each read drains the entities that stopped\n * matching since the last read (via `runQuery` / `iterQuery` / `forEachEntity`).\n *\n * **MUST-DRAIN CONTRACT (unbounded buffer).** The exit buffer has **no cap** —\n * same discipline as {@link enterQuery}. An unread exit view accumulates one id\n * per matching structural change (including every `destroyEntity` of a matching\n * entity) without bound. Read every exit view you create, once per frame. Capping\n * is intentionally not done because dropping ids would break enter/exit symmetry.\n */\nexport function exitQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `exit:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'exit',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n// --- Per-world query setup ---\n\nfunction ensureQueryRegistered(state: WorldState, q: QueryInternal): void {\n if (state.queries[q.id] === q && state.queryMasks.has(q.id)) return\n\n // Build per-world bitmasks (this may register new bits)\n const ww = state.options.maskWordCount\n const withMask = createMask(ww)\n const anyMask = createMask(ww)\n const noneMask = createMask(ww)\n for (const compId of q.all) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(withMask, bit)\n }\n for (const compId of q.any) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(anyMask, bit)\n }\n for (const compId of q.none) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(noneMask, bit)\n }\n\n const bundle: QueryMaskBundle = {\n withMask,\n anyMask,\n noneMask,\n anyHasBits: !isMaskZero(anyMask),\n }\n state.queryMasks.set(q.id, bundle)\n\n state.queries[q.id] = q\n state.queryArchetypeCache[q.id] = null\n state.queryArchetypeStamp[q.id] = -1\n\n // Build bit → queries index for fast reactive lookup\n const involvedBits: number[] = [\n ...listBits(withMask),\n ...listBits(anyMask),\n ...listBits(noneMask),\n ]\n for (const b of involvedBits) {\n let s = state.bitToQueries.get(b)\n if (!s) {\n s = new Set<number>()\n state.bitToQueries.set(b, s)\n }\n s.add(q.id)\n }\n\n // Initialize reactive buffer for enter/exit queries\n if (q.reactiveKind !== 'normal') {\n if (!state.reactiveBuffers.has(q.id)) {\n state.reactiveBuffers.set(q.id, { entered: [], exited: [] })\n }\n // Also register the source query so recordEntityMaskChange will see it\n if (q.sourceQuery) ensureQueryRegistered(state, q.sourceQuery)\n }\n}\n\nfunction getQueryArchetypes(state: WorldState, q: QueryInternal): number[] {\n ensureQueryRegistered(state, q)\n if (state.queryArchetypeCache[q.id] && state.queryArchetypeStamp[q.id] === state.queryVersion) {\n return state.queryArchetypeCache[q.id]!\n }\n const bundle = state.queryMasks.get(q.id)!\n const words = state.options.maskWordCount\n const list: number[] = []\n for (let i = 0; i < state.archetypes.length; i++) {\n const arch = state.archetypes[i]!\n if (\n matches(arch.mask, bundle.withMask, bundle.anyMask, bundle.noneMask, bundle.anyHasBits, words)\n ) {\n list.push(i)\n }\n }\n state.queryArchetypeCache[q.id] = list\n state.queryArchetypeStamp[q.id] = state.queryVersion\n return list\n}\n\nexport function queryArchetypes(world: World, query: Query): readonly Archetype[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const ids = getQueryArchetypes(state, q)\n const out: Archetype[] = []\n for (const id of ids) {\n const arch = state.archetypes[id]!\n out.push({ id: arch.id, mask: Array.from(arch.mask), size: arch.size })\n }\n return out\n}\n\nexport function runQuery(world: World, query: Query): readonly EntityId[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const out: EntityId[] = []\n if (q.reactiveKind === 'enter') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.entered) out.push(e as EntityId)\n buf.entered.length = 0\n }\n return out\n }\n if (q.reactiveKind === 'exit') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.exited) out.push(e as EntityId)\n buf.exited.length = 0\n }\n return out\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n out.push(arch.entities[r] as EntityId)\n }\n }\n return out\n}\n\nexport function* iterQuery(world: World, query: Query): IterableIterator<EntityId> {\n const state = getWorldState(world)\n const q = query as QueryInternal\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n for (const e of src) yield e as EntityId\n src.length = 0\n return\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n yield arch.entities[r] as EntityId\n }\n }\n}\n\n/**\n * Iterate every entity matching `query`, invoking `fn(e, ...cols)` once per row\n * with the packed {@link EntityId} and the query's SoA column views.\n *\n * **Caution — `e` is a packed EntityId, not a column subscript.** It carries the\n * generation in its high bits, so indexing a column view with it directly\n * (`pos.x[e]`) reads out of bounds once a slot has been recycled. Use `e` only\n * for identity operations (`destroyEntity` / `hasComponent` / `refOf`). To index\n * columns safely, prefer {@link forEachEntityIndexed} — which yields the masked\n * slot index `i` alongside `e` — or mask it yourself with {@link getEntityIndex}.\n *\n * @see {@link forEachEntityIndexed} — same iteration plus the safe column index `i`.\n * @see {@link getEntityIndex} — mask a packed EntityId to its raw slot index.\n */\nexport function forEachEntity(\n world: World,\n query: Query,\n fn: (eid: EntityId, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithCols(fn, e, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n // Re-read `arch.size` each iteration (do NOT cache it as `n`): an in-loop\n // `destroyEntity` swap-pops the visited row, shrinks `arch.size`, and zeroes\n // the freed tail slot. A cached bound would keep walking into those zeroed\n // tail rows and hand the callback the reserved sentinel eid 0 (ECS-B-01).\n // The swapped-in survivor is intentionally skipped this pass (deferred to the\n // next). This is a scalar property read — no per-iteration allocation, so the\n // zero-allocation hot-path contract holds. Mirrors runQuery (:230) / iterQuery.\n for (let r = 0; r < arch.size; r++) {\n callWithCols(fn, ents[r] as EntityId, cols)\n }\n }\n}\n\nfunction callWithCols(\n fn: (eid: EntityId, ...cols: any[]) => void,\n eid: EntityId,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(eid)\n break\n case 1:\n fn(eid, cols[0])\n break\n case 2:\n fn(eid, cols[0], cols[1])\n break\n case 3:\n fn(eid, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(eid, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(eid, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(eid, ...cols)\n }\n}\n\n/**\n * Like {@link forEachEntity}, but yields the masked column index `i` alongside\n * the packed `EntityId`. The callback signature is `(e, i, ...cols)`:\n *\n * - `e` — the packed EntityId (carries the generation in its high bits). Use\n * it for in-loop `destroyEntity` / `hasComponent` / `refOf`, exactly as with\n * `forEachEntity`.\n * - `i` — `e & indexMask`, the raw slot index. This is the **correct subscript**\n * for SoA column views (`pos.x[i]`), and stays correct after a slot is\n * recycled — where indexing with the packed `e` would read out of bounds.\n * - `...cols` — the same column views `forEachEntity` passes.\n *\n * This closes the packed-EntityId footgun (A1): callers no longer need to call\n * `getEntityIndex(e)` (or hand-mask) themselves to index columns safely.\n */\nexport function forEachEntityIndexed(\n world: World,\n query: Query,\n fn: (e: EntityId, i: number, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const indexMask = state.options.indexMask\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithColsIndexed(fn, e, e & indexMask, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n // Re-read `arch.size` each iteration — see forEachEntity for the rationale.\n // An in-loop `destroyEntity` swap-pops the row and zeroes the freed tail; a\n // cached bound would replay the sentinel eid 0 across the public boundary\n // (ECS-B-01). Scalar read only; the zero-allocation hot-path contract holds.\n for (let r = 0; r < arch.size; r++) {\n const e = ents[r] as EntityId\n callWithColsIndexed(fn, e, e & indexMask, cols)\n }\n }\n}\n\nfunction callWithColsIndexed(\n fn: (e: EntityId, i: number, ...cols: any[]) => void,\n e: EntityId,\n i: number,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(e, i)\n break\n case 1:\n fn(e, i, cols[0])\n break\n case 2:\n fn(e, i, cols[0], cols[1])\n break\n case 3:\n fn(e, i, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(e, i, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(e, i, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(e, i, ...cols)\n }\n}\n\nfunction buildColumnViews(state: WorldState, q: QueryInternal): any[] {\n const out: any[] = []\n for (const comp of q.columnViewCache) {\n const info = getComponentInfo(comp)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) {\n out.push(undefined)\n continue\n }\n const storage = state.componentStorageByBit[bit]\n if (!storage) {\n out.push(undefined)\n continue\n }\n if (storage.kind === 'soa') out.push(storage.soa)\n else if (storage.kind === 'aos') out.push(storage.aos)\n else out.push(true) // tag\n }\n return out\n}\n\n// --- Reactive query updates (called from migration code) ---\n\nexport function recordEntityMaskChange(\n state: WorldState,\n eid: EntityId,\n changedBit: number,\n prevMask: Uint32Array,\n nextMask: Uint32Array,\n): void {\n // Lazy-register any reactive queries (and their sources) so we can correctly\n // determine match transitions even if the user only ever called enterQuery/exitQuery.\n for (const q of moduleQueryCache.values()) {\n if (q.reactiveKind === 'normal') continue\n if (q.sourceQuery && state.queries[q.sourceQuery.id] !== q.sourceQuery) {\n ensureQueryRegistered(state, q.sourceQuery)\n }\n }\n\n const involved = state.bitToQueries.get(changedBit)\n if (!involved) return\n const words = state.options.maskWordCount\n for (const qid of involved) {\n const q = state.queries[qid]\n if (!q) continue\n if (q.reactiveKind !== 'normal') continue\n const bundle = state.queryMasks.get(qid)\n if (!bundle) continue\n const wasMatch = matches(\n prevMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n const isMatch = matches(\n nextMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n if (!wasMatch && isMatch) {\n pushReactive(state, qid, 'enter', eid)\n } else if (wasMatch && !isMatch) {\n pushReactive(state, qid, 'exit', eid)\n }\n }\n}\n\nfunction pushReactive(\n state: WorldState,\n queryId: number,\n kind: 'enter' | 'exit',\n eid: EntityId,\n): void {\n // Walk the module cache (not just state.queries) so reactive variants that\n // haven't been registered with this world yet still receive events.\n for (const r of moduleQueryCache.values()) {\n if (r.sourceQueryId !== queryId) continue\n if (r.reactiveKind !== kind) continue\n // Lazily register the reactive query in this world so subsequent reads can find it\n ensureQueryRegistered(state, r)\n const buf = ensureReactiveBuffer(state, r.id)\n if (kind === 'enter') buf.entered.push(eid as number)\n else buf.exited.push(eid as number)\n }\n}\n\nfunction ensureReactiveBuffer(state: WorldState, qid: number): ReactiveBuffer {\n let buf = state.reactiveBuffers.get(qid)\n if (!buf) {\n buf = { entered: [], exited: [] }\n state.reactiveBuffers.set(qid, buf)\n }\n return buf\n}\n\n// --- Helpers ---\n\nfunction getComponentInfoById(componentId: number): ComponentInfo {\n // We need access to the component registry's lookup by id. Re-import dynamically to avoid cycles.\n const info = lazyGetComponentInfo(componentId)\n if (!info) throw new Error(`aiecsjs: component id ${componentId} not registered`)\n return info\n}\n\nlet _getComponentInfoFn: ((id: number) => ComponentInfo | undefined) | null = null\nexport function registerComponentLookup(fn: (id: number) => ComponentInfo | undefined): void {\n _getComponentInfoFn = fn\n}\nfunction lazyGetComponentInfo(id: number): ComponentInfo | undefined {\n return _getComponentInfoFn ? _getComponentInfoFn(id) : undefined\n}\n\nexport function _resetQueryRegistry_FOR_TESTS_ONLY(): void {\n moduleQueryCache.clear()\n nextQueryId = 1\n}\n"]}
|
package/dist/chunk-N5OETPTK.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {j,J,e,b,q,c,d,f as f$1}from'./chunk-YFTCD2UG.js';var E=1,f=new Map;function A(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 T(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=A(e),r=f.get(t);if(r)return r;let o={id:E++,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 f.set(t,o),o}function $(n){let e=n,t=`enter:${e.id}`,r=f.get(t);if(r)return r;let o={id:E++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"enter",sourceQueryId:e.id,sourceQuery:e};return f.set(t,o),o}function D(n){let e=n,t=`exit:${e.id}`,r=f.get(t);if(r)return r;let o={id:E++,mask:[],all:e.all,any:e.any,none:e.none,columnViewCache:e.columnViewCache,reactiveKind:"exit",sourceQueryId:e.id,sourceQuery:e};return f.set(t,o),o}function p(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 a of e.all){let u=C(a),d=q(n,u);c(r,d);}for(let a of e.any){let u=C(a),d=q(n,u);c(o,d);}for(let a of e.none){let u=C(a),d=q(n,u);c(i,d);}let c$1={withMask:r,anyMask:o,noneMask:i,anyHasBits:!d(o)};n.queryMasks.set(e.id,c$1),n.queries[e.id]=e,n.queryArchetypeCache[e.id]=null,n.queryArchetypeStamp[e.id]=-1;let s=[...f$1(r),...f$1(o),...f$1(i)];for(let a of s){let u=n.bitToQueries.get(a);u||(u=new Set,n.bitToQueries.set(a,u)),u.add(e.id);}e.reactiveKind!=="normal"&&(n.reactiveBuffers.has(e.id)||n.reactiveBuffers.set(e.id,{entered:[],exited:[]}),e.sourceQuery&&p(n,e.sourceQuery));}function m(n,e$1){if(p(n,e$1),n.queryArchetypeCache[e$1.id]&&n.queryArchetypeStamp[e$1.id]===n.queryVersion)return n.queryArchetypeCache[e$1.id];let t=n.queryMasks.get(e$1.id),r=n.options.maskWordCount,o=[];for(let i=0;i<n.archetypes.length;i++){let c=n.archetypes[i];e(c.mask,t.withMask,t.anyMask,t.noneMask,t.anyHasBits,r)&&o.push(i);}return n.queryArchetypeCache[e$1.id]=o,n.queryArchetypeStamp[e$1.id]=n.queryVersion,o}function H(n,e){let t=j(n),o=m(t,e),i=[];for(let c of o){let s=t.archetypes[c];i.push({id:s.id,mask:Array.from(s.mask),size:s.size});}return i}function L(n,e){let t=j(n),r=e,o=[];if(r.reactiveKind==="enter"){let c=t.reactiveBuffers.get(r.id);if(c){for(let s of c.entered)o.push(s);c.entered.length=0;}return o}if(r.reactiveKind==="exit"){let c=t.reactiveBuffers.get(r.id);if(c){for(let s of c.exited)o.push(s);c.exited.length=0;}return o}let i=m(t,r);for(let c of i){let s=t.archetypes[c];for(let a=0;a<s.size;a++)o.push(s.entities[a]);}return o}function*F(n,e){let t=j(n),r=e;if(r.reactiveKind!=="normal"){let i=t.reactiveBuffers.get(r.id);if(!i)return;let c=r.reactiveKind==="enter"?i.entered:i.exited;for(let s of c)yield s;c.length=0;return}let o=m(t,r);for(let i of o){let c=t.archetypes[i];for(let s=0;s<c.size;s++)yield c.entities[s];}}function O(n,e,t){let r=j(n),o=e;if(o.reactiveKind!=="normal"){let s=r.reactiveBuffers.get(o.id);if(!s)return;let a=o.reactiveKind==="enter"?s.entered:s.exited;if(a.length===0)return;let u=g(r,o);for(let d=0;d<a.length;d++){let y=a[d];w(t,y,u);}a.length=0;return}p(r,o);let i=m(r,o),c=g(r,o);for(let s of i){let a=r.archetypes[s],u=a.entities;for(let d=0;d<a.size;d++)w(t,u[d],c);}}function w(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 G(n,e,t){let r=j(n),o=e,i=r.options.indexMask;if(o.reactiveKind!=="normal"){let a=r.reactiveBuffers.get(o.id);if(!a)return;let u=o.reactiveKind==="enter"?a.entered:a.exited;if(u.length===0)return;let d=g(r,o);for(let y=0;y<u.length;y++){let h=u[y];W(t,h,h&i,d);}u.length=0;return}p(r,o);let c=m(r,o),s=g(r,o);for(let a of c){let u=r.archetypes[a],d=u.entities;for(let y=0;y<u.size;y++){let h=d[y];W(t,h,h&i,s);}}}function W(n,e,t,r){switch(r.length){case 0:n(e,t);break;case 1:n(e,t,r[0]);break;case 2:n(e,t,r[0],r[1]);break;case 3:n(e,t,r[0],r[1],r[2]);break;case 4:n(e,t,r[0],r[1],r[2],r[3]);break;case 5:n(e,t,r[0],r[1],r[2],r[3],r[4]);break;default:n(e,t,...r);}}function g(n,e){let t=[];for(let r of e.columnViewCache){let o=J(r),i=n.componentBitFor.get(o.id);if(i===void 0){t.push(void 0);continue}let c=n.componentStorageByBit[i];if(!c){t.push(void 0);continue}c.kind==="soa"?t.push(c.soa):c.kind==="aos"?t.push(c.aos):t.push(true);}return t}function N(n,e$1,t,r,o){for(let s of f.values())s.reactiveKind!=="normal"&&s.sourceQuery&&n.queries[s.sourceQuery.id]!==s.sourceQuery&&p(n,s.sourceQuery);let i=n.bitToQueries.get(t);if(!i)return;let c=n.options.maskWordCount;for(let s of i){let a=n.queries[s];if(!a||a.reactiveKind!=="normal")continue;let u=n.queryMasks.get(s);if(!u)continue;let d=e(r,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,c),y=e(o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits,c);!d&&y?_(n,s,"enter",e$1):d&&!y&&_(n,s,"exit",e$1);}}function _(n,e,t,r){for(let o of f.values()){if(o.sourceQueryId!==e||o.reactiveKind!==t)continue;p(n,o);let i=K(n,o.id);t==="enter"?i.entered.push(r):i.exited.push(r);}}function K(n,e){let t=n.reactiveBuffers.get(e);return t||(t={entered:[],exited:[]},n.reactiveBuffers.set(e,t)),t}function C(n){let e=S(n);if(!e)throw new Error(`aiecsjs: component id ${n} not registered`);return e}var x=null;function U(n){x=n;}function S(n){return x?x(n):void 0}export{T as a,$ as b,D as c,H as d,L as e,F as f,O as g,G as h,N as i,U as j};//# sourceMappingURL=chunk-N5OETPTK.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-N5OETPTK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/query.ts"],"names":["nextQueryId","moduleQueryCache","descKey","d","all","c","a","b","any","none","defineQuery","arg","desc","key","cached","q","enterQuery","query","reactive","exitQuery","ensureQueryRegistered","state","ww","withMask","createMask","anyMask","noneMask","compId","info","getComponentInfoById","bit","getOrRegisterComponentBit","setBit","bundle","isMaskZero","involvedBits","listBits","s","getQueryArchetypes","words","list","arch","matches","queryArchetypes","world","getWorldState","ids","out","id","runQuery","buf","e","archIds","r","iterQuery","src","forEachEntity","fn","cols","buildColumnViews","i","callWithCols","ents","eid","forEachEntityIndexed","indexMask","callWithColsIndexed","comp","getComponentInfo","storage","recordEntityMaskChange","changedBit","prevMask","nextMask","involved","qid","wasMatch","isMatch","pushReactive","queryId","kind","ensureReactiveBuffer","componentId","lazyGetComponentInfo","_getComponentInfoFn","registerComponentLookup"],"mappings":"yDAsBA,IAAIA,CAAAA,CAAc,EACZC,CAAAA,CAAmB,IAAI,IAE7B,SAASC,CAAAA,CAAQC,EAA4B,CAC3C,I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AAyBsD,CAAW,iBAAiB,CAAA,CAChF,OAAOtD,CACT,CAEA,IAAIwD,EAA0E,IAAA,CACvE,SAASC,CAAAA,CAAwB5B,CAAAA,CAAqD,CAC3F2B,CAAAA,CAAsB3B,EACxB,CACA,SAAS0B,EAAqBnC,CAAAA,CAAuC,CACnE,OAAOoC,CAAAA,CAAsBA,CAAAA,CAAoBpC,CAAE,CAAA,CAAI,MACzD","file":"chunk-N5OETPTK.js","sourcesContent":["import { createMask, isMaskZero, listBits, matches, setBit } from './bitmask.js'\nimport { getComponentInfo } from './component.js'\nimport type {\n Archetype,\n ComponentInfo,\n ComponentLike,\n EntityId,\n Query,\n QueryDescriptor,\n QueryInternal,\n QueryMaskBundle,\n ReactiveBuffer,\n World,\n WorldState,\n} from './types.js'\nimport {\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n} from './world.js'\n\nlet nextQueryId = 1\nconst moduleQueryCache = new Map<string, QueryInternal>()\n\nfunction descKey(d: QueryDescriptor): string {\n const all = (d.all ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const any = (d.any ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const none = (d.none ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n return `A${all}|Y${any}|N${none}`\n}\n\nexport function defineQuery(arg: ComponentLike[] | QueryDescriptor): Query {\n const desc: QueryDescriptor = Array.isArray(arg) ? { all: arg } : arg\n\n // Validate all members are components\n for (const c of [...(desc.all ?? []), ...(desc.any ?? []), ...(desc.none ?? [])]) {\n if (!c || typeof c !== 'object' || typeof (c as any).__id !== 'number') {\n throw new TypeError('aiecsjs: defineQuery received a non-component value')\n }\n }\n\n const key = descKey(desc)\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n\n const q: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: (desc.all ?? []).map((c) => c.__id),\n any: (desc.any ?? []).map((c) => c.__id),\n none: (desc.none ?? []).map((c) => c.__id),\n columnViewCache: [...(desc.all ?? []), ...(desc.any ?? [])],\n reactiveKind: 'normal',\n sourceQueryId: -1,\n sourceQuery: null,\n }\n moduleQueryCache.set(key, q)\n return q\n}\n\n/**\n * Reactive \"entered\" view of `query`: each read drains the entities that began\n * matching since the last read (via `runQuery` / `iterQuery` / `forEachEntity`).\n *\n * **MUST-DRAIN CONTRACT (unbounded buffer).** The enter buffer has **no cap**.\n * Every structural change that makes an entity newly match pushes one id; the\n * buffer only shrinks when you read the reactive view. A view that is created\n * but never read — e.g. a disabled system, or reading only the {@link exitQuery}\n * twin — accumulates one number per event **forever**, an unbounded memory leak\n * at churn rates (e.g. ~1k spawns/frame). Read every enter view you create, once\n * per frame. Dropping ids silently would corrupt enter/exit symmetry, so capping\n * is intentionally not done — draining is the caller's responsibility.\n */\nexport function enterQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `enter:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'enter',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n/**\n * Reactive \"exited\" view of `query`: each read drains the entities that stopped\n * matching since the last read (via `runQuery` / `iterQuery` / `forEachEntity`).\n *\n * **MUST-DRAIN CONTRACT (unbounded buffer).** The exit buffer has **no cap** —\n * same discipline as {@link enterQuery}. An unread exit view accumulates one id\n * per matching structural change (including every `destroyEntity` of a matching\n * entity) without bound. Read every exit view you create, once per frame. Capping\n * is intentionally not done because dropping ids would break enter/exit symmetry.\n */\nexport function exitQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `exit:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'exit',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n// --- Per-world query setup ---\n\nfunction ensureQueryRegistered(state: WorldState, q: QueryInternal): void {\n if (state.queries[q.id] === q && state.queryMasks.has(q.id)) return\n\n // Build per-world bitmasks (this may register new bits)\n const ww = state.options.maskWordCount\n const withMask = createMask(ww)\n const anyMask = createMask(ww)\n const noneMask = createMask(ww)\n for (const compId of q.all) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(withMask, bit)\n }\n for (const compId of q.any) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(anyMask, bit)\n }\n for (const compId of q.none) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(noneMask, bit)\n }\n\n const bundle: QueryMaskBundle = {\n withMask,\n anyMask,\n noneMask,\n anyHasBits: !isMaskZero(anyMask),\n }\n state.queryMasks.set(q.id, bundle)\n\n state.queries[q.id] = q\n state.queryArchetypeCache[q.id] = null\n state.queryArchetypeStamp[q.id] = -1\n\n // Build bit → queries index for fast reactive lookup\n const involvedBits: number[] = [\n ...listBits(withMask),\n ...listBits(anyMask),\n ...listBits(noneMask),\n ]\n for (const b of involvedBits) {\n let s = state.bitToQueries.get(b)\n if (!s) {\n s = new Set<number>()\n state.bitToQueries.set(b, s)\n }\n s.add(q.id)\n }\n\n // Initialize reactive buffer for enter/exit queries\n if (q.reactiveKind !== 'normal') {\n if (!state.reactiveBuffers.has(q.id)) {\n state.reactiveBuffers.set(q.id, { entered: [], exited: [] })\n }\n // Also register the source query so recordEntityMaskChange will see it\n if (q.sourceQuery) ensureQueryRegistered(state, q.sourceQuery)\n }\n}\n\nfunction getQueryArchetypes(state: WorldState, q: QueryInternal): number[] {\n ensureQueryRegistered(state, q)\n if (state.queryArchetypeCache[q.id] && state.queryArchetypeStamp[q.id] === state.queryVersion) {\n return state.queryArchetypeCache[q.id]!\n }\n const bundle = state.queryMasks.get(q.id)!\n const words = state.options.maskWordCount\n const list: number[] = []\n for (let i = 0; i < state.archetypes.length; i++) {\n const arch = state.archetypes[i]!\n if (\n matches(arch.mask, bundle.withMask, bundle.anyMask, bundle.noneMask, bundle.anyHasBits, words)\n ) {\n list.push(i)\n }\n }\n state.queryArchetypeCache[q.id] = list\n state.queryArchetypeStamp[q.id] = state.queryVersion\n return list\n}\n\nexport function queryArchetypes(world: World, query: Query): readonly Archetype[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const ids = getQueryArchetypes(state, q)\n const out: Archetype[] = []\n for (const id of ids) {\n const arch = state.archetypes[id]!\n out.push({ id: arch.id, mask: Array.from(arch.mask), size: arch.size })\n }\n return out\n}\n\nexport function runQuery(world: World, query: Query): readonly EntityId[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const out: EntityId[] = []\n if (q.reactiveKind === 'enter') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.entered) out.push(e as EntityId)\n buf.entered.length = 0\n }\n return out\n }\n if (q.reactiveKind === 'exit') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.exited) out.push(e as EntityId)\n buf.exited.length = 0\n }\n return out\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n out.push(arch.entities[r] as EntityId)\n }\n }\n return out\n}\n\nexport function* iterQuery(world: World, query: Query): IterableIterator<EntityId> {\n const state = getWorldState(world)\n const q = query as QueryInternal\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n for (const e of src) yield e as EntityId\n src.length = 0\n return\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n yield arch.entities[r] as EntityId\n }\n }\n}\n\n/**\n * Iterate every entity matching `query`, invoking `fn(e, ...cols)` once per row\n * with the packed {@link EntityId} and the query's SoA column views.\n *\n * **Caution — `e` is a packed EntityId, not a column subscript.** It carries the\n * generation in its high bits, so indexing a column view with it directly\n * (`pos.x[e]`) reads out of bounds once a slot has been recycled. Use `e` only\n * for identity operations (`destroyEntity` / `hasComponent` / `refOf`). To index\n * columns safely, prefer {@link forEachEntityIndexed} — which yields the masked\n * slot index `i` alongside `e` — or mask it yourself with {@link getEntityIndex}.\n *\n * @see {@link forEachEntityIndexed} — same iteration plus the safe column index `i`.\n * @see {@link getEntityIndex} — mask a packed EntityId to its raw slot index.\n */\nexport function forEachEntity(\n world: World,\n query: Query,\n fn: (eid: EntityId, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithCols(fn, e, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n // Re-read `arch.size` each iteration (do NOT cache it as `n`): an in-loop\n // `destroyEntity` swap-pops the visited row, shrinks `arch.size`, and zeroes\n // the freed tail slot. A cached bound would keep walking into those zeroed\n // tail rows and hand the callback the reserved sentinel eid 0 (ECS-B-01).\n // The swapped-in survivor is intentionally skipped this pass (deferred to the\n // next). This is a scalar property read — no per-iteration allocation, so the\n // zero-allocation hot-path contract holds. Mirrors runQuery (:230) / iterQuery.\n for (let r = 0; r < arch.size; r++) {\n callWithCols(fn, ents[r] as EntityId, cols)\n }\n }\n}\n\nfunction callWithCols(\n fn: (eid: EntityId, ...cols: any[]) => void,\n eid: EntityId,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(eid)\n break\n case 1:\n fn(eid, cols[0])\n break\n case 2:\n fn(eid, cols[0], cols[1])\n break\n case 3:\n fn(eid, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(eid, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(eid, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(eid, ...cols)\n }\n}\n\n/**\n * Like {@link forEachEntity}, but yields the masked column index `i` alongside\n * the packed `EntityId`. The callback signature is `(e, i, ...cols)`:\n *\n * - `e` — the packed EntityId (carries the generation in its high bits). Use\n * it for in-loop `destroyEntity` / `hasComponent` / `refOf`, exactly as with\n * `forEachEntity`.\n * - `i` — `e & indexMask`, the raw slot index. This is the **correct subscript**\n * for SoA column views (`pos.x[i]`), and stays correct after a slot is\n * recycled — where indexing with the packed `e` would read out of bounds.\n * - `...cols` — the same column views `forEachEntity` passes.\n *\n * This closes the packed-EntityId footgun (A1): callers no longer need to call\n * `getEntityIndex(e)` (or hand-mask) themselves to index columns safely.\n */\nexport function forEachEntityIndexed(\n world: World,\n query: Query,\n fn: (e: EntityId, i: number, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const indexMask = state.options.indexMask\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithColsIndexed(fn, e, e & indexMask, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n // Re-read `arch.size` each iteration — see forEachEntity for the rationale.\n // An in-loop `destroyEntity` swap-pops the row and zeroes the freed tail; a\n // cached bound would replay the sentinel eid 0 across the public boundary\n // (ECS-B-01). Scalar read only; the zero-allocation hot-path contract holds.\n for (let r = 0; r < arch.size; r++) {\n const e = ents[r] as EntityId\n callWithColsIndexed(fn, e, e & indexMask, cols)\n }\n }\n}\n\nfunction callWithColsIndexed(\n fn: (e: EntityId, i: number, ...cols: any[]) => void,\n e: EntityId,\n i: number,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(e, i)\n break\n case 1:\n fn(e, i, cols[0])\n break\n case 2:\n fn(e, i, cols[0], cols[1])\n break\n case 3:\n fn(e, i, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(e, i, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(e, i, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(e, i, ...cols)\n }\n}\n\nfunction buildColumnViews(state: WorldState, q: QueryInternal): any[] {\n const out: any[] = []\n for (const comp of q.columnViewCache) {\n const info = getComponentInfo(comp)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) {\n out.push(undefined)\n continue\n }\n const storage = state.componentStorageByBit[bit]\n if (!storage) {\n out.push(undefined)\n continue\n }\n if (storage.kind === 'soa') out.push(storage.soa)\n else if (storage.kind === 'aos') out.push(storage.aos)\n else out.push(true) // tag\n }\n return out\n}\n\n// --- Reactive query updates (called from migration code) ---\n\nexport function recordEntityMaskChange(\n state: WorldState,\n eid: EntityId,\n changedBit: number,\n prevMask: Uint32Array,\n nextMask: Uint32Array,\n): void {\n // Lazy-register any reactive queries (and their sources) so we can correctly\n // determine match transitions even if the user only ever called enterQuery/exitQuery.\n for (const q of moduleQueryCache.values()) {\n if (q.reactiveKind === 'normal') continue\n if (q.sourceQuery && state.queries[q.sourceQuery.id] !== q.sourceQuery) {\n ensureQueryRegistered(state, q.sourceQuery)\n }\n }\n\n const involved = state.bitToQueries.get(changedBit)\n if (!involved) return\n const words = state.options.maskWordCount\n for (const qid of involved) {\n const q = state.queries[qid]\n if (!q) continue\n if (q.reactiveKind !== 'normal') continue\n const bundle = state.queryMasks.get(qid)\n if (!bundle) continue\n const wasMatch = matches(\n prevMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n const isMatch = matches(\n nextMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n if (!wasMatch && isMatch) {\n pushReactive(state, qid, 'enter', eid)\n } else if (wasMatch && !isMatch) {\n pushReactive(state, qid, 'exit', eid)\n }\n }\n}\n\nfunction pushReactive(\n state: WorldState,\n queryId: number,\n kind: 'enter' | 'exit',\n eid: EntityId,\n): void {\n // Walk the module cache (not just state.queries) so reactive variants that\n // haven't been registered with this world yet still receive events.\n for (const r of moduleQueryCache.values()) {\n if (r.sourceQueryId !== queryId) continue\n if (r.reactiveKind !== kind) continue\n // Lazily register the reactive query in this world so subsequent reads can find it\n ensureQueryRegistered(state, r)\n const buf = ensureReactiveBuffer(state, r.id)\n if (kind === 'enter') buf.entered.push(eid as number)\n else buf.exited.push(eid as number)\n }\n}\n\nfunction ensureReactiveBuffer(state: WorldState, qid: number): ReactiveBuffer {\n let buf = state.reactiveBuffers.get(qid)\n if (!buf) {\n buf = { entered: [], exited: [] }\n state.reactiveBuffers.set(qid, buf)\n }\n return buf\n}\n\n// --- Helpers ---\n\nfunction getComponentInfoById(componentId: number): ComponentInfo {\n // We need access to the component registry's lookup by id. Re-import dynamically to avoid cycles.\n const info = lazyGetComponentInfo(componentId)\n if (!info) throw new Error(`aiecsjs: component id ${componentId} not registered`)\n return info\n}\n\nlet _getComponentInfoFn: ((id: number) => ComponentInfo | undefined) | null = null\nexport function registerComponentLookup(fn: (id: number) => ComponentInfo | undefined): void {\n _getComponentInfoFn = fn\n}\nfunction lazyGetComponentInfo(id: number): ComponentInfo | undefined {\n return _getComponentInfoFn ? _getComponentInfoFn(id) : undefined\n}\n\nexport function _resetQueryRegistry_FOR_TESTS_ONLY(): void {\n moduleQueryCache.clear()\n nextQueryId = 1\n}\n"]}
|
package/dist/chunk-YFTCD2UG.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var F="0.5.8";function T(t){return new Uint32Array(t)}function z(t,n){let e=n>>>5;t[e]=(t[e]??0)|1<<(n&31);}function E(t,n){let e=n>>>5;t[e]=(t[e]??0)&~(1<<(n&31));}function A(t,n){let e=n>>>5;return ((t[e]??0)&1<<(n&31))!==0}function b(t){let n=new Uint32Array(t.length);for(let e=0;e<t.length;e++)n[e]=t[e]??0;return n}function W(t){let n=[];for(let e=0;e<t.length;e++)n.push((t[e]??0).toString(16));return n.join(",")}function xn(t){for(let n=0;n<t.length;n++)if((t[n]??0)!==0)return false;return true}function gn(t,n,e,o,r,i){let s=!r;for(let a=0;a<i;a++){let c=t[a]??0,f=n[a]??0,d=e[a]??0,u=o[a]??0;if((c&f)!==f||(c&u)!==0)return false;!s&&(c&d)!==0&&(s=true);}return s}function kn(t){let n=[];for(let e=0;e<t.length;e++){let o=t[e]??0;for(;o!==0;){let r=(e<<5)+D(o);n.push(r),o&=o-1;}}return n}function B(t,n,e,o){for(let r=0;r<e;r++){let i=t[n+r]??0;for(;i!==0;){let s=(r<<5)+D(i);o(s),i&=i-1;}}}function Cn(t,n,e,o,r,i,s){let a=!s;for(let c=0;c<e;c++){let f=t[n+c]??0,d=o[c]??0,u=r[c]??0,l=i[c]??0;if((f&d)!==d||(f&l)!==0)return false;!a&&(f&u)!==0&&(a=true);}return a}function D(t){return 31-Math.clz32(t&-t)}var p=class extends Error{constructor(n){super(n),this.name="EcsError";}};var S={initialCapacity:1024,maxEntities:1e6,indexBits:24,generationBits:8},nn=256,tn=1,w=new Map;function y(t){let n=w.get(t.id);if(!n)throw new p(`aiecsjs: world ${t.id} is destroyed or unknown`);if(n.destroyed)throw new p(`aiecsjs: world ${t.id} is destroyed`);return n}function en(t){w.set(t.id,t);}function on(t){w.delete(t);}function Mn(t){return w.has(t)}function rn(t){let n=t??{},e=n.indexBits??S.indexBits,o=n.generationBits??S.generationBits,r=nn;if(e<1||e>24)throw new p("aiecsjs: indexBits must be in [1, 24]");if(o<0||o>16)throw new p("aiecsjs: generationBits must be in [0, 16]");if(e+o>32)throw new p(`aiecsjs: indexBits (${e}) + generationBits (${o}) must be <= 32`);let i=1<<e,s=Math.max(1,Math.min(n.initialCapacity??S.initialCapacity,i)),a=Math.max(s,Math.min(n.maxEntities??S.maxEntities,i));return {initialCapacity:s,maxEntities:a,indexBits:e,generationBits:o,indexMask:(1<<e)-1,generationMask:o===0?0:(1<<o)-1,maxComponents:r,maskWordCount:Math.ceil(r/32),buffer:n.buffer??null,bufferByteOffset:n.bufferByteOffset??0}}function sn(t,n){return {id:0,mask:T(t),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:[],edgeAdd:new Int32Array(n).fill(-1),edgeRemove:new Int32Array(n).fill(-1)}}function Un(t){let n=rn(t),e=tn++,o=n.generationBits>8?Uint16Array:Uint8Array,r=new o(n.initialCapacity),i={id:e,capacity:n.initialCapacity,version:F,options:n,size:0,nextFreshIndex:1,freeList:[],generations:r,destroyed:false,componentBitFor:new Map,componentInfoByBit:new Array(n.maxComponents).fill(null),componentStorageByBit:new Array(n.maxComponents).fill(null),nextComponentBit:0,entityArchetype:new Uint32Array(n.initialCapacity),entityMask:new Uint32Array(n.initialCapacity*n.maskWordCount),archetypes:[],archetypeByMaskHash:new Map,queryVersion:0,queries:[],queryMasks:new Map,queryArchetypeCache:[],queryArchetypeStamp:[],bitToQueries:new Map,reactiveBuffers:new Map,observers:[],relationStorage:new Map,sab:n.buffer,readOnly:false},s=sn(n.maskWordCount,n.maxComponents);return s.id=0,i.archetypes.push(s),i.archetypeByMaskHash.set(W(s.mask),0),en(i),an(i)}function an(t){return {id:t.id,get capacity(){return t.capacity},version:t.version}}function On(t){let n=w.get(t.id);!n||n.destroyed||(n.destroyed=true,n.archetypes=[],n.archetypeByMaskHash.clear(),n.componentInfoByBit=[],n.componentStorageByBit=[],n.queries=[],n.queryMasks.clear(),n.queryArchetypeCache=[],n.observers=[],n.relationStorage.clear(),n.reactiveBuffers.clear(),n.entityMask=new Uint32Array(0),n.entityArchetype=new Uint32Array(0),n.generations=new Uint8Array(0),n.freeList=[],n.componentBitFor.clear(),n.bitToQueries.clear(),n.queryArchetypeStamp=[],n.sab=null,on(t.id));}function Rn(t){let n=y(t);n.size=0,n.nextFreshIndex=1,n.freeList=[],n.generations.fill(0),n.entityArchetype.fill(0),n.entityMask.fill(0);for(let e of n.archetypes)e.size=0,e.entityRow.clear();for(let e of n.componentStorageByBit)if(e)if(e.kind==="soa"&&e.soa)for(let o of Object.keys(e.soa))e.soa[o]?.fill(0);else e.kind==="aos"&&e.aos&&e.aos.fill(void 0);n.queryVersion++;for(let e of n.reactiveBuffers.values())e.entered.length=0,e.exited.length=0;}function _n(t){return y(t).size}function Ln(t){return y(t).capacity}function M(t,n){if(n<=t.capacity)return;if(n>t.options.maxEntities)throw new p(`aiecsjs: requested capacity ${n} exceeds maxEntities ${t.options.maxEntities}`);let e=t.capacity;for(;e<n;)e=Math.min(e*2,t.options.maxEntities);cn(t,e);}function cn(t,n){let e=t.generations.constructor,o=new e(n);o.set(t.generations),t.generations=o;let r=new Uint32Array(n);r.set(t.entityArchetype),t.entityArchetype=r;let i=t.options.maskWordCount,s=new Uint32Array(n*i);s.set(t.entityMask),t.entityMask=s;for(let a of t.componentStorageByBit)if(a)if(a.kind==="soa"&&a.soa){let c=t.componentInfoByBit[a.bit];c&&fn(a.soa,c.fields,n);}else a.kind==="aos"&&a.aos&&(a.aos.length=n);t.capacity=n;}function fn(t,n,e){for(let o of n){let r=t[o.name];if(!r)continue;let i=e*o.vectorLen;if(r.length>=i)continue;let s=new o.ctor(i);s.set(r),t[o.name]=s;}}function N(t,n){let e=W(n),o=t.archetypeByMaskHash.get(e);if(o!==void 0)return {archId:o,created:false};let r=t.archetypes.length,i={id:r,mask:b(n),size:0,capacity:16,entities:new Uint32Array(16),entityRow:new Map,componentBits:dn(n),edgeAdd:new Int32Array(t.options.maxComponents).fill(-1),edgeRemove:new Int32Array(t.options.maxComponents).fill(-1)};return t.archetypes.push(i),t.archetypeByMaskHash.set(e,r),t.queryVersion++,{archId:r,created:true}}function k(t,n){if(n<=t.capacity)return;let e=t.capacity;for(;e<n;)e*=2;let o=new Uint32Array(e);o.set(t.entities),t.entities=o,t.capacity=e;}function dn(t){let n=[];for(let e=0;e<t.length;e++){let o=t[e]??0;for(;o!==0;){let r=o&-o,i=(e<<5)+(31-Math.clz32(r));n.push(i),o&=o-1;}}return n}function P(t,n){let e=t.componentBitFor.get(n.id);if(e!==void 0)return e;if(t.nextComponentBit>=t.options.maxComponents)throw new p(`aiecsjs: world reached maxComponents=${t.options.maxComponents}`);let o=t.nextComponentBit++;t.componentBitFor.set(n.id,o),t.componentInfoByBit[o]=n;let r;if(n.kind==="soa"){let i={};for(let s of n.fields)i[s.name]=new s.ctor(t.capacity*s.vectorLen);r={kind:"soa",componentId:n.id,bit:o,soa:i};}else n.kind==="aos"?r={kind:"aos",componentId:n.id,bit:o,aos:new Array(t.capacity)}:r={kind:"tag",componentId:n.id,bit:o};return t.componentStorageByBit[o]=r,o}function h(t,n){let e=t.options.maskWordCount,o=new Uint32Array(e),i=(n&t.options.indexMask)*e;for(let s=0;s<e;s++)o[s]=t.entityMask[i+s]??0;return o}function q(t,n,e){let o=t.options.maskWordCount,i=(n&t.options.indexMask)*o;for(let s=0;s<o;s++)t.entityMask[i+s]=e[s]??0;}function C(t,n){return t.componentBitFor.get(n.id)}function jn(t){if(!t||typeof t!="object")return false;let n=t;return typeof n.id!="number"||typeof n.version!="string"?false:w.has(n.id)}var O=1,un={i8:Int8Array,u8:Uint8Array,i16:Int16Array,u16:Uint16Array,i32:Int32Array,u32:Uint32Array,f32:Float32Array,f64:Float64Array,eid:Uint32Array,bool:Uint8Array},x=new Map;function Nn(t){let n=[];for(let[i,s]of Object.entries(t)){let a,c=1;if(typeof s=="string")a=s;else if(Array.isArray(s)){let[d,u]=s;a=d,c=u;}else throw new TypeError(`aiecsjs: invalid field declaration for "${i}"`);let f=un[a];if(!f)throw new TypeError(`aiecsjs: unknown field type "${a}" for field "${i}"`);n.push({name:i,type:a,vectorLen:c,ctor:f,bytesPerElement:f.BYTES_PER_ELEMENT});}let e=O++,o={id:e,kind:"soa",schema:t,fields:n,factory:null};return x.set(e,o),{__kind:"soa",__id:e,__schema:t}}function Pn(){let t=O++,n={id:t,kind:"tag",schema:null,fields:[],factory:null};return x.set(t,n),{__kind:"tag",__id:t}}function qn(t){let n=O++,e=t??(()=>({})),o={id:n,kind:"aos",schema:null,fields:[],factory:e};return x.set(n,o),{__kind:"aos",__id:n,__factory:e}}function g(t){let n=x.get(t.__id);if(!n)throw new Error("aiecsjs: component is not registered (call defineComponent/defineTag/defineObjectComponent)");return n}function $(t,n,e,o){let r=y(t);if(r.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!m(r,n))throw new Error(`aiecsjs: addComponent on dead entity ${n}`);let i=g(e),s=P(r,i),a=h(r,n);if(A(a,s)){o!==void 0&&U(r,n,e,o);return}let c=b(a);z(c,s),V(r,n,c),U(r,n,e,o),ln(r,n,s),R(r,n,s,a,c);}function $n(t,n,e){let o=y(t);if(o.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!m(o,n))return;let r=g(e),i=C(o,r);if(i===void 0)return;let s=h(o,n);if(!A(s,i))return;let a=b(s);E(a,i),V(o,n,a),yn(o,n,i);let c=n&o.options.indexMask,f=o.componentStorageByBit[i];f?.kind==="soa"&&f.soa?G(f.soa,r.fields,c):f?.kind==="aos"&&f.aos&&(f.aos[c]=void 0),R(o,n,i,s,a);}function Gn(t,n,e){let o=y(t);if(!m(o,n))return false;let r=g(e),i=C(o,r);if(i===void 0)return false;let s=h(o,n);return A(s,i)}function Hn(t,n,e){let o=y(t);if(!m(o,n))return;let r=g(e),i=C(o,r);if(i===void 0)return;let s=h(o,n);if(!A(s,i))return;let a=o.componentStorageByBit[i];if(a){if(a.kind==="soa")return a.soa;if(a.kind==="aos"){let c=n&o.options.indexMask;return a.aos?.[c]}return true}}function Vn(t,n,e,o){let r=y(t);if(r.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");if(!m(r,n))throw new Error(`aiecsjs: setComponent on dead entity ${n}`);let i=g(e),s=C(r,i);if(s===void 0){$(t,n,e,o);return}let a=h(r,n);if(!A(a,s)){$(t,n,e,o);return}U(r,n,e,o),pn(r,n,s,o);}function U(t,n,e,o){let r=g(e),i=t.componentBitFor.get(r.id);if(i===void 0)return;let s=t.componentStorageByBit[i];if(!s)return;let a=n&t.options.indexMask;if(r.kind==="soa"&&s.soa){if(o==null)return;let c=o;for(let f of r.fields){if(!(f.name in c))continue;let d=s.soa[f.name];if(!d)continue;let u=c[f.name];if(f.vectorLen===1)d[a]=typeof u=="boolean"?u?1:0:Number(u);else if(Array.isArray(u)||ArrayBuffer.isView(u)){let l=a*f.vectorLen,J=u;for(let I=0;I<f.vectorLen;I++)d[l+I]=Number(J[I]??0);}}}else if(r.kind==="aos"&&s.aos){let c=r.factory??(()=>({})),f=s.aos[a];if(f===void 0&&(f=c(),s.aos[a]=f),o&&typeof o=="object"){let d=o,u=f;for(let l of Object.keys(d))l==="__proto__"||l==="constructor"||l==="prototype"||(u[l]=d[l]);}}}function G(t,n,e){for(let o of n){let r=t[o.name];if(r)if(o.vectorLen===1)r[e]=0;else {let i=e*o.vectorLen;for(let s=0;s<o.vectorLen;s++)r[i+s]=0;}}}function H(t,n){let e=t.options.maskWordCount,o=n&t.options.indexMask,r=o*e;B(t.entityMask,r,e,i=>{let s=t.componentStorageByBit[i],a=t.componentInfoByBit[i];s?.kind==="soa"&&s.soa&&a?G(s.soa,a.fields,o):s?.kind==="aos"&&s.aos&&(s.aos[o]=void 0);});}function V(t,n,e){let o=n&t.options.indexMask,r=t.entityArchetype[o]??0,i=t.archetypes[r];if(!i)return;let a=N(t,e).archId,c=t.archetypes[a];if(c){if(a!==r){let f=i.entityRow.get(n);if(f!==void 0){let u=i.size-1;if(f!==u){let l=i.entities[u]??0;i.entities[f]=l,i.entityRow.set(l,f);}i.entities[u]=0,i.entityRow.delete(n),i.size--;}k(c,c.size+1);let d=c.size;c.entities[d]=n,c.entityRow.set(n,d),c.size++,t.entityArchetype[o]=a;}q(t,n,e);}}var v={fireAdd:()=>{},fireRemove:()=>{},fireSet:()=>{}},X=()=>{};function Xn(t){X=t;}function R(t,n,e,o,r){X(t,n,e,o,r);}function Y(t,n,e){let o=t.options.maskWordCount,r=b(e),i=b(e);B(e,0,o,s=>{E(i,s),R(t,n,s,r,i),E(r,s);});}function Yn(t){v=t;}function ln(t,n,e){v.fireAdd(t,n,e);}function yn(t,n,e){v.fireRemove(t,n,e);}function pn(t,n,e,o){v.fireSet(t,n,e,o);}function Kn(t){return x.get(t)}function Qn(){return Array.from(x.values())}var j=24,mn=8,K=(1<<j)-1,Q=(1<<mn)-1;function Z(t,n,e){return ((n&e.generationMask)<<e.indexBits|t&e.indexMask)>>>0}function tt(t,n){return t&n.indexMask}function et(t,n){return t>>>n.indexBits&n.generationMask}function ot(t){let n=y(t);if(n.readOnly)throw new Error("aiecsjs: cannot createEntity on a read-only world (worker-attached)");let e;if(n.freeList.length>0)e=n.freeList.pop();else {if(n.nextFreshIndex>=n.options.maxEntities)throw new Error(`aiecsjs: reached maxEntities ${n.options.maxEntities}`);n.nextFreshIndex>=n.capacity&&M(n,n.nextFreshIndex+1),e=n.nextFreshIndex++;}let o=n.generations[e]??0,r=Z(e,o,n.options),i=n.archetypes[0];if(!i)throw new Error("aiecsjs: missing empty archetype");k(i,i.size+1);let s=i.size;i.entities[s]=r,i.entityRow.set(r,s),i.size++,n.entityArchetype[e]=0;let a=n.options.maskWordCount,c=e*a;for(let f=0;f<a;f++)n.entityMask[c+f]=0;return n.size++,r}function rt(t,n){if(t.readOnly)throw new Error("aiecsjs: cannot create entities on a read-only world (worker-attached)");if(n<=0||n>=t.options.maxEntities)throw new Error(`aiecsjs: slot index ${n} out of range`);n>=t.capacity&&M(t,n+1);let e=t.generations[n]??0,o=Z(n,e,t.options);if(m(t,o))return o;if(n>=t.nextFreshIndex){for(let c=t.nextFreshIndex;c<n;c++)t.freeList.push(c);t.nextFreshIndex=n+1;}else {let c=t.freeList.lastIndexOf(n);if(c!==-1){let f=t.freeList.length-1;t.freeList[c]=t.freeList[f],t.freeList.pop();}}let r=t.archetypes[0];if(!r)throw new Error("aiecsjs: missing empty archetype");k(r,r.size+1);let i=r.size;r.entities[i]=o,r.entityRow.set(o,i),r.size++,t.entityArchetype[n]=0;let s=t.options.maskWordCount,a=n*s;for(let c=0;c<s;c++)t.entityMask[a+c]=0;return t.size++,o}function it(t,n){let e=y(t);if(e.readOnly)throw new Error("aiecsjs: cannot destroyEntity on a read-only world");if(!m(e,n))return;let o=n&e.options.indexMask,r=h(e,n),{dispatchDestroyObservers:i}=bn();i(e,n),An(e,n),H(e,n);let s=e.entityArchetype[o]??0,a=e.archetypes[s];if(a){let d=a.entityRow.get(n);if(d!==void 0){let u=a.size-1;if(d!==u){let l=a.entities[u]??0;a.entities[d]=l,a.entityRow.set(l,d);}a.entities[u]=0,a.entityRow.delete(n),a.size--;}}Y(e,n,r),e.entityArchetype[o]=0;let c=e.options.maskWordCount,f=o*c;for(let d=0;d<c;d++)e.entityMask[f+d]=0;e.generations[o]=(e.generations[o]??0)+1&e.options.generationMask,e.freeList.push(o),e.size--;}function hn(t,n){let e=y(t);return m(e,n)}function m(t,n){let e=n&t.options.indexMask;if(e<=0||e>=t.capacity)return false;let o=t.entityArchetype[e]??0,r=t.archetypes[o];if(!r||!r.entityRow.has(n))return false;let i=t.generations[e]??0,s=n>>>t.options.indexBits&t.options.generationMask;return i===s}function st(t){return t&K}function at(t){return t>>>j&Q}function ct(t,n){return ((n&Q)<<j|t&K)>>>0}function ft(t,n){return typeof n!="number"?false:hn(t,n)}var _=null;function dt(t){_=t;}function bn(){return _||{dispatchDestroyObservers:()=>{}}}var L=null;function ut(t){L=t;}function An(t,n){L&&L(t,n);}export{st as A,at as B,ct as C,ft as D,dt as E,ut as F,Nn as G,Pn as H,qn as I,g as J,$ as K,$n as L,Gn as M,Hn as N,Vn as O,Xn as P,Yn as Q,Kn as R,Qn as S,F as a,T as b,z as c,xn as d,gn as e,kn as f,B as g,Cn as h,p as i,y as j,Mn as k,Un as l,On as m,Rn as n,_n as o,Ln as p,P as q,jn as r,Z as s,tt as t,et as u,ot as v,rt as w,it as x,hn as y,m as z};//# sourceMappingURL=chunk-YFTCD2UG.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-YFTCD2UG.js.map
|