Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitecs

Package Overview
Dependencies
Maintainers
1
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitecs - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

2

dist/index.es.js

@@ -1,2 +0,2 @@

const e=(e,t)=>{const{entities:n,systems:o}=t,r=[],i=((e,t=Uint32Array)=>{const n=8*t.BYTES_PER_ELEMENT,o=Math.ceil(e/n)*t.BYTES_PER_ELEMENT,r=new t(new SharedArrayBuffer(o)),i=e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]|=i},s=e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]&=~i};return{on:i,off:s,set:(e,t)=>{t?i(e):s(e)},get:e=>{const t=Math.floor(e/n),o=e-n*t;return 0!=(Math.pow(2,o)&r[t])?1:0},toggle:e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]^=i}}})(e.maxEntities,Uint32Array),s=[];let a=1;const f=()=>a-1;return{entityCount:f,addEntity:()=>{if(f()+1>e.maxEntities)return void console.warn("❌ Could not add entity, maximum number of entities reached.");const t=r.length?r.shift():a;return a++,n.forEach((e=>{e[t]=0})),i.on(t),t},removeEntity:e=>{s.push((()=>(e=>{if(i.get(e)){for(const t in o)o[t].remove(e);r.push(e),a--,i.off(e),n.forEach((t=>{t[e]=0}))}})(e)))},deferredEntityRemovals:s}},t=(e,t,n)=>{const{entities:o,components:r,systems:i}=t,s=[],a=e=>{if(void 0===r[e])throw new Error(`❌ Component '${e}' is not registered.`);return r[e]},f=(e,t)=>{s.push((()=>((e,t)=>{const n=a(e),{_generationId:r,_bitflag:s}=n;if(o[r][t]&s){o[r][t]&=~s;for(const e in i){const o=i[e];o.components.length&&o.checkComponent(n)&&!o.check(t)&&o.remove(t)}}})(e,t)))},c=(e,t)=>{const n=r[e],{_generationId:i,_bitflag:s}=n;return(o[i][t]&s)===s};return{registerComponent:(t,o)=>{if(Object.keys(r).length+1>e.maxComponentTypes)throw new Error(`❌ Can not register component '${t}'. Max components '${e.maxComponentTypes}' reached.`);return r[t]=n(e.maxEntities,o),r[t].name=t,r[t]},addComponent:(e,t,n={},r=!0)=>{const s=a(e);if(c(e,t))return;const{_generationId:f,_bitflag:p}=s;o[f][t]|=p,r&&s._reset(t),s._set(t,n);for(const e in i){const n=i[e];n.components.length&&n.checkComponent(s)&&n.check(t)&&n.add(t)}},removeComponent:f,removeAllComponents:(e,t=!1)=>{Object.keys(r).forEach((t=>{f(t,e)}))},hasComponent:c,deferredComponentRemovals:s}},n={bool:"bool",int8:"int8",uint8:"uint8",uint8clamped:"uint8clamped",int16:"int16",uint16:"uint16",int32:"int32",uint32:"uint32",float32:"float32",float64:"float64"},o={bool:"bool",int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float32:Float32Array,float64:Float64Array},r={uint8:255,uint16:65535,uint32:4294967295};export default(i={})=>{const s=(()=>{let e=1,t=0;const n={},i=(s,a={},f=!0)=>{const c={},p={};let l;return Object.keys(a).forEach((e=>{if("bool"===a[e]){const t=o.uint8,n=s*o.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);p[e]=a[e],c[e]=new t(r),c[e]._boolType=!0}else if(Array.isArray(a[e])&&"string"==typeof a[e][0]){const t=o.uint8,n=s*o.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);p[e]=a[e],c[e]=new t(r)}else if(Array.isArray(a[e])&&"object"==typeof a[e][0]){let{index:t,type:i,length:f}=a[e][0];if(f||(f=r[t]),!o[i])throw new Error(`❌ Invalid component array property type ${i}.`);if(!o[t])throw new Error(`❌ Invalid component array index type ${t}.`);if(!r[t])throw new Error(`❌ Index type for component array must be unsigned (non-negative), instead was ${t}.`);if(!n[i]){const e=new SharedArrayBuffer(o[t].BYTES_PER_ELEMENT*s*f),r=new o[i](e);r._indexType=t,r._indexBytes=o[t].BYTES_PER_ELEMENT,n[i]=r}c[e]={};for(let t=0;t<s;t++){const o=t*f,r=o+f;c[e][t]=n[i].subarray(o,r)}c[e]._reset=t=>c[e][t].fill(0)}else if("object"==typeof a[e])c[e]=i(s,a[e],!1);else if("string"==typeof a[e]){const t=a[e],n=s*o[t].BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);c[e]=new o[t](r)}else{if("function"!=typeof a[e])throw new Error("ECS Error: invalid property type "+a[e]);{const t=a[e],n=s*t.BYTES_PER_ELEMENT,o=new SharedArrayBuffer(n);c[e]=new t(o)}}})),Object.defineProperty(c,"_schema",{value:a}),Object.defineProperty(c,"_props",{value:Object.keys(a)}),Object.defineProperty(c,"_mapping",{value:e=>p[e]}),Object.defineProperty(c,"_reset",{value:e=>{for(const t of c._props)ArrayBuffer.isView(c[t])?c[t][e]=0:c[t]._reset(e)}}),Object.defineProperty(c,"_set",{value:(e,t)=>{for(const n in t)c._mapping(n)&&"string"==typeof t[n]?c.enum(n,e,t[n]):ArrayBuffer.isView(c[n])?c[n][e]=t[n]:"object"==typeof c[n]&&c[n]._set(e,t[n])}}),Object.defineProperty(c,"_get",{value:e=>{const t={};for(const n of c._props)c._mapping(n)?t[n]=c.enum(n,e):ArrayBuffer.isView(c[n])?t[n]=c[n][e]:"object"==typeof c[n]&&(t[n]=c[n]._get(e));return t}}),Object.defineProperty(c,"_flatten",{value:(e=[])=>{if(l)return l;for(const t of c._props)ArrayBuffer.isView(c[t])?e.push(c[t]):"object"==typeof c[t]&&c[t]._flatten(e);return l=e,e}}),Object.defineProperty(c,"_bitflag",{value:e}),Object.defineProperty(c,"_generationId",{value:t}),Object.defineProperty(c,"check",{value:e=>(e&c._bitflag)===c._bitflag}),Object.defineProperty(c,"enum",{value:(e,t,n)=>{const o=c._mapping(e);if(o){if(!n)return o[c[e][t]];{const r=o.indexOf(n);if(-1===r)return void console.warn(`Value '${n}' is not part of enum.`);c[e][t]=r}}else console.warn("Manager is not an enum.")}}),f&&(e*=2,e>=Math.pow(2,32)&&(e=1,t+=1)),c};return i})(),a=(({maxEntities:e=1e4,maxComponentTypes:t=128,tickRate:n=30,devtools:o=!1})=>({maxEntities:e,maxComponentTypes:t,tickRate:n,devtools:o}))(i),f=(({maxEntities:e,maxComponentTypes:t})=>({entities:Array(Math.ceil(t/32)).fill(null).map((()=>new Uint32Array(e))),components:{},systems:{}}))(a),{entityCount:c,addEntity:p,removeEntity:l,deferredEntityRemovals:m}=e(a,f),{registerComponent:y,addComponent:d,removeComponent:u,removeAllComponents:E,updateComponent:g,getComponent:h,hasComponent:_,deferredComponentRemovals:b}=t(a,f,s),{enabled:v,registerSystem:w,toggle:C,step:x}=((e,t,n,o)=>{const{entities:r,components:i,systems:s}=t,a=[];let f=!0;const c=()=>{for(;o.length>0;)o.shift()();for(;n.length>0;)n.shift()()};return{registerSystem:({name:e,components:t=[],enter:n,update:o,exit:f})=>{const p=[],l={count:0,name:e,enabled:!0,components:t,entityIndexes:{},localEntities:p,update:o,enter:n,exit:f},m=t.map((t=>{if(void 0===i[t])throw new Error(`❌ Cannot register system '${e}', '${t}' is not a registered component.`);return i[t]})),y={};m.forEach((e=>{const{_generationId:t,_bitflag:n}=e;y[t]|=n})),l.masks=y,l.check=e=>Object.keys(y).every((t=>{const n=r[t][e],o=y[t];return(n&o)===o})),l.checkComponent=e=>(y[e._generationId]&e._bitflag)===e._bitflag;const d=o?o(...m):null;l.execute=e=>{(e||l.enabled)&&d&&d(p),c()},l.add=e=>{l.entityIndexes[e]||(p.push(e),l.entityIndexes[e]=p.length-1,l.count=p.length,n&&n(e))},l.remove=e=>{const t=l.entityIndexes[e];if(void 0===t)return;const n=p.length-1,o=p[n];p[n]=p[t],p[t]=o,l.entityIndexes[o]=t,delete l.entityIndexes[p[n]],p.pop(),l.count=p.length,f&&f(e)};for(let e=0;e<r[0].length;e++)l.components.length&&l.check(e)&&l.add(e);return s[e]=l,e.includes("query")||a.push(l),l},enabled:e=>e?s[e]?s[e].enabled:void console.warn(`System '${e}' is not registered.`):f,step:(e,t=!1)=>{if("boolean"==typeof e&&(t=e),"string"!=typeof e){if(t||f)for(let e=0;e<a.length;e++)a[e].execute();c()}else s[e].execute(t)},toggle:e=>{if(e)return s[e]?void(s[e].enabled=!s[e].enabled):void console.warn(`System '${e} is not registered.`);f=!f}}})(0,f,m,b);let A=0;return{TYPES:n,config:a,registry:f,entityCount:c,addEntity:p,removeEntity:l,registerComponent:y,removeComponent:u,removeAllComponents:E,addComponent:d,updateComponent:g,getComponent:h,hasComponent:_,registerSystem:w,createQuery:e=>w({name:"query-"+A++,components:e}).localEntities,enabled:v,toggle:C,step:x}};
const e={bool:"bool",int8:"int8",uint8:"uint8",uint8clamped:"uint8clamped",int16:"int16",uint16:"uint16",int32:"int32",uint32:"uint32",float32:"float32",float64:"float64"},t={bool:"bool",int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float32:Float32Array,float64:Float64Array},n={uint8:255,uint16:65535,uint32:4294967295};export default(o={})=>{const r=(()=>{let e=1,o=0;const r={},i=(s,a={},l=!0)=>{const c={},f={};let p;return Object.keys(a).forEach((e=>{if("bool"===a[e]){const n=t.uint8,o=s*t.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);f[e]=a[e],c[e]=new n(r),c[e]._boolType=!0}else if(Array.isArray(a[e])&&"string"==typeof a[e][0]){const n=t.uint8,o=s*t.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);f[e]=a[e],c[e]=new n(r)}else if(Array.isArray(a[e])&&"object"==typeof a[e][0]){let{index:o,type:i,length:l}=a[e][0];if(l||(l=n[o]),!t[i])throw new Error(`❌ Invalid component array property type ${i}.`);if(!t[o])throw new Error(`❌ Invalid component array index type ${o}.`);if(!n[o])throw new Error(`❌ Index type for component array must be unsigned (non-negative), instead was ${o}.`);if(!r[i]){const e=new SharedArrayBuffer(t[o].BYTES_PER_ELEMENT*s*l),n=new t[i](e);n._indexType=o,n._indexBytes=t[o].BYTES_PER_ELEMENT,r[i]=n}c[e]={};for(let t=0;t<s;t++){const n=t*l,o=n+l;c[e][t]=r[i].subarray(n,o)}c[e]._reset=t=>c[e][t].fill(0)}else if("object"==typeof a[e])c[e]=i(s,a[e],!1);else if("string"==typeof a[e]){const n=a[e],o=s*t[n].BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);c[e]=new t[n](r)}else{if("function"!=typeof a[e])throw new Error("ECS Error: invalid property type "+a[e]);{const t=a[e],n=s*t.BYTES_PER_ELEMENT,o=new SharedArrayBuffer(n);c[e]=new t(o)}}})),Object.defineProperty(c,"_schema",{value:a}),Object.defineProperty(c,"_props",{value:Object.keys(a)}),Object.defineProperty(c,"_mapping",{value:e=>f[e]}),Object.defineProperty(c,"_reset",{value:e=>{for(const t of c._props)ArrayBuffer.isView(c[t])?c[t][e]=0:c[t]._reset(e)}}),Object.defineProperty(c,"_set",{value:(e,t)=>{for(const n in t)c._mapping(n)&&"string"==typeof t[n]?c.enum(n,e,t[n]):ArrayBuffer.isView(c[n])?c[n][e]=t[n]:"object"==typeof c[n]&&c[n]._set(e,t[n])}}),Object.defineProperty(c,"_get",{value:e=>{const t={};for(const n of c._props)c._mapping(n)?t[n]=c.enum(n,e):ArrayBuffer.isView(c[n])?t[n]=c[n][e]:"object"==typeof c[n]&&(t[n]=c[n]._get(e));return t}}),Object.defineProperty(c,"_flatten",{value:(e=[])=>{if(p)return p;for(const t of c._props)ArrayBuffer.isView(c[t])?e.push(c[t]):"object"==typeof c[t]&&c[t]._flatten(e);return p=e,e}}),Object.defineProperty(c,"_bitflag",{value:e}),Object.defineProperty(c,"_generationId",{value:o}),Object.defineProperty(c,"check",{value:e=>(e&c._bitflag)===c._bitflag}),Object.defineProperty(c,"enum",{value:(e,t,n)=>{const o=c._mapping(e);if(o){if(!n)return o[c[e][t]];{const r=o.indexOf(n);if(-1===r)return void console.warn(`Value '${n}' is not part of enum.`);c[e][t]=r}}else console.warn("Manager is not an enum.")}}),l&&(e*=2,e>=Math.pow(2,32)&&(e=1,o+=1)),c};return i})(),i=(({maxEntities:e=1e4,maxComponentTypes:t=128,tickRate:n=30,devtools:o=!1})=>({maxEntities:e,maxComponentTypes:t,maxGenerations:Math.ceil(t/32),tickRate:n,devtools:o}))(o),s=(({maxEntities:e,maxGenerations:t})=>({entities:Array.from({length:t},(()=>new Uint32Array(e))),components:{},systems:{}}))(i),{entityCount:a,addEntity:l,removeEntity:c,commitEntityRemovals:f}=((e,t)=>{const{entities:n,systems:o}=t,r=[],i=[],s=new Uint8Array(e.maxEntities);let a=0;return{entityCount:()=>a-r.length,addEntity:()=>{if(a>=e.maxEntities)return void console.warn("❌ Could not add entity, maximum number of entities reached.");const t=r.length>0?r.pop():a++;return s[t]=1,t},removeEntity:e=>{i.push(e)},commitEntityRemovals:()=>{if(0!==i.length){for(let e of i)if(0!==s[e]){for(const t in o)o[t].remove(e);r.push(e),s[e]=0;for(let t of n)t[e]=0}i.length=0}}}})(i,s),{registerComponent:p,addComponent:m,removeComponent:u,removeAllComponents:y,hasComponent:d,commitComponentRemovals:g}=((e,t,n)=>{const{entities:o,components:r,systems:i}=t,s=[],a=e=>{if(void 0===r[e])throw new Error(`❌ Component '${e}' is not registered.`);return r[e]},l=(e,t)=>{s.push(e,t)},c=(e,t)=>{const n=r[e],{_generationId:i,_bitflag:s}=n;return(o[i][t]&s)===s};return{registerComponent:(t,o)=>{if(Object.keys(r).length+1>e.maxComponentTypes)throw new Error(`❌ Can not register component '${t}'. Max components '${e.maxComponentTypes}' reached.`);return r[t]=n(e.maxEntities,o),r[t].name=t,r[t]},addComponent:(e,t,n={},r=!0)=>{if(c(e,t))return;const s=a(e),{_generationId:l,_bitflag:f}=s;o[l][t]|=f,r&&s._reset(t),s._set(t,n);for(const e in i){const n=i[e];n.components.length&&n.checkComponent(s)&&n.check(t)&&n.add(t)}},removeComponent:l,removeAllComponents:e=>{Object.keys(r).forEach((t=>{l(t,e)}))},hasComponent:c,commitComponentRemovals:()=>{if(0!==s.length){for(let e=0;e<s.length;e+=2){const t=s[e],n=s[e+1],r=a(t),{_generationId:l,_bitflag:c}=r;if(!(o[l][n]&c))return;o[l][n]&=~c;for(const e in i){const t=i[e];t.components.length&&t.checkComponent(r)&&!t.check(n)&&t.remove(n)}}s.length=0}}}})(i,s,r),{enabled:E,registerSystem:h,toggle:_,step:b}=((e,t,n,o)=>{const{entities:r,components:i,systems:s}=t,a=[];let l=!0;const c=()=>{o(),n()};return{registerSystem:({name:t,components:n=[],enter:o,update:l,exit:f})=>{const p=[],m=new Int32Array(e.maxEntities).fill(-1),u={count:0,name:t,enabled:!0,components:n,localEntities:p,update:l,enter:o,exit:f},y=n.map((e=>{if(void 0===i[e])throw new Error(`❌ Cannot register system '${t}', '${e}' is not a registered component.`);return i[e]})),d=Array.from({length:e.maxGenerations},(()=>0));for(const e of y){const{_generationId:t,_bitflag:n}=e;d[t]|=n}u.masks=d,u.check=e=>{for(let t=0;t<d.length;t++){const n=r[t][e],o=d[t];if((n&o)!==o)return!1}return!0},u.checkComponent=e=>(d[e._generationId]&e._bitflag)===e._bitflag;const g=l?l(...y):null;u.execute=e=>{(e||u.enabled)&&g&&g(p),c()},u.add=e=>{-1===m[e]&&(m[e]=p.push(e)-1,u.count=p.length,o&&o(e))},u.remove=e=>{const t=m[e];if(-1===t)return;const n=p.pop();n!==e&&(p[t]=n,m[n]=t),m[e]=-1,u.count=p.length,f&&f(e)};for(let e=0;e<r[0].length;e++)u.components.length&&u.check(e)&&u.add(e);return s[t]=u,t.includes("query")||a.push(u),u},enabled:e=>e?s[e]?s[e].enabled:void console.warn(`System '${e}' is not registered.`):l,step:(e,t=!1)=>{if("boolean"==typeof e&&(t=e),"string"!=typeof e){if(t||l)for(let e=0;e<a.length;e++)a[e].execute();c()}else s[e].execute(t)},toggle:e=>{if(e)return s[e]?void(s[e].enabled=!s[e].enabled):void console.warn(`System '${e} is not registered.`);l=!l}}})(i,s,f,g);let v=0;return{TYPES:e,config:i,registry:s,entityCount:a,addEntity:l,removeEntity:c,registerComponent:p,removeComponent:u,removeAllComponents:y,addComponent:m,hasComponent:d,registerSystem:h,createQuery:e=>h({name:"query-"+v++,components:e}).localEntities,enabled:E,toggle:_,step:b}};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

