Comparing version 0.3.16-2 to 0.3.16-3
@@ -168,4 +168,4 @@ const TYPES_ENUM = { | ||
const indexType = length < UNSIGNED_MAX.uint8 ? 'ui8' : length < UNSIGNED_MAX.uint16 ? 'ui16' : 'ui32'; | ||
if (!length) throw new Error('โ Must define a length for component array.'); | ||
if (!TYPES[type]) throw new Error(`โ Invalid component array property type ${type}.`); // create buffer for type if it does not already exist | ||
if (!length) throw new Error('bitECS - Must define component array length'); | ||
if (!TYPES[type]) throw new Error(`bitECS - Invalid component array property type ${type}`); // create buffer for type if it does not already exist | ||
@@ -335,3 +335,3 @@ if (!metadata[$storeSubarrays][type]) { | ||
componentProps = target.map(p => { | ||
if (!p) throw new Error('๐พ bitECS - undefined component passed into serializer.'); | ||
if (!p) throw new Error('bitECS - Cannot serializer undefined component'); | ||
@@ -530,8 +530,3 @@ if (typeof p === 'function' && p.name === 'QueryChanged') { | ||
where += 4; | ||
let newEid = newEntities.get(eid); | ||
if (newEid !== undefined) { | ||
eid = newEid; | ||
} | ||
if (mode === DESERIALIZE_MODE.MAP) { | ||
@@ -551,3 +546,3 @@ if (localEntities.has(eid)) { | ||
if (mode === DESERIALIZE_MODE.APPEND || mode === DESERIALIZE_MODE.REPLACE && !world[$entitySparseSet].has(eid)) { | ||
const newEid = addEntity(world); | ||
const newEid = newEntities.get(eid) || addEntity(world); | ||
newEntities.set(eid, newEid); | ||
@@ -990,3 +985,3 @@ eid = newEid; | ||
const registerComponent = (world, component) => { | ||
if (!component) throw new Error(`๐พ bitECS - cannot register component as it is null or undefined.`); | ||
if (!component) throw new Error(`bitECS - Cannot register null or undefined component`); | ||
const queries = new Set(); | ||
@@ -993,0 +988,0 @@ const notQueries = new Set(); |
@@ -172,4 +172,4 @@ 'use strict'; | ||
const indexType = length < UNSIGNED_MAX.uint8 ? 'ui8' : length < UNSIGNED_MAX.uint16 ? 'ui16' : 'ui32'; | ||
if (!length) throw new Error('โ Must define a length for component array.'); | ||
if (!TYPES[type]) throw new Error(`โ Invalid component array property type ${type}.`); // create buffer for type if it does not already exist | ||
if (!length) throw new Error('bitECS - Must define component array length'); | ||
if (!TYPES[type]) throw new Error(`bitECS - Invalid component array property type ${type}`); // create buffer for type if it does not already exist | ||
@@ -339,3 +339,3 @@ if (!metadata[$storeSubarrays][type]) { | ||
componentProps = target.map(p => { | ||
if (!p) throw new Error('๐พ bitECS - undefined component passed into serializer.'); | ||
if (!p) throw new Error('bitECS - Cannot serializer undefined component'); | ||
@@ -534,8 +534,3 @@ if (typeof p === 'function' && p.name === 'QueryChanged') { | ||
where += 4; | ||
let newEid = newEntities.get(eid); | ||
if (newEid !== undefined) { | ||
eid = newEid; | ||
} | ||
if (mode === DESERIALIZE_MODE.MAP) { | ||
@@ -555,3 +550,3 @@ if (localEntities.has(eid)) { | ||
if (mode === DESERIALIZE_MODE.APPEND || mode === DESERIALIZE_MODE.REPLACE && !world[$entitySparseSet].has(eid)) { | ||
const newEid = addEntity(world); | ||
const newEid = newEntities.get(eid) || addEntity(world); | ||
newEntities.set(eid, newEid); | ||
@@ -994,3 +989,3 @@ eid = newEid; | ||
const registerComponent = (world, component) => { | ||
if (!component) throw new Error(`๐พ bitECS - cannot register component as it is null or undefined.`); | ||
if (!component) throw new Error(`bitECS - Cannot register null or undefined component`); | ||
const queries = new Set(); | ||
@@ -997,0 +992,0 @@ const notQueries = new Set(); |
@@ -1,1 +0,10 @@ | ||
strings | ||
# FAQ | ||
Q: How does this ECS differ from other libraries? | ||
A: Iteration performance. See benchmarks. | ||
Q: Why are there no string types for components? | ||
A: Strings are expensive and unnecessary to serialize. | ||
Q: How do I handle strings? | ||
A: Map integers to string values, and store the integers on components. This makes string serialization minimal and fast. |
@@ -50,2 +50,32 @@ | ||
``` | ||
<a name="createWorld"></a> | ||
## createWorld โ <code>object</code> | ||
> Creates a new world. | ||
<a name="resetWorld"></a> | ||
## resetWorld โ <code>object</code> | ||
> Resets a world. | ||
| Param | Type | | ||
| --- | --- | | ||
| world | <code>World</code> | | ||
<a name="deleteWorld"></a> | ||
## deleteWorld | ||
> Deletes a world. | ||
| Param | Type | | ||
| --- | --- | | ||
| world | <code>World</code> | | ||
## ๐พ Entity | ||
@@ -217,2 +247,36 @@ | ||
## ๐ญ Component Proxy | ||
Component proxies are a way to interact with component data using regular objects (not to be confused with JavaScript's `Proxy`, but the behavior is basically identical). | ||
This enables cleaner syntax and easier interop with other libraries, but comes at the cost of performance. | ||
```js | ||
const PositionProxy = defineProxy(Position) | ||
const position = new PositionProxy(eid) | ||
position.x = 123 | ||
console.log(Position.x[eid]) // => 123 | ||
``` | ||
Instances should be reused to maximize iteration performance: | ||
```js | ||
const systemA = defineSystem(world => { | ||
const ents = query(world) | ||
for (let i = 0; i < ents.length; i++) { | ||
const eid = ents[i] | ||
// load data for this eid into reused proxy instances | ||
loadProxy(position, eid) | ||
loadProxy(velocity, eid) | ||
position.x += velocity.x | ||
position.y += velocity.y | ||
} | ||
}) | ||
``` | ||
## ๐พ Serialization | ||
@@ -219,0 +283,0 @@ |
{ | ||
"name": "bitecs", | ||
"version": "0.3.16-2", | ||
"version": "0.3.16-3", | ||
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
@@ -41,1 +41,41 @@ # ๐พ 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) | ||
| ๐ [API Documentation](https://github.com/NateTheGreatt/bitECS/blob/master/docs/API.md) | | ||
## ๐น Example | ||
```js | ||
import { | ||
createWorld, | ||
addEntity, | ||
defineComponent, | ||
addComponent, | ||
defineQuery, | ||
defineSystem, | ||
Types, | ||
} from 'bitecs' | ||
const world = createWorld() | ||
const Vector3 = { x: Types.f32, y: Types.f32, z: Types.f32 } | ||
const Position = defineComponent(Vector3) | ||
const Velocity = defineComponent(Vector3) | ||
const eid = addEntity(world) | ||
addComponent(world, Position, eid) | ||
addComponent(world, Velocity, eid) | ||
const movementSystem = defineSystem((world) => { | ||
const ents = movementQuery(world) | ||
for (let i = 0; i < ents.length; i++) { | ||
const eid = ents[i] | ||
Position.x[eid] += Velocity.x[eid] | ||
Position.y[eid] += Velocity.y[eid] | ||
Position.z[eid] += Velocity.z[eid] | ||
} | ||
}) | ||
setInterval(() => { | ||
movementSystem(world) | ||
}, 16) | ||
``` |
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
320809
80
2837