@arancini/core
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -1,4 +0,3 @@ | ||
import { BitSet } from './bit-set'; | ||
import { ObjectPool } from './object-pool'; | ||
type EntityMetadata = { | ||
import type { BitSet } from './bit-set'; | ||
export type EntityMetadata = { | ||
bitset: BitSet; | ||
@@ -10,4 +9,2 @@ id?: number; | ||
}; | ||
export declare const entityMetadataPool: ObjectPool<EntityMetadata>; | ||
export declare const ARANCINI_SYMBOL: unique symbol; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
class t{listeners=new Set;add(t){return this.listeners.add(t),()=>this.remove(t)}remove(t){this.listeners.delete(t)}emit(...t){for(const e of this.listeners)e(...t)}clear(){this.listeners.clear()}}class e{entities=[];version=0;onEntityAdded=new t;onEntityRemoved=new t;_entityPositions=new Map;_entitySet=new Set;get first(){return this.entities[0]||void 0}[Symbol.iterator](){let t=this.entities.length;const e={value:void 0,done:!1};return{next:()=>(e.value=this.entities[--t],e.done=t<0,e)}}has(t){return this._entitySet.has(t)}}const s=(t,e)=>{e&&!t.has(e)&&(t.entities.push(e),t._entityPositions.set(e,t.entities.length-1),t._entitySet.add(e),t.version++,t.onEntityAdded.emit(e))},i=(t,e)=>{if(!t.has(e))return;const s=t._entityPositions.get(e);t._entityPositions.delete(e),t._entitySet.delete(e);const i=t.entities[t.entities.length-1];i!==e&&(t.entities[s]=i,t._entityPositions.set(i,s)),t.entities.pop(),t.version++,t.onEntityRemoved.emit(e)};class n{availableObjects=[];factory;get available(){return this.availableObjects.length}get used(){return this.size-this.availableObjects.length}size=0;constructor(t,e){this.factory=t,void 0!==e&&this.grow(e)}grow(t){for(let e=0;e<t;e++)this.availableObjects.push(this.factory());this.size+=t}free(t){for(let e=0;e<t;e++){if(!this.availableObjects.pop())break;this.size--}}request(){return this.availableObjects.length<=0&&this.grow(Math.round(.2*this.size)+1),this.availableObjects.pop()}recycle(t){this.availableObjects.push(t),this.availableObjects.length>Math.round(.2*this.size)&&this.free(this.availableObjects.length-Math.round(.2*this.size))}}class r{words;constructor(t=[]){this.words=new Uint32Array(8);for(const e of t)this.add(e)}add(...t){for(let e=0;e<t.length;e++){const s=t[e];this.resize(s),this.words[s>>>5]|=1<<s}}remove(...t){for(let e=0;e<t.length;e++){const s=t[e];this.resize(s),this.words[s>>>5]&=~(1<<s)}}has(t){return 0!=(this.words[t>>>5]&1<<t)}resize(t){if(this.words.length<<5>t)return;const e=new Uint32Array(t+32>>>5<<1);e.set(this.words),this.words=e}reset(){for(let t=0;t<this.words.length;t++)this.words[t]=0}copy(t){const e=new Uint32Array(t.words.length);e.set(t.words),this.words=e}clone(){const t=new Uint32Array(this.words.length);t.set(this.words);const e=new r;return e.words=t,e}containsAll(t){for(let e=0;e<this.words.length;e++)if(0!=(~this.words[e]&t.words[e]))return!1;return!0}containsAny(t){for(let e=0;e<this.words.length;e++)if(0!=(this.words[e]&t.words[e]))return!0;return!1}}const o=new n((()=>({bitset:new r,id:void 0}))),h=Symbol("__arancini");class a extends e{world;key;conditions;bitSets;constructor(t,e,s,i){super(),this.world=t,this.key=e,this.conditions=s,this.bitSets=i}destroy(){this.world.destroyQuery(this)}}const l=(t,e)=>{const s=[];for(const i of e)d(t,i)&&s.push(i);return s},d=(t,e)=>{const s=e;for(const e of t){if("all"===e.type&&!s[h].bitset.containsAll(e.bitset))return!1;if("any"===e.type&&!s[h].bitset.containsAny(e.bitset))return!1;if("not"===e.type&&s[h].bitset.containsAny(e.bitset))return!1}return!0},y=t=>{const e=new m;t(e);const s=e.conditions;if(s.length<=0)throw new Error("Query must have at least one condition");if(s.some((t=>t.components.length<=0)))throw new Error("Query conditions must have at least one component");const i={type:"all",components:[]},n=[];for(const t of s)"all"===t.type?i.components.push(...t.components):n.push(t);return[i,...n]},c=(t,e)=>e.map((({type:e,components:s})=>"all"===e?s.map((e=>t[e])).sort().join(","):[`${e}:${s.map((e=>t[e])).sort().join(",")}`])).sort().join("&"),u=(t,e)=>e.map((e=>({type:e.type,bitset:new r(e.components.map((e=>t[e])))})));class m{T;conditions=[];all=(...t)=>(this.conditions.push({type:"all",components:t}),this);any=(...t)=>(this.conditions.push({type:"any",components:t}),this);not=(...t)=>(this.conditions.push({type:"not",components:t}),this);with=this.all;have=this.all;has=this.all;every=this.all;is=this.all;some=this.any;one=this.any;none=this.not;without=this.not;get and(){return this}get but(){return this}get where(){return this}get are(){return this}}class p{enabled=!0;world;__internal={class:null,queries:new Set,priority:0,order:0,requiredQueries:[]};constructor(t){this.world=t}onDestroy(){}onInit(){}onUpdate(t,e){}unregister(){this.world.unregisterSystem(this.__internal.class)}query(t,e){return this.world.systemManager.createSystemQuery(this,t,e)}singleton(t,e){return{__internal:{systemSingletonPlaceholder:!0,component:t,options:e}}}attach(t){return{__internal:{attachedSystemPlaceholder:!0,systemClass:t}}}}class g{systems=new Map;sortedSystems=[];systemCounter=0;systemAttachments=new Map;world;constructor(t){this.world=t}init(){for(const t of this.systems.values())this.initSystem(t);this.sortSystems()}update(t,e){for(let s=0;s<this.sortedSystems.length;s++){const i=this.sortedSystems[s];i.enabled&&(i.__internal.requiredQueries.length>0&&i.__internal.requiredQueries.some((t=>0===t.entities.length))||i.onUpdate(t,e))}}destroy(){for(const t of this.systems.values())t.onDestroy()}registerSystem(t,e){if(this.systems.has(t))throw new Error(`System "${t.name}" has already been registered`);this.systemCounter++;const s=new t(this.world);this.systems.set(t,s),s.__internal.class=t,s.__internal.priority=e?.priority??0,s.__internal.order=this.systemCounter,this.initSingletonQueries(s),this.updateAllSystemAttachments();const i=(n=t,r="onUpdate",Object.getOwnPropertyNames(n.prototype).includes(r));var n,r;i&&this.sortedSystems.push(s),this.world.initialised&&(this.initSystem(s),i&&this.sortSystems())}unregisterSystem(t){const e=this.systems.get(t);e&&(this.systems.delete(t),this.sortedSystems=this.sortedSystems.filter((e=>e.__internal.class!==t)),e.__internal.queries.forEach((t=>{this.world.destroyQuery(t,e)})),e.__internal.requiredQueries=[],e.onDestroy(),this.updateAllSystemAttachments())}createSystemQuery(t,e,s){const i=this.world.query(e,{owner:t});return s?.required&&t.__internal.requiredQueries.push(i),i}initSystem(t){t.onInit()}initSingletonQueries(t){for(const e in t){const s=t,i=s[e];if(i?.__internal?.systemSingletonPlaceholder){const{__internal:{component:n,options:r}}=i,o=t=>t.has(n),h=this.createSystemQuery(t,o,r),a=()=>{s[e]=h.first?.[n]};h.onEntityAdded.add(a),h.onEntityRemoved.add(a),a()}}}updateSystemAttachments(t){for(const e in t){const s=t[e];if(s?.__internal?.attachedSystemPlaceholder){const i=this.systemAttachments.get(t)??[];i.push({field:e,systemClass:s.__internal.systemClass}),this.systemAttachments.set(t,i);const{__internal:{systemClass:n}}=s;t[e]=this.world.getSystem(n)}}const e=this.systemAttachments.get(t)??[];for(const{field:s,systemClass:i}of e)t[s]=this.world.getSystem(i)}updateAllSystemAttachments(){for(const t of this.systems.values())this.updateSystemAttachments(t)}sortSystems(){this.sortedSystems.sort(((t,e)=>e.__internal.priority-t.__internal.priority||t.__internal.order-e.__internal.order))}}class f extends e{time=0;initialised=!1;systemManager;queries=new Map;queryConsumers=new Map;componentIndexCounter=-1;componentRegistry={};idToEntity=new Map;entityIdCounter=0;bulkUpdateInProgress=!1;bulkUpdateEntities=new Set;constructor(t){super(),this.systemManager=new g(this),t?.components&&this.registerComponents(t.components)}init(){this.initialised=!0,this.systemManager.init()}step(t){this.time+=t,this.systemManager.update(t,this.time)}reset(){this.time=0,this.initialised=!1,this.systemManager.destroy(),this.entities.forEach((t=>this.destroy(t))),this.entityIdCounter=0,this.idToEntity.clear(),this._entityPositions.clear()}id(t){if(!this.has(t))return;const e=t;let s=e[h].id;return void 0===s&&(s=this.entityIdCounter++,this.idToEntity.set(s,t),e[h].id=s),s}entity(t){return this.idToEntity.get(t)}create(t){s(this,t);const e=t;return e[h]=o.request(),e[h].bitset.add(...Object.keys(t).map((t=>this.componentRegistry[t]))),this.index(t),t}destroy(t){i(this,t);const e=t;e[h].bitset.reset(),this.index(t),this.queries.forEach((e=>i(e,t)));let s=e[h].id;s&&this.idToEntity.delete(s),e[h].bitset.reset(),e[h].id=void 0,o.recycle(e[h]),delete e[h]}add(t,e,s){if(void 0!==t[e])return this;t[e]=s;return t[h].bitset.add(this.componentRegistry[e]),this.index(t),this}remove(t,e){if(void 0!==t[e]){if(this.has(t)){t[h].bitset.remove(this.componentRegistry[e]),this.index(t)}delete t[e]}}update(t,e){if("function"==typeof e){const s=e,i=new Proxy(t,{set:(e,s,i)=>{const n=s,r=n in t;return r&&void 0===i?this.remove(t,n):r?Reflect.set(t,s,i):this.add(t,n,i),!0},deleteProperty:(e,s)=>(this.remove(t,s),!0)});this.bulk((()=>{s(i)}))}else{const s=e;this.bulk((()=>{for(const e in s){const i=s[e];void 0!==i?this.add(t,e,i):this.remove(t,e)}}))}}bulk(t){this.bulkUpdateInProgress=!0,t(),this.bulkUpdateInProgress=!1;for(const t of this.bulkUpdateEntities)this.index(t);this.bulkUpdateEntities.clear()}query(t,e){const i=y(t),n=c(this.componentRegistry,i);let r=this.queries.get(n);if(r)return r;r=new a(this,n,i,u(this.componentRegistry,i));const o=l(r.bitSets,this.entities.values());for(const t of o)s(r,t);this.queries.set(n,r);const h=e?.owner??"standalone",d=this.queryConsumers.get(r.key)??[];return d.push(h),this.queryConsumers.set(r.key,d),r}destroyQuery(t,e="standalone"){if(!this.queries.has(t.key))return;let s=this.queryConsumers.get(t.key)??[];s=s.filter((t=>t!==e)),s.length>0?this.queryConsumers.set(t.key,s):(this.queries.delete(t.key),this.queryConsumers.delete(t.key),t.onEntityAdded.clear(),t.onEntityRemoved.clear())}filter(t){const e=y(t),s=c(this.componentRegistry,e),i=this.queries.get(s);if(i)return i.entities;const n=u(this.componentRegistry,e);return l(n,this.entities)}find(t){const e=y(t),s=c(this.componentRegistry,e),i=this.queries.get(s);if(i)return i.first;return((t,e)=>{for(const s of e)if(d(t,s))return s})(u(this.componentRegistry,e),this.entities)}registerComponents(t){for(const e of t)this.registerComponent(e);if(this.initialised)for(const t of this.entities.values()){t[h].bitset.resize(this.componentIndexCounter)}}registerSystem(t,e){return this.systemManager.registerSystem(t,e),this}unregisterSystem(t){return this.systemManager.unregisterSystem(t),this}getSystem(t){return this.systemManager.systems.get(t)}getSystems(){return Array.from(this.systemManager.systems.values())}index(t){if(this.has(t))if(this.bulkUpdateInProgress)this.bulkUpdateEntities.add(t);else for(const e of this.queries.values()){const n=d(e.bitSets,t),r=e.has(t);n&&!r?s(e,t):!n&&r&&i(e,t)}}registerComponent(t){let e=this.componentRegistry[t];return void 0===e&&(this.componentIndexCounter++,e=this.componentIndexCounter,this.componentRegistry[t]=e),e}}export{e as EntityContainer,n as ObjectPool,a as Query,m as QueryBuilder,p as System,t as Topic,f as World}; | ||
class t{listeners=new Set;add(t){return this.listeners.add(t),()=>this.remove(t)}remove(t){this.listeners.delete(t)}emit(...t){for(const e of this.listeners)e(...t)}clear(){this.listeners.clear()}}class e{entities=[];version=0;onEntityAdded=new t;onEntityRemoved=new t;_entityPositions=new Map;_entitySet=new Set;get first(){return this.entities[0]||void 0}[Symbol.iterator](){let t=this.entities.length;const e={value:void 0,done:!1};return{next:()=>(e.value=this.entities[--t],e.done=t<0,e)}}has(t){return this._entitySet.has(t)}}const s=(t,e)=>{e&&!t.has(e)&&(t.entities.push(e),t._entityPositions.set(e,t.entities.length-1),t._entitySet.add(e),t.version++,t.onEntityAdded.emit(e))},i=(t,e)=>{if(!t.has(e))return;const s=t._entityPositions.get(e);t._entityPositions.delete(e),t._entitySet.delete(e);const i=t.entities[t.entities.length-1];i!==e&&(t.entities[s]=i,t._entityPositions.set(i,s)),t.entities.pop(),t.version++,t.onEntityRemoved.emit(e)};class n{availableObjects=[];factory;get available(){return this.availableObjects.length}get used(){return this.size-this.availableObjects.length}size=0;constructor(t,e){this.factory=t,void 0!==e&&this.grow(e)}grow(t){for(let e=0;e<t;e++)this.availableObjects.push(this.factory());this.size+=t}free(t){for(let e=0;e<t;e++){if(!this.availableObjects.pop())break;this.size--}}request(){return this.availableObjects.length<=0&&this.grow(Math.round(.2*this.size)+1),this.availableObjects.pop()}recycle(t){this.availableObjects.push(t),this.availableObjects.length>Math.round(.2*this.size)&&this.free(this.availableObjects.length-Math.round(.2*this.size))}}class r{words;constructor(t=[]){this.words=new Uint32Array(8);for(const e of t)this.add(e)}add(...t){for(let e=0;e<t.length;e++){const s=t[e];this.resize(s),this.words[s>>>5]|=1<<s}}remove(...t){for(let e=0;e<t.length;e++){const s=t[e];this.resize(s),this.words[s>>>5]&=~(1<<s)}}has(t){return 0!=(this.words[t>>>5]&1<<t)}resize(t){if(this.words.length<<5>t)return;const e=new Uint32Array(t+32>>>5<<1);e.set(this.words),this.words=e}reset(){for(let t=0;t<this.words.length;t++)this.words[t]=0}copy(t){const e=new Uint32Array(t.words.length);e.set(t.words),this.words=e}clone(){const t=new Uint32Array(this.words.length);t.set(this.words);const e=new r;return e.words=t,e}containsAll(t){for(let e=0;e<this.words.length;e++)if(0!=(~this.words[e]&t.words[e]))return!1;return!0}containsAny(t){for(let e=0;e<this.words.length;e++)if(0!=(this.words[e]&t.words[e]))return!0;return!1}}const o=Symbol("__arancini");class h extends e{world;key;conditions;bitSets;constructor(t,e,s,i){super(),this.world=t,this.key=e,this.conditions=s,this.bitSets=i}destroy(){this.world.destroyQuery(this)}}const a=(t,e)=>{const s=[];for(const i of e)l(t,i)&&s.push(i);return s},l=(t,e)=>{const s=e;for(const e of t){if("all"===e.type&&!s[o].bitset.containsAll(e.bitset))return!1;if("any"===e.type&&!s[o].bitset.containsAny(e.bitset))return!1;if("not"===e.type&&s[o].bitset.containsAny(e.bitset))return!1}return!0},d=t=>{const e=new u;t(e);const s=e.conditions;if(s.length<=0)throw new Error("Query must have at least one condition");if(s.some((t=>t.components.length<=0)))throw new Error("Query conditions must have at least one component");const i={type:"all",components:[]},n=[];for(const t of s)"all"===t.type?i.components.push(...t.components):n.push(t);return[i,...n]},y=(t,e)=>e.map((({type:e,components:s})=>"all"===e?s.map((e=>t[e])).sort().join(","):[`${e}:${s.map((e=>t[e])).sort().join(",")}`])).sort().join("&"),c=(t,e)=>e.map((e=>({type:e.type,bitset:new r(e.components.map((e=>t[e])))})));class u{T;conditions=[];all=(...t)=>(this.conditions.push({type:"all",components:t}),this);any=(...t)=>(this.conditions.push({type:"any",components:t}),this);not=(...t)=>(this.conditions.push({type:"not",components:t}),this);with=this.all;have=this.all;has=this.all;every=this.all;is=this.all;some=this.any;one=this.any;none=this.not;without=this.not;get and(){return this}get but(){return this}get where(){return this}get are(){return this}}class m{enabled=!0;world;__internal={class:null,queries:new Set,priority:0,order:0,requiredQueries:[]};constructor(t){this.world=t}onDestroy(){}onInit(){}onUpdate(t,e){}unregister(){this.world.unregisterSystem(this.__internal.class)}query(t,e){return this.world.systemManager.createSystemQuery(this,t,e)}singleton(t,e){return{__internal:{systemSingletonPlaceholder:!0,component:t,options:e}}}attach(t){return{__internal:{attachedSystemPlaceholder:!0,systemClass:t}}}}class p{systems=new Map;sortedSystems=[];systemCounter=0;systemAttachments=new Map;world;constructor(t){this.world=t}init(){for(const t of this.systems.values())this.initSystem(t);this.sortSystems()}update(t,e){for(let s=0;s<this.sortedSystems.length;s++){const i=this.sortedSystems[s];i.enabled&&(i.__internal.requiredQueries.length>0&&i.__internal.requiredQueries.some((t=>0===t.entities.length))||i.onUpdate(t,e))}}destroy(){for(const t of this.systems.values())t.onDestroy()}registerSystem(t,e){if(this.systems.has(t))throw new Error(`System "${t.name}" has already been registered`);this.systemCounter++;const s=new t(this.world);this.systems.set(t,s),s.__internal.class=t,s.__internal.priority=e?.priority??0,s.__internal.order=this.systemCounter,this.initSingletonQueries(s),this.updateAllSystemAttachments();const i=(n=t,r="onUpdate",Object.getOwnPropertyNames(n.prototype).includes(r));var n,r;i&&this.sortedSystems.push(s),this.world.initialised&&(this.initSystem(s),i&&this.sortSystems())}unregisterSystem(t){const e=this.systems.get(t);e&&(this.systems.delete(t),this.sortedSystems=this.sortedSystems.filter((e=>e.__internal.class!==t)),e.__internal.queries.forEach((t=>{this.world.destroyQuery(t,e)})),e.__internal.requiredQueries=[],e.onDestroy(),this.updateAllSystemAttachments())}createSystemQuery(t,e,s){const i=this.world.query(e,{owner:t});return s?.required&&t.__internal.requiredQueries.push(i),i}initSystem(t){t.onInit()}initSingletonQueries(t){for(const e in t){const s=t,i=s[e];if(i?.__internal?.systemSingletonPlaceholder){const{__internal:{component:n,options:r}}=i,o=t=>t.has(n),h=this.createSystemQuery(t,o,r),a=()=>{s[e]=h.first?.[n]};h.onEntityAdded.add(a),h.onEntityRemoved.add(a),a()}}}updateSystemAttachments(t){for(const e in t){const s=t[e];if(s?.__internal?.attachedSystemPlaceholder){const i=this.systemAttachments.get(t)??[];i.push({field:e,systemClass:s.__internal.systemClass}),this.systemAttachments.set(t,i);const{__internal:{systemClass:n}}=s;t[e]=this.world.getSystem(n)}}const e=this.systemAttachments.get(t)??[];for(const{field:s,systemClass:i}of e)t[s]=this.world.getSystem(i)}updateAllSystemAttachments(){for(const t of this.systems.values())this.updateSystemAttachments(t)}sortSystems(){this.sortedSystems.sort(((t,e)=>e.__internal.priority-t.__internal.priority||t.__internal.order-e.__internal.order))}}class g extends e{time=0;initialised=!1;systemManager;queries=new Map;queryConsumers=new Map;componentIndexCounter=-1;componentRegistry={};idToEntity=new Map;entityIdCounter=0;bulkUpdateInProgress=!1;bulkUpdateEntities=new Set;entityMetadataPool=new n((()=>({bitset:new r,id:void 0})));constructor(t){super(),this.systemManager=new p(this),t?.components&&this.registerComponents(t.components)}init(){this.initialised=!0,this.systemManager.init()}step(t){this.time+=t,this.systemManager.update(t,this.time)}reset(){this.time=0,this.initialised=!1,this.systemManager.destroy(),this.entities.forEach((t=>this.destroy(t))),this.entityIdCounter=0,this.idToEntity.clear(),this._entityPositions.clear()}id(t){if(!this.has(t))return;const e=t;let s=e[o].id;return void 0===s&&(s=this.entityIdCounter++,this.idToEntity.set(s,t),e[o].id=s),s}entity(t){return this.idToEntity.get(t)}create(t){s(this,t);const e=t;return e[o]=this.entityMetadataPool.request(),e[o].bitset.add(...Object.keys(t).map((t=>this.componentRegistry[t]))),this.index(t),t}destroy(t){i(this,t);const e=t;e[o].bitset.reset(),this.index(t),this.queries.forEach((e=>i(e,t)));let s=e[o].id;s&&this.idToEntity.delete(s),e[o].bitset.reset(),e[o].id=void 0,this.entityMetadataPool.recycle(e[o]),delete e[o]}add(t,e,s){if(void 0!==t[e])return this;t[e]=s;return t[o].bitset.add(this.componentRegistry[e]),this.index(t),this}remove(t,e){if(void 0!==t[e]){if(this.has(t)){t[o].bitset.remove(this.componentRegistry[e]),this.index(t)}delete t[e]}}update(t,e){if("function"==typeof e){const s=e,i=new Proxy(t,{set:(e,s,i)=>{const n=s,r=n in t;return r&&void 0===i?this.remove(t,n):r?Reflect.set(t,s,i):this.add(t,n,i),!0},deleteProperty:(e,s)=>(this.remove(t,s),!0)});this.bulk((()=>{s(i)}))}else{const s=e;this.bulk((()=>{for(const e in s){const i=s[e];void 0!==i?this.add(t,e,i):this.remove(t,e)}}))}}bulk(t){this.bulkUpdateInProgress=!0,t(),this.bulkUpdateInProgress=!1;for(const t of this.bulkUpdateEntities)this.index(t);this.bulkUpdateEntities.clear()}query(t,e){const i=d(t),n=y(this.componentRegistry,i);let r=this.queries.get(n);if(r)return r;r=new h(this,n,i,c(this.componentRegistry,i));const o=a(r.bitSets,this.entities.values());for(const t of o)s(r,t);this.queries.set(n,r);const l=e?.owner??"standalone",u=this.queryConsumers.get(r.key)??[];return u.push(l),this.queryConsumers.set(r.key,u),r}destroyQuery(t,e="standalone"){if(!this.queries.has(t.key))return;let s=this.queryConsumers.get(t.key)??[];s=s.filter((t=>t!==e)),s.length>0?this.queryConsumers.set(t.key,s):(this.queries.delete(t.key),this.queryConsumers.delete(t.key),t.onEntityAdded.clear(),t.onEntityRemoved.clear())}filter(t){const e=d(t),s=y(this.componentRegistry,e),i=this.queries.get(s);if(i)return i.entities;const n=c(this.componentRegistry,e);return a(n,this.entities)}find(t){const e=d(t),s=y(this.componentRegistry,e),i=this.queries.get(s);if(i)return i.first;return((t,e)=>{for(const s of e)if(l(t,s))return s})(c(this.componentRegistry,e),this.entities)}registerComponents(t){for(const e of t)this.registerComponent(e);if(this.initialised)for(const t of this.entities.values()){t[o].bitset.resize(this.componentIndexCounter)}}registerSystem(t,e){return this.systemManager.registerSystem(t,e),this}unregisterSystem(t){return this.systemManager.unregisterSystem(t),this}getSystem(t){return this.systemManager.systems.get(t)}getSystems(){return Array.from(this.systemManager.systems.values())}index(t){if(this.has(t))if(this.bulkUpdateInProgress)this.bulkUpdateEntities.add(t);else for(const e of this.queries.values()){const n=l(e.bitSets,t),r=e.has(t);n&&!r?s(e,t):!n&&r&&i(e,t)}}registerComponent(t){let e=this.componentRegistry[t];return void 0===e&&(this.componentIndexCounter++,e=this.componentIndexCounter,this.componentRegistry[t]=e),e}}export{e as EntityContainer,n as ObjectPool,h as Query,u as QueryBuilder,m as System,t as Topic,g as World}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -23,2 +23,3 @@ import { EntityContainer } from './entity-container'; | ||
private bulkUpdateEntities; | ||
private entityMetadataPool; | ||
constructor(options?: WorldOptions<E>); | ||
@@ -25,0 +26,0 @@ /** |
@@ -12,3 +12,3 @@ { | ||
"license": "MIT", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"homepage": "https://github.com/isaac-mason/arancini", | ||
@@ -31,6 +31,6 @@ "bugs": { | ||
"@mdx-js/react": "^2.3.0", | ||
"@rollup/plugin-commonjs": "^25.0.4", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@rollup/plugin-typescript": "^11.1.3", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@storybook/addon-essentials": "^7.5.1", | ||
@@ -52,3 +52,3 @@ "@storybook/addon-interactions": "^7.5.1", | ||
"eslint-plugin-es": "^4.1.0", | ||
"eslint-plugin-import": "^2.28.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
@@ -62,3 +62,3 @@ "eslint-plugin-simple-import-sort": "^10.0.0", | ||
"react-dom": "^18.2.0", | ||
"rollup": "^3.26.3", | ||
"rollup": "^4.4.0", | ||
"rollup-plugin-copy": "^3.5.0", | ||
@@ -65,0 +65,0 @@ "rollup-plugin-filesize": "^10.0.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85640
585