"use strict";const e=(e,t)=>{const{entities:n,systems:o}=t,r=[],i=((e,t=Uint32Array)=>{const n=8*t.BYTES_PER_ELEMENT,o=Math.ceil(e/n)*t.BYTES_PER_ELEMENT,r=new t(new SharedArrayBuffer(o)),i=e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]|=i},s=e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]&=~i};return{on:i,off:s,set:(e,t)=>{t?i(e):s(e)},get:e=>{const t=Math.floor(e/n),o=e-n*t;return 0!=(Math.pow(2,o)&r[t])?1:0},toggle:e=>{const t=Math.floor(e/n),o=e-n*t,i=Math.pow(2,o);r[t]^=i}}})(e.maxEntities,Uint32Array),s=[];let a=1;const c=()=>a-1;return{entityCount:c,addEntity:()=>{if(c()+1>e.maxEntities)return void console.warn("❌ Could not add entity, maximum number of entities reached.");const t=r.length?r.shift():a;return a++,n.forEach((e=>{e[t]=0})),i.on(t),t},removeEntity:e=>{s.push((()=>(e=>{if(i.get(e)){for(const t in o)o[t].remove(e);r.push(e),a--,i.off(e),n.forEach((t=>{t[e]=0}))}})(e)))},deferredEntityRemovals:s}},t=(e,t,n)=>{const{entities:o,components:r,systems:i}=t,s=[],a=e=>{if(void 0===r[e])throw new Error(`❌ Component '${e}' is not registered.`);return r[e]},c=(e,t)=>{s.push((()=>((e,t)=>{const n=a(e),{_generationId:r,_bitflag:s}=n;if(o[r][t]&s){o[r][t]&=~s;for(const e in i){const o=i[e];o.components.length&&o.checkComponent(n)&&!o.check(t)&&o.remove(t)}}})(e,t)))},f=(e,t)=>{const n=r[e],{_generationId:i,_bitflag:s}=n;return(o[i][t]&s)===s};return{registerComponent:(t,o)=>{if(Object.keys(r).length+1>e.maxComponentTypes)throw new Error(`❌ Can not register component '${t}'. Max components '${e.maxComponentTypes}' reached.`);return r[t]=n(e.maxEntities,o),r[t].name=t,r[t]},addComponent:(e,t,n={},r=!0)=>{const s=a(e);if(f(e,t))return;const{_generationId:c,_bitflag:p}=s;o[c][t]|=p,r&&s._reset(t),s._set(t,n);for(const e in i){const n=i[e];n.components.length&&n.checkComponent(s)&&n.check(t)&&n.add(t)}},removeComponent:c,removeAllComponents:(e,t=!1)=>{Object.keys(r).forEach((t=>{c(t,e)}))},hasComponent:f,deferredComponentRemovals:s}},n={bool:"bool",int8:"int8",uint8:"uint8",uint8clamped:"uint8clamped",int16:"int16",uint16:"uint16",int32:"int32",uint32:"uint32",float32:"float32",float64:"float64"},o={bool:"bool",int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float32:Float32Array,float64:Float64Array},r={uint8:255,uint16:65535,uint32:4294967295};module.exports=(i={})=>{const s=(()=>{let e=1,t=0;const n={},i=(s,a={},c=!0)=>{const f={},p={};let l;return Object.keys(a).forEach((e=>{if("bool"===a[e]){const t=o.uint8,n=s*o.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);p[e]=a[e],f[e]=new t(r),f[e]._boolType=!0}else if(Array.isArray(a[e])&&"string"==typeof a[e][0]){const t=o.uint8,n=s*o.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);p[e]=a[e],f[e]=new t(r)}else if(Array.isArray(a[e])&&"object"==typeof a[e][0]){let{index:t,type:i,length:c}=a[e][0];if(c||(c=r[t]),!o[i])throw new Error(`❌ Invalid component array property type ${i}.`);if(!o[t])throw new Error(`❌ Invalid component array index type ${t}.`);if(!r[t])throw new Error(`❌ Index type for component array must be unsigned (non-negative), instead was ${t}.`);if(!n[i]){const e=new SharedArrayBuffer(o[t].BYTES_PER_ELEMENT*s*c),r=new o[i](e);r._indexType=t,r._indexBytes=o[t].BYTES_PER_ELEMENT,n[i]=r}f[e]={};for(let t=0;t<s;t++){const o=t*c,r=o+c;f[e][t]=n[i].subarray(o,r)}f[e]._reset=t=>f[e][t].fill(0)}else if("object"==typeof a[e])f[e]=i(s,a[e],!1);else if("string"==typeof a[e]){const t=a[e],n=s*o[t].BYTES_PER_ELEMENT,r=new SharedArrayBuffer(n);f[e]=new o[t](r)}else{if("function"!=typeof a[e])throw new Error("ECS Error: invalid property type "+a[e]);{const t=a[e],n=s*t.BYTES_PER_ELEMENT,o=new SharedArrayBuffer(n);f[e]=new t(o)}}})),Object.defineProperty(f,"_schema",{value:a}),Object.defineProperty(f,"_props",{value:Object.keys(a)}),Object.defineProperty(f,"_mapping",{value:e=>p[e]}),Object.defineProperty(f,"_reset",{value:e=>{for(const t of f._props)ArrayBuffer.isView(f[t])?f[t][e]=0:f[t]._reset(e)}}),Object.defineProperty(f,"_set",{value:(e,t)=>{for(const n in t)f._mapping(n)&&"string"==typeof t[n]?f.enum(n,e,t[n]):ArrayBuffer.isView(f[n])?f[n][e]=t[n]:"object"==typeof f[n]&&f[n]._set(e,t[n])}}),Object.defineProperty(f,"_get",{value:e=>{const t={};for(const n of f._props)f._mapping(n)?t[n]=f.enum(n,e):ArrayBuffer.isView(f[n])?t[n]=f[n][e]:"object"==typeof f[n]&&(t[n]=f[n]._get(e));return t}}),Object.defineProperty(f,"_flatten",{value:(e=[])=>{if(l)return l;for(const t of f._props)ArrayBuffer.isView(f[t])?e.push(f[t]):"object"==typeof f[t]&&f[t]._flatten(e);return l=e,e}}),Object.defineProperty(f,"_bitflag",{value:e}),Object.defineProperty(f,"_generationId",{value:t}),Object.defineProperty(f,"check",{value:e=>(e&f._bitflag)===f._bitflag}),Object.defineProperty(f,"enum",{value:(e,t,n)=>{const o=f._mapping(e);if(o){if(!n)return o[f[e][t]];{const r=o.indexOf(n);if(-1===r)return void console.warn(`Value '${n}' is not part of enum.`);f[e][t]=r}}else console.warn("Manager is not an enum.")}}),c&&(e*=2,e>=Math.pow(2,32)&&(e=1,t+=1)),f};return i})(),a=(({maxEntities:e=1e4,maxComponentTypes:t=128,tickRate:n=30,devtools:o=!1})=>({maxEntities:e,maxComponentTypes:t,tickRate:n,devtools:o}))(i),c=(({maxEntities:e,maxComponentTypes:t})=>({entities:Array(Math.ceil(t/32)).fill(null).map((()=>new Uint32Array(e))),components:{},systems:{}}))(a),{entityCount:f,addEntity:p,removeEntity:l,deferredEntityRemovals:m}=e(a,c),{registerComponent:y,addComponent:d,removeComponent:u,removeAllComponents:E,updateComponent:g,getComponent:h,hasComponent:_,deferredComponentRemovals:b}=t(a,c,s),{enabled:v,registerSystem:w,toggle:C,step:x}=((e,t,n,o)=>{const{entities:r,components:i,systems:s}=t,a=[];let c=!0;const f=()=>{for(;o.length>0;)o.shift()();for(;n.length>0;)n.shift()()};return{registerSystem:({name:e,components:t=[],enter:n,update:o,exit:c})=>{const p=[],l={count:0,name:e,enabled:!0,components:t,entityIndexes:{},localEntities:p,update:o,enter:n,exit:c},m=t.map((t=>{if(void 0===i[t])throw new Error(`❌ Cannot register system '${e}', '${t}' is not a registered component.`);return i[t]})),y={};m.forEach((e=>{const{_generationId:t,_bitflag:n}=e;y[t]|=n})),l.masks=y,l.check=e=>Object.keys(y).every((t=>{const n=r[t][e],o=y[t];return(n&o)===o})),l.checkComponent=e=>(y[e._generationId]&e._bitflag)===e._bitflag;const d=o?o(...m):null;l.execute=e=>{(e||l.enabled)&&d&&d(p),f()},l.add=e=>{l.entityIndexes[e]||(p.push(e),l.entityIndexes[e]=p.length-1,l.count=p.length,n&&n(e))},l.remove=e=>{const t=l.entityIndexes[e];if(void 0===t)return;const n=p.length-1,o=p[n];p[n]=p[t],p[t]=o,l.entityIndexes[o]=t,delete l.entityIndexes[p[n]],p.pop(),l.count=p.length,c&&c(e)};for(let e=0;e<r[0].length;e++)l.components.length&&l.check(e)&&l.add(e);return s[e]=l,e.includes("query")||a.push(l),l},enabled:e=>e?s[e]?s[e].enabled:void console.warn(`System '${e}' is not registered.`):c,step:(e,t=!1)=>{if("boolean"==typeof e&&(t=e),"string"!=typeof e){if(t||c)for(let e=0;e<a.length;e++)a[e].execute();f()}else s[e].execute(t)},toggle:e=>{if(e)return s[e]?void(s[e].enabled=!s[e].enabled):void console.warn(`System '${e} is not registered.`);c=!c}}})(0,c,m,b);let A=0;return{TYPES:n,config:a,registry:c,entityCount:f,addEntity:p,removeEntity:l,registerComponent:y,removeComponent:u,removeAllComponents:E,addComponent:d,updateComponent:g,getComponent:h,hasComponent:_,registerSystem:w,createQuery:e=>w({name:"query-"+A++,components:e}).localEntities,enabled:v,toggle:C,step:x}};
"use strict";const e={bool:"bool",int8:"int8",uint8:"uint8",uint8clamped:"uint8clamped",int16:"int16",uint16:"uint16",int32:"int32",uint32:"uint32",float32:"float32",float64:"float64"},t={bool:"bool",int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float32:Float32Array,float64:Float64Array},n={uint8:255,uint16:65535,uint32:4294967295};module.exports=(o={})=>{const r=(()=>{let e=1,o=0;const r={},i=(s,a={},l=!0)=>{const c={},f={};let m;return Object.keys(a).forEach((e=>{if("bool"===a[e]){const n=t.uint8,o=s*t.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);f[e]=a[e],c[e]=new n(r),c[e]._boolType=!0}else if(Array.isArray(a[e])&&"string"==typeof a[e][0]){const n=t.uint8,o=s*t.uint8.BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);f[e]=a[e],c[e]=new n(r)}else if(Array.isArray(a[e])&&"object"==typeof a[e][0]){let{index:o,type:i,length:l}=a[e][0];if(l||(l=n[o]),!t[i])throw new Error(`❌ Invalid component array property type ${i}.`);if(!t[o])throw new Error(`❌ Invalid component array index type ${o}.`);if(!n[o])throw new Error(`❌ Index type for component array must be unsigned (non-negative), instead was ${o}.`);if(!r[i]){const e=new SharedArrayBuffer(t[o].BYTES_PER_ELEMENT*s*l),n=new t[i](e);n._indexType=o,n._indexBytes=t[o].BYTES_PER_ELEMENT,r[i]=n}c[e]={};for(let t=0;t<s;t++){const n=t*l,o=n+l;c[e][t]=r[i].subarray(n,o)}c[e]._reset=t=>c[e][t].fill(0)}else if("object"==typeof a[e])c[e]=i(s,a[e],!1);else if("string"==typeof a[e]){const n=a[e],o=s*t[n].BYTES_PER_ELEMENT,r=new SharedArrayBuffer(o);c[e]=new t[n](r)}else{if("function"!=typeof a[e])throw new Error("ECS Error: invalid property type "+a[e]);{const t=a[e],n=s*t.BYTES_PER_ELEMENT,o=new SharedArrayBuffer(n);c[e]=new t(o)}}})),Object.defineProperty(c,"_schema",{value:a}),Object.defineProperty(c,"_props",{value:Object.keys(a)}),Object.defineProperty(c,"_mapping",{value:e=>f[e]}),Object.defineProperty(c,"_reset",{value:e=>{for(const t of c._props)ArrayBuffer.isView(c[t])?c[t][e]=0:c[t]._reset(e)}}),Object.defineProperty(c,"_set",{value:(e,t)=>{for(const n in t)c._mapping(n)&&"string"==typeof t[n]?c.enum(n,e,t[n]):ArrayBuffer.isView(c[n])?c[n][e]=t[n]:"object"==typeof c[n]&&c[n]._set(e,t[n])}}),Object.defineProperty(c,"_get",{value:e=>{const t={};for(const n of c._props)c._mapping(n)?t[n]=c.enum(n,e):ArrayBuffer.isView(c[n])?t[n]=c[n][e]:"object"==typeof c[n]&&(t[n]=c[n]._get(e));return t}}),Object.defineProperty(c,"_flatten",{value:(e=[])=>{if(m)return m;for(const t of c._props)ArrayBuffer.isView(c[t])?e.push(c[t]):"object"==typeof c[t]&&c[t]._flatten(e);return m=e,e}}),Object.defineProperty(c,"_bitflag",{value:e}),Object.defineProperty(c,"_generationId",{value:o}),Object.defineProperty(c,"check",{value:e=>(e&c._bitflag)===c._bitflag}),Object.defineProperty(c,"enum",{value:(e,t,n)=>{const o=c._mapping(e);if(o){if(!n)return o[c[e][t]];{const r=o.indexOf(n);if(-1===r)return void console.warn(`Value '${n}' is not part of enum.`);c[e][t]=r}}else console.warn("Manager is not an enum.")}}),l&&(e*=2,e>=Math.pow(2,32)&&(e=1,o+=1)),c};return i})(),i=(({maxEntities:e=1e4,maxComponentTypes:t=128,tickRate:n=30,devtools:o=!1})=>({maxEntities:e,maxComponentTypes:t,maxGenerations:Math.ceil(t/32),tickRate:n,devtools:o}))(o),s=(({maxEntities:e,maxGenerations:t})=>({entities:Array.from({length:t},(()=>new Uint32Array(e))),components:{},systems:{}}))(i),{entityCount:a,addEntity:l,removeEntity:c,commitEntityRemovals:f}=((e,t)=>{const{entities:n,systems:o}=t,r=[],i=[],s=new Uint8Array(e.maxEntities);let a=0;return{entityCount:()=>a-r.length,addEntity:()=>{if(a>=e.maxEntities)return void console.warn("❌ Could not add entity, maximum number of entities reached.");const t=r.length>0?r.pop():a++;return s[t]=1,t},removeEntity:e=>{i.push(e)},commitEntityRemovals:()=>{if(0!==i.length){for(let e of i)if(0!==s[e]){for(const t in o)o[t].remove(e);r.push(e),s[e]=0;for(let t of n)t[e]=0}i.length=0}}}})(i,s),{registerComponent:m,addComponent:p,removeComponent:u,removeAllComponents:y,hasComponent:d,commitComponentRemovals:g}=((e,t,n)=>{const{entities:o,components:r,systems:i}=t,s=[],a=e=>{if(void 0===r[e])throw new Error(`❌ Component '${e}' is not registered.`);return r[e]},l=(e,t)=>{s.push(e,t)},c=(e,t)=>{const n=r[e],{_generationId:i,_bitflag:s}=n;return(o[i][t]&s)===s};return{registerComponent:(t,o)=>{if(Object.keys(r).length+1>e.maxComponentTypes)throw new Error(`❌ Can not register component '${t}'. Max components '${e.maxComponentTypes}' reached.`);return r[t]=n(e.maxEntities,o),r[t].name=t,r[t]},addComponent:(e,t,n={},r=!0)=>{if(c(e,t))return;const s=a(e),{_generationId:l,_bitflag:f}=s;o[l][t]|=f,r&&s._reset(t),s._set(t,n);for(const e in i){const n=i[e];n.components.length&&n.checkComponent(s)&&n.check(t)&&n.add(t)}},removeComponent:l,removeAllComponents:e=>{Object.keys(r).forEach((t=>{l(t,e)}))},hasComponent:c,commitComponentRemovals:()=>{if(0!==s.length){for(let e=0;e<s.length;e+=2){const t=s[e],n=s[e+1],r=a(t),{_generationId:l,_bitflag:c}=r;if(!(o[l][n]&c))return;o[l][n]&=~c;for(const e in i){const t=i[e];t.components.length&&t.checkComponent(r)&&!t.check(n)&&t.remove(n)}}s.length=0}}}})(i,s,r),{enabled:E,registerSystem:h,toggle:_,step:b}=((e,t,n,o)=>{const{entities:r,components:i,systems:s}=t,a=[];let l=!0;const c=()=>{o(),n()};return{registerSystem:({name:t,components:n=[],enter:o,update:l,exit:f})=>{const m=[],p=new Int32Array(e.maxEntities).fill(-1),u={count:0,name:t,enabled:!0,components:n,localEntities:m,update:l,enter:o,exit:f},y=n.map((e=>{if(void 0===i[e])throw new Error(`❌ Cannot register system '${t}', '${e}' is not a registered component.`);return i[e]})),d=Array.from({length:e.maxGenerations},(()=>0));for(const e of y){const{_generationId:t,_bitflag:n}=e;d[t]|=n}u.masks=d,u.check=e=>{for(let t=0;t<d.length;t++){const n=r[t][e],o=d[t];if((n&o)!==o)return!1}return!0},u.checkComponent=e=>(d[e._generationId]&e._bitflag)===e._bitflag;const g=l?l(...y):null;u.execute=e=>{(e||u.enabled)&&g&&g(m),c()},u.add=e=>{-1===p[e]&&(p[e]=m.push(e)-1,u.count=m.length,o&&o(e))},u.remove=e=>{const t=p[e];if(-1===t)return;const n=m.pop();n!==e&&(m[t]=n,p[n]=t),p[e]=-1,u.count=m.length,f&&f(e)};for(let e=0;e<r[0].length;e++)u.components.length&&u.check(e)&&u.add(e);return s[t]=u,t.includes("query")||a.push(u),u},enabled:e=>e?s[e]?s[e].enabled:void console.warn(`System '${e}' is not registered.`):l,step:(e,t=!1)=>{if("boolean"==typeof e&&(t=e),"string"!=typeof e){if(t||l)for(let e=0;e<a.length;e++)a[e].execute();c()}else s[e].execute(t)},toggle:e=>{if(e)return s[e]?void(s[e].enabled=!s[e].enabled):void console.warn(`System '${e} is not registered.`);l=!l}}})(i,s,f,g);let v=0;return{TYPES:e,config:i,registry:s,entityCount:a,addEntity:l,removeEntity:c,registerComponent:m,removeComponent:u,removeAllComponents:y,addComponent:p,hasComponent:d,registerSystem:h,createQuery:e=>h({name:"query-"+v++,components:e}).localEntities,enabled:E,toggle:_,step:b}};
//# sourceMappingURL=index.min.js.map

@@ -26,3 +26,3 @@

* [.removeComponent(name, eid)](#module_World.removeComponent)
* [.removeAllComponents(eid, immediate)](#module_World.removeAllComponents)
* [.removeAllComponents(eid)](#module_World.removeAllComponents)
* [.hasComponent(name, eid)](#module_World.hasComponent) ⇒ <code>boolean</code>

@@ -185,10 +185,9 @@ * [.entityCount()](#module_World.entityCount)

### removeAllComponents
#### World.removeAllComponents(eid, immediate)
#### World.removeAllComponents(eid)
> Removes all components from the given entity.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| eid | <code>uint32</code> | | Entity id. |
| immediate | <code>boolean</code> | <code>false</code> | Remove immediately. If false, defer until end of tick. |
| Param | Type | Description |
| --- | --- | --- |
| eid | <code>uint32</code> | Entity id. |

@@ -195,0 +194,0 @@ **Example** *(Remove all components from an entity deferred.)*

{
"name": "bitecs",
"version": "0.2.1",
"version": "0.2.2",
"description": "Tiny, data-driven, high performance ECS library written in Javascript",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc