Comparing version 0.3.3 to 0.3.4
@@ -129,5 +129,7 @@ const TYPES_ENUM = { | ||
const resetStoreFor = (store, eid) => { | ||
store[$storeFlattened].forEach(ta => { | ||
if (ArrayBuffer.isView(ta)) ta[eid] = 0;else ta[eid].fill(0); | ||
}); | ||
if (store[$storeFlattened]) { | ||
store[$storeFlattened].forEach(ta => { | ||
if (ArrayBuffer.isView(ta)) ta[eid] = 0;else ta[eid].fill(0); | ||
}); | ||
} | ||
}; | ||
@@ -318,4 +320,9 @@ | ||
let world; | ||
if (Object.getOwnPropertySymbols(ents).includes($componentMap)) { | ||
world = ents; | ||
ents = ents[$entityArray]; | ||
} else { | ||
world = eidToWorld.get(ents[0]); | ||
} | ||
@@ -338,4 +345,9 @@ | ||
for (let i = 0; i < ents.length; i++) { | ||
const eid = ents[i]; // skip if diffing and no change | ||
const eid = ents[i]; // skip if entity doesn't have this component | ||
if (!hasComponent(world, prop[$storeBase](), eid)) { | ||
continue; | ||
} // skip if diffing and no change | ||
if (diff && prop[eid] === prop[$serializeShadow][eid]) { | ||
@@ -417,2 +429,3 @@ continue; | ||
let where = 0; | ||
const newEntities = new Map(); | ||
@@ -425,16 +438,24 @@ while (where < packet.byteLength) { | ||
const entityCount = view.getUint32(where); | ||
where += 4; // typed array | ||
where += 4; // component property | ||
const ta = componentProps[pid]; // Get the properties and set the new state | ||
const prop = componentProps[pid]; // Get the entities and set their prop values | ||
for (let i = 0; i < entityCount; i++) { | ||
let eid = view.getUint32(where); | ||
where += 4; // if this world hasn't seen this eid yet | ||
where += 4; | ||
let newEid = newEntities.get(eid); | ||
if (newEid !== undefined) { | ||
eid = newEid; | ||
} // if this world hasn't seen this eid yet | ||
if (!world[$entityEnabled][eid]) { | ||
// make a new entity for the data | ||
eid = addEntity(world); | ||
const newEid = addEntity(world); | ||
newEntities.set(eid, newEid); | ||
eid = newEid; | ||
} | ||
const component = ta[$storeBase](); | ||
const component = prop[$storeBase](); | ||
@@ -449,4 +470,4 @@ if (!hasComponent(world, component, eid)) { | ||
if (ArrayBuffer.isView(ta[eid])) { | ||
const array = ta[eid]; | ||
if (ArrayBuffer.isView(prop[eid])) { | ||
const array = prop[eid]; | ||
const count = view[`get${array[$indexType]}`](where); | ||
@@ -460,8 +481,8 @@ where += array[$indexBytes]; // iterate over count | ||
where += array.BYTES_PER_ELEMENT; | ||
ta[eid][index] = value; | ||
prop[eid][index] = value; | ||
} | ||
} else { | ||
const value = view[`get${ta.constructor.name.replace('Array', '')}`](where); | ||
where += ta.BYTES_PER_ELEMENT; | ||
ta[eid] = value; | ||
const value = view[`get${prop.constructor.name.replace('Array', '')}`](where); | ||
where += prop.BYTES_PER_ELEMENT; | ||
prop[eid] = value; | ||
} | ||
@@ -490,7 +511,9 @@ } | ||
const getEntityCursor = () => globalEntityCursor; | ||
const eidToWorld = new Map(); | ||
const addEntity = world => { | ||
const enabled = world[$entityEnabled]; | ||
const eid = removed.length > 0 ? removed.pop() : globalEntityCursor++; | ||
const eid = removed.length > 0 ? removed.shift() : globalEntityCursor++; | ||
enabled[eid] = 1; | ||
world[$entityIndices][eid] = world[$entityArray].push(eid) - 1; // if data stores are 80% full | ||
world[$entityIndices][eid] = world[$entityArray].push(eid) - 1; | ||
eidToWorld.set(eid, world); // if data stores are 80% full | ||
@@ -835,3 +858,3 @@ if (globalEntityCursor >= resizeThreshold()) { | ||
}; | ||
const removeComponent = (world, component, eid, reset = false) => { | ||
const removeComponent = (world, component, eid, reset = true) => { | ||
const { | ||
@@ -838,0 +861,0 @@ generationId, |
@@ -133,5 +133,7 @@ 'use strict'; | ||
const resetStoreFor = (store, eid) => { | ||
store[$storeFlattened].forEach(ta => { | ||
if (ArrayBuffer.isView(ta)) ta[eid] = 0;else ta[eid].fill(0); | ||
}); | ||
if (store[$storeFlattened]) { | ||
store[$storeFlattened].forEach(ta => { | ||
if (ArrayBuffer.isView(ta)) ta[eid] = 0;else ta[eid].fill(0); | ||
}); | ||
} | ||
}; | ||
@@ -322,4 +324,9 @@ | ||
let world; | ||
if (Object.getOwnPropertySymbols(ents).includes($componentMap)) { | ||
world = ents; | ||
ents = ents[$entityArray]; | ||
} else { | ||
world = eidToWorld.get(ents[0]); | ||
} | ||
@@ -342,4 +349,9 @@ | ||
for (let i = 0; i < ents.length; i++) { | ||
const eid = ents[i]; // skip if diffing and no change | ||
const eid = ents[i]; // skip if entity doesn't have this component | ||
if (!hasComponent(world, prop[$storeBase](), eid)) { | ||
continue; | ||
} // skip if diffing and no change | ||
if (diff && prop[eid] === prop[$serializeShadow][eid]) { | ||
@@ -421,2 +433,3 @@ continue; | ||
let where = 0; | ||
const newEntities = new Map(); | ||
@@ -429,16 +442,24 @@ while (where < packet.byteLength) { | ||
const entityCount = view.getUint32(where); | ||
where += 4; // typed array | ||
where += 4; // component property | ||
const ta = componentProps[pid]; // Get the properties and set the new state | ||
const prop = componentProps[pid]; // Get the entities and set their prop values | ||
for (let i = 0; i < entityCount; i++) { | ||
let eid = view.getUint32(where); | ||
where += 4; // if this world hasn't seen this eid yet | ||
where += 4; | ||
let newEid = newEntities.get(eid); | ||
if (newEid !== undefined) { | ||
eid = newEid; | ||
} // if this world hasn't seen this eid yet | ||
if (!world[$entityEnabled][eid]) { | ||
// make a new entity for the data | ||
eid = addEntity(world); | ||
const newEid = addEntity(world); | ||
newEntities.set(eid, newEid); | ||
eid = newEid; | ||
} | ||
const component = ta[$storeBase](); | ||
const component = prop[$storeBase](); | ||
@@ -453,4 +474,4 @@ if (!hasComponent(world, component, eid)) { | ||
if (ArrayBuffer.isView(ta[eid])) { | ||
const array = ta[eid]; | ||
if (ArrayBuffer.isView(prop[eid])) { | ||
const array = prop[eid]; | ||
const count = view[`get${array[$indexType]}`](where); | ||
@@ -464,8 +485,8 @@ where += array[$indexBytes]; // iterate over count | ||
where += array.BYTES_PER_ELEMENT; | ||
ta[eid][index] = value; | ||
prop[eid][index] = value; | ||
} | ||
} else { | ||
const value = view[`get${ta.constructor.name.replace('Array', '')}`](where); | ||
where += ta.BYTES_PER_ELEMENT; | ||
ta[eid] = value; | ||
const value = view[`get${prop.constructor.name.replace('Array', '')}`](where); | ||
where += prop.BYTES_PER_ELEMENT; | ||
prop[eid] = value; | ||
} | ||
@@ -494,7 +515,9 @@ } | ||
const getEntityCursor = () => globalEntityCursor; | ||
const eidToWorld = new Map(); | ||
const addEntity = world => { | ||
const enabled = world[$entityEnabled]; | ||
const eid = removed.length > 0 ? removed.pop() : globalEntityCursor++; | ||
const eid = removed.length > 0 ? removed.shift() : globalEntityCursor++; | ||
enabled[eid] = 1; | ||
world[$entityIndices][eid] = world[$entityArray].push(eid) - 1; // if data stores are 80% full | ||
world[$entityIndices][eid] = world[$entityArray].push(eid) - 1; | ||
eidToWorld.set(eid, world); // if data stores are 80% full | ||
@@ -839,3 +862,3 @@ if (globalEntityCursor >= resizeThreshold()) { | ||
}; | ||
const removeComponent = (world, component, eid, reset = false) => { | ||
const removeComponent = (world, component, eid, reset = true) => { | ||
const { | ||
@@ -842,0 +865,0 @@ generationId, |
{ | ||
"name": "bitecs", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Functional, minimal, data-driven, ultra-high performance ECS library written in Javascript", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
@@ -13,3 +13,3 @@ # ๐พ bitECS ๐พ | ||
| ๐ Zero dependencies | ๐ Node or browser | | ||
| ๐ค `~5kb` gzipped | ๐ท TypeScript support | | ||
| ๐ค `~4kb` gzipped | ๐ท TypeScript support | | ||
| โค Made with love | ๐บ [glMatrix](https://github.com/toji/gl-matrix) support | | ||
@@ -16,0 +16,0 @@ |
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
255051
2133