Comparing version 0.2.16 to 0.2.18
@@ -49,2 +49,3 @@ const TYPES_ENUM = { | ||
const $storeFlattened = Symbol('storeFlattened'); | ||
const $storeBase = Symbol('storeBase'); | ||
const $storeArrayCount = Symbol('storeArrayCount'); | ||
@@ -165,2 +166,3 @@ const $storeSubarrays = Symbol('storeSubarrays'); | ||
const isArrayType = x => Array.isArray(x) && typeof x[0] === 'object' && x[0].hasOwnProperty('type') && x[0].hasOwnProperty('length'); | ||
const createStore = (schema, size = 1000000) => { | ||
@@ -199,19 +201,9 @@ const $store = Symbol('store'); | ||
if (typeof schema === 'string') { | ||
stores[$store] = Object.assign(createTypeStore(schema, size), metadata); | ||
metadata[$storeFlattened].push(stores[$store]); | ||
createShadows(stores[$store]); | ||
return stores[$store]; | ||
} else if (isArrayType(schema)) { | ||
const { | ||
type, | ||
length | ||
} = schema[0]; | ||
stores[$store] = Object.assign(createArrayStore(metadata, type, length), metadata); | ||
metadata[$storeFlattened].push(stores[$store]); | ||
return stores[$store]; | ||
} else if (schema instanceof Object && Object.keys(schema).length) { | ||
if (schema instanceof Object && Object.keys(schema).length) { | ||
const recursiveTransform = (a, k) => { | ||
if (typeof a[k] === 'string') { | ||
a[k] = createTypeStore(a[k], size); | ||
a[k][$storeBase] = () => stores[$store]; | ||
metadata[$storeFlattened].push(a[k]); | ||
@@ -225,2 +217,5 @@ createShadows(a[k]); | ||
a[k] = createArrayStore(metadata, type, length); | ||
a[k][$storeBase] = () => stores[$store]; | ||
metadata[$storeFlattened].push(a[k]); | ||
@@ -235,2 +230,5 @@ } else if (a[k] instanceof Object) { | ||
stores[$store] = Object.assign(Object.keys(schema).reduce(recursiveTransform, schema), metadata); | ||
stores[$store][$storeBase] = () => stores[$store]; | ||
return stores[$store]; | ||
@@ -434,3 +432,3 @@ } | ||
const [componentProps] = canonicalize(target); | ||
return packet => { | ||
return (world, packet) => { | ||
const view = new DataView(packet); | ||
@@ -450,5 +448,16 @@ let where = 0; | ||
for (let i = 0; i < entityCount; i++) { | ||
const eid = view.getUint32(where); | ||
where += 4; | ||
let eid = view.getUint32(where); | ||
where += 4; // if this world hasn't seen this eid yet | ||
if (!world[$entityEnabled][eid]) { | ||
// make a new entity for the data | ||
eid = addEntity(world); | ||
} | ||
const component = ta[$storeBase](); | ||
if (!hasComponent(world, component, eid)) { | ||
addComponent(world, component, eid); | ||
} | ||
if (ArrayBuffer.isView(ta[eid])) { | ||
@@ -455,0 +464,0 @@ const array = ta[eid]; |
@@ -53,2 +53,3 @@ 'use strict'; | ||
const $storeFlattened = Symbol('storeFlattened'); | ||
const $storeBase = Symbol('storeBase'); | ||
const $storeArrayCount = Symbol('storeArrayCount'); | ||
@@ -169,2 +170,3 @@ const $storeSubarrays = Symbol('storeSubarrays'); | ||
const isArrayType = x => Array.isArray(x) && typeof x[0] === 'object' && x[0].hasOwnProperty('type') && x[0].hasOwnProperty('length'); | ||
const createStore = (schema, size = 1000000) => { | ||
@@ -203,19 +205,9 @@ const $store = Symbol('store'); | ||
if (typeof schema === 'string') { | ||
stores[$store] = Object.assign(createTypeStore(schema, size), metadata); | ||
metadata[$storeFlattened].push(stores[$store]); | ||
createShadows(stores[$store]); | ||
return stores[$store]; | ||
} else if (isArrayType(schema)) { | ||
const { | ||
type, | ||
length | ||
} = schema[0]; | ||
stores[$store] = Object.assign(createArrayStore(metadata, type, length), metadata); | ||
metadata[$storeFlattened].push(stores[$store]); | ||
return stores[$store]; | ||
} else if (schema instanceof Object && Object.keys(schema).length) { | ||
if (schema instanceof Object && Object.keys(schema).length) { | ||
const recursiveTransform = (a, k) => { | ||
if (typeof a[k] === 'string') { | ||
a[k] = createTypeStore(a[k], size); | ||
a[k][$storeBase] = () => stores[$store]; | ||
metadata[$storeFlattened].push(a[k]); | ||
@@ -229,2 +221,5 @@ createShadows(a[k]); | ||
a[k] = createArrayStore(metadata, type, length); | ||
a[k][$storeBase] = () => stores[$store]; | ||
metadata[$storeFlattened].push(a[k]); | ||
@@ -239,2 +234,5 @@ } else if (a[k] instanceof Object) { | ||
stores[$store] = Object.assign(Object.keys(schema).reduce(recursiveTransform, schema), metadata); | ||
stores[$store][$storeBase] = () => stores[$store]; | ||
return stores[$store]; | ||
@@ -438,3 +436,3 @@ } | ||
const [componentProps] = canonicalize(target); | ||
return packet => { | ||
return (world, packet) => { | ||
const view = new DataView(packet); | ||
@@ -454,5 +452,16 @@ let where = 0; | ||
for (let i = 0; i < entityCount; i++) { | ||
const eid = view.getUint32(where); | ||
where += 4; | ||
let eid = view.getUint32(where); | ||
where += 4; // if this world hasn't seen this eid yet | ||
if (!world[$entityEnabled][eid]) { | ||
// make a new entity for the data | ||
eid = addEntity(world); | ||
} | ||
const component = ta[$storeBase](); | ||
if (!hasComponent(world, component, eid)) { | ||
addComponent(world, component, eid); | ||
} | ||
if (ArrayBuffer.isView(ta[eid])) { | ||
@@ -459,0 +468,0 @@ const array = ta[eid]; |
{ | ||
"name": "bitecs", | ||
"version": "0.2.16", | ||
"version": "0.2.18", | ||
"description": "Tiny, data-driven, high performance ECS library written in Javascript", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
@@ -5,20 +5,30 @@ # ๐พ bitECS ๐พ | ||
## Features | ||
๐ฎ Functional | ||
๐ค `<3kb` gzipped | ||
๐ฎ Simple & functional API | ||
๐ โโ๏ธ Zero dependencies | ||
๐ฅ Blazing fast iteration | ||
๐พ Serialization | ||
๐ Powerful & performant queries | ||
โจ Queries with modifiers | ||
๐พ Swift serialization | ||
๐ Zero dependencies | ||
๐ Node or browser | ||
๐ฅ Blazing fast | ||
๐ค `~5kb` gzipped | ||
- [ecs-benchmark](https://github.com/noctjs/ecs-benchmark) | ||
- [js-ecs-benchmark](https://github.com/ddmills/js-ecs-benchmark) | ||
๐ Unparalleled performance | ||
- [noctjs/ecs-benchmark](https://github.com/noctjs/ecs-benchmark) | ||
- [ddmills/js-ecs-benchmarks](https://github.com/ddmills/js-ecs-benchmarks) | ||
### In Development | ||
๐งต Multithreading | ||
## Install | ||
@@ -29,2 +39,3 @@ ``` | ||
## Example | ||
@@ -72,2 +83,4 @@ | ||
// can store whatever you need on the world | ||
world.metadata = 123 | ||
@@ -140,3 +153,3 @@ /** | ||
/** | ||
* Entity | ||
* addEntity | ||
* | ||
@@ -202,7 +215,8 @@ * An entity is a single ID which components can be associated with. | ||
// deserializes the state back onto the world | ||
// note: creates entities/components if they do not exist | ||
deserialize(world, packet) | ||
// creates a serializer/deserializer which will serialize select component stores | ||
const serializePositions = createSerializer([Positions]) | ||
const deserializePositions = createDeserializer([Positions]) | ||
const serializePositions = createSerializer([Position]) | ||
const deserializePositions = createDeserializer([Position]) | ||
@@ -213,7 +227,7 @@ // serializes the Position data of entities which match the movementQuery | ||
// deserializes the Position data back onto the world | ||
deserializePositions(packet) | ||
deserializePositions(world, packet) | ||
// creates a serializer which will serialize select component stores of entities | ||
// whose component state has changed since the last call of the function | ||
const serializeOnlyChangedPositions = createSerializer([Changed(Positions)]) | ||
const serializeOnlyChangedPositions = createSerializer([Changed(Position)]) | ||
@@ -225,3 +239,1 @@ // serializes the Position data of entities which match the movementQuery | ||
``` | ||
Full documentation and feature rich examples can be found [here](DOCS.md). |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
233
1
0
216041
8
1362