Comparing version 0.3.19 to 0.3.20
@@ -205,5 +205,5 @@ | ||
Systems are functions and are run against a world to update component state of entities, or anything else. | ||
Systems are regular functions which are run against a world to update component state of entities, or anything else. | ||
Queries are used inside of systems to obtain a relevant set of entities and perform operations on their component data. | ||
Queries should be used inside of system functions to obtain a relevant set of entities and perform operations on their component data. | ||
@@ -214,3 +214,3 @@ While not required, it is greatly encouraged that you keep all component data mutations inside of systems. | ||
```js | ||
const movementSystem = defineSystem((world) => { | ||
const movementSystem = (world) => { | ||
// optionally apply logic to entities added to the query | ||
@@ -220,3 +220,3 @@ const entered = enteredMovementQuery(world) | ||
const eid = ents[i] | ||
// ... | ||
} | ||
@@ -243,5 +243,7 @@ | ||
const eid = ents[i] | ||
// ... | ||
} | ||
}) | ||
return world | ||
} | ||
``` | ||
@@ -257,9 +259,11 @@ | ||
} | ||
const timeSystem = defineSystem(world => { | ||
const timeSystem = world => { | ||
const { time } = world | ||
const now = performance.now() | ||
const delta = now - world.time.then | ||
world.time.delta = delta | ||
world.time.elapsed += delta | ||
world.time.then = now | ||
}) | ||
const delta = now - time.then | ||
time.delta = delta | ||
time.elapsed += delta | ||
time.then = now | ||
return world | ||
} | ||
``` | ||
@@ -272,3 +276,3 @@ | ||
Pipelines of systems can be composed with the `pipe` function: | ||
Pipelines of functions can be composed with the `pipe` function: | ||
```js | ||
@@ -275,0 +279,0 @@ const pipeline = pipe( |
{ | ||
"name": "bitecs", | ||
"version": "0.3.19", | ||
"version": "0.3.20", | ||
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
# 👾 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) | ||
Functional, minimal, [data-oriented](https://www.dataorienteddesign.com), ultra-high performance [ECS](https://en.wikipedia.org/wiki/Entity_component_system) library written using JavaScript TypedArrays. | ||
Functional, minimal, [data-oriented](https://www.dataorienteddesign.com/dodbook/), ultra-high performance [ECS](https://en.wikipedia.org/wiki/Entity_component_system) library written using JavaScript TypedArrays. | ||
@@ -36,2 +36,3 @@ </center> | ||
| ❔ [FAQ](https://github.com/NateTheGreatt/bitECS/blob/master/docs/FAQ.md) | | ||
| 🏛 [Tutorial](https://github.com/ourcade/phaser3-bitecs-getting-started) | | ||
@@ -48,3 +49,2 @@ ## 🕹 Example | ||
addComponent, | ||
defineSystem, | ||
pipe, | ||
@@ -59,3 +59,3 @@ } from 'bitecs' | ||
const movementSystem = defineSystem((world) => { | ||
const movementSystem = (world) => { | ||
const ents = movementQuery(world) | ||
@@ -68,5 +68,5 @@ for (let i = 0; i < ents.length; i++) { | ||
} | ||
}) | ||
} | ||
const timeSystem = defineSystem(world => { | ||
const timeSystem = world => { | ||
const { time } = world | ||
@@ -78,3 +78,3 @@ const now = performance.now() | ||
time.then = now | ||
}) | ||
} | ||
@@ -81,0 +81,0 @@ const pipeline = pipe(movementSystem, timeSystem) |
@@ -34,9 +34,9 @@ import { strictEqual } from 'assert' | ||
const eid1 = addEntity(world) | ||
const eid0 = addEntity(world) | ||
let ents = notFooQuery(world) | ||
strictEqual(ents.length, 1) | ||
strictEqual(ents[0], eid1) | ||
strictEqual(ents[0], eid0) | ||
addComponent(world, Foo, eid1) | ||
addComponent(world, Foo, eid0) | ||
@@ -46,9 +46,9 @@ ents = notFooQuery(world) | ||
const eid2 = addEntity(world) | ||
const eid1 = addEntity(world) | ||
ents = notFooQuery(world) | ||
strictEqual(ents.length, 1) | ||
strictEqual(ents[0], eid2) | ||
strictEqual(ents[0], eid1) | ||
removeEntity(world, eid2) | ||
removeEntity(world, eid1) | ||
@@ -64,4 +64,4 @@ ents = notFooQuery(world) | ||
const fooQuery = defineQuery([Foo]) | ||
const notFooQuery = defineQuery([Not(Foo)]) | ||
const fooQuery = defineQuery([Foo]) | ||
@@ -88,12 +88,11 @@ const fooBarQuery = defineQuery([Foo, Bar]) | ||
/* add components */ | ||
addComponent(world, Foo, eid0) | ||
addComponent(world, Bar, eid1) | ||
addComponent(world, Foo, eid2) | ||
addComponent(world, Bar, eid2) | ||
// now fooQuery should have eid 0 & 2 | ||
@@ -104,3 +103,3 @@ ents = fooQuery(world) | ||
strictEqual(ents[1], 2) | ||
// fooBarQuery should only have eid 2 | ||
@@ -111,3 +110,3 @@ ents = fooBarQuery(world) | ||
// notFooBarQuery should have eid 0 and 1 (inverse of fooBarQuery) | ||
// notFooBarQuery should have nothing | ||
ents = notFooBarQuery(world) | ||
@@ -114,0 +113,0 @@ strictEqual(ents.length, 0) |
@@ -1,2 +0,2 @@ | ||
import { strictEqual } from 'assert' | ||
import assert, { strictEqual } from 'assert' | ||
import { createWorld } from '../../src/World.js' | ||
@@ -8,2 +8,4 @@ import { addComponent, defineComponent } from '../../src/Component.js' | ||
const arraysEqual = (a,b) => !!a && !!b && !(a<b || b<a) | ||
describe('Serialize Integration Tests', () => { | ||
@@ -74,2 +76,35 @@ afterEach(() => { | ||
}) | ||
it('should serialize/deserialize array types on components', () => { | ||
const world1 = createWorld() | ||
const world2 = createWorld() | ||
const ArrayComponent = defineComponent({ array: [Types.f32, 4] }) | ||
const TestComponent = defineComponent({ value: Types.f32 }) | ||
const query = defineQuery([ArrayComponent, TestComponent]) | ||
const serialize = defineSerializer([ArrayComponent, TestComponent]) | ||
const deserialize = defineDeserializer([ArrayComponent, TestComponent]) | ||
const eid = addEntity(world1) | ||
addComponent(world1, TestComponent, eid) | ||
addComponent(world1, ArrayComponent, eid) | ||
TestComponent.value[eid] = 1 | ||
ArrayComponent.array[eid].set([1,2,3,4]) | ||
strictEqual(TestComponent.value[eid], 1) | ||
assert(arraysEqual(Array.from(ArrayComponent.array[eid]), [1,2,3,4])) | ||
const packet = serialize(query(world1)) | ||
strictEqual(packet.byteLength, 43) | ||
TestComponent.value[eid] = 0 | ||
ArrayComponent.array[eid].set([0,0,0,0]) | ||
deserialize(world1, packet) | ||
strictEqual(TestComponent.value[eid], 1) | ||
assert(arraysEqual(Array.from(ArrayComponent.array[eid]), [1,2,3,4])) | ||
}) | ||
it('should deserialize properly with APPEND behavior', () => { | ||
@@ -125,2 +160,5 @@ const world = createWorld() | ||
}) | ||
it('should maintain references when deserializing', () => { | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
256540
2717