@woosh/meep-engine 2.84.5 → 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 +30 -30
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +30 -30
- 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/ecs/storage/BinaryBufferDeSerializer.js +8 -1
package/build/meep.module.js
CHANGED
|
@@ -61269,7 +61269,7 @@ class List {
|
|
|
61269
61269
|
this.data.push(el);
|
|
61270
61270
|
const oldLength = this.length;
|
|
61271
61271
|
|
|
61272
|
-
this.length
|
|
61272
|
+
this.length = oldLength + 1;
|
|
61273
61273
|
|
|
61274
61274
|
this.on.added.send2(el, oldLength);
|
|
61275
61275
|
return this;
|
|
@@ -96084,40 +96084,38 @@ LinearValue.prototype.fromJSON = function (json) {
|
|
|
96084
96084
|
|
|
96085
96085
|
/**
|
|
96086
96086
|
*
|
|
96087
|
-
* @param {
|
|
96088
|
-
* @param {string}
|
|
96087
|
+
* @param {string} string
|
|
96088
|
+
* @param {string} trailing_sequence
|
|
96089
96089
|
* @returns {string}
|
|
96090
96090
|
*/
|
|
96091
|
-
function
|
|
96091
|
+
function string_strip_trailing(string, trailing_sequence) {
|
|
96092
|
+
const trailing_sequence_length = trailing_sequence.length;
|
|
96092
96093
|
|
|
96093
|
-
|
|
96094
|
+
if (trailing_sequence_length <= 0) {
|
|
96095
|
+
// special case to avoid infinite looping
|
|
96096
|
+
return string;
|
|
96097
|
+
}
|
|
96098
|
+
|
|
96099
|
+
let end_index = string.length;
|
|
96100
|
+
|
|
96101
|
+
while (string.substring(end_index - trailing_sequence_length, end_index) === trailing_sequence) {
|
|
96102
|
+
end_index -= trailing_sequence_length;
|
|
96103
|
+
}
|
|
96104
|
+
|
|
96105
|
+
return string.substring(0, end_index);
|
|
96094
96106
|
}
|
|
96095
96107
|
|
|
96096
96108
|
/**
|
|
96097
96109
|
*
|
|
96098
|
-
* @param {
|
|
96099
|
-
* @
|
|
96110
|
+
* @param {number} x
|
|
96111
|
+
* @param {string} [separator=',']
|
|
96112
|
+
* @returns {string}
|
|
96100
96113
|
*/
|
|
96101
|
-
function
|
|
96102
|
-
if (value % 1 === 0) {
|
|
96103
|
-
//whole number
|
|
96104
|
-
return 0;
|
|
96105
|
-
}
|
|
96106
|
-
const s = value.toString();
|
|
96107
|
-
const index = s.indexOf('.');
|
|
96108
|
-
|
|
96109
|
-
if (index === -1) {
|
|
96110
|
-
return 0;
|
|
96111
|
-
}
|
|
96112
|
-
|
|
96113
|
-
//find last 0
|
|
96114
|
-
let endIndex = s.length - 1;
|
|
96115
|
-
for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {
|
|
96116
|
-
|
|
96117
|
-
}
|
|
96118
|
-
return endIndex - index;
|
|
96119
|
-
}
|
|
96114
|
+
function number_format_by_thousands(x, separator = ',') {
|
|
96120
96115
|
|
|
96116
|
+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
96117
|
+
}
|
|
96118
|
+
|
|
96121
96119
|
/**
|
|
96122
96120
|
*
|
|
96123
96121
|
* @param {number} value
|
|
@@ -96128,10 +96126,12 @@ function number_pretty_print(value) {
|
|
|
96128
96126
|
const MAX_DECIMALS = 2;
|
|
96129
96127
|
|
|
96130
96128
|
const fraction = value % 1;
|
|
96131
|
-
|
|
96132
|
-
|
|
96133
|
-
|
|
96134
|
-
|
|
96129
|
+
|
|
96130
|
+
const would_produce_decimals = fraction * Math.pow(10, MAX_DECIMALS) > 0;
|
|
96131
|
+
|
|
96132
|
+
if (would_produce_decimals && Math.abs(value) < 100) {
|
|
96133
|
+
const truncated = value.toFixed(MAX_DECIMALS);
|
|
96134
|
+
return string_strip_trailing(truncated, "0");
|
|
96135
96135
|
} else {
|
|
96136
96136
|
//no fraction
|
|
96137
96137
|
return number_format_by_thousands(value - fraction, ",");
|
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number} value
|
|
6
|
+
* @returns {number}
|
|
7
|
+
*/
|
|
8
|
+
export function number_count_decimals(value) {
|
|
9
|
+
assert.isNumber(value, 'value');
|
|
10
|
+
|
|
11
|
+
if (value % 1 === 0) {
|
|
12
|
+
//whole number
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const s = value.toString();
|
|
17
|
+
const index = s.indexOf('.');
|
|
18
|
+
|
|
19
|
+
if (index === -1) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//find last 0
|
|
24
|
+
let endIndex = s.length - 1;
|
|
25
|
+
for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return endIndex - index;
|
|
30
|
+
}
|
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
import { assert } from "../../assert.js";
|
|
2
|
+
import { string_strip_trailing } from "../strings/string_strip_trailing.js";
|
|
2
3
|
import { number_format_by_thousands } from "./number_format_by_thousands.js";
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {string} value
|
|
7
|
-
* @returns {number}
|
|
8
|
-
*/
|
|
9
|
-
function countDecimals(value) {
|
|
10
|
-
if (value % 1 === 0) {
|
|
11
|
-
//whole number
|
|
12
|
-
return 0;
|
|
13
|
-
}
|
|
14
|
-
const s = value.toString();
|
|
15
|
-
const index = s.indexOf('.');
|
|
16
|
-
|
|
17
|
-
if (index === -1) {
|
|
18
|
-
return 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//find last 0
|
|
22
|
-
let endIndex = s.length - 1;
|
|
23
|
-
for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return endIndex - index;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
5
|
/**
|
|
30
6
|
*
|
|
31
7
|
* @param {number} value
|
|
@@ -37,10 +13,12 @@ export function number_pretty_print(value) {
|
|
|
37
13
|
const MAX_DECIMALS = 2;
|
|
38
14
|
|
|
39
15
|
const fraction = value % 1;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
|
|
17
|
+
const would_produce_decimals = fraction * Math.pow(10, MAX_DECIMALS) > 0;
|
|
18
|
+
|
|
19
|
+
if (would_produce_decimals && Math.abs(value) < 100) {
|
|
20
|
+
const truncated = value.toFixed(MAX_DECIMALS);
|
|
21
|
+
return string_strip_trailing(truncated, "0");
|
|
44
22
|
} else {
|
|
45
23
|
//no fraction
|
|
46
24
|
return number_format_by_thousands(value - fraction, ",");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {string} string
|
|
4
|
+
* @param {string} trailing_sequence
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
export function string_strip_trailing(string, trailing_sequence) {
|
|
8
|
+
const trailing_sequence_length = trailing_sequence.length;
|
|
9
|
+
|
|
10
|
+
if (trailing_sequence_length <= 0) {
|
|
11
|
+
// special case to avoid infinite looping
|
|
12
|
+
return string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let end_index = string.length;
|
|
16
|
+
|
|
17
|
+
while (string.substring(end_index - trailing_sequence_length, end_index) === trailing_sequence) {
|
|
18
|
+
end_index -= trailing_sequence_length;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return string.substring(0, end_index);
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { string_strip_trailing } from "./string_strip_trailing.js";
|
|
2
|
+
|
|
3
|
+
test("strip empty from empty", () => {
|
|
4
|
+
expect(
|
|
5
|
+
string_strip_trailing("", "")
|
|
6
|
+
).toBe("");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("strip repeating 2 character sequence", () => {
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
string_strip_trailing("Cabab", "ab")
|
|
13
|
+
).toBe("C");
|
|
14
|
+
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("mistakes", () => {
|
|
18
|
+
|
|
19
|
+
expect(
|
|
20
|
+
string_strip_trailing("food", "o")
|
|
21
|
+
).toBe("food");
|
|
22
|
+
|
|
23
|
+
expect(
|
|
24
|
+
string_strip_trailing("food", "f")
|
|
25
|
+
).toBe("food");
|
|
26
|
+
|
|
27
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assert } from "../../../core/assert.js";
|
|
2
|
+
import { number_pretty_print } from "../../../core/primitives/numbers/number_pretty_print.js";
|
|
2
3
|
import Task from "../../../core/process/task/Task.js";
|
|
3
4
|
import { TaskSignal } from "../../../core/process/task/TaskSignal.js";
|
|
4
5
|
import { emptyTask } from "../../../core/process/task/util/emptyTask.js";
|
|
@@ -24,6 +25,7 @@ class BinaryBufferDeSerializer {
|
|
|
24
25
|
assert.notEqual(engine, undefined, 'engine is undefined');
|
|
25
26
|
assert.notEqual(dataset, undefined, 'dataset is undefined');
|
|
26
27
|
|
|
28
|
+
const entity_count_before = dataset.entityCount;
|
|
27
29
|
|
|
28
30
|
const version = buffer.readUint16();
|
|
29
31
|
const numSerializedTypes = buffer.readUint16();
|
|
@@ -37,7 +39,12 @@ class BinaryBufferDeSerializer {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
task.on.completed.add(function () {
|
|
40
|
-
|
|
42
|
+
const entity_count_after = dataset.entityCount;
|
|
43
|
+
|
|
44
|
+
const execution_time = task.getExecutedCpuTime();
|
|
45
|
+
const entity_count = entity_count_after - entity_count_before;
|
|
46
|
+
|
|
47
|
+
console.log(`Binary Buffer De-Serialization took ${number_pretty_print(execution_time)}ms. ${entity_count} Entities`);
|
|
41
48
|
});
|
|
42
49
|
|
|
43
50
|
return task;
|