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.4 to 0.3.5

39

dist/index.d.ts

@@ -71,3 +71,3 @@ declare module 'bitecs' {

type QueryModifier = (c: (IComponent | IComponentProp)[]) => (world: IWorld) => IComponent | IComponentProp
type QueryModifier = (c: (IComponent | IComponentProp)[]) => (world: IWorld) => IComponent | QueryModifier

@@ -78,22 +78,21 @@ type Query = (world: IWorld) => number[]

export function createWorld (size?: number): IWorld
export function addEntity (world: IWorld): number
export function removeEntity (world: IWorld, eid: number): void
export function registerComponent (world: IWorld, component: IComponent): void
export function registerComponents (world: IWorld, components: IComponent[]): void
export function defineComponent <T extends ISchema>(schema: T): ComponentType<T>
export function addComponent (world: IWorld, component: IComponent, eid: number): void
export function removeComponent (world: IWorld, component: IComponent, eid: number): void
export function hasComponent (world: IWorld, component: IComponent, eid: number): boolean
export function defineQuery (components: (IComponent | QueryModifier)[]): Query
export function Changed (c: (IComponent | IComponentProp)[]): (world: IWorld) => IComponent | IComponentProp
export function Not (c: (IComponent | IComponentProp)[]): (world: IWorld) => IComponent | IComponentProp
export function enterQuery (query: Query): Query
export function exitQuery (query: Query): Query
export function commitRemovals (world: IWorld): void
export function defineSystem (update: (world: IWorld) => void): System
export function defineSerializer (target: IWorld | IComponent | IComponentProp | QueryModifier, maxBytes?: number): (target: IWorld | number[]) => ArrayBuffer
export function defineDeserializer (target: IWorld | IComponent | IComponentProp | QueryModifier): (world: IWorld, packet: ArrayBuffer) => void
export function createWorld(size?: number): IWorld
export function addEntity(world: IWorld): number
export function removeEntity(world: IWorld, eid: number): void
export function registerComponent(world: IWorld, component: IComponent): void
export function registerComponents(world: IWorld, components: IComponent[]): void
export function defineComponent<T extends ISchema>(schema?: T): ComponentType<T>
export function addComponent(world: IWorld, component: IComponent, eid: number): void
export function removeComponent(world: IWorld, component: IComponent, eid: number): void
export function hasComponent(world: IWorld, component: IComponent, eid: number): boolean
export function defineQuery(components: (ComponentType<ISchema> | IComponent | QueryModifier)[]): Query
export function Changed(c: ComponentType<ISchema>): IComponent | QueryModifier
export function Not(c: ComponentType<ISchema>): IComponent | QueryModifier
export function enterQuery(query: Query): Query
export function exitQuery(query: Query): Query
export function commitRemovals(world: IWorld): void
export function defineSystem(update: (world: IWorld) => void): System
export function defineSerializer(target: IWorld | IComponent | IComponentProp | QueryModifier, maxBytes?: number): (target: IWorld | number[]) => ArrayBuffer
export function defineDeserializer(target: IWorld | IComponent | IComponentProp | QueryModifier): (world: IWorld, packet: ArrayBuffer) => void
export function pipe(...fns: ((...args: any[]) => any)[]): (input: any) => any
}

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

const TYPES_ENUM = {
const TYPE_ENUM = {
i8: 'i8',

@@ -12,3 +12,3 @@ ui8: 'ui8',

};
const TYPES_NAMES = {
const TYPE_NAME = {
i8: 'Int8',

@@ -41,2 +41,4 @@ ui8: 'Uint8',

const roundToMultiple4 = x => Math.ceil(x / 4) * 4;
const $storeRef = Symbol('storeRef');

@@ -60,3 +62,3 @@ const $storeSize = Symbol('storeSize');

const resize = (ta, size) => {
const newBuffer = new ArrayBuffer(size * ta.BYTES_PER_ELEMENT);
const newBuffer = new SharedArrayBuffer(size * ta.BYTES_PER_ELEMENT);
const newTa = new ta.constructor(newBuffer);

@@ -74,7 +76,7 @@ newTa.set(ta, 0);

const summedLength = Array(arrayCount).fill(0).reduce((a, p) => a + length, 0); // for threaded impl
// const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0)
// const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size)
// const buffer = new ArrayBuffer(totalBytes)
const array = new TYPES[type](summedLength * size);
const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0);
const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size);
const buffer = new SharedArrayBuffer(totalBytes);
const array = new TYPES[type](buffer);
array.set(metadata[$storeSubarrays][type]);

@@ -84,3 +86,3 @@ metadata[$storeSubarrays][type] = array;

metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
array[$indexType] = TYPES_NAMES[indexType];
array[$indexType] = TYPE_NAME[indexType];
array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -143,3 +145,3 @@ let end = 0;

const totalBytes = length * TYPES[type].BYTES_PER_ELEMENT;
const buffer = new ArrayBuffer(totalBytes);
const buffer = new SharedArrayBuffer(totalBytes);
return new TYPES[type](buffer);

@@ -160,11 +162,11 @@ };

const summedLength = Array(arrayCount).fill(0).reduce((a, p) => a + length, 0); // for threaded impl
// const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0)
// const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size)
// const buffer = new ArrayBuffer(totalBytes)
const array = new TYPES[type](summedLength * size);
const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0);
const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size);
const buffer = new SharedArrayBuffer(totalBytes);
const array = new TYPES[type](buffer);
metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
array[$indexType] = TYPES_NAMES[indexType];
array[$indexType] = TYPE_NAME[indexType];
array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -185,3 +187,3 @@ } // pre-generate subarrays for each eid

