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.3.10 to 0.3.11

5

dist/index.d.ts

@@ -11,3 +11,4 @@ declare module 'bitecs' {

'f32' |
'f64'
'f64' |
any[]

@@ -74,3 +75,3 @@ export const Types: {

export type Query = (world: IWorld, clearDiff: Boolean = true) => number[]
export type Query = (world: IWorld, clearDiff?: Boolean) => number[]

@@ -77,0 +78,0 @@ export type System = (world: IWorld) => IWorld

138

dist/index.es.js

@@ -51,2 +51,4 @@ const TYPES_ENUM = {

const $subarray = Symbol('subarray');
const $subarrayFrom = Symbol('subarrayFrom');
const $subarrayTo = Symbol('subarrayTo');
const $parentArray = Symbol('subStore');

@@ -65,3 +67,16 @@ const $tagStore = Symbol('tagStore');

};
const createShadow = (store, key) => {
if (!ArrayBuffer.isView(store)) {
const shadow = store[$parentArray].slice(0);
for (const k in store[key]) {
const from = store[key][k][$subarrayFrom];
const to = store[key][k][$subarrayTo];
store[key][k] = shadow.subarray(from, to);
}
} else {
store[key] = store.slice(0);
}
};
const resizeSubarray = (metadata, store, size) => {

@@ -81,4 +96,4 @@ const cursors = metadata[$subarrayCursors];

metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
createShadow(metadata[$storeSubarrays][type], $queryShadow);
createShadow(metadata[$storeSubarrays][type], $serializeShadow);
array[$indexType] = TYPES_NAMES[indexType];

@@ -93,4 +108,4 @@ array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

store[eid] = metadata[$storeSubarrays][type].subarray(from, to);
store[eid].from = from;
store[eid].to = to;
store[eid][$subarrayFrom] = from;
store[eid][$subarrayTo] = to;
store[eid][$queryShadow] = metadata[$storeSubarrays][type][$queryShadow].subarray(from, to);

@@ -169,4 +184,4 @@ store[eid][$serializeShadow] = metadata[$storeSubarrays][type][$serializeShadow].subarray(from, to);

metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
createShadow(metadata[$storeSubarrays][type], $queryShadow);
createShadow(metadata[$storeSubarrays][type], $serializeShadow);
array[$indexType] = TYPES_NAMES[indexType];

@@ -184,4 +199,4 @@ array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

store[eid] = metadata[$storeSubarrays][type].subarray(from, to);
store[eid].from = from;
store[eid].to = to;
store[eid][$subarrayFrom] = from;
store[eid][$subarrayTo] = to;
store[eid][$queryShadow] = metadata[$storeSubarrays][type][$queryShadow].subarray(from, to);

@@ -200,7 +215,2 @@ store[eid][$serializeShadow] = metadata[$storeSubarrays][type][$serializeShadow].subarray(from, to);

const createShadows = store => {
store[$queryShadow] = store.slice(0);
store[$serializeShadow] = store.slice(0);
};
const isArrayType = x => Array.isArray(x) && typeof x[0] === 'string' && typeof x[1] === 'number';

@@ -255,3 +265,4 @@

a[k] = createTypeStore(a[k], size);
createShadows(a[k]);
createShadow(a[k], $queryShadow);
createShadow(a[k], $serializeShadow);

@@ -288,2 +299,4 @@ a[k][$storeBase] = () => stores[$store];

dense.count = () => dense.length;
const has = val => dense[sparse[val]] === val;

@@ -323,9 +336,13 @@

let componentProps = [];
let changedProps = new Set();
let changedProps = new Map();
if (Array.isArray(target)) {
componentProps = target.map(p => {
if (!p) throw new Error('๐Ÿ‘พ bitECS - undefined component passed into serializer.');
if (typeof p === 'function' && p.name === 'QueryChanged') {
p()[$storeFlattened].forEach(prop => {
changedProps.add(prop);
const $ = Symbol();
createShadow(prop, $);
changedProps.set(prop, $);
});

@@ -381,3 +398,3 @@ return p()[$storeFlattened];

const prop = componentProps[pid];
const diff = changedProps.has(prop); // write pid
const diff = changedProps.get(prop); // write pid

@@ -397,5 +414,6 @@ view.setUint8(where, pid);

} // skip if diffing and no change
// TODO: check array diff
if (diff && prop[eid] === prop[$serializeShadow][eid]) {
if (diff && prop[eid] === prop[diff][eid]) {
continue;

@@ -540,3 +558,2 @@ }

const $entityMasks = Symbol('entityMasks');
const $entityEnabled = Symbol('entityEnabled');
const $entitySparseSet = Symbol('entitySparseSet');

@@ -592,11 +609,12 @@ const $entityArray = Symbol('entityArray');

// TODO: archetype graph
// world[$queries].forEach(q => {
// queryRemoveEntity(world, q, eid)
// })
// Free the entity
world[$queries].forEach(q => {
queryRemoveEntity(world, q, eid);
}); // Free the entity
removed.push(eid); // pop swap
world[$entitySparseSet].remove(eid); // Clear entity bitmasks
// for (let i = 0; i < world[$entityMasks].length; i++) world[$entityMasks][i][eid] = 0
for (let i = 0; i < world[$entityMasks].length; i++) world[$entityMasks][i][eid] = 0;
};

@@ -633,14 +651,16 @@

query[$queryComponents].forEach(c => {
if (!world[$componentMap].has(c)) registerComponent(world, c);
if (typeof c === 'function') {
const comp = c();
if (!world[$componentMap].has(comp)) registerComponent(world, comp);
if (typeof c === 'function') {
if (c.name === 'QueryNot') {
notComponents.push(c());
notComponents.push(comp);
}
if (c.name === 'QueryChanged') {
changedComponents.push(c());
components.push(c());
changedComponents.push(comp);
components.push(comp);
}
} else {
if (!world[$componentMap].has(c)) registerComponent(world, c);
components.push(c);

@@ -650,4 +670,5 @@ }

const mapComponents = c => world[$componentMap].get(c);
const mapComponents = c => world[$componentMap].get(c); // const sparseSet = Uint32SparseSet(getGlobalSize())
const sparseSet = SparseSet();

@@ -665,3 +686,3 @@ const archetypes = [];

const reduceBitmasks = (a, c) => {
const reduceBitflags = (a, c) => {
if (!a[c.generationId]) a[c.generationId] = 0;

@@ -672,3 +693,3 @@ a[c.generationId] |= c.bitflag;

const masks = components.map(mapComponents).reduce(reduceBitmasks, {});
const masks = components.map(mapComponents).reduce(reduceBitflags, {});
const notMasks = notComponents.map(mapComponents).reduce((a, c) => {

@@ -686,2 +707,7 @@ if (!a[c.generationId]) {

const flatProps = components.filter(c => !c[$tagStore]).map(c => Object.getOwnPropertySymbols(c).includes($storeFlattened) ? c[$storeFlattened] : [c]).reduce((a, v) => a.concat(v), []);
const shadows = flatProps.map(prop => {
const $ = Symbol();
createShadow(prop, $);
return prop[$];
}, []);
const q = Object.assign(sparseSet, {

@@ -700,3 +726,4 @@ archetypes,

entered,
exited
exited,
shadows
});

@@ -710,3 +737,3 @@ world[$queryMap].set(query, q);

if (queryCheckEntity(world, q, eid)) {
queryAddEntity(world, q, eid);
queryAddEntity(q, eid);
}

@@ -718,10 +745,14 @@ }

if (clearDiff) q.changed.length = 0;
const flat = q.flatProps;
const {
flatProps,
shadows
} = q;
for (let i = 0; i < q.dense.length; i++) {
for (let i = 0; i < q.dense.count(); i++) {
const eid = q.dense[i];
let dirty = false;
for (let pid = 0; pid < flat.length; pid++) {
const prop = flat[pid];
for (let pid = 0; pid < flatProps.length; pid++) {
const prop = flatProps[pid];
const shadow = shadows[pid];

@@ -736,5 +767,5 @@ if (ArrayBuffer.isView(prop[eid])) {

} else {
if (prop[eid] !== prop[$queryShadow][eid]) {
if (prop[eid] !== shadow[eid]) {
dirty = true;
prop[$queryShadow][eid] = prop[eid];
shadow[eid] = prop[eid];
}

@@ -758,3 +789,3 @@ }

const q = world[$queryMap].get(query);
queryCommitRemovals(world, q);
queryCommitRemovals(q);
if (q.changedComponents.length) return diff(q, clearDiff);

@@ -807,3 +838,3 @@ return q.dense;

};
const queryAddEntity = (world, q, eid) => {
const queryAddEntity = (q, eid) => {
if (q.has(eid)) return;

@@ -814,18 +845,14 @@ q.add(eid);

const queryCommitRemovals = (world, q) => {
const queryCommitRemovals = q => {
while (q.toRemove.length) {
q.remove(q.toRemove.pop());
}
world[$dirtyQueries].delete(q);
};
const commitRemovals = world => {
world[$dirtyQueries].forEach(q => {
queryCommitRemovals(world, q);
});
world[$dirtyQueries].forEach(queryCommitRemovals);
world[$dirtyQueries].clear();
};
const queryRemoveEntity = (world, q, eid) => {
if (!q.has(eid)) return;
q.remove(eid);
q.toRemove.push(eid);

@@ -864,2 +891,3 @@ world[$dirtyQueries].add(q);

const registerComponent = (world, component) => {
if (!component) throw new Error(`๐Ÿ‘พ bitECS - cannot register component as it is null or undefined.`);
world[$componentMap].set(component, {

@@ -909,3 +937,3 @@ generationId: world[$entityMasks].length - 1,

const match = queryCheckEntity(world, q, eid);
if (match) queryAddEntity(world, q, eid);
if (match) queryAddEntity(q, eid);
}); // Zero out each property value

@@ -942,6 +970,8 @@

const $bitflag = Symbol('bitflag');
const $archetypes = Symbol('archetypes');
const worlds = [];
const resizeWorlds = size => {
worlds.forEach(world => {
world[$size] = size;
world[$size] = size; // resize(world[$entitySparseSet].sparse, size)
// resize(world[$entitySparseSet].dense, size)

@@ -966,4 +996,6 @@ for (let i = 0; i < world[$entityMasks].length; i++) {

world[$entityMasks] = [new Uint32Array(size)];
world[$archetypes] = [];
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entitySparseSet] = SparseSet();
world[$entitySparseSet] = SparseSet(); // world[$entitySparseSet] = Uint32SparseSet(size)
world[$entityArray] = world[$entitySparseSet].dense;

@@ -979,3 +1011,3 @@ world[$bitflag] = 1;

delete world[$size];
delete world[$entityEnabled];
delete world[$archetypes];
delete world[$entityMasks];

@@ -982,0 +1014,0 @@ delete world[$entityArray];

@@ -55,2 +55,4 @@ 'use strict';

const $subarray = Symbol('subarray');
const $subarrayFrom = Symbol('subarrayFrom');
const $subarrayTo = Symbol('subarrayTo');
const $parentArray = Symbol('subStore');

@@ -69,3 +71,16 @@ const $tagStore = Symbol('tagStore');

};
const createShadow = (store, key) => {
if (!ArrayBuffer.isView(store)) {
const shadow = store[$parentArray].slice(0);
for (const k in store[key]) {
const from = store[key][k][$subarrayFrom];
const to = store[key][k][$subarrayTo];
store[key][k] = shadow.subarray(from, to);
}
} else {
store[key] = store.slice(0);
}
};
const resizeSubarray = (metadata, store, size) => {

@@ -85,4 +100,4 @@ const cursors = metadata[$subarrayCursors];

metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
createShadow(metadata[$storeSubarrays][type], $queryShadow);
createShadow(metadata[$storeSubarrays][type], $serializeShadow);
array[$indexType] = TYPES_NAMES[indexType];

@@ -97,4 +112,4 @@ array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

store[eid] = metadata[$storeSubarrays][type].subarray(from, to);
store[eid].from = from;
store[eid].to = to;
store[eid][$subarrayFrom] = from;
store[eid][$subarrayTo] = to;
store[eid][$queryShadow] = metadata[$storeSubarrays][type][$queryShadow].subarray(from, to);

@@ -173,4 +188,4 @@ store[eid][$serializeShadow] = metadata[$storeSubarrays][type][$serializeShadow].subarray(from, to);

metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
createShadow(metadata[$storeSubarrays][type], $queryShadow);
createShadow(metadata[$storeSubarrays][type], $serializeShadow);
array[$indexType] = TYPES_NAMES[indexType];

@@ -188,4 +203,4 @@ array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

store[eid] = metadata[$storeSubarrays][type].subarray(from, to);
store[eid].from = from;
store[eid].to = to;
store[eid][$subarrayFrom] = from;
store[eid][$subarrayTo] = to;
store[eid][$queryShadow] = metadata[$storeSubarrays][type][$queryShadow].subarray(from, to);

@@ -204,7 +219,2 @@ store[eid][$serializeShadow] = metadata[$storeSubarrays][type][$serializeShadow].subarray(from, to);

const createShadows = store => {
store[$queryShadow] = store.slice(0);
store[$serializeShadow] = store.slice(0);
};
const isArrayType = x => Array.isArray(x) && typeof x[0] === 'string' && typeof x[1] === 'number';

@@ -259,3 +269,4 @@

a[k] = createTypeStore(a[k], size);
createShadows(a[k]);
createShadow(a[k], $queryShadow);
createShadow(a[k], $serializeShadow);

@@ -292,2 +303,4 @@ a[k][$storeBase] = () => stores[$store];

dense.count = () => dense.length;
const has = val => dense[sparse[val]] === val;

@@ -327,9 +340,13 @@

let componentProps = [];
let changedProps = new Set();
let changedProps = new Map();
if (Array.isArray(target)) {
componentProps = target.map(p => {
if (!p) throw new Error('๐Ÿ‘พ bitECS - undefined component passed into serializer.');
if (typeof p === 'function' && p.name === 'QueryChanged') {
p()[$storeFlattened].forEach(prop => {
changedProps.add(prop);
const $ = Symbol();
createShadow(prop, $);
changedProps.set(prop, $);
});

@@ -385,3 +402,3 @@ return p()[$storeFlattened];

const prop = componentProps[pid];
const diff = changedProps.has(prop); // write pid
const diff = changedProps.get(prop); // write pid

@@ -401,5 +418,6 @@ view.setUint8(where, pid);

} // skip if diffing and no change
// TODO: check array diff
if (diff && prop[eid] === prop[$serializeShadow][eid]) {
if (diff && prop[eid] === prop[diff][eid]) {
continue;

@@ -544,3 +562,2 @@ }

const $entityMasks = Symbol('entityMasks');
const $entityEnabled = Symbol('entityEnabled');
const $entitySparseSet = Symbol('entitySparseSet');

@@ -596,11 +613,12 @@ const $entityArray = Symbol('entityArray');

// TODO: archetype graph
// world[$queries].forEach(q => {
// queryRemoveEntity(world, q, eid)
// })
// Free the entity
world[$queries].forEach(q => {
queryRemoveEntity(world, q, eid);
}); // Free the entity
removed.push(eid); // pop swap
world[$entitySparseSet].remove(eid); // Clear entity bitmasks
// for (let i = 0; i < world[$entityMasks].length; i++) world[$entityMasks][i][eid] = 0
for (let i = 0; i < world[$entityMasks].length; i++) world[$entityMasks][i][eid] = 0;
};

@@ -637,14 +655,16 @@

query[$queryComponents].forEach(c => {
if (!world[$componentMap].has(c)) registerComponent(world, c);
if (typeof c === 'function') {
const comp = c();
if (!world[$componentMap].has(comp)) registerComponent(world, comp);
if (typeof c === 'function') {
if (c.name === 'QueryNot') {
notComponents.push(c());
notComponents.push(comp);
}
if (c.name === 'QueryChanged') {
changedComponents.push(c());
components.push(c());
changedComponents.push(comp);
components.push(comp);
}
} else {
if (!world[$componentMap].has(c)) registerComponent(world, c);
components.push(c);

@@ -654,4 +674,5 @@ }

const mapComponents = c => world[$componentMap].get(c);
const mapComponents = c => world[$componentMap].get(c); // const sparseSet = Uint32SparseSet(getGlobalSize())
const sparseSet = SparseSet();

@@ -669,3 +690,3 @@ const archetypes = [];

const reduceBitmasks = (a, c) => {
const reduceBitflags = (a, c) => {
if (!a[c.generationId]) a[c.generationId] = 0;

@@ -676,3 +697,3 @@ a[c.generationId] |= c.bitflag;

const masks = components.map(mapComponents).reduce(reduceBitmasks, {});
const masks = components.map(mapComponents).reduce(reduceBitflags, {});
const notMasks = notComponents.map(mapComponents).reduce((a, c) => {

@@ -690,2 +711,7 @@ if (!a[c.generationId]) {

const flatProps = components.filter(c => !c[$tagStore]).map(c => Object.getOwnPropertySymbols(c).includes($storeFlattened) ? c[$storeFlattened] : [c]).reduce((a, v) => a.concat(v), []);
const shadows = flatProps.map(prop => {
const $ = Symbol();
createShadow(prop, $);
return prop[$];
}, []);
const q = Object.assign(sparseSet, {

@@ -704,3 +730,4 @@ archetypes,

entered,
exited
exited,
shadows
});

@@ -714,3 +741,3 @@ world[$queryMap].set(query, q);

if (queryCheckEntity(world, q, eid)) {
queryAddEntity(world, q, eid);
queryAddEntity(q, eid);
}

@@ -722,10 +749,14 @@ }

if (clearDiff) q.changed.length = 0;
const flat = q.flatProps;
const {
flatProps,
shadows
} = q;
for (let i = 0; i < q.dense.length; i++) {
for (let i = 0; i < q.dense.count(); i++) {
const eid = q.dense[i];
let dirty = false;
for (let pid = 0; pid < flat.length; pid++) {
const prop = flat[pid];
for (let pid = 0; pid < flatProps.length; pid++) {
const prop = flatProps[pid];
const shadow = shadows[pid];

@@ -740,5 +771,5 @@ if (ArrayBuffer.isView(prop[eid])) {

} else {
if (prop[eid] !== prop[$queryShadow][eid]) {
if (prop[eid] !== shadow[eid]) {
dirty = true;
prop[$queryShadow][eid] = prop[eid];
shadow[eid] = prop[eid];
}

@@ -762,3 +793,3 @@ }

const q = world[$queryMap].get(query);
queryCommitRemovals(world, q);
queryCommitRemovals(q);
if (q.changedComponents.length) return diff(q, clearDiff);

@@ -811,3 +842,3 @@ return q.dense;

};
const queryAddEntity = (world, q, eid) => {
const queryAddEntity = (q, eid) => {
if (q.has(eid)) return;

@@ -818,18 +849,14 @@ q.add(eid);

const queryCommitRemovals = (world, q) => {
const queryCommitRemovals = q => {
while (q.toRemove.length) {
q.remove(q.toRemove.pop());
}
world[$dirtyQueries].delete(q);
};
const commitRemovals = world => {
world[$dirtyQueries].forEach(q => {
queryCommitRemovals(world, q);
});
world[$dirtyQueries].forEach(queryCommitRemovals);
world[$dirtyQueries].clear();
};
const queryRemoveEntity = (world, q, eid) => {
if (!q.has(eid)) return;
q.remove(eid);
q.toRemove.push(eid);

@@ -868,2 +895,3 @@ world[$dirtyQueries].add(q);

const registerComponent = (world, component) => {
if (!component) throw new Error(`๐Ÿ‘พ bitECS - cannot register component as it is null or undefined.`);
world[$componentMap].set(component, {

@@ -913,3 +941,3 @@ generationId: world[$entityMasks].length - 1,

const match = queryCheckEntity(world, q, eid);
if (match) queryAddEntity(world, q, eid);
if (match) queryAddEntity(q, eid);
}); // Zero out each property value

@@ -946,6 +974,8 @@

const $bitflag = Symbol('bitflag');
const $archetypes = Symbol('archetypes');
const worlds = [];
const resizeWorlds = size => {
worlds.forEach(world => {
world[$size] = size;
world[$size] = size; // resize(world[$entitySparseSet].sparse, size)
// resize(world[$entitySparseSet].dense, size)

@@ -970,4 +1000,6 @@ for (let i = 0; i < world[$entityMasks].length; i++) {

world[$entityMasks] = [new Uint32Array(size)];
world[$archetypes] = [];
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entitySparseSet] = SparseSet();
world[$entitySparseSet] = SparseSet(); // world[$entitySparseSet] = Uint32SparseSet(size)
world[$entityArray] = world[$entitySparseSet].dense;

@@ -983,3 +1015,3 @@ world[$bitflag] = 1;

delete world[$size];
delete world[$entityEnabled];
delete world[$archetypes];
delete world[$entityMasks];

@@ -986,0 +1018,0 @@ delete world[$entityArray];

@@ -11,3 +11,4 @@ declare module 'bitecs' {

'f32' |
'f64'
'f64' |
any[]

@@ -74,3 +75,3 @@ export const Types: {

export type Query = (world: IWorld, clearDiff: Boolean = true) => number[]
export type Query = (world: IWorld, clearDiff?: Boolean) => number[]

@@ -77,0 +78,0 @@ export type System = (world: IWorld) => IWorld

{
"name": "bitecs",
"version": "0.3.10",
"version": "0.3.11",
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript",

@@ -55,3 +55,4 @@ "license": "MPL-2.0",

]
}
},
"type": "module"
}

@@ -26,7 +26,6 @@ # ๐Ÿ‘พ bitECS ๐Ÿ‘พ [![npm](https://img.shields.io/npm/v/bitecs.svg)](https://www.npmjs.com/package/bitecs) [![Minzipped](https://badgen.net/bundlephobia/minzip/bitecs)](https://www.npmjs.com/package/bitecs) [![npm](https://img.shields.io/npm/dt/bitecs.svg)](https://www.npmjs.com/package/bitecs) [![License](https://badgen.net/npm/license/bitecs)](https://www.npmjs.com/package/bitecs)

### ๐Ÿ‘ฉโ€๐Ÿ’ป In Development
| |
| ----------------- |
| ๐Ÿงฌ Archetypes |
| ๐Ÿงฉ Sparse Sets |
| ๐Ÿงต Multithreading |
| |
| ---------------- |
| ๐ŸงฌArchetypes |
|๐Ÿงต Multithreading |

@@ -33,0 +32,0 @@

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