@woosh/meep-engine 2.84.4 → 2.84.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +111 -51
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +111 -51
- package/package.json +1 -1
- package/src/core/collection/list/List.js +1 -1
- package/src/core/primitives/numbers/number_count_decimals.js +30 -0
- package/src/core/primitives/numbers/number_pretty_print.js +7 -29
- package/src/core/primitives/strings/string_format_camel_to_kebab.js +2 -0
- package/src/core/primitives/strings/string_strip_trailing.js +22 -0
- package/src/core/primitives/strings/string_strip_trailing.spec.js +27 -0
- package/src/engine/asset/AssetDescription.js +6 -0
- package/src/engine/ecs/Entity.js +5 -0
- package/src/engine/ecs/EntityComponentDataset.js +78 -26
- package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +8 -1
package/build/meep.cjs
CHANGED
|
@@ -61271,7 +61271,7 @@ class List {
|
|
|
61271
61271
|
this.data.push(el);
|
|
61272
61272
|
const oldLength = this.length;
|
|
61273
61273
|
|
|
61274
|
-
this.length
|
|
61274
|
+
this.length = oldLength + 1;
|
|
61275
61275
|
|
|
61276
61276
|
this.on.added.send2(el, oldLength);
|
|
61277
61277
|
return this;
|
|
@@ -72504,6 +72504,7 @@ class Entity {
|
|
|
72504
72504
|
* @returns {*|null}
|
|
72505
72505
|
*/
|
|
72506
72506
|
removeComponent(klass) {
|
|
72507
|
+
|
|
72507
72508
|
const elements = this.components;
|
|
72508
72509
|
const n = elements.length;
|
|
72509
72510
|
|
|
@@ -72629,6 +72630,7 @@ class Entity {
|
|
|
72629
72630
|
dataset.removeEntity(entity);
|
|
72630
72631
|
|
|
72631
72632
|
this.id = -1;
|
|
72633
|
+
this.generation = -1;
|
|
72632
72634
|
|
|
72633
72635
|
this.clearFlag(EntityFlags.Built);
|
|
72634
72636
|
|
|
@@ -72654,6 +72656,7 @@ class Entity {
|
|
|
72654
72656
|
}
|
|
72655
72657
|
|
|
72656
72658
|
const entity = this.id = dataset.createEntity();
|
|
72659
|
+
this.generation = dataset.getEntityGeneration(entity);
|
|
72657
72660
|
this.dataset = dataset;
|
|
72658
72661
|
|
|
72659
72662
|
let i;
|
|
@@ -72711,6 +72714,7 @@ class Entity {
|
|
|
72711
72714
|
r.setFlag(EntityFlags.Built);
|
|
72712
72715
|
r.id = entity;
|
|
72713
72716
|
r.dataset = dataset;
|
|
72717
|
+
r.generation = dataset.getEntityGeneration(entity);
|
|
72714
72718
|
|
|
72715
72719
|
return r;
|
|
72716
72720
|
}
|
|
@@ -84052,7 +84056,13 @@ class AssetDescription {
|
|
|
84052
84056
|
toString() {
|
|
84053
84057
|
return `{ type: '${this.type}', path: '${this.path}' }`;
|
|
84054
84058
|
}
|
|
84055
|
-
}
|
|
84059
|
+
}
|
|
84060
|
+
|
|
84061
|
+
/**
|
|
84062
|
+
* @readonly
|
|
84063
|
+
* @type {boolean}
|
|
84064
|
+
*/
|
|
84065
|
+
AssetDescription.prototype.isAssetDescription = true;
|
|
84056
84066
|
|
|
84057
84067
|
/**
|
|
84058
84068
|
* @enum {number}
|
|
@@ -92362,6 +92372,15 @@ class EntityComponentDataset {
|
|
|
92362
92372
|
* @type {BitSet}
|
|
92363
92373
|
*/
|
|
92364
92374
|
entityOccupancy = new BitSet();
|
|
92375
|
+
|
|
92376
|
+
/**
|
|
92377
|
+
* For each entity ID records generation when entity was created
|
|
92378
|
+
* Values are invalid for unused entity IDs
|
|
92379
|
+
* @private
|
|
92380
|
+
* @type {Uint32Array}
|
|
92381
|
+
*/
|
|
92382
|
+
entityGeneration = new Uint32Array(0);
|
|
92383
|
+
|
|
92365
92384
|
/**
|
|
92366
92385
|
* @private
|
|
92367
92386
|
* @type {BitSet}
|
|
@@ -92413,7 +92432,7 @@ class EntityComponentDataset {
|
|
|
92413
92432
|
|
|
92414
92433
|
/**
|
|
92415
92434
|
* @readonly
|
|
92416
|
-
* @type {Signal}
|
|
92435
|
+
* @type {Signal<number>}
|
|
92417
92436
|
*/
|
|
92418
92437
|
onEntityCreated = new Signal();
|
|
92419
92438
|
|
|
@@ -92963,38 +92982,79 @@ class EntityComponentDataset {
|
|
|
92963
92982
|
|
|
92964
92983
|
/**
|
|
92965
92984
|
*
|
|
92966
|
-
* @
|
|
92985
|
+
* @param {number} min_size
|
|
92967
92986
|
*/
|
|
92968
|
-
|
|
92969
|
-
const
|
|
92970
|
-
this.entityOccupancy.set(entityIndex, true);
|
|
92987
|
+
enlargeGenerationTable(min_size) {
|
|
92988
|
+
const old_generation_table_size = this.entityGeneration.length;
|
|
92971
92989
|
|
|
92972
|
-
|
|
92990
|
+
const new_size = max3(
|
|
92991
|
+
min_size,
|
|
92992
|
+
Math.ceil(old_generation_table_size * 1.2),
|
|
92993
|
+
old_generation_table_size + 16
|
|
92994
|
+
);
|
|
92973
92995
|
|
|
92974
|
-
|
|
92996
|
+
const new_generation_table = new Uint32Array(new_size);
|
|
92975
92997
|
|
|
92976
|
-
this.
|
|
92998
|
+
new_generation_table.set(this.entityGeneration);
|
|
92977
92999
|
|
|
92978
|
-
|
|
93000
|
+
this.entityGeneration = new_generation_table;
|
|
92979
93001
|
}
|
|
92980
93002
|
|
|
92981
93003
|
/**
|
|
92982
|
-
*
|
|
92983
|
-
* @param {number}
|
|
92984
|
-
* @
|
|
93004
|
+
* Produces generation ID for a given entity
|
|
93005
|
+
* @param {number} entity_id
|
|
93006
|
+
* @returns {number}
|
|
93007
|
+
*/
|
|
93008
|
+
getEntityGeneration(entity_id) {
|
|
93009
|
+
return this.entityGeneration[entity_id];
|
|
93010
|
+
}
|
|
93011
|
+
|
|
93012
|
+
/**
|
|
93013
|
+
* @private
|
|
93014
|
+
* @param {number} entity_id
|
|
92985
93015
|
*/
|
|
92986
|
-
|
|
92987
|
-
|
|
92988
|
-
|
|
93016
|
+
createEntityUnsafe(entity_id) {
|
|
93017
|
+
this.entityOccupancy.set(entity_id, true);
|
|
93018
|
+
|
|
93019
|
+
// record entity generation
|
|
93020
|
+
if (this.entityGeneration.length <= entity_id) {
|
|
93021
|
+
// needs to be resized
|
|
93022
|
+
this.enlargeGenerationTable(entity_id + 1);
|
|
92989
93023
|
}
|
|
92990
93024
|
|
|
92991
|
-
this.
|
|
93025
|
+
const current_generation = this.generation;
|
|
93026
|
+
this.generation = current_generation + 1;
|
|
93027
|
+
|
|
93028
|
+
this.entityGeneration[entity_id] = current_generation;
|
|
92992
93029
|
|
|
92993
93030
|
this.entityCount++;
|
|
92994
93031
|
|
|
92995
|
-
this.onEntityCreated.send1(
|
|
93032
|
+
this.onEntityCreated.send1(entity_id);
|
|
93033
|
+
}
|
|
93034
|
+
|
|
93035
|
+
/**
|
|
93036
|
+
*
|
|
93037
|
+
* @returns {number} entityIndex
|
|
93038
|
+
*/
|
|
93039
|
+
createEntity() {
|
|
93040
|
+
const entity_id = this.entityOccupancy.nextClearBit(0);
|
|
92996
93041
|
|
|
92997
|
-
this.
|
|
93042
|
+
this.createEntityUnsafe(entity_id);
|
|
93043
|
+
|
|
93044
|
+
return entity_id;
|
|
93045
|
+
}
|
|
93046
|
+
|
|
93047
|
+
/**
|
|
93048
|
+
*
|
|
93049
|
+
* @param {number} entity_id
|
|
93050
|
+
* @throws {Error} if entity index is already in use
|
|
93051
|
+
*/
|
|
93052
|
+
createEntitySpecific(entity_id) {
|
|
93053
|
+
if (this.entityExists(entity_id)) {
|
|
93054
|
+
throw new Error(`EntityId ${entity_id} is already in use`);
|
|
93055
|
+
}
|
|
93056
|
+
|
|
93057
|
+
this.createEntityUnsafe(entity_id);
|
|
92998
93058
|
}
|
|
92999
93059
|
|
|
93000
93060
|
/**
|
|
@@ -93119,7 +93179,7 @@ class EntityComponentDataset {
|
|
|
93119
93179
|
const componentClass = this.componentTypeMap[componentIndex];
|
|
93120
93180
|
|
|
93121
93181
|
//dispatch event to components
|
|
93122
|
-
this.sendEvent(entityIndex, EventType.ComponentRemoved, {klass: componentClass, instance: componentInstance});
|
|
93182
|
+
this.sendEvent(entityIndex, EventType.ComponentRemoved, { klass: componentClass, instance: componentInstance });
|
|
93123
93183
|
}
|
|
93124
93184
|
|
|
93125
93185
|
/**
|
|
@@ -93220,7 +93280,7 @@ class EntityComponentDataset {
|
|
|
93220
93280
|
const componentClass = this.componentTypeMap[componentIndex];
|
|
93221
93281
|
|
|
93222
93282
|
//dispatch event to components
|
|
93223
|
-
this.sendEvent(entityIndex, EventType.ComponentAdded, {klass: componentClass, instance: componentInstance});
|
|
93283
|
+
this.sendEvent(entityIndex, EventType.ComponentAdded, { klass: componentClass, instance: componentInstance });
|
|
93224
93284
|
}
|
|
93225
93285
|
|
|
93226
93286
|
/**
|
|
@@ -96026,40 +96086,38 @@ LinearValue.prototype.fromJSON = function (json) {
|
|
|
96026
96086
|
|
|
96027
96087
|
/**
|
|
96028
96088
|
*
|
|
96029
|
-
* @param {
|
|
96030
|
-
* @param {string}
|
|
96089
|
+
* @param {string} string
|
|
96090
|
+
* @param {string} trailing_sequence
|
|
96031
96091
|
* @returns {string}
|
|
96032
96092
|
*/
|
|
96033
|
-
function
|
|
96093
|
+
function string_strip_trailing(string, trailing_sequence) {
|
|
96094
|
+
const trailing_sequence_length = trailing_sequence.length;
|
|
96034
96095
|
|
|
96035
|
-
|
|
96096
|
+
if (trailing_sequence_length <= 0) {
|
|
96097
|
+
// special case to avoid infinite looping
|
|
96098
|
+
return string;
|
|
96099
|
+
}
|
|
96100
|
+
|
|
96101
|
+
let end_index = string.length;
|
|
96102
|
+
|
|
96103
|
+
while (string.substring(end_index - trailing_sequence_length, end_index) === trailing_sequence) {
|
|
96104
|
+
end_index -= trailing_sequence_length;
|
|
96105
|
+
}
|
|
96106
|
+
|
|
96107
|
+
return string.substring(0, end_index);
|
|
96036
96108
|
}
|
|
96037
96109
|
|
|
96038
96110
|
/**
|
|
96039
96111
|
*
|
|
96040
|
-
* @param {
|
|
96041
|
-
* @
|
|
96112
|
+
* @param {number} x
|
|
96113
|
+
* @param {string} [separator=',']
|
|
96114
|
+
* @returns {string}
|
|
96042
96115
|
*/
|
|
96043
|
-
function
|
|
96044
|
-
if (value % 1 === 0) {
|
|
96045
|
-
//whole number
|
|
96046
|
-
return 0;
|
|
96047
|
-
}
|
|
96048
|
-
const s = value.toString();
|
|
96049
|
-
const index = s.indexOf('.');
|
|
96050
|
-
|
|
96051
|
-
if (index === -1) {
|
|
96052
|
-
return 0;
|
|
96053
|
-
}
|
|
96054
|
-
|
|
96055
|
-
//find last 0
|
|
96056
|
-
let endIndex = s.length - 1;
|
|
96057
|
-
for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {
|
|
96058
|
-
|
|
96059
|
-
}
|
|
96060
|
-
return endIndex - index;
|
|
96061
|
-
}
|
|
96116
|
+
function number_format_by_thousands(x, separator = ',') {
|
|
96062
96117
|
|
|
96118
|
+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
96119
|
+
}
|
|
96120
|
+
|
|
96063
96121
|
/**
|
|
96064
96122
|
*
|
|
96065
96123
|
* @param {number} value
|
|
@@ -96070,10 +96128,12 @@ function number_pretty_print(value) {
|
|
|
96070
96128
|
const MAX_DECIMALS = 2;
|
|
96071
96129
|
|
|
96072
96130
|
const fraction = value % 1;
|
|
96073
|
-
|
|
96074
|
-
|
|
96075
|
-
|
|
96076
|
-
|
|
96131
|
+
|
|
96132
|
+
const would_produce_decimals = fraction * Math.pow(10, MAX_DECIMALS) > 0;
|
|
96133
|
+
|
|
96134
|
+
if (would_produce_decimals && Math.abs(value) < 100) {
|
|
96135
|
+
const truncated = value.toFixed(MAX_DECIMALS);
|
|
96136
|
+
return string_strip_trailing(truncated, "0");
|
|
96077
96137
|
} else {
|
|
96078
96138
|
//no fraction
|
|
96079
96139
|
return number_format_by_thousands(value - fraction, ",");
|