store[eid][$subarray] = true;
store[eid][$indexType] = TYPES_NAMES[indexType];
store[eid][$indexType] = TYPE_NAME[indexType];
store[eid][$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -260,5 +262,7 @@ end = to;

metadata[$storeFlattened].push(a[k]); // Object.freeze(a[k])
metadata[$storeFlattened].push(a[k]);
Object.seal(a[k]);
} else if (a[k] instanceof Object) {
a[k] = Object.keys(a[k]).reduce(recursiveTransform, a[k]); // Object.freeze(a[k])
a[k] = Object.keys(a[k]).reduce(recursiveTransform, a[k]);
Object.seal(a[k]);
}

@@ -271,5 +275,5 @@

stores[$store][$storeBase] = () => stores[$store]; // Object.freeze(stores[$store])
stores[$store][$storeBase] = () => stores[$store];
Object.seal(stores[$store]);
return stores[$store];

@@ -315,3 +319,4 @@ }

const buffer = new ArrayBuffer(maxBytes);
const view = new DataView(buffer);
const view = new DataView(buffer); // const write = defineWriter(view, componentProps, changedProps)
return ents => {

@@ -326,3 +331,3 @@ if (resized) {

target[$componentMap].forEach((c, component) => {
componentProps.push(...component[$storeFlattened]);
if (component[$storeFlattened]) componentProps.push(...component[$storeFlattened]);else componentProps.push(component);
});

@@ -340,3 +345,16 @@ }

if (!ents.length) return;
if (!ents.length) return; // view.where = 0
// // save space for entity count
// const countWhere = where
// view.where += 4
// // write eid,val,val,val..., eid,val,val...
// for (let i = 0; i < ents.length; i++) {
// const eid = ents[i]
// write(world, eid)
// }
// // view.setUint32(countWhere, count)
// const end = view.where
// view.where = 0
// return buffer.slice(0, end)
let where = 0; // iterate over component props

@@ -433,3 +451,3 @@

target[$componentMap].forEach((c, component) => {
componentProps.push(...component[$storeFlattened]);
if (component[$storeFlattened]) componentProps.push(...component[$storeFlattened]);else componentProps.push(component);
});

@@ -803,9 +821,9 @@ }

const $componentMap = Symbol('componentMap');
const components = [];
const storeComponents = [];
const resizeComponents = size => {
components.forEach(component => resizeStore(component, size));
storeComponents.forEach(component => resizeStore(component, size));
};
const defineComponent = schema => {
const component = createStore(schema, defaultSize);
if (schema && Object.keys(schema).length) components.push(component);
if (schema && Object.keys(schema).length) storeComponents.push(component);
return component;

@@ -962,5 +980,5 @@ };

};
const Types = TYPES_ENUM;
const Types = TYPE_ENUM;
export { Changed, Not, Types, addComponent, addEntity, commitRemovals, createWorld, defineComponent, defineDeserializer, defineQuery, defineSerializer, defineSystem, enterQuery, exitQuery, hasComponent, pipe, registerComponent, registerComponents, removeComponent, removeEntity };
//# sourceMappingURL=index.es.js.map

@@ -5,3 +5,3 @@ 'use strict';

