@oasys/oecs 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +169 -182
- package/dist/archetype.d.ts +12 -9
- package/dist/archetype.d.ts.map +1 -1
- package/dist/component.d.ts +10 -0
- package/dist/component.d.ts.map +1 -1
- package/dist/ecs.d.ts +14 -14
- package/dist/ecs.d.ts.map +1 -1
- package/dist/entity.d.ts.map +1 -1
- package/dist/event.d.ts +6 -0
- package/dist/event.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +621 -459
- package/dist/query.d.ts +36 -16
- package/dist/query.d.ts.map +1 -1
- package/dist/ref.d.ts +4 -0
- package/dist/ref.d.ts.map +1 -1
- package/dist/resource.d.ts +21 -21
- package/dist/resource.d.ts.map +1 -1
- package/dist/schedule.d.ts +8 -6
- package/dist/schedule.d.ts.map +1 -1
- package/dist/store.d.ts +13 -6
- package/dist/store.d.ts.map +1 -1
- package/dist/system.d.ts.map +1 -1
- package/dist/type_primitives/assertions.d.ts +1 -0
- package/dist/type_primitives/assertions.d.ts.map +1 -1
- package/dist/type_primitives/binary_heap/binary_heap.d.ts +33 -0
- package/dist/type_primitives/binary_heap/binary_heap.d.ts.map +1 -0
- package/dist/type_primitives/bitset/bitset.d.ts +5 -0
- package/dist/type_primitives/bitset/bitset.d.ts.map +1 -1
- package/dist/type_primitives/error.d.ts +2 -1
- package/dist/type_primitives/error.d.ts.map +1 -1
- package/dist/type_primitives/index.d.ts +2 -0
- package/dist/type_primitives/index.d.ts.map +1 -1
- package/dist/type_primitives/topological_sort/topological_sort.d.ts +25 -0
- package/dist/type_primitives/topological_sort/topological_sort.d.ts.map +1 -0
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts +2 -0
- package/dist/type_primitives/typed_arrays/typed_arrays.d.ts.map +1 -1
- package/dist/utils/arrays.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +0 -8
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/error.d.ts +4 -1
- package/dist/utils/error.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ecs.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Archetype } from './archetype';
|
|
|
3
3
|
import { SystemContext, Query, QueryBuilder, QueryResolver } from './query';
|
|
4
4
|
import { EntityID } from './entity';
|
|
5
5
|
import { ComponentDef, ComponentSchema, ComponentFields, FieldValues } from './component';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { EventKey, EventReader } from './event';
|
|
7
|
+
import { ResourceKey } from './resource';
|
|
8
8
|
import { SystemFn, SystemConfig, SystemDescriptor } from './system';
|
|
9
9
|
import { BitSet, TypedArrayTag } from './type_primitives';
|
|
10
10
|
export interface WorldOptions {
|
|
@@ -18,6 +18,7 @@ export declare class ECS implements QueryResolver {
|
|
|
18
18
|
private readonly ctx;
|
|
19
19
|
private readonly systems;
|
|
20
20
|
private next_system_id;
|
|
21
|
+
private _tick;
|
|
21
22
|
private _fixed_timestep;
|
|
22
23
|
private _accumulator;
|
|
23
24
|
private _max_fixed_steps;
|
|
@@ -32,15 +33,12 @@ export declare class ECS implements QueryResolver {
|
|
|
32
33
|
readonly [K in F[number]]: T;
|
|
33
34
|
}>;
|
|
34
35
|
register_tag(): ComponentDef<Record<string, never>>;
|
|
35
|
-
register_event<F extends readonly string[]>(fields: F):
|
|
36
|
-
register_signal(
|
|
37
|
-
register_resource<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
set_resource<F extends ComponentFields>(def: ResourceDef<F>, values: {
|
|
42
|
-
readonly [K in F[number]]: number;
|
|
43
|
-
}): void;
|
|
36
|
+
register_event<F extends readonly string[]>(key: EventKey<F>, fields: F): void;
|
|
37
|
+
register_signal(key: EventKey<readonly []>): void;
|
|
38
|
+
register_resource<T>(key: ResourceKey<T>, value: T): void;
|
|
39
|
+
resource<T>(key: ResourceKey<T>): T;
|
|
40
|
+
set_resource<T>(key: ResourceKey<T>, value: T): void;
|
|
41
|
+
has_resource<T>(key: ResourceKey<T>): boolean;
|
|
44
42
|
create_entity(): EntityID;
|
|
45
43
|
destroy_entity_deferred(id: EntityID): void;
|
|
46
44
|
is_alive(id: EntityID): boolean;
|
|
@@ -67,11 +65,13 @@ export declare class ECS implements QueryResolver {
|
|
|
67
65
|
batch_remove_component(src_arch: Archetype, def: ComponentDef): void;
|
|
68
66
|
get_field<S extends ComponentSchema>(entity_id: EntityID, def: ComponentDef<S>, field: string & keyof S): number;
|
|
69
67
|
set_field<S extends ComponentSchema>(entity_id: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): void;
|
|
70
|
-
emit(
|
|
71
|
-
emit<F extends ComponentFields>(
|
|
68
|
+
emit(key: EventKey<readonly []>): void;
|
|
69
|
+
emit<F extends ComponentFields>(key: EventKey<F>, values: {
|
|
72
70
|
readonly [K in F[number]]: number;
|
|
73
71
|
}): void;
|
|
72
|
+
read<F extends ComponentFields>(key: EventKey<F>): EventReader<F>;
|
|
74
73
|
query<T extends ComponentDef[]>(...defs: T): Query<T>;
|
|
74
|
+
_get_last_run_tick(): number;
|
|
75
75
|
/** QueryResolver implementation — creates or retrieves a cached Query. */
|
|
76
76
|
_resolve_query(include: BitSet, exclude: BitSet | null, any_of: BitSet | null, defs: readonly ComponentDef[]): Query<any>;
|
|
77
77
|
private _find_cached;
|
|
@@ -83,7 +83,7 @@ export declare class ECS implements QueryResolver {
|
|
|
83
83
|
*
|
|
84
84
|
* // Function + query builder
|
|
85
85
|
* world.register_system(
|
|
86
|
-
* (q, ctx, dt) => {
|
|
86
|
+
* (q, ctx, dt) => { q.for_each((arch) => { ... }); },
|
|
87
87
|
* (qb) => qb.every(Pos, Vel),
|
|
88
88
|
* );
|
|
89
89
|
*
|
package/dist/ecs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;KAkBK;AAEL,OAAO,EAAE,KAAK,EAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;KAkBK;AAEL,OAAO,EAAE,KAAK,EAAe,MAAM,mBAAmB,CAAC;AAIvD,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAElD,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,UAAU,QAAwB,CAAC;AAChD,eAAO,MAAM,SAAS,QAAa,CAAC;AACpC,eAAO,MAAM,eAAe,QAAiC,CAAC;AAC9D,eAAO,MAAM,cAAc,QAA6B,CAAC;AAEzD,eAAO,MAAM,gBAAgB,UAAW,MAAM,cAAc,MAAM,KAAG,QAWpE,CAAC;AAEF,eAAO,MAAM,gBAAgB,OAAQ,QAAQ,KAAG,MAAyB,CAAC;AAE1E,eAAO,MAAM,qBAAqB,OAAQ,QAAQ,KAAG,MAAsC,CAAC"}
|
package/dist/event.d.ts
CHANGED
|
@@ -20,5 +20,11 @@ export declare class EventChannel {
|
|
|
20
20
|
emit_signal(): void;
|
|
21
21
|
clear(): void;
|
|
22
22
|
}
|
|
23
|
+
declare const __event_key_schema: unique symbol;
|
|
24
|
+
export type EventKey<F extends ComponentFields = ComponentFields> = symbol & {
|
|
25
|
+
readonly [__event_key_schema]: F;
|
|
26
|
+
};
|
|
27
|
+
export declare function event_key<F extends readonly string[]>(name: string): EventKey<F>;
|
|
28
|
+
export declare function signal_key(name: string): EventKey<readonly []>;
|
|
23
29
|
export {};
|
|
24
30
|
//# sourceMappingURL=event.d.ts.map
|
package/dist/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4BK;AAEL,OAAO,EAAE,KAAK,EAA2D,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAChD,eAAO,MAAM,WAAW,UAAW,MAAM,YAKtC,CAAC;AAGJ,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAE5C,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,OAAO,GAAG;IAC5E,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;CAC9B,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,eAAe,IAAI;IACnD,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAExB,qBAAa,YAAY;IACvB,SAAgB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtC,SAAgB,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;IAEpC,SAAgB,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;gBAE7B,WAAW,EAAE,MAAM,EAAE;IAgB1B,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IASjD,wCAAwC;IACjC,WAAW,IAAI,IAAI;IAInB,KAAK,IAAI,IAAI;CAOrB;AAMD,OAAO,CAAC,MAAM,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAEhD,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,MAAM,GAAG;IAC3E,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;CAClC,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAEhF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAE9D"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class tt extends Error{constructor(t,e,s){super(t),this.is_operational=e,this.context=s,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}}var z=(l=>(l.EID_MAX_INDEX_OVERFLOW="EID_MAX_INDEX_OVERFLOW",l.EID_MAX_GEN_OVERFLOW="EID_MAX_GEN_OVERFLOW",l.COMPONENT_NOT_REGISTERED="COMPONENT_NOT_REGISTERED",l.ENTITY_NOT_ALIVE="ENTITY_NOT_ALIVE",l.CIRCULAR_SYSTEM_DEPENDENCY="CIRCULAR_SYSTEM_DEPENDENCY",l.DUPLICATE_SYSTEM="DUPLICATE_SYSTEM",l.ARCHETYPE_NOT_FOUND="ARCHETYPE_NOT_FOUND",l.RESOURCE_NOT_REGISTERED="RESOURCE_NOT_REGISTERED",l))(z||{});class et extends tt{constructor(t,e,s){super(e??t,!0,s),this.category=t}}function N(l,t,e){return l}const v=-1,y=-1,D=Object.freeze(Object.create(null)),k=5,I=31,st=2166136261,nt=16777619,rt=2654435769,it=1367130551,x=16,G=2,V=1024,R=0,j=0,ot=31,_t=1/60,ct=4,ht=0,lt=4;class b{_words;constructor(t){this._words=t??new Array(lt).fill(0)}has(t){const e=t>>>k;return e>=this._words.length?!1:(this._words[e]&1<<(t&I))!==0}set(t){const e=t>>>k;e>=this._words.length&&this.grow(e+1),this._words[e]|=1<<(t&I)}clear(t){const e=t>>>k;e>=this._words.length||(this._words[e]&=~(1<<(t&I)))}overlaps(t){const e=this._words,s=t._words,n=e.length<s.length?e.length:s.length;for(let r=0;r<n;r++)if((e[r]&s[r])!==0)return!0;return!1}contains(t){const e=t._words,s=this._words,n=s.length;for(let r=0;r<e.length;r++){const i=e[r];if(i!==0&&(r>=n||(s[r]&i)!==i))return!1}return!0}equals(t){const e=this._words,s=t._words,n=e.length>s.length?e.length:s.length;for(let r=0;r<n;r++){const i=r<e.length?e[r]:0,_=r<s.length?s[r]:0;if(i!==_)return!1}return!0}copy(){return new b(this._words.slice())}copy_with_set(t){const e=t>>>k,s=e+1,n=this._words.length>s?this._words.length:s,r=new Array(n).fill(0);for(let i=0;i<this._words.length;i++)r[i]=this._words[i];return r[e]|=1<<(t&I),new b(r)}copy_with_clear(t){const e=this._words.slice(),s=t>>>k;return s<e.length&&(e[s]&=~(1<<(t&I))),new b(e)}hash(){let t=st;const e=this._words;let s=e.length-1;for(;s>=0&&e[s]===0;)s--;for(let n=0;n<=s;n++)t^=e[n],t=Math.imul(t,nt);return t}for_each(t){const e=this._words;for(let s=0;s<e.length;s++){let n=e[s];if(n===0)continue;const r=s<<k;for(;n!==0;){const i=n&-n>>>0,_=I-Math.clz32(i);t(r+_),n^=i}}}grow(t){let e=this._words.length;for(;e<t;)e*=2;const s=new Array(e).fill(0);for(let n=0;n<this._words.length;n++)s[n]=this._words[n];this._words=s}}class A{constructor(t,e=x){this._ctor=t,this._buf=new t(e)}_buf;_len=0;get length(){return this._len}push(t){this._len>=this._buf.length&&this._grow(),this._buf[this._len++]=t}pop(){return this._buf[--this._len]}get(t){return this._buf[t]}set_at(t,e){this._buf[t]=e}swap_remove(t){const e=this._buf[t];return this._buf[t]=this._buf[--this._len],e}clear(){this._len=0}get buf(){return this._buf}view(){return this._buf.subarray(0,this._len)}[Symbol.iterator](){let t=0;const e=this._buf,s=this._len;return{next(){return t<s?{value:e[t++],done:!1}:{value:0,done:!0}}}}ensure_capacity(t){if(t<=this._buf.length)return;let e=this._buf.length||1;for(;e<t;)e*=G;const s=new this._ctor(e);s.set(this._buf.subarray(0,this._len)),this._buf=s}bulk_append(t,e,s){this.ensure_capacity(this._len+s),this._buf.set(t.subarray(e,e+s),this._len),this._len+=s}bulk_append_zeroes(t){this.ensure_capacity(this._len+t),this._buf.fill(0,this._len,this._len+t),this._len+=t}_grow(){const t=new this._ctor(this._buf.length*G);t.set(this._buf),this._buf=t}}class at extends A{constructor(t=x){super(Float32Array,t)}}class dt extends A{constructor(t=x){super(Float64Array,t)}}class ut extends A{constructor(t=x){super(Int8Array,t)}}class ft extends A{constructor(t=x){super(Int16Array,t)}}class gt extends A{constructor(t=x){super(Int32Array,t)}}class mt extends A{constructor(t=x){super(Uint8Array,t)}}class yt extends A{constructor(t=x){super(Uint16Array,t)}}class B extends A{constructor(t=x){super(Uint32Array,t)}}const pt={f32:at,f64:dt,i8:ut,i16:ft,i32:gt,u8:mt,u16:yt,u32:B},S=20,F=(1<<S)-1,wt=ot-S,X=(1<<wt)-1,vt=(l,t)=>t<<S|l,m=l=>l&F,Y=l=>l>>S,bt=l=>N(l),xt=l=>N(l);class Tt{field_names;columns;reader;constructor(t){this.field_names=t,this.columns=[];for(let s=0;s<t.length;s++)this.columns.push([]);const e={length:0};for(let s=0;s<t.length;s++)e[t[s]]=this.columns[s];this.reader=e}emit(t){const e=this.field_names,s=this.columns;for(let n=0;n<e.length;n++)s[n].push(t[e[n]]);this.reader.length++}emit_signal(){this.reader.length++}clear(){this.reader.length=0;const t=this.columns;for(let e=0;e<t.length;e++)t[e].length=0}}const At=l=>N(l);class Et{field_names;field_index;columns;reader;constructor(t,e){this.field_names=t,this.field_index=Object.create(null),this.columns=[];for(let r=0;r<t.length;r++)this.field_index[t[r]]=r,this.columns.push([e[t[r]]??0]);const s=Object.create(null),n=this.columns;for(let r=0;r<t.length;r++){const i=n[r];Object.defineProperty(s,t[r],{get(){return i[R]},enumerable:!0})}this.reader=s}write(t){const e=this.field_names,s=this.columns;for(let n=0;n<e.length;n++)e[n]in t&&(s[n][R]=t[e[n]])}read_field(t){return this.columns[t][R]}write_field(t,e){this.columns[t][R]=e}}const kt=l=>N(l);class It{id;mask;has_columns;_entity_ids;length=0;edges=[];_flat_columns=[];_col_offset=[];_field_count=[];_field_index=[];_field_names=[];column_groups=[];_column_ids=[];constructor(t,e,s,n=V){if(this.id=t,this.mask=e,this._entity_ids=new B(n),s){let r=0;for(let i=0;i<s.length;i++){const _=s[i],c=_.component_id,o=new Array(_.field_names.length);this._col_offset[c]=r,this._field_count[c]=_.field_names.length,this._field_index[c]=_.field_index,this._field_names[c]=_.field_names;for(let h=0;h<_.field_names.length;h++){const a=new pt[_.field_types[h]](n);o[h]=a,this._flat_columns[r++]=a}this.column_groups[c]={layout:_,columns:o},this._column_ids.push(c)}}this.has_columns=this._column_ids.length>0}get entity_count(){return this.length}get entity_ids(){return this._entity_ids.buf}get entity_list(){return this._entity_ids.view()}has_component(t){return this.mask.has(t)}matches(t){return this.mask.contains(t)}get_column(t,e){const s=t,n=this._field_index[s][e];return this._flat_columns[this._col_offset[s]+n].buf}write_fields(t,e,s){const n=e,r=this._col_offset[n];if(r===void 0)return;const i=this._field_names[n],_=this._flat_columns;for(let c=0;c<i.length;c++)_[r+c].buf[t]=s[i[c]]}write_fields_positional(t,e,s){const n=e,r=this._col_offset[n];if(r===void 0)return;const i=this._flat_columns;for(let _=0;_<s.length;_++)i[r+_].buf[t]=s[_]}read_field(t,e,s){const n=e,r=this._col_offset[n];if(r===void 0)return NaN;const i=this._field_index[n][s];return i===void 0?NaN:this._flat_columns[r+i].buf[t]}copy_shared_from(t,e,s){const n=t._col_offset,r=t._field_count,i=t._flat_columns,_=this._flat_columns,c=this._column_ids;for(let o=0;o<c.length;o++){const h=c[o],a=n[h];if(a===void 0)continue;const u=this._col_offset[h],d=r[h];for(let g=0;g<d;g++)_[u+g].buf[s]=i[a+g].buf[e]}}add_entity(t){const e=this.length;this._entity_ids.push(t);const s=this._flat_columns;for(let n=0;n<s.length;n++)s[n].push(0);return this.length++,e}remove_entity(t){const e=this.length-1;let s=y;const n=this._flat_columns,r=this._entity_ids.buf;if(t!==e){r[t]=r[e],s=m(r[t]);for(let i=0;i<n.length;i++)n[i].swap_remove(t)}else for(let i=0;i<n.length;i++)n[i].pop();return this._entity_ids.pop(),this.length--,s}add_entity_tag(t){const e=this.length;return this._entity_ids.push(t),this.length++,e}remove_entity_tag(t){const e=this.length-1;let s=y;const n=this._entity_ids.buf;return t!==e&&(n[t]=n[e],s=m(n[t])),this._entity_ids.pop(),this.length--,s}move_entity_from(t,e,s,n){const r=this.length;this._entity_ids.push(s);const i=this._flat_columns,_=t._flat_columns;for(let o=0;o<i.length;o++){const h=n[o];i[o].push(h>=0?_[h].buf[e]:0)}this.length++;const c=t.has_columns?t.remove_entity(e):t.remove_entity_tag(e);f[0]=r,f[1]=c}move_entity_from_tag(t,e,s){const n=this.length;this._entity_ids.push(s),this.length++;const r=t.remove_entity_tag(e);f[0]=n,f[1]=r}bulk_move_all_from(t,e){const s=t.length;if(s===0)return this.length;const n=this.length,r=this._flat_columns,i=t._flat_columns;this._entity_ids.bulk_append(t._entity_ids.buf,0,s);for(let _=0;_<r.length;_++){const c=e[_];c>=0?r[_].bulk_append(i[c].buf,0,s):r[_].bulk_append_zeroes(s)}this.length+=s,t.length=0,t._entity_ids.clear();for(let _=0;_<i.length;_++)i[_].clear();return n}get_edge(t){return this.edges[t]}set_edge(t,e){this.edges[t]=e}}const f=[0,y];function M(l,t){const e=t._flat_columns,s=new Int16Array(e.length),n=t._column_ids,r=l._col_offset,i=t._col_offset,_=t._field_count;for(let c=0;c<n.length;c++){const o=n[c],h=i[o],a=_[o],u=r[o];if(u!==void 0)for(let d=0;d<a;d++)s[h+d]=u+d;else for(let d=0;d<a;d++)s[h+d]=-1}return s}function Q(l,t,e){const s=l.get(t);s!==void 0?s.push(e):l.set(t,[e])}class St{entity_generations=[];entity_high_water=0;entity_free_indices=[];entity_alive_count=0;component_metas=[];component_count=0;event_channels=[];event_count=0;resource_channels=[];resource_count=0;archetypes=[];archetype_map=new Map;next_archetype_id=0;component_index=new Map;registered_queries=[];empty_archetype_id;entity_archetype=[];entity_row=[];pending_destroy=[];pending_add_ids=[];pending_add_defs=[];pending_add_values=[];pending_remove_ids=[];pending_remove_defs=[];initial_capacity;constructor(t){this.initial_capacity=t??V,this.empty_archetype_id=this.arch_get_or_create_from_mask(new b)}arch_get(t){return this.archetypes[t]}arch_get_or_create_from_mask(t){const e=t.hash(),s=this.archetype_map.get(e);if(s!==void 0){for(let c=0;c<s.length;c++)if(this.archetypes[s[c]].mask.equals(t))return s[c]}const n=kt(this.next_archetype_id++),r=[];t.for_each(c=>{const o=c,h=this.component_metas[o];h&&h.field_names.length>0&&r.push({component_id:o,field_names:h.field_names,field_index:h.field_index,field_types:h.field_types})});const i=new It(n,t,r,this.initial_capacity);this.archetypes.push(i),Q(this.archetype_map,e,n),t.for_each(c=>{const o=c;let h=this.component_index.get(o);h||(h=new Set,this.component_index.set(o,h)),h.add(n)});const _=this.registered_queries;for(let c=0;c<_.length;c++){const o=_[c];i.matches(o.include_mask)&&(!o.exclude_mask||!i.mask.overlaps(o.exclude_mask))&&(!o.any_of_mask||i.mask.overlaps(o.any_of_mask))&&o.result.push(i)}return n}arch_resolve_add(t,e){const s=this.arch_get(t);if(s.mask.has(e))return t;const n=s.get_edge(e);if(n?.add!=null)return n.add;const r=this.arch_get_or_create_from_mask(s.mask.copy_with_set(e));return this.arch_cache_edge(s,this.arch_get(r),e),r}arch_resolve_remove(t,e){const s=this.arch_get(t);if(!s.mask.has(e))return t;const n=s.get_edge(e);if(n?.remove!=null)return n.remove;const r=this.arch_get_or_create_from_mask(s.mask.copy_with_clear(e));return this.arch_cache_edge(this.arch_get(r),s,e),r}arch_cache_edge(t,e,s){const n=t.get_edge(s)??{add:null,remove:null,add_map:null,remove_map:null};n.add=e.id,n.add_map=M(t,e),t.set_edge(s,n);const r=e.get_edge(s)??{add:null,remove:null,add_map:null,remove_map:null};r.remove=t.id,r.remove_map=M(e,t),e.set_edge(s,r)}create_entity(){let t,e;this.entity_free_indices.length>0?(t=this.entity_free_indices.pop(),e=this.entity_generations[t]):(t=this.entity_high_water++,this.entity_generations[t]=j,e=j),this.entity_alive_count++;const s=vt(t,e);return this.entity_archetype[t]=this.empty_archetype_id,this.entity_row[t]=v,s}destroy_entity(t){if(!this.is_alive(t))return;const e=m(t),s=this.entity_row[e];if(s!==v){const i=this.arch_get(this.entity_archetype[e]).remove_entity(s);i!==y&&(this.entity_row[i]=s)}this.entity_archetype[e]=v,this.entity_row[e]=v;const n=Y(t);this.entity_generations[e]=n+1&X,this.entity_free_indices.push(e),this.entity_alive_count--}is_alive(t){const e=m(t);return e<this.entity_high_water&&this.entity_generations[e]===Y(t)}get entity_count(){return this.entity_alive_count}destroy_entity_deferred(t){this.pending_destroy.push(t)}flush_destroyed(){const t=this.pending_destroy;if(t.length===0)return;const e=this.entity_archetype,s=this.entity_row,n=this.entity_generations,r=this.archetypes,i=this.entity_high_water;for(let _=0;_<t.length;_++){const c=t[_],o=c&F,h=c>>S;if(o>=i||n[o]!==h)continue;const a=s[o];if(a!==v){const u=r[e[o]],d=u.has_columns?u.remove_entity(a):u.remove_entity_tag(a);d!==y&&(s[d]=a)}e[o]=v,s[o]=v,n[o]=h+1&X,this.entity_free_indices.push(o),this.entity_alive_count--}t.length=0}get pending_destroy_count(){return this.pending_destroy.length}add_component_deferred(t,e,s){this.pending_add_ids.push(t),this.pending_add_defs.push(e),this.pending_add_values.push(s??D)}remove_component_deferred(t,e){this.pending_remove_ids.push(t),this.pending_remove_defs.push(e)}flush_structural(){this.pending_add_ids.length>0&&this._flush_adds(),this.pending_remove_ids.length>0&&this._flush_removes()}_flush_adds(){const t=this.pending_add_ids,e=this.pending_add_defs,s=this.pending_add_values,n=t.length,r=this.entity_archetype,i=this.entity_row,_=this.entity_generations,c=this.archetypes,o=this.component_metas,h=this.entity_high_water;for(let a=0;a<n;a++){const u=t[a],d=u&F,g=u>>S;if(d>=h||_[d]!==g)continue;const T=r[d],p=e[a],w=c[T];if(w.mask.has(p)){o[p].field_names.length>0&&w.write_fields(i[d],p,s[a]);continue}const P=this.arch_resolve_add(T,p),E=c[P],O=i[d],L=!E.has_columns&&!w.has_columns;let U;if(O!==v){if(L)E.move_entity_from_tag(w,O,u);else{const Z=w.get_edge(p);E.move_entity_from(w,O,u,Z.add_map)}U=f[0],f[1]!==y&&(i[f[1]]=O)}else U=L?E.add_entity_tag(u):E.add_entity(u);o[p].field_names.length>0&&E.write_fields(U,p,s[a]),r[d]=P,i[d]=U}t.length=0,e.length=0,s.length=0}_flush_removes(){const t=this.pending_remove_ids,e=this.pending_remove_defs,s=t.length,n=this.entity_archetype,r=this.entity_row,i=this.entity_generations,_=this.archetypes,c=this.entity_high_water;for(let o=0;o<s;o++){const h=t[o],a=h&F,u=h>>S;if(a>=c||i[a]!==u)continue;const d=n[a],g=e[o],T=_[d];if(!T.mask.has(g))continue;const p=this.arch_resolve_remove(d,g),w=_[p],P=r[a];if(!w.has_columns&&!T.has_columns)w.move_entity_from_tag(T,P,h);else{const O=T.get_edge(g);w.move_entity_from(T,P,h,O.remove_map)}f[1]!==y&&(r[f[1]]=P),n[a]=p,r[a]=f[0]}t.length=0,e.length=0}get pending_structural_count(){return this.pending_add_ids.length+this.pending_remove_ids.length}register_component(t){const e=bt(this.component_count++),s=Object.keys(t),n=new Array(s.length),r=Object.create(null);for(let i=0;i<s.length;i++)r[s[i]]=i,n[i]=t[s[i]];return this.component_metas.push({field_names:s,field_index:r,field_types:n}),e}add_component(t,e,s){if(!this.is_alive(t))return;const n=m(t),r=this.entity_archetype[n],i=this.arch_get(r);if(i.has_component(e)){i.write_fields(this.entity_row[n],e,s);return}const _=this.arch_resolve_add(r,e),c=this.arch_get(_),o=this.entity_row[n];let h;if(o!==v){const a=i.get_edge(e);!c.has_columns&&!i.has_columns?c.move_entity_from_tag(i,o,t):c.move_entity_from(i,o,t,a.add_map),h=f[0],f[1]!==y&&(this.entity_row[f[1]]=o)}else h=c.has_columns?c.add_entity(t):c.add_entity_tag(t);c.write_fields(h,e,s),this.entity_archetype[n]=_,this.entity_row[n]=h}add_components(t,e){if(!this.is_alive(t))return;const s=m(t),n=this.entity_archetype[s];let r=n;for(let i=0;i<e.length;i++)r=this.arch_resolve_add(r,e[i].def);if(r!==n){const i=this.arch_get(n),_=this.arch_get(r),c=this.entity_row[s];let o;if(c!==v){const h=M(i,_);_.move_entity_from(i,c,t,h),o=f[0],f[1]!==y&&(this.entity_row[f[1]]=c)}else o=_.add_entity(t);for(let h=0;h<e.length;h++)_.write_fields(o,e[h].def,e[h].values??D);this.entity_archetype[s]=r,this.entity_row[s]=o}else{const i=this.arch_get(n),_=this.entity_row[s];for(let c=0;c<e.length;c++)i.write_fields(_,e[c].def,e[c].values??D)}}remove_component(t,e){if(!this.is_alive(t))return;const s=m(t),n=this.entity_archetype[s],r=this.arch_get(n);if(!r.has_component(e))return;const i=this.arch_resolve_remove(n,e),_=this.arch_get(i),c=this.entity_row[s],o=r.get_edge(e);!_.has_columns&&!r.has_columns?_.move_entity_from_tag(r,c,t):_.move_entity_from(r,c,t,o.remove_map),f[1]!==y&&(this.entity_row[f[1]]=c),this.entity_archetype[s]=i,this.entity_row[s]=f[0]}remove_components(t,e){if(!this.is_alive(t))return;const s=m(t),n=this.entity_archetype[s];let r=n;for(let h=0;h<e.length;h++)r=this.arch_resolve_remove(r,e[h]);if(r===n)return;const i=this.arch_get(n),_=this.arch_get(r),c=this.entity_row[s],o=M(i,_);_.move_entity_from(i,c,t,o),f[1]!==y&&(this.entity_row[f[1]]=c),this.entity_archetype[s]=r,this.entity_row[s]=f[0]}has_component(t,e){if(!this.is_alive(t))return!1;const s=m(t);return this.arch_get(this.entity_archetype[s]).has_component(e)}batch_add_component(t,e,s){if(t.length===0)return;const n=e;if(t.mask.has(n))return;const r=this.arch_resolve_add(t.id,n),i=this.arch_get(r),_=t.get_edge(n),c=t.length,o=this.entity_archetype,h=this.entity_row,a=i.bulk_move_all_from(t,_.add_map);for(let d=0;d<c;d++){const g=m(i.entity_ids[a+d]);o[g]=r,h[g]=a+d}if(this.component_metas[n].field_names.length>0&&s)for(let d=0;d<c;d++)i.write_fields(a+d,n,s)}batch_remove_component(t,e){if(t.length===0)return;const s=e;if(!t.mask.has(s))return;const n=this.arch_resolve_remove(t.id,s),r=this.arch_get(n),i=t.get_edge(s),_=t.length,c=r.bulk_move_all_from(t,i.remove_map),o=this.entity_archetype,h=this.entity_row;for(let a=0;a<_;a++){const u=m(r.entity_ids[c+a]);o[u]=n,h[u]=c+a}}get_entity_archetype(t){return this.arch_get(this.entity_archetype[m(t)])}get_entity_row(t){return this.entity_row[m(t)]}get_matching_archetypes(t,e,s){const n=t._words;let r=!1;for(let o=0;o<n.length;o++)if(n[o]!==0){r=!0;break}if(!r)return this.archetypes.filter(o=>(!e||!o.mask.overlaps(e))&&(!s||o.mask.overlaps(s)));let i,_=!1;for(let o=0;o<n.length;o++){let h=n[o];if(h===0)continue;const a=o<<k;for(;h!==0;){const u=h&-h>>>0,d=a+(I-Math.clz32(u));h^=u;const g=this.component_index.get(d);if(!g||g.size===0){_=!0;break}(!i||g.size<i.size)&&(i=g)}if(_)break}if(_||!i)return[];const c=[];for(const o of i){const h=this.arch_get(o);h.matches(t)&&(!e||!h.mask.overlaps(e))&&(!s||h.mask.overlaps(s))&&c.push(h)}return c}register_query(t,e,s){const n=this.get_matching_archetypes(t,e,s);return this.registered_queries.push({include_mask:t.copy(),exclude_mask:e?e.copy():null,any_of_mask:s?s.copy():null,result:n}),n}get archetype_count(){return this.archetypes.length}register_event(t){const e=xt(this.event_count++),s=new Tt(t);return this.event_channels.push(s),e}emit_event(t,e){this.event_channels[t].emit(e)}emit_signal(t){this.event_channels[t].emit_signal()}get_event_reader(t){return this.event_channels[t].reader}clear_events(){const t=this.event_channels;for(let e=0;e<t.length;e++)t[e].clear()}register_resource(t,e){const s=At(this.resource_count++),n=new Et(t,e);return this.resource_channels.push(n),s}get_resource_reader(t){return this.resource_channels[t].reader}get_resource_channel(t){return this.resource_channels[t]}}var H=(l=>(l.PRE_STARTUP="PRE_STARTUP",l.STARTUP="STARTUP",l.POST_STARTUP="POST_STARTUP",l.FIXED_UPDATE="FIXED_UPDATE",l.PRE_UPDATE="PRE_UPDATE",l.UPDATE="UPDATE",l.POST_UPDATE="POST_UPDATE",l))(H||{});const q=["PRE_STARTUP","STARTUP","POST_STARTUP"],C=["PRE_UPDATE","UPDATE","POST_UPDATE"];class Pt{label_systems=new Map;sorted_cache=new Map;system_index=new Map;next_insertion_order=0;constructor(){for(let t=0;t<q.length;t++)this.label_systems.set(q[t],[]);this.label_systems.set("FIXED_UPDATE",[]);for(let t=0;t<C.length;t++)this.label_systems.set(C[t],[])}add_systems(t,...e){for(const s of e){const n="system"in s?s.system:s,r="system"in s?s.ordering:void 0,i={descriptor:n,insertion_order:this.next_insertion_order++,before:new Set(r?.before??[]),after:new Set(r?.after??[])};this.label_systems.get(t).push(i),this.system_index.set(n,t),this.sorted_cache.delete(t)}}remove_system(t){const e=this.system_index.get(t);if(e===void 0)return;const s=this.label_systems.get(e),n=s.findIndex(r=>r.descriptor===t);if(n!==-1){const r=s.length-1;n!==r&&(s[n]=s[r]),s.pop();for(const i of s)i.before.delete(t),i.after.delete(t)}this.system_index.delete(t),this.sorted_cache.delete(e)}run_startup(t){for(const e of q)this.run_label(e,t,ht)}run_update(t,e){for(const s of C)this.run_label(s,t,e)}run_fixed_update(t,e){this.run_label("FIXED_UPDATE",t,e)}has_fixed_systems(){return this.label_systems.get("FIXED_UPDATE").length>0}get_all_systems(){const t=[];for(const e of this.label_systems.values())for(const s of e)t.push(s.descriptor);return t}has_system(t){return this.system_index.has(t)}clear(){for(const t of this.label_systems.values())t.length=0;this.sorted_cache.clear(),this.system_index.clear()}run_label(t,e,s){const n=this.get_sorted(t);for(let r=0;r<n.length;r++)n[r].fn(e,s);e.flush()}get_sorted(t){const e=this.sorted_cache.get(t);if(e!==void 0)return e;const s=this.label_systems.get(t),n=this.topological_sort(s,t);return this.sorted_cache.set(t,n),n}topological_sort(t,e){if(t.length===0)return[];const s=new Map,n=new Map,r=new Map,i=new Set;for(const o of t)s.set(o.descriptor,new Set),n.set(o.descriptor,0),r.set(o.descriptor,o.insertion_order),i.add(o.descriptor);for(const o of t){for(const h of o.before)i.has(h)&&(s.get(o.descriptor).add(h),n.set(h,n.get(h)+1));for(const h of o.after)i.has(h)&&(s.get(h).add(o.descriptor),n.set(o.descriptor,n.get(o.descriptor)+1))}let _=[];for(const o of t)n.get(o.descriptor)===0&&_.push(o.descriptor);_.sort((o,h)=>r.get(h)-r.get(o));const c=[];for(;_.length>0;){const o=_.pop();c.push(o);for(const h of s.get(o)){const a=n.get(h)-1;n.set(h,a),a===0&&_.push(h)}_.sort((h,a)=>r.get(a)-r.get(h))}if(c.length!==t.length){const o=new Set(c),h=t.filter(a=>!o.has(a.descriptor)).map(a=>a.descriptor.name??`system_${a.descriptor.id}`);throw new et(z.CIRCULAR_SYSTEM_DEPENDENCY,`Circular system dependency detected in ${e}: [${h.join(", ")}]`)}return c}}const W=new WeakMap;function Ot(l,t){let e=W.get(l);if(!e){e=Object.create(null);const{field_names:r}=l.layout;for(let i=0;i<r.length;i++){const _=i;Object.defineProperty(e,r[i],{get(){return this._columns[_][this._row]},set(c){this._columns[_][this._row]=c},enumerable:!0,configurable:!1})}W.set(l,e)}const s=Object.create(e),n=new Array(l.columns.length);for(let r=0;r<l.columns.length;r++)n[r]=l.columns[r].buf;return s._columns=n,s._row=t,s}class K{_archetypes;_defs;_resolver;_include;_exclude;_any_of;constructor(t,e,s,n,r,i){this._archetypes=t,this._defs=e,this._resolver=s,this._include=n,this._exclude=r,this._any_of=i}get archetype_count(){return this._archetypes.length}count(){const t=this._archetypes;let e=0;for(let s=0;s<t.length;s++)e+=t[s].entity_count;return e}get archetypes(){return this._archetypes}*[Symbol.iterator](){const t=this._archetypes;for(let e=0;e<t.length;e++)t[e].entity_count>0&&(yield t[e])}and(...t){const e=this._include.copy(),s=this._defs.slice();for(let n=0;n<t.length;n++)e.has(t[n])||(e.set(t[n]),s.push(t[n]));return this._resolver._resolve_query(e,this._exclude,this._any_of,s)}not(...t){const e=this._exclude?this._exclude.copy():new b;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(this._include,e,this._any_of,this._defs)}any_of(...t){const e=this._any_of?this._any_of.copy():new b;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(this._include,this._exclude,e,this._defs)}}class ${constructor(t){this._resolver=t}every(...t){const e=new b;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(e,null,null,t)}}class J{store;constructor(t){this.store=t}create_entity(){return this.store.create_entity()}get_field(t,e,s){const n=this.store.get_entity_archetype(t),r=this.store.get_entity_row(t);return n.read_field(r,e,s)}set_field(t,e,s,n){const r=this.store.get_entity_archetype(t),i=this.store.get_entity_row(t),_=r.get_column(e,s);_[i]=n}ref(t,e){const s=this.store.get_entity_archetype(e),n=this.store.get_entity_row(e);return Ot(s.column_groups[t],n)}destroy_entity(t){return this.store.destroy_entity_deferred(t),this}add_component(t,e,s){return this.store.add_component_deferred(t,e,s??D),this}remove_component(t,e){return this.store.remove_component_deferred(t,e),this}flush(){this.store.flush_structural(),this.store.flush_destroyed()}emit(t,e){e===void 0?this.store.emit_signal(t):this.store.emit_event(t,e)}read(t){return this.store.get_event_reader(t)}resource(t){return this.store.get_resource_reader(t)}set_resource(t,e){this.store.get_resource_channel(t).write(e)}}const Dt=l=>N(l);class Nt{store;schedule;ctx;systems=new Set;next_system_id=0;_fixed_timestep;_accumulator=0;_max_fixed_steps;query_cache=new Map;scratch_mask=new b;constructor(t){this.store=new St(t?.initial_capacity),this.schedule=new Pt,this.ctx=new J(this.store),this._fixed_timestep=t?.fixed_timestep??_t,this._max_fixed_steps=t?.max_fixed_steps??ct}get fixed_timestep(){return this._fixed_timestep}set fixed_timestep(t){this._fixed_timestep=t}get fixed_alpha(){return this._accumulator/this._fixed_timestep}register_component(t,e){if(Array.isArray(t)){const s=e??"f64",n=Object.create(null);for(const r of t)n[r]=s;return this.store.register_component(n)}return this.store.register_component(t)}register_tag(){return this.store.register_component({})}register_event(t){return this.store.register_event(t)}register_signal(){return this.store.register_event([])}register_resource(t,e){return this.store.register_resource(t,e)}resource(t){return this.store.get_resource_reader(t)}set_resource(t,e){this.store.get_resource_channel(t).write(e)}create_entity(){return this.store.create_entity()}destroy_entity_deferred(t){this.store.destroy_entity_deferred(t)}is_alive(t){return this.store.is_alive(t)}get entity_count(){return this.store.entity_count}add_component(t,e,s){return this.store.add_component(t,e,s??D),this}add_components(t,e){this.store.add_components(t,e)}remove_component(t,e){return this.store.remove_component(t,e),this}remove_components(t,...e){this.store.remove_components(t,e)}has_component(t,e){return this.store.has_component(t,e)}batch_add_component(t,e,s){this.store.batch_add_component(t,e,s)}batch_remove_component(t,e){this.store.batch_remove_component(t,e)}get_field(t,e,s){const n=this.store.get_entity_archetype(t),r=this.store.get_entity_row(t);return n.read_field(r,e,s)}set_field(t,e,s,n){const r=this.store.get_entity_archetype(t),i=this.store.get_entity_row(t),_=r.get_column(e,s);_[i]=n}emit(t,e){e===void 0?this.store.emit_signal(t):this.store.emit_event(t,e)}query(...t){const e=this.scratch_mask;e._words.fill(0);for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolve_query(e.copy(),null,null,t)}_resolve_query(t,e,s,n){const r=t.hash(),i=e?e.hash():0,_=s?s.hash():0,c=r^Math.imul(i,rt)^Math.imul(_,it)|0,o=this._find_cached(c,t,e,s);if(o!==void 0)return o.query;const h=this.store.register_query(t,e??void 0,s??void 0),a=new K(h,n,this,t.copy(),e?.copy()??null,s?.copy()??null);return Q(this.query_cache,c,{include_mask:t.copy(),exclude_mask:e?.copy()??null,any_of_mask:s?.copy()??null,query:a}),a}_find_cached(t,e,s,n){const r=this.query_cache.get(t);if(r)for(let i=0;i<r.length;i++){const _=r[i];if(!(!_.include_mask.equals(e)||!(s===null?_.exclude_mask===null:_.exclude_mask!==null&&_.exclude_mask.equals(s))||!(n===null?_.any_of_mask===null:_.any_of_mask!==null&&_.any_of_mask.equals(n))))return _}}register_system(t,e){let s;if(typeof t=="function")if(e!==void 0){const i=e(new $(this)),_=this.ctx,c=t;s={fn:(o,h)=>c(i,_,h)}}else s={fn:t};else s=t;const n=Dt(this.next_system_id++),r=Object.freeze(Object.assign({id:n},s));return this.systems.add(r),r}add_systems(t,...e){return this.schedule.add_systems(t,...e),this}remove_system(t){this.schedule.remove_system(t),t.on_removed?.(),this.systems.delete(t)}get system_count(){return this.systems.size}startup(){for(const t of this.systems.values())t.on_added?.(this.ctx);this.schedule.run_startup(this.ctx)}update(t){if(this.schedule.has_fixed_systems()){this._accumulator+=t;const e=this._max_fixed_steps*this._fixed_timestep;for(this._accumulator>e&&(this._accumulator=e);this._accumulator>=this._fixed_timestep;)this.schedule.run_fixed_update(this.ctx,this._fixed_timestep),this._accumulator-=this._fixed_timestep}this.schedule.run_update(this.ctx,t),this.store.clear_events()}flush(){this.ctx.flush()}dispose(){for(const t of this.systems.values())t.dispose?.(),t.on_removed?.();this.systems.clear(),this.schedule.clear()}}exports.ECS=Nt;exports.Query=K;exports.QueryBuilder=$;exports.SCHEDULE=H;exports.SystemContext=J;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class nt extends Error{constructor(t,e,s){super(t),this.is_operational=e,this.context=s,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}}var D=(a=>(a.EID_MAX_INDEX_OVERFLOW="EID_MAX_INDEX_OVERFLOW",a.EID_MAX_GEN_OVERFLOW="EID_MAX_GEN_OVERFLOW",a.COMPONENT_NOT_REGISTERED="COMPONENT_NOT_REGISTERED",a.ENTITY_NOT_ALIVE="ENTITY_NOT_ALIVE",a.CIRCULAR_SYSTEM_DEPENDENCY="CIRCULAR_SYSTEM_DEPENDENCY",a.DUPLICATE_SYSTEM="DUPLICATE_SYSTEM",a.ARCHETYPE_NOT_FOUND="ARCHETYPE_NOT_FOUND",a.RESOURCE_NOT_REGISTERED="RESOURCE_NOT_REGISTERED",a.RESOURCE_ALREADY_REGISTERED="RESOURCE_ALREADY_REGISTERED",a.EVENT_ALREADY_REGISTERED="EVENT_ALREADY_REGISTERED",a.EVENT_NOT_REGISTERED="EVENT_NOT_REGISTERED",a))(D||{});class O extends nt{constructor(t,e,s){super(e??t,!0,s),this.category=t}}function F(a,t,e){return a}const S=5,I=31,rt=2166136261,it=16777619,_t=4;class k{_words;constructor(t){this._words=t??new Array(_t).fill(0)}has(t){const e=t>>>S;return e>=this._words.length?!1:(this._words[e]&1<<(t&I))!==0}set(t){const e=t>>>S;e>=this._words.length&&this.grow(e+1),this._words[e]|=1<<(t&I)}clear(t){const e=t>>>S;e>=this._words.length||(this._words[e]&=~(1<<(t&I)))}overlaps(t){const e=this._words,s=t._words,n=e.length<s.length?e.length:s.length;for(let r=0;r<n;r++)if((e[r]&s[r])!==0)return!0;return!1}contains(t){const e=t._words,s=this._words,n=s.length;for(let r=0;r<e.length;r++){const i=e[r];if(i!==0&&(r>=n||(s[r]&i)!==i))return!1}return!0}equals(t){const e=this._words,s=t._words,n=e.length>s.length?e.length:s.length;for(let r=0;r<n;r++){const i=r<e.length?e[r]:0,c=r<s.length?s[r]:0;if(i!==c)return!1}return!0}copy(){return new k(this._words.slice())}copy_with_set(t){const e=t>>>S,s=e+1,n=this._words.length>s?this._words.length:s,r=new Array(n).fill(0);for(let i=0;i<this._words.length;i++)r[i]=this._words[i];return r[e]|=1<<(t&I),new k(r)}copy_with_clear(t){const e=this._words.slice(),s=t>>>S;return s<e.length&&(e[s]&=~(1<<(t&I))),new k(e)}hash(){let t=rt;const e=this._words;let s=e.length-1;for(;s>=0&&e[s]===0;)s--;for(let n=0;n<=s;n++)t^=e[n],t=Math.imul(t,it);return t}for_each(t){const e=this._words;for(let s=0;s<e.length;s++){let n=e[s];if(n===0)continue;const r=s<<S;for(;n!==0;){const i=n&-n>>>0,c=I-Math.clz32(i);t(r+c),n^=i}}}grow(t){let e=this._words.length;for(;e<t;)e*=2;const s=new Array(e).fill(0);for(let n=0;n<this._words.length;n++)s[n]=this._words[n];this._words=s}}const b=16,j=2;class A{constructor(t,e=16){this._ctor=t,this._buf=new t(e)}_buf;_len=0;get length(){return this._len}push(t){this._len>=this._buf.length&&this._grow(),this._buf[this._len++]=t}pop(){return this._buf[--this._len]}get(t){return this._buf[t]}set_at(t,e){this._buf[t]=e}swap_remove(t){const e=this._buf[t];return this._buf[t]=this._buf[--this._len],e}clear(){this._len=0}get buf(){return this._buf}view(){return this._buf.subarray(0,this._len)}[Symbol.iterator](){let t=0;const e=this._buf,s=this._len;return{next(){return t<s?{value:e[t++],done:!1}:{value:0,done:!0}}}}ensure_capacity(t){if(t<=this._buf.length)return;let e=this._buf.length||1;for(;e<t;)e*=j;const s=new this._ctor(e);s.set(this._buf.subarray(0,this._len)),this._buf=s}bulk_append(t,e,s){this.ensure_capacity(this._len+s),this._buf.set(t.subarray(e,e+s),this._len),this._len+=s}bulk_append_zeroes(t){this.ensure_capacity(this._len+t),this._buf.fill(0,this._len,this._len+t),this._len+=t}_grow(){const t=new this._ctor(this._buf.length*j);t.set(this._buf),this._buf=t}}class ot extends A{constructor(t=b){super(Float32Array,t)}}class ct extends A{constructor(t=b){super(Float64Array,t)}}class ht extends A{constructor(t=b){super(Int8Array,t)}}class at extends A{constructor(t=b){super(Int16Array,t)}}class lt extends A{constructor(t=b){super(Int32Array,t)}}class dt extends A{constructor(t=b){super(Uint8Array,t)}}class ut extends A{constructor(t=b){super(Uint16Array,t)}}class Q extends A{constructor(t=b){super(Uint32Array,t)}}const ft={f32:ot,f64:ct,i8:ht,i16:at,i32:lt,u8:dt,u16:ut,u32:Q};class gt{_compare;_data=[];constructor(t){this._compare=t}get size(){return this._data.length}peek(){return this._data[0]}push(t){this._data.push(t),this._sift_up(this._data.length-1)}pop(){const t=this._data;if(t.length===0)return;const s=t[0],n=t.pop();return t.length>0&&(t[0]=n,this._sift_down(0)),s}clear(){this._data.length=0}_sift_up(t){const e=this._data,s=this._compare,n=e[t];for(;t>0;){const r=t-1>>1;if(s(n,e[r])>=0)break;e[t]=e[r],t=r}e[t]=n}_sift_down(t){const e=this._data,s=this._compare,n=e.length,r=n>>1,i=e[t];for(;t<r;){let c=(t<<1)+1;const o=c+1;if(o<n&&s(e[o],e[c])<0&&(c=o),s(e[c],i)>=0)break;e[t]=e[c],t=c}e[t]=i}}function yt(a,t,e,s){const n=s??(o=>String(o)),r=new Map;for(let o=0;o<a.length;o++)r.set(a[o],0);for(const[,o]of t)for(let _=0;_<o.length;_++){const h=o[_];r.has(h)&&r.set(h,r.get(h)+1)}const i=new gt(e);for(let o=0;o<a.length;o++)r.get(a[o])===0&&i.push(a[o]);const c=[];for(;i.size>0;){const o=i.pop();c.push(o);const _=t.get(o);if(_!==void 0)for(let h=0;h<_.length;h++){const l=_[h];if(!r.has(l))continue;const d=r.get(l)-1;r.set(l,d),d===0&&i.push(l)}}if(c.length!==a.length){const o=[];for(const[_,h]of r)h>0&&o.push(n(_));throw new globalThis.TypeError(`Cycle detected in topological sort. Nodes still pending: ${o.join(", ")}`)}return c}const E=-1,m=-1,U=Object.freeze(Object.create(null)),mt=2654435769,pt=1367130551,H=1024,X=0,wt=31,vt=1/60,Et=4,kt=0,R=20,G=(1<<R)-1,Tt=wt-R,V=(1<<Tt)-1,bt=(a,t)=>t<<R|a,y=a=>a&G,z=a=>a>>R,At=a=>F(a),xt=a=>F(a);class St{field_names;columns;reader;constructor(t){this.field_names=t,this.columns=[];for(let s=0;s<t.length;s++)this.columns.push([]);const e={length:0};for(let s=0;s<t.length;s++)e[t[s]]=this.columns[s];this.reader=e}emit(t){const e=this.field_names,s=this.columns;for(let n=0;n<e.length;n++)s[n].push(t[e[n]]);this.reader.length++}emit_signal(){this.reader.length++}clear(){this.reader.length=0;const t=this.columns;for(let e=0;e<t.length;e++)t[e].length=0}}function It(a){return Symbol(a)}function Dt(a){return Symbol(a)}const Rt=a=>F(a);class Nt{id;mask;has_columns;_entity_ids;length=0;edges=[];_flat_columns=[];_col_offset=[];_field_count=[];_field_index=[];_field_names=[];column_groups=[];_column_ids=[];_changed_tick=[];constructor(t,e,s,n=H){if(this.id=t,this.mask=e,this._entity_ids=new Q(n),s){let r=0;for(let i=0;i<s.length;i++){const c=s[i],o=c.component_id,_=new Array(c.field_names.length);this._col_offset[o]=r,this._field_count[o]=c.field_names.length,this._field_index[o]=c.field_index,this._field_names[o]=c.field_names;for(let h=0;h<c.field_names.length;h++){const l=new ft[c.field_types[h]](n);_[h]=l,this._flat_columns[r++]=l}this.column_groups[o]={layout:c,columns:_},this._column_ids.push(o),this._changed_tick[o]=0}}this.has_columns=this._column_ids.length>0}get entity_count(){return this.length}get entity_ids(){return this._entity_ids.buf}get entity_list(){return this._entity_ids.view()}has_component(t){return this.mask.has(t)}matches(t){return this.mask.contains(t)}get_column(t,e){const s=t,n=this._field_index[s][e];return this._flat_columns[this._col_offset[s]+n].buf}get_column_mut(t,e,s){const n=t;this._changed_tick[n]=s;const r=this._field_index[n][e];return this._flat_columns[this._col_offset[n]+r].buf}write_fields(t,e,s,n){const r=e,i=this._col_offset[r];if(i===void 0)return;this._changed_tick[r]=n;const c=this._field_names[r],o=this._flat_columns;for(let _=0;_<c.length;_++)o[i+_].buf[t]=s[c[_]]}write_fields_positional(t,e,s,n){const r=e,i=this._col_offset[r];if(i===void 0)return;this._changed_tick[r]=n;const c=this._flat_columns;for(let o=0;o<s.length;o++)c[i+o].buf[t]=s[o]}read_field(t,e,s){const n=e,r=this._col_offset[n];if(r===void 0)return NaN;const i=this._field_index[n][s];return i===void 0?NaN:this._flat_columns[r+i].buf[t]}copy_shared_from(t,e,s,n){const r=t._col_offset,i=t._field_count,c=t._flat_columns,o=this._flat_columns,_=this._column_ids;for(let h=0;h<_.length;h++){const l=_[h],d=r[l];if(d===void 0)continue;this._changed_tick[l]=n;const u=this._col_offset[l],g=i[l];for(let p=0;p<g;p++)o[u+p].buf[s]=c[d+p].buf[e]}}add_entity(t){const e=this.length;this._entity_ids.push(t);const s=this._flat_columns;for(let n=0;n<s.length;n++)s[n].push(0);return this.length++,e}remove_entity(t){const e=this.length-1;let s=m;const n=this._flat_columns,r=this._entity_ids.buf;if(t!==e){r[t]=r[e],s=y(r[t]);for(let i=0;i<n.length;i++)n[i].swap_remove(t)}else for(let i=0;i<n.length;i++)n[i].pop();return this._entity_ids.pop(),this.length--,s}add_entity_tag(t){const e=this.length;return this._entity_ids.push(t),this.length++,e}remove_entity_tag(t){const e=this.length-1;let s=m;const n=this._entity_ids.buf;return t!==e&&(n[t]=n[e],s=y(n[t])),this._entity_ids.pop(),this.length--,s}move_entity_from(t,e,s,n,r){const i=this.length;this._entity_ids.push(s);const c=this._flat_columns,o=t._flat_columns;for(let l=0;l<c.length;l++){const d=n[l];c[l].push(d>=0?o[d].buf[e]:0)}const _=this._column_ids;for(let l=0;l<_.length;l++)this._changed_tick[_[l]]=r;this.length++;const h=t.has_columns?t.remove_entity(e):t.remove_entity_tag(e);f[0]=i,f[1]=h}move_entity_from_tag(t,e,s){const n=this.length;this._entity_ids.push(s),this.length++;const r=t.remove_entity_tag(e);f[0]=n,f[1]=r}bulk_move_all_from(t,e,s){const n=t.length;if(n===0)return this.length;const r=this.length,i=this._flat_columns,c=t._flat_columns;this._entity_ids.bulk_append(t._entity_ids.buf,0,n);for(let _=0;_<i.length;_++){const h=e[_];h>=0?i[_].bulk_append(c[h].buf,0,n):i[_].bulk_append_zeroes(n)}const o=this._column_ids;for(let _=0;_<o.length;_++)this._changed_tick[o[_]]=s;this.length+=n,t.length=0,t._entity_ids.clear();for(let _=0;_<c.length;_++)c[_].clear();return r}get_edge(t){return this.edges[t]}set_edge(t,e){this.edges[t]=e}}const f=[0,m];function M(a,t){const e=t._flat_columns,s=new Int16Array(e.length),n=t._column_ids,r=a._col_offset,i=t._col_offset,c=t._field_count;for(let o=0;o<n.length;o++){const _=n[o],h=i[_],l=c[_],d=r[_];if(d!==void 0)for(let u=0;u<l;u++)s[h+u]=d+u;else for(let u=0;u<l;u++)s[h+u]=-1}return s}function $(a,t,e){const s=a.get(t);s!==void 0?s.push(e):a.set(t,[e])}class Pt{entity_generations=[];entity_high_water=0;entity_free_indices=[];entity_alive_count=0;component_metas=[];component_count=0;event_channels=[];event_count=0;archetypes=[];archetype_map=new Map;next_archetype_id=0;component_index=new Map;registered_queries=[];empty_archetype_id;entity_archetype=[];entity_row=[];pending_destroy=[];pending_add_ids=[];pending_add_defs=[];pending_add_values=[];pending_remove_ids=[];pending_remove_defs=[];_tick=0;initial_capacity;constructor(t){this.initial_capacity=t??H,this.empty_archetype_id=this.arch_get_or_create_from_mask(new k)}arch_get(t){return this.archetypes[t]}arch_get_or_create_from_mask(t){const e=t.hash(),s=this.archetype_map.get(e);if(s!==void 0){for(let o=0;o<s.length;o++)if(this.archetypes[s[o]].mask.equals(t))return s[o]}const n=Rt(this.next_archetype_id++),r=[];t.for_each(o=>{const _=o,h=this.component_metas[_];h&&h.field_names.length>0&&r.push({component_id:_,field_names:h.field_names,field_index:h.field_index,field_types:h.field_types})});const i=new Nt(n,t,r,this.initial_capacity);this.archetypes.push(i),$(this.archetype_map,e,n),t.for_each(o=>{const _=o;let h=this.component_index.get(_);h||(h=new Set,this.component_index.set(_,h)),h.add(n)});const c=this.registered_queries;for(let o=0;o<c.length;o++){const _=c[o];i.matches(_.include_mask)&&(!_.exclude_mask||!i.mask.overlaps(_.exclude_mask))&&(!_.any_of_mask||i.mask.overlaps(_.any_of_mask))&&(_.result.push(i),_.query?.mark_non_empty_dirty())}return n}arch_resolve_add(t,e){const s=this.arch_get(t);if(s.mask.has(e))return t;const n=s.get_edge(e);if(n?.add!=null)return n.add;const r=this.arch_get_or_create_from_mask(s.mask.copy_with_set(e));return this.arch_cache_edge(s,this.arch_get(r),e),r}arch_resolve_remove(t,e){const s=this.arch_get(t);if(!s.mask.has(e))return t;const n=s.get_edge(e);if(n?.remove!=null)return n.remove;const r=this.arch_get_or_create_from_mask(s.mask.copy_with_clear(e));return this.arch_cache_edge(this.arch_get(r),s,e),r}arch_cache_edge(t,e,s){const n=t.get_edge(s)??{add:null,remove:null,add_map:null,remove_map:null};n.add=e.id,n.add_map=M(t,e),t.set_edge(s,n);const r=e.get_edge(s)??{add:null,remove:null,add_map:null,remove_map:null};r.remove=t.id,r.remove_map=M(e,t),e.set_edge(s,r)}create_entity(){let t,e;this.entity_free_indices.length>0?(t=this.entity_free_indices.pop(),e=this.entity_generations[t]):(t=this.entity_high_water++,this.entity_generations[t]=X,e=X),this.entity_alive_count++;const s=bt(t,e);return this.entity_archetype[t]=this.empty_archetype_id,this.entity_row[t]=E,s}destroy_entity(t){if(!this.is_alive(t))return;const e=y(t),s=this.entity_row[e];if(s!==E){const i=this.arch_get(this.entity_archetype[e]).remove_entity(s);i!==m&&(this.entity_row[i]=s)}this.entity_archetype[e]=E,this.entity_row[e]=E;const n=z(t);this.entity_generations[e]=n+1&V,this.entity_free_indices.push(e),this.entity_alive_count--}is_alive(t){const e=y(t);return e<this.entity_high_water&&this.entity_generations[e]===z(t)}get entity_count(){return this.entity_alive_count}_mark_queries_dirty(){const t=this.registered_queries;for(let e=0;e<t.length;e++)t[e].query?.mark_non_empty_dirty()}destroy_entity_deferred(t){this.pending_destroy.push(t)}flush_destroyed(){const t=this.pending_destroy;if(t.length===0)return;const e=this.entity_archetype,s=this.entity_row,n=this.entity_generations,r=this.archetypes,i=this.entity_high_water;for(let c=0;c<t.length;c++){const o=t[c],_=o&G,h=o>>R;if(_>=i||n[_]!==h)continue;const l=s[_];if(l!==E){const d=r[e[_]],u=d.has_columns?d.remove_entity(l):d.remove_entity_tag(l);u!==m&&(s[u]=l)}e[_]=E,s[_]=E,n[_]=h+1&V,this.entity_free_indices.push(_),this.entity_alive_count--}t.length=0,this._mark_queries_dirty()}get pending_destroy_count(){return this.pending_destroy.length}add_component_deferred(t,e,s){this.pending_add_ids.push(t),this.pending_add_defs.push(e),this.pending_add_values.push(s??U)}remove_component_deferred(t,e){this.pending_remove_ids.push(t),this.pending_remove_defs.push(e)}flush_structural(){const t=this.pending_add_ids.length>0,e=this.pending_remove_ids.length>0;t&&this._flush_adds(),e&&this._flush_removes(),(t||e)&&this._mark_queries_dirty()}_flush_adds(){const t=this.pending_add_ids,e=this.pending_add_defs,s=this.pending_add_values,n=t.length,r=this.entity_archetype,i=this.entity_row,c=this.entity_generations,o=this.archetypes,_=this.component_metas,h=this.entity_high_water,l=this._tick;for(let d=0;d<n;d++){const u=t[d],g=u&G,p=u>>R;if(g>=h||c[g]!==p)continue;const T=r[g],w=e[d],v=o[T];if(v.mask.has(w)){_[w].field_names.length>0&&v.write_fields(i[g],w,s[d],l);continue}const N=this.arch_resolve_add(T,w),x=o[N],P=i[g],Y=!x.has_columns&&!v.has_columns;let q;if(P!==E){if(Y)x.move_entity_from_tag(v,P,u);else{const st=v.get_edge(w);x.move_entity_from(v,P,u,st.add_map,l)}q=f[0],f[1]!==m&&(i[f[1]]=P)}else q=Y?x.add_entity_tag(u):x.add_entity(u);_[w].field_names.length>0&&x.write_fields(q,w,s[d],l),r[g]=N,i[g]=q}t.length=0,e.length=0,s.length=0}_flush_removes(){const t=this.pending_remove_ids,e=this.pending_remove_defs,s=t.length,n=this.entity_archetype,r=this.entity_row,i=this.entity_generations,c=this.archetypes,o=this.entity_high_water,_=this._tick;for(let h=0;h<s;h++){const l=t[h],d=l&G,u=l>>R;if(d>=o||i[d]!==u)continue;const g=n[d],p=e[h],T=c[g];if(!T.mask.has(p))continue;const w=this.arch_resolve_remove(g,p),v=c[w],N=r[d];if(!v.has_columns&&!T.has_columns)v.move_entity_from_tag(T,N,l);else{const P=T.get_edge(p);v.move_entity_from(T,N,l,P.remove_map,_)}f[1]!==m&&(r[f[1]]=N),n[d]=w,r[d]=f[0]}t.length=0,e.length=0}get pending_structural_count(){return this.pending_add_ids.length+this.pending_remove_ids.length}register_component(t){const e=At(this.component_count++),s=Object.keys(t),n=new Array(s.length),r=Object.create(null);for(let i=0;i<s.length;i++)r[s[i]]=i,n[i]=t[s[i]];return this.component_metas.push({field_names:s,field_index:r,field_types:n}),e}add_component(t,e,s){if(!this.is_alive(t))return;const n=y(t),r=this.entity_archetype[n],i=this.arch_get(r);if(i.has_component(e)){i.write_fields(this.entity_row[n],e,s,this._tick);return}const c=this.arch_resolve_add(r,e),o=this.arch_get(c),_=this.entity_row[n];let h;if(_!==E){const l=i.get_edge(e);!o.has_columns&&!i.has_columns?o.move_entity_from_tag(i,_,t):o.move_entity_from(i,_,t,l.add_map,this._tick),h=f[0],f[1]!==m&&(this.entity_row[f[1]]=_)}else h=o.has_columns?o.add_entity(t):o.add_entity_tag(t);o.write_fields(h,e,s,this._tick),this.entity_archetype[n]=c,this.entity_row[n]=h,this._mark_queries_dirty()}add_components(t,e){if(!this.is_alive(t))return;const s=y(t),n=this.entity_archetype[s];let r=n;for(let i=0;i<e.length;i++)r=this.arch_resolve_add(r,e[i].def);if(r!==n){const i=this.arch_get(n),c=this.arch_get(r),o=this.entity_row[s];let _;if(o!==E){const h=M(i,c);c.move_entity_from(i,o,t,h,this._tick),_=f[0],f[1]!==m&&(this.entity_row[f[1]]=o)}else _=c.add_entity(t);for(let h=0;h<e.length;h++)c.write_fields(_,e[h].def,e[h].values??U,this._tick);this.entity_archetype[s]=r,this.entity_row[s]=_,this._mark_queries_dirty()}else{const i=this.arch_get(n),c=this.entity_row[s];for(let o=0;o<e.length;o++)i.write_fields(c,e[o].def,e[o].values??U,this._tick)}}remove_component(t,e){if(!this.is_alive(t))return;const s=y(t),n=this.entity_archetype[s],r=this.arch_get(n);if(!r.has_component(e))return;const i=this.arch_resolve_remove(n,e),c=this.arch_get(i),o=this.entity_row[s],_=r.get_edge(e);!c.has_columns&&!r.has_columns?c.move_entity_from_tag(r,o,t):c.move_entity_from(r,o,t,_.remove_map,this._tick),f[1]!==m&&(this.entity_row[f[1]]=o),this.entity_archetype[s]=i,this.entity_row[s]=f[0],this._mark_queries_dirty()}remove_components(t,e){if(!this.is_alive(t))return;const s=y(t),n=this.entity_archetype[s];let r=n;for(let h=0;h<e.length;h++)r=this.arch_resolve_remove(r,e[h]);if(r===n)return;const i=this.arch_get(n),c=this.arch_get(r),o=this.entity_row[s],_=M(i,c);c.move_entity_from(i,o,t,_,this._tick),f[1]!==m&&(this.entity_row[f[1]]=o),this.entity_archetype[s]=r,this.entity_row[s]=f[0],this._mark_queries_dirty()}has_component(t,e){if(!this.is_alive(t))return!1;const s=y(t);return this.arch_get(this.entity_archetype[s]).has_component(e)}batch_add_component(t,e,s){if(t.length===0)return;const n=e;if(t.mask.has(n))return;const r=this.arch_resolve_add(t.id,n),i=this.arch_get(r),c=t.get_edge(n),o=t.length,_=this.entity_archetype,h=this.entity_row,l=i.bulk_move_all_from(t,c.add_map,this._tick);for(let u=0;u<o;u++){const g=y(i.entity_ids[l+u]);_[g]=r,h[g]=l+u}if(this.component_metas[n].field_names.length>0&&s)for(let u=0;u<o;u++)i.write_fields(l+u,n,s,this._tick);this._mark_queries_dirty()}batch_remove_component(t,e){if(t.length===0)return;const s=e;if(!t.mask.has(s))return;const n=this.arch_resolve_remove(t.id,s),r=this.arch_get(n),i=t.get_edge(s),c=t.length,o=r.bulk_move_all_from(t,i.remove_map,this._tick),_=this.entity_archetype,h=this.entity_row;for(let l=0;l<c;l++){const d=y(r.entity_ids[o+l]);_[d]=n,h[d]=o+l}this._mark_queries_dirty()}get_entity_archetype(t){return this.arch_get(this.entity_archetype[y(t)])}get_entity_row(t){return this.entity_row[y(t)]}get_matching_archetypes(t,e,s){const n=t._words;let r=!1;for(let _=0;_<n.length;_++)if(n[_]!==0){r=!0;break}if(!r)return this.archetypes.filter(_=>(!e||!_.mask.overlaps(e))&&(!s||_.mask.overlaps(s)));let i,c=!1;for(let _=0;_<n.length;_++){let h=n[_];if(h===0)continue;const l=_<<S;for(;h!==0;){const d=h&-h>>>0,u=l+(I-Math.clz32(d));h^=d;const g=this.component_index.get(u);if(!g||g.size===0){c=!0;break}(!i||g.size<i.size)&&(i=g)}if(c)break}if(c||!i)return[];const o=[];for(const _ of i){const h=this.arch_get(_);h.matches(t)&&(!e||!h.mask.overlaps(e))&&(!s||h.mask.overlaps(s))&&o.push(h)}return o}register_query(t,e,s){const n=this.get_matching_archetypes(t,e,s);return this.registered_queries.push({include_mask:t.copy(),exclude_mask:e?e.copy():null,any_of_mask:s?s.copy():null,result:n,query:null}),n}update_query_ref(t,e){const s=this.registered_queries;for(let n=0;n<s.length;n++)if(s[n].result===t){s[n].query=e;return}}get archetype_count(){return this.archetypes.length}register_event(t){const e=xt(this.event_count++),s=new St(t);return this.event_channels.push(s),e}emit_event(t,e){this.event_channels[t].emit(e)}emit_signal(t){this.event_channels[t].emit_signal()}get_event_reader(t){return this.event_channels[t].reader}clear_events(){const t=this.event_channels;for(let e=0;e<t.length;e++)t[e].clear()}event_key_map=new Map;register_event_by_key(t,e){if(this.event_key_map.has(t))throw new O(D.EVENT_ALREADY_REGISTERED,"Event key already registered");const s=this.register_event(e);return this.event_key_map.set(t,s),s}get_event_def_by_key(t){const e=this.event_key_map.get(t);if(e===void 0)throw new O(D.EVENT_NOT_REGISTERED,"Event key not registered");return e}has_event_key(t){return this.event_key_map.has(t)}resource_key_map=new Map;register_resource(t,e){if(this.resource_key_map.has(t))throw new O(D.RESOURCE_ALREADY_REGISTERED,"Resource key already registered");this.resource_key_map.set(t,e)}get_resource(t){if(!this.resource_key_map.has(t))throw new O(D.RESOURCE_NOT_REGISTERED,"Resource key not registered");return this.resource_key_map.get(t)}set_resource(t,e){if(!this.resource_key_map.has(t))throw new O(D.RESOURCE_NOT_REGISTERED,"Resource key not registered");this.resource_key_map.set(t,e)}has_resource(t){return this.resource_key_map.has(t)}}var K=(a=>(a.PRE_STARTUP="PRE_STARTUP",a.STARTUP="STARTUP",a.POST_STARTUP="POST_STARTUP",a.FIXED_UPDATE="FIXED_UPDATE",a.PRE_UPDATE="PRE_UPDATE",a.UPDATE="UPDATE",a.POST_UPDATE="POST_UPDATE",a))(K||{});const L=["PRE_STARTUP","STARTUP","POST_STARTUP"],C=["PRE_UPDATE","UPDATE","POST_UPDATE"];class Ot{label_systems=new Map;sorted_cache=new Map;system_index=new Map;system_last_run=new Map;next_insertion_order=0;constructor(){for(let t=0;t<L.length;t++)this.label_systems.set(L[t],[]);this.label_systems.set("FIXED_UPDATE",[]);for(let t=0;t<C.length;t++)this.label_systems.set(C[t],[])}add_systems(t,...e){for(const s of e){const n="system"in s?s.system:s,r="system"in s?s.ordering:void 0,i={descriptor:n,insertion_order:this.next_insertion_order++,before:new Set(r?.before??[]),after:new Set(r?.after??[])};this.label_systems.get(t).push(i),this.system_index.set(n,t),this.system_last_run.set(n,0),this.sorted_cache.delete(t)}}remove_system(t){const e=this.system_index.get(t);if(e===void 0)return;const s=this.label_systems.get(e),n=s.findIndex(r=>r.descriptor===t);if(n!==-1){const r=s.length-1;n!==r&&(s[n]=s[r]),s.pop();for(const i of s)i.before.delete(t),i.after.delete(t)}this.system_index.delete(t),this.system_last_run.delete(t),this.sorted_cache.delete(e)}run_startup(t,e){for(const s of L)this.run_label(s,t,kt,e)}run_update(t,e,s){for(const n of C)this.run_label(n,t,e,s)}run_fixed_update(t,e,s){this.run_label("FIXED_UPDATE",t,e,s)}has_fixed_systems(){return this.label_systems.get("FIXED_UPDATE").length>0}get_all_systems(){const t=[];for(const e of this.label_systems.values())for(const s of e)t.push(s.descriptor);return t}has_system(t){return this.system_index.has(t)}clear(){for(const t of this.label_systems.values())t.length=0;this.sorted_cache.clear(),this.system_index.clear(),this.system_last_run.clear()}run_label(t,e,s,n){const r=this.get_sorted(t);for(let i=0;i<r.length;i++)this.system_last_run.set(r[i],n),e.last_run_tick=n,r[i].fn(e,s);e.flush()}get_sorted(t){const e=this.sorted_cache.get(t);if(e!==void 0)return e;const s=this.label_systems.get(t),n=this.sort_systems(s,t);return this.sorted_cache.set(t,n),n}sort_systems(t,e){if(t.length===0)return[];const s=[],n=new Map,r=new Set;for(const _ of t)s.push(_.descriptor),n.set(_.descriptor,_.insertion_order),r.add(_.descriptor);const i=new Map;for(const _ of t)i.set(_.descriptor,[]);for(const _ of t){for(const h of _.before)r.has(h)&&i.get(_.descriptor).push(h);for(const h of _.after)r.has(h)&&i.get(h).push(_.descriptor)}const c=(_,h)=>n.get(_)-n.get(h),o=_=>_.name??`system_${_.id}`;try{return yt(s,i,c,o)}catch(_){throw _ instanceof TypeError?new O(D.CIRCULAR_SYSTEM_DEPENDENCY,`Circular system dependency detected in ${e}: ${_.message}`):_}}}const W=new WeakMap;function B(a,t){let e=W.get(a);if(!e){e=Object.create(null);const{field_names:r}=a.layout;for(let i=0;i<r.length;i++){const c=i;Object.defineProperty(e,r[i],{get(){return this._columns[c][this._row]},set(o){this._columns[c][this._row]=o},enumerable:!0,configurable:!1})}W.set(a,e)}const s=Object.create(e),n=new Array(a.columns.length);for(let r=0;r<a.columns.length;r++)n[r]=a.columns[r].buf;return s._columns=n,s._row=t,s}class J{_archetypes;_defs;_resolver;_include;_exclude;_any_of;_non_empty_archetypes=[];_non_empty_dirty=!0;constructor(t,e,s,n,r,i){this._archetypes=t,this._defs=e,this._resolver=s,this._include=n,this._exclude=r,this._any_of=i}get archetype_count(){return this._archetypes.length}count(){const t=this._archetypes;let e=0;for(let s=0;s<t.length;s++)e+=t[s].entity_count;return e}get archetypes(){return this._archetypes}and(...t){const e=this._include.copy(),s=this._defs.slice();for(let n=0;n<t.length;n++)e.has(t[n])||(e.set(t[n]),s.push(t[n]));return this._resolver._resolve_query(e,this._exclude,this._any_of,s)}not(...t){const e=this._exclude?this._exclude.copy():new k;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(this._include,e,this._any_of,this._defs)}for_each(t){const e=this._non_empty();for(let s=0;s<e.length;s++)t(e[s])}mark_non_empty_dirty(){this._non_empty_dirty=!0}_non_empty(){if(this._non_empty_dirty){const t=this._archetypes,e=this._non_empty_archetypes;e.length=0;for(let s=0;s<t.length;s++)t[s].entity_count>0&&e.push(t[s]);this._non_empty_dirty=!1}return this._non_empty_archetypes}any_of(...t){const e=this._any_of?this._any_of.copy():new k;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(this._include,this._exclude,e,this._defs)}changed(...t){const e=new Array(t.length);for(let s=0;s<t.length;s++)e[s]=t[s];return new et(this,e)}_ctx_last_run_tick(){return this._resolver._get_last_run_tick()}}class Z{constructor(t){this._resolver=t}every(...t){const e=new k;for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolver._resolve_query(e,null,null,t)}}class tt{store;last_run_tick=0;get world_tick(){return this.store._tick}constructor(t){this.store=t}create_entity(){return this.store.create_entity()}get_field(t,e,s){const n=this.store.get_entity_archetype(t),r=this.store.get_entity_row(t);return n.read_field(r,e,s)}set_field(t,e,s,n){const r=this.store.get_entity_archetype(t),i=this.store.get_entity_row(t),c=r.get_column_mut(e,s,this.store._tick);c[i]=n}ref(t,e){const s=this.store.get_entity_archetype(e),n=this.store.get_entity_row(e);return B(s.column_groups[t],n)}ref_mut(t,e){const s=this.store.get_entity_archetype(e),n=this.store.get_entity_row(e);return s._changed_tick[t]=this.store._tick,B(s.column_groups[t],n)}destroy_entity(t){return this.store.destroy_entity_deferred(t),this}add_component(t,e,s){return this.store.add_component_deferred(t,e,s??U),this}remove_component(t,e){return this.store.remove_component_deferred(t,e),this}flush(){this.store.flush_structural(),this.store.flush_destroyed()}emit(t,e){const s=this.store.get_event_def_by_key(t);e===void 0?this.store.emit_signal(s):this.store.emit_event(s,e)}read(t){const e=this.store.get_event_def_by_key(t);return this.store.get_event_reader(e)}resource(t){return this.store.get_resource(t)}set_resource(t,e){this.store.set_resource(t,e)}has_resource(t){return this.store.has_resource(t)}}class et{_query;_changed_ids;constructor(t,e){this._query=t,this._changed_ids=e}for_each(t){const e=this._query._ctx_last_run_tick(),s=this._query._non_empty(),n=this._changed_ids;for(let r=0;r<s.length;r++){const i=s[r];for(let c=0;c<n.length;c++)if(i._changed_tick[n[c]]>=e){t(i);break}}}}const Ut=a=>F(a);class qt{store;schedule;ctx;systems=new Set;next_system_id=0;_tick=0;_fixed_timestep;_accumulator=0;_max_fixed_steps;query_cache=new Map;scratch_mask=new k;constructor(t){this.store=new Pt(t?.initial_capacity),this.schedule=new Ot,this.ctx=new tt(this.store),this._fixed_timestep=t?.fixed_timestep??vt,this._max_fixed_steps=t?.max_fixed_steps??Et}get fixed_timestep(){return this._fixed_timestep}set fixed_timestep(t){this._fixed_timestep=t}get fixed_alpha(){return this._accumulator/this._fixed_timestep}register_component(t,e){if(Array.isArray(t)){const s=e??"f64",n=Object.create(null);for(const r of t)n[r]=s;return this.store.register_component(n)}return this.store.register_component(t)}register_tag(){return this.store.register_component({})}register_event(t,e){this.store.register_event_by_key(t,e)}register_signal(t){this.store.register_event_by_key(t,[])}register_resource(t,e){this.store.register_resource(t,e)}resource(t){return this.store.get_resource(t)}set_resource(t,e){this.store.set_resource(t,e)}has_resource(t){return this.store.has_resource(t)}create_entity(){return this.store.create_entity()}destroy_entity_deferred(t){this.store.destroy_entity_deferred(t)}is_alive(t){return this.store.is_alive(t)}get entity_count(){return this.store.entity_count}add_component(t,e,s){return this.store.add_component(t,e,s??U),this}add_components(t,e){this.store.add_components(t,e)}remove_component(t,e){return this.store.remove_component(t,e),this}remove_components(t,...e){this.store.remove_components(t,e)}has_component(t,e){return this.store.has_component(t,e)}batch_add_component(t,e,s){this.store.batch_add_component(t,e,s)}batch_remove_component(t,e){this.store.batch_remove_component(t,e)}get_field(t,e,s){const n=this.store.get_entity_archetype(t),r=this.store.get_entity_row(t);return n.read_field(r,e,s)}set_field(t,e,s,n){const r=this.store.get_entity_archetype(t),i=this.store.get_entity_row(t),c=r.get_column_mut(e,s,this.store._tick);c[i]=n}emit(t,e){const s=this.store.get_event_def_by_key(t);e===void 0?this.store.emit_signal(s):this.store.emit_event(s,e)}read(t){const e=this.store.get_event_def_by_key(t);return this.store.get_event_reader(e)}query(...t){const e=this.scratch_mask;e._words.fill(0);for(let s=0;s<t.length;s++)e.set(t[s]);return this._resolve_query(e.copy(),null,null,t)}_get_last_run_tick(){return this.ctx.last_run_tick}_resolve_query(t,e,s,n){const r=t.hash(),i=e?e.hash():0,c=s?s.hash():0,o=r^Math.imul(i,mt)^Math.imul(c,pt)|0,_=this._find_cached(o,t,e,s);if(_!==void 0)return _.query;const h=this.store.register_query(t,e??void 0,s??void 0),l=new J(h,n,this,t.copy(),e?.copy()??null,s?.copy()??null);return this.store.update_query_ref(h,l),$(this.query_cache,o,{include_mask:t.copy(),exclude_mask:e?.copy()??null,any_of_mask:s?.copy()??null,query:l}),l}_find_cached(t,e,s,n){const r=this.query_cache.get(t);if(r)for(let i=0;i<r.length;i++){const c=r[i];if(!(!c.include_mask.equals(e)||!(s===null?c.exclude_mask===null:c.exclude_mask!==null&&c.exclude_mask.equals(s))||!(n===null?c.any_of_mask===null:c.any_of_mask!==null&&c.any_of_mask.equals(n))))return c}}register_system(t,e){let s;if(typeof t=="function")if(e!==void 0){const i=e(new Z(this)),c=this.ctx,o=t;s={fn:(_,h)=>o(i,c,h)}}else s={fn:t};else s=t;const n=Ut(this.next_system_id++),r=Object.freeze(Object.assign({id:n},s));return this.systems.add(r),r}add_systems(t,...e){return this.schedule.add_systems(t,...e),this}remove_system(t){this.schedule.remove_system(t),t.on_removed?.(),this.systems.delete(t)}get system_count(){return this.systems.size}startup(){for(const t of this.systems.values())t.on_added?.(this.ctx);this.schedule.run_startup(this.ctx,this._tick)}update(t){if(this.store._tick=this._tick,this.schedule.has_fixed_systems()){this._accumulator+=t;const e=this._max_fixed_steps*this._fixed_timestep;for(this._accumulator>e&&(this._accumulator=e);this._accumulator>=this._fixed_timestep;)this.schedule.run_fixed_update(this.ctx,this._fixed_timestep,this._tick),this._accumulator-=this._fixed_timestep}this.schedule.run_update(this.ctx,t,this._tick),this.store.clear_events(),this._tick++}flush(){this.ctx.flush()}dispose(){for(const t of this.systems.values())t.dispose?.(),t.on_removed?.();this.systems.clear(),this.schedule.clear()}}function Mt(a){return Symbol(a)}exports.ChangedQuery=et;exports.ECS=qt;exports.Query=J;exports.QueryBuilder=Z;exports.SCHEDULE=K;exports.SystemContext=tt;exports.event_key=It;exports.resource_key=Mt;exports.signal_key=Dt;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { ECS, type WorldOptions } from './ecs';
|
|
2
2
|
export { SCHEDULE, type SystemEntry, type SystemOrdering } from './schedule';
|
|
3
3
|
export { SystemContext } from './query';
|
|
4
|
-
export type { SystemConfig, SystemDescriptor } from './system';
|
|
5
|
-
export type { ComponentRef } from './ref';
|
|
6
|
-
export { Query, QueryBuilder } from './query';
|
|
4
|
+
export type { SystemFn, SystemConfig, SystemDescriptor } from './system';
|
|
5
|
+
export type { ComponentRef, ReadonlyComponentRef } from './ref';
|
|
6
|
+
export { Query, QueryBuilder, ChangedQuery } from './query';
|
|
7
7
|
export type { EntityID } from './entity';
|
|
8
|
-
export type { ComponentDef, ComponentSchema, ComponentFields, FieldValues, TagToTypedArray, ColumnsForSchema, } from './component';
|
|
9
|
-
export type {
|
|
10
|
-
export
|
|
8
|
+
export type { ComponentDef, ComponentSchema, ComponentFields, FieldValues, TagToTypedArray, ColumnsForSchema, ReadonlyColumn, ReadonlyUint32Array, } from './component';
|
|
9
|
+
export type { EventReader, EventKey } from './event';
|
|
10
|
+
export { event_key, signal_key } from './event';
|
|
11
|
+
export type { ResourceKey } from './resource';
|
|
12
|
+
export { resource_key } from './resource';
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAG7E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAG7E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAGzE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5D,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,YAAY,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGhD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|