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.12 to 0.3.13

27

dist/index.es.js

@@ -320,2 +320,7 @@ const TYPES_ENUM = {

const DESERIALIZE_MODE = {
REPLACE: 0,
APPEND: 1,
MAP: 2
};
let resized = false;

@@ -477,6 +482,7 @@ const setSerializationResized = v => {

const newEntities = new Map();
const localEntities = new Map();
const defineDeserializer = target => {
const isWorld = Object.getOwnPropertySymbols(target).includes($componentMap);
let [componentProps] = canonicalize(target);
return (world, packet, overwrite = true) => {
return (world, packet, mode = 0) => {
newEntities.clear();

@@ -516,7 +522,18 @@

eid = newEid;
} // if this world hasn't seen this eid yet, or if not overwriting
}
if (mode === DESERIALIZE_MODE.MAP) {
if (localEntities.has(eid)) {
eid = localEntities.get(eid);
} else if (newEntities.has(eid)) {
eid = newEntities.get(eid);
} else {
const newEid = addEntity(world);
localEntities.set(eid, newEid);
newEntities.set(eid, newEid);
eid = newEid;
}
}
if (!world[$entitySparseSet].has(eid) || !overwrite) {
// make a new entity for the data
if (mode === DESERIALIZE_MODE.APPEND || mode === DESERIALIZE_MODE.REPLACE && !world[$entitySparseSet].has(eid)) {
const newEid = addEntity(world);

@@ -980,5 +997,5 @@ newEntities.set(eid, newEid);

world[$size] = size;
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entityMasks] = [new Uint32Array(size)];
world[$archetypes] = [];
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entitySparseSet] = SparseSet(); // world[$entitySparseSet] = Uint32SparseSet(size)

@@ -985,0 +1002,0 @@

@@ -324,2 +324,7 @@ 'use strict';

const DESERIALIZE_MODE = {
REPLACE: 0,
APPEND: 1,
MAP: 2
};
let resized = false;

@@ -481,6 +486,7 @@ const setSerializationResized = v => {

const newEntities = new Map();
const localEntities = new Map();
const defineDeserializer = target => {
const isWorld = Object.getOwnPropertySymbols(target).includes($componentMap);
let [componentProps] = canonicalize(target);
return (world, packet, overwrite = true) => {
return (world, packet, mode = 0) => {
newEntities.clear();

@@ -520,7 +526,18 @@

eid = newEid;
} // if this world hasn't seen this eid yet, or if not overwriting
}
if (mode === DESERIALIZE_MODE.MAP) {
if (localEntities.has(eid)) {
eid = localEntities.get(eid);
} else if (newEntities.has(eid)) {
eid = newEntities.get(eid);
} else {
const newEid = addEntity(world);
localEntities.set(eid, newEid);
newEntities.set(eid, newEid);
eid = newEid;
}
}
if (!world[$entitySparseSet].has(eid) || !overwrite) {
// make a new entity for the data
if (mode === DESERIALIZE_MODE.APPEND || mode === DESERIALIZE_MODE.REPLACE && !world[$entitySparseSet].has(eid)) {
const newEid = addEntity(world);

@@ -984,5 +1001,5 @@ newEntities.set(eid, newEid);

world[$size] = size;
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entityMasks] = [new Uint32Array(size)];
world[$archetypes] = [];
if (world[$entityArray]) world[$entityArray].forEach(eid => removeEntity(world, eid));
world[$entitySparseSet] = SparseSet(); // world[$entitySparseSet] = Uint32SparseSet(size)

@@ -989,0 +1006,0 @@

2

package.json
{
"name": "bitecs",
"version": "0.3.12",
"version": "0.3.13",
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript",

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

@@ -6,2 +6,3 @@ import { strictEqual } from 'assert'

import { defineQuery, defineSerializer, defineDeserializer, Types } from '../../src/index.js'
import { DESERIALIZE_MODE } from '../../src/Serialize.js'

@@ -73,2 +74,52 @@ describe('Serialize Integration Tests', () => {

})
it('should deserialize properly with APPEND behavior', () => {
const world = createWorld()
const TestComponent = defineComponent({ value: Types.f32 })
const query = defineQuery([TestComponent])
const eid = addEntity(world)
addComponent(world, TestComponent, eid)
const serialize = defineSerializer([TestComponent])
const deserialize = defineDeserializer(world)
const packet = serialize(query(world))
strictEqual(packet.byteLength, 13)
strictEqual(TestComponent.value[eid], 0)
TestComponent.value[eid]++
deserialize(world, packet, DESERIALIZE_MODE.APPEND)
strictEqual(TestComponent.value[eid], 1)
strictEqual(TestComponent.value[eid+1], 0)
})
it('should deserialize properly with MAP behavior', () => {
const world = createWorld()
const TestComponent = defineComponent({ value: Types.f32 })
const query = defineQuery([TestComponent])
const eid = addEntity(world)
addComponent(world, TestComponent, eid)
const serialize = defineSerializer([TestComponent])
const deserialize = defineDeserializer(world)
let packet = serialize(query(world))
strictEqual(packet.byteLength, 13)
strictEqual(TestComponent.value[eid], 0)
TestComponent.value[eid]++
deserialize(world, packet, DESERIALIZE_MODE.MAP)
strictEqual(TestComponent.value[eid], 1)
strictEqual(TestComponent.value[eid+1], 0)
TestComponent.value[eid+1] = 1
packet = serialize(query(world))
deserialize(world, packet, DESERIALIZE_MODE.MAP)
strictEqual(TestComponent.value[eid+1], 1)
})
})

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