const TYPES_ENUM = {
const TYPE_ENUM = {
i8: 'i8',

@@ -17,3 +17,3 @@ ui8: 'ui8',

};
const TYPES_NAMES = {
const TYPE_NAME = {
i8: 'Int8',

@@ -46,2 +46,4 @@ ui8: 'Uint8',

const roundToMultiple4 = x => Math.ceil(x / 4) * 4;
const $storeRef = Symbol('storeRef');

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

const resize = (ta, size) => {
const newBuffer = new ArrayBuffer(size * ta.BYTES_PER_ELEMENT);
const newBuffer = new SharedArrayBuffer(size * ta.BYTES_PER_ELEMENT);
const newTa = new ta.constructor(newBuffer);

@@ -79,7 +81,7 @@ newTa.set(ta, 0);

const summedLength = Array(arrayCount).fill(0).reduce((a, p) => a + length, 0); // for threaded impl
// const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0)
// const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size)
// const buffer = new ArrayBuffer(totalBytes)
const array = new TYPES[type](summedLength * size);
const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0);
const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size);
const buffer = new SharedArrayBuffer(totalBytes);
const array = new TYPES[type](buffer);
array.set(metadata[$storeSubarrays][type]);

@@ -89,3 +91,3 @@ metadata[$storeSubarrays][type] = array;

metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
array[$indexType] = TYPES_NAMES[indexType];
array[$indexType] = TYPE_NAME[indexType];
array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -148,3 +150,3 @@ let end = 0;

const totalBytes = length * TYPES[type].BYTES_PER_ELEMENT;
const buffer = new ArrayBuffer(totalBytes);
const buffer = new SharedArrayBuffer(totalBytes);
return new TYPES[type](buffer);

@@ -165,11 +167,11 @@ };

const summedLength = Array(arrayCount).fill(0).reduce((a, p) => a + length, 0); // for threaded impl
// const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0)
// const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size)
// const buffer = new ArrayBuffer(totalBytes)
const array = new TYPES[type](summedLength * size);
const summedBytesPerElement = Array(arrayCount).fill(0).reduce((a, p) => a + TYPES[type].BYTES_PER_ELEMENT, 0);
const totalBytes = roundToMultiple4(summedBytesPerElement * summedLength * size);
const buffer = new SharedArrayBuffer(totalBytes);
const array = new TYPES[type](buffer);
metadata[$storeSubarrays][type] = array;
metadata[$storeSubarrays][type][$queryShadow] = array.slice(0);
metadata[$storeSubarrays][type][$serializeShadow] = array.slice(0);
array[$indexType] = TYPES_NAMES[indexType];
array[$indexType] = TYPE_NAME[indexType];
array[$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -190,3 +192,3 @@ } // pre-generate subarrays for each eid

store[eid][$subarray] = true;
store[eid][$indexType] = TYPES_NAMES[indexType];
store[eid][$indexType] = TYPE_NAME[indexType];
store[eid][$indexBytes] = TYPES[indexType].BYTES_PER_ELEMENT;

@@ -265,5 +267,7 @@ end = to;

metadata[$storeFlattened].push(a[k]); // Object.freeze(a[k])
metadata[$storeFlattened].push(a[k]);
Object.seal(a[k]);
} else if (a[k] instanceof Object) {
a[k] = Object.keys(a[k]).reduce(recursiveTransform, a[k]); // Object.freeze(a[k])
a[k] = Object.keys(a[k]).reduce(recursiveTransform, a[k]);
Object.seal(a[k]);
}

@@ -276,5 +280,5 @@

stores[$store][$storeBase] = () => stores[$store]; // Object.freeze(stores[$store])
stores[$store][$storeBase] = () => stores[$store];
Object.seal(stores[$store]);
return stores[$store];

@@ -320,3 +324,4 @@ }

const buffer = new ArrayBuffer(maxBytes);
const view = new DataView(buffer);
const view = new DataView(buffer); // const write = defineWriter(view, componentProps, changedProps)
return ents => {

@@ -331,3 +336,3 @@ if (resized) {

target[$componentMap].forEach((c, component) => {
componentProps.push(...component[$storeFlattened]);
if (component[$storeFlattened]) componentProps.push(...component[$storeFlattened]);else componentProps.push(component);
});

@@ -345,3 +350,16 @@ }

if (!ents.length) return;
if (!ents.length) return; // view.where = 0
// // save space for entity count
// const countWhere = where
// view.where += 4
// // write eid,val,val,val..., eid,val,val...
// for (let i = 0; i < ents.length; i++) {
// const eid = ents[i]
// write(world, eid)
// }
// // view.setUint32(countWhere, count)
// const end = view.where
// view.where = 0
// return buffer.slice(0, end)
let where = 0; // iterate over component props

@@ -438,3 +456,3 @@

target[$componentMap].forEach((c, component) => {
componentProps.push(...component[$storeFlattened]);
if (component[$storeFlattened]) componentProps.push(...component[$storeFlattened]);else componentProps.push(component);
});

@@ -808,9 +826,9 @@ }

