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.16-3-alpha to 0.3.16-3-alpha1

3

dist/index.es.js

@@ -362,3 +362,3 @@ const TYPES_ENUM = {

* @param {number} [maxBytes=20000000]
* @returns {ArrayBuffer}
* @returns {function} serializer
*/

@@ -492,2 +492,3 @@

* @param {object|array} target
* @returns {function} deserializer
*/

@@ -494,0 +495,0 @@

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

* @param {number} [maxBytes=20000000]
* @returns {ArrayBuffer}
* @returns {function} serializer
*/

@@ -496,2 +496,3 @@

* @param {object|array} target
* @returns {function} deserializer
*/

@@ -498,0 +499,0 @@

@@ -49,6 +49,6 @@ ## Constants

</dd>
<dt><a href="#defineSerializer">defineSerializer</a> ⇒ <code>ArrayBuffer</code></dt>
<dt><a href="#defineSerializer">defineSerializer</a> ⇒ <code>function</code></dt>
<dd><p>Defines a new serializer which targets the given components to serialize the data of when called on a world or array of EIDs.</p>
</dd>
<dt><a href="#defineDeserializer">defineDeserializer</a></dt>
<dt><a href="#defineDeserializer">defineDeserializer</a> ⇒ <code>function</code></dt>
<dd><p>Defines a new deserializer which targets the given components to deserialize onto a given world.</p>

@@ -256,5 +256,6 @@ </dd>

## defineSerializer ⇒ <code>ArrayBuffer</code>
## defineSerializer ⇒ <code>function</code>
> Defines a new serializer which targets the given components to serialize the data of when called on a world or array of EIDs.
**Returns**: <code>function</code> - serializer

@@ -269,5 +270,6 @@ | Param | Type | Default |

## defineDeserializer
## defineDeserializer ⇒ <code>function</code>
> Defines a new deserializer which targets the given components to deserialize onto a given world.
**Returns**: <code>function</code> - deserializer

@@ -274,0 +276,0 @@ | Param | Type |

@@ -128,2 +128,45 @@

## ♟ Component Proxy
Component proxies are a way to interact with component data using regular objects while maintaining high performance iteration. Not to be confused with ES6 `Proxy`, but the behavior is basically identical with much higher performance.
This enables cleaner syntax, component references, and enhanced interoperability with other libraries.
Proxy instances need to be reused in order to maintain high performance iteration.
```js
class Vector2Proxy {
constructor(store, eid) {
this.eid = eid
this.store = store
}
get x () { return this.store.x[this.eid] }
set x (val) { this.store.x[this.eid] = val }
get y () { return this.store.y[this.eid] }
set y (val) { this.store.y[this.eid] = val }
}
class PositionProxy extends Vector2Proxy {
constructor(eid) { super(Position, eid) }
}
class VelocityProxy extends Vector2Proxy {
constructor(eid) { super(Velocity, eid) }
}
const position = new PositionProxy(eid)
const velocity = new VelocityProxy(eid)
position.x = 123
console.log(Position.x[eid]) // => 123
// to set data for another entity, reuse the proxy by setting the eid property:
position.eid = eid2
position.x = 456
console.log(Position.x[eid2]) // => 456
```
## 🔍 Query

@@ -148,3 +191,3 @@

Wrapping a component with the `Change` modifier creates a query which returns entities whose component's state has changed since last call of the function:
Wrapping a component with the `Change` modifier creates a query which returns entities who are marked as changed since last call of the function:
```js

@@ -158,2 +201,5 @@ const changedPositionQuery = defineQuery([ Changed(Position) ])

// mark component as changed for this entity
entityChanged(world, Position, eid)
ents = changedPositionQuery(world)

@@ -199,10 +245,12 @@ console.log(ents) // => [0]

const eid = ents[i]
Position.x[eid] += Velocity.x[eid]
Position.y[eid] += Velocity.y[eid]
// or reuse component proxies by resetting the eid for each proxy
position.eid = velocity.eid = eid
// or with proxies:
const positionProxy = PositionProxies[eid]
const velocityProxy = VelocityProxies[eid]
positionProxy.x += velocityProxy.x
positionProxy.y += velocityProxy.y
// proxies will persist data for the current eid based on the defined getters/setters
position.x += velocity.x
position.y += velocity.y
}

@@ -250,44 +298,2 @@

## ♟ Component Proxy
Component proxies are a way to interact with component data using regular objects (not to be confused with ES6 `Proxy`, but the behavior is basically identical).
This allows cleaner syntax, references, and enhanced interoperability with other libraries.
⚠ Comes at the cost of performance and extra boilerplate. Try not to use these for hot paths.
```js
class PositionProxy {
constructor(eid) { this.eid = eid }
get x () { return Position.x[this.eid] }
set x (val) { Position.x[this.eid] = val }
get y () { return Position.y[this.eid] }
set y (val) { Position.y[this.eid] = val }
}
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]
// set eid on proxies
position.eid = velocity.eid = eid
// proxies persist data for the respective eid
position.x += velocity.x
position.y += velocity.y
}
})
```
## 💾 Serialization

@@ -294,0 +300,0 @@

{
"name": "bitecs",
"version": "0.3.16-3-alpha",
"version": "0.3.16-3-alpha1",
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript",

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

@@ -24,10 +24,2 @@ # 👾 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)

### 👩‍💻 In Development
| |
| ---------------- |
| 🧬 Archetypes |
|🧵 Multithreading |
## 🔋 Powering

@@ -37,3 +29,3 @@ | |

| Bokeh Network Engine (coming soon) |
| [Phaser 4](https://github.com/phaserjs/phaser) |
| [Phaser 4](https://github.com/phaserjs/dev) |
| [XREngine](https://github.com/XRFoundation/XREngine) |

@@ -56,3 +48,2 @@

```js
import {

@@ -91,3 +82,2 @@ createWorld,

}, 16)
```

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