Comparing version 0.2.18 to 0.2.19
{ | ||
"name": "bitecs", | ||
"version": "0.2.18", | ||
"version": "0.2.19", | ||
"description": "Tiny, data-driven, high performance ECS library written in Javascript", | ||
@@ -38,4 +38,3 @@ "license": "MPL-2.0", | ||
"jsdoc-to-markdown": "^6.0.1", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-terser": "^7.0.2" | ||
"rollup": "^2.32.1" | ||
}, | ||
@@ -42,0 +41,0 @@ "babel": { |
# 👾 bitECS 👾 | ||
Functional, tiny, data-oriented, high performance [ECS](https://en.wikipedia.org/wiki/Entity_component_system) library written using JavaScript TypedArrays. | ||
Functional, small, data-oriented, high performance [ECS](https://en.wikipedia.org/wiki/Entity_component_system) library written using JavaScript TypedArrays. | ||
@@ -77,8 +77,8 @@ | ||
// returns an empty object which can be used to store miscellaneous state about the world | ||
// creating worlds returns empty objects | ||
const world = createWorld() | ||
const world2 = createWorld() | ||
// can store whatever you need on the world | ||
world.metadata = 123 | ||
// store whatever you need on the world object | ||
world.time = { delta: 0, elapsed: 0 } | ||
@@ -117,2 +117,6 @@ /** | ||
// wrapping a component with the Not modifier creates a query which | ||
// returns entities who explicitly do not have the component | ||
const positionWithoutVelocityQuery = defineQuery([ Position, Not(Velocity) ]) | ||
// wrapping a component with the Change modifier creates a query which | ||
@@ -122,6 +126,2 @@ // returns entities whose component's state has changed since last call of the function | ||
// wrapping a component with the Not modifier creates a query which | ||
// returns entities who explicitly do not have the component | ||
const notVelocityQuery = defineQuery([ Position, Not(Velocity) ]) | ||
// enter-query hook, called when an entity's components matches the query | ||
@@ -141,3 +141,3 @@ enterQuery(world, movementQuery, eid => {}) | ||
// define a system | ||
// movement system | ||
const movementSystem = defineSystem(world => { | ||
@@ -152,3 +152,13 @@ const ents = movementQuery(world) | ||
// delta time system | ||
let then = performance.now() | ||
const timeSystem = defineSystem(world => { | ||
const now = performance.now() | ||
const delta = now - then | ||
world.time.delta = delta | ||
world.time.elapsed += delta | ||
then = now | ||
}) | ||
/** | ||
@@ -189,4 +199,3 @@ * addEntity | ||
movementSystem, | ||
movementSystem, | ||
movementSystem, | ||
timeSystem, | ||
) | ||
@@ -199,6 +208,9 @@ | ||
movementSystem(world) // executes movement system on world | ||
pipeline(world) // executes a pipeline of systems on world | ||
// execute movement system on world | ||
movementSystem(world) | ||
// executes a pipeline of systems on world | ||
pipeline(world) | ||
/** | ||
@@ -218,3 +230,3 @@ * createSerializer / Deserializer | ||
// deserializes the state back onto the world | ||
// note: creates entities/components if they do not exist | ||
// note: creates entities and adds components if they do not exist | ||
deserialize(world, packet) | ||
@@ -221,0 +233,0 @@ |
216211
7
245