const $componentMap = Symbol('componentMap');
const components = [];
const storeComponents = [];
const resizeComponents = size => {
components.forEach(component => resizeStore(component, size));
storeComponents.forEach(component => resizeStore(component, size));
};
const defineComponent = schema => {
const component = createStore(schema, defaultSize);
if (schema && Object.keys(schema).length) components.push(component);
if (schema && Object.keys(schema).length) storeComponents.push(component);
return component;

@@ -967,3 +985,3 @@ };

};
const Types = TYPES_ENUM;
const Types = TYPE_ENUM;

@@ -970,0 +988,0 @@ exports.Changed = Changed;

@@ -71,3 +71,3 @@ declare module 'bitecs' {

type QueryModifier = (c: (IComponent | IComponentProp)[]) => (world: IWorld) => IComponent | IComponentProp
type QueryModifier = (c: (IComponent | IComponentProp)[]) => (world: IWorld) => IComponent | QueryModifier

@@ -78,22 +78,21 @@ type Query = (world: IWorld) => number[]

export function createWorld (size?: number): IWorld
export function addEntity (world: IWorld): number
export function removeEntity (world: IWorld, eid: number): void
export function registerComponent (world: IWorld, component: IComponent): void
export function registerComponents (world: IWorld, components: IComponent[]): void
export function defineComponent <T extends ISchema>(schema: T): ComponentType<T>
export function addComponent (world: IWorld, component: IComponent, eid: number): void
export function removeComponent (world: IWorld, component: IComponent, eid: number): void
export function hasComponent (world: IWorld, component: IComponent, eid: number): boolean
export function defineQuery (components: (IComponent | QueryModifier)[]): Query
export function Changed (c: (IComponent | IComponentProp)[]): (world: IWorld) => IComponent | IComponentProp
export function Not (c: (IComponent | IComponentProp)[]): (world: IWorld) => IComponent | IComponentProp
export function enterQuery (query: Query): Query
export function exitQuery (query: Query): Query
export function commitRemovals (world: IWorld): void
export function defineSystem (update: (world: IWorld) => void): System
export function defineSerializer (target: IWorld | IComponent | IComponentProp | QueryModifier, maxBytes?: number): (target: IWorld | number[]) => ArrayBuffer
export function defineDeserializer (target: IWorld | IComponent | IComponentProp | QueryModifier): (world: IWorld, packet: ArrayBuffer) => void
export function createWorld(size?: number): IWorld
export function addEntity(world: IWorld): number
export function removeEntity(world: IWorld, eid: number): void
export function registerComponent(world: IWorld, component: IComponent): void
export function registerComponents(world: IWorld, components: IComponent[]): void
export function defineComponent<T extends ISchema>(schema?: T): ComponentType<T>
export function addComponent(world: IWorld, component: IComponent, eid: number): void
export function removeComponent(world: IWorld, component: IComponent, eid: number): void
export function hasComponent(world: IWorld, component: IComponent, eid: number): boolean
export function defineQuery(components: (ComponentType<ISchema> | IComponent | QueryModifier)[]): Query
export function Changed(c: ComponentType<ISchema>): IComponent | QueryModifier
export function Not(c: ComponentType<ISchema>): IComponent | QueryModifier
export function enterQuery(query: Query): Query
export function exitQuery(query: Query): Query
export function commitRemovals(world: IWorld): void
export function defineSystem(update: (world: IWorld) => void): System
export function defineSerializer(target: IWorld | IComponent | IComponentProp | QueryModifier, maxBytes?: number): (target: IWorld | number[]) => ArrayBuffer
export function defineDeserializer(target: IWorld | IComponent | IComponentProp | QueryModifier): (world: IWorld, packet: ArrayBuffer) => void
export function pipe(...fns: ((...args: any[]) => any)[]): (input: any) => any
}
{
"name": "bitecs",
"version": "0.3.4",
"version": "0.3.5",
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript",

@@ -5,0 +5,0 @@ "license": "MPL-2.0",

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

# ๐Ÿ‘พ bitECS ๐Ÿ‘พ
# ๐Ÿ‘พ 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)

@@ -3,0 +3,0 @@ Functional, minimal, data-oriented, ultra-high performance [ECS](https://en.wikipedia.org/wiki/Entity_component_system) library written using JavaScript TypedArrays.

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