@woosh/meep-engine 2.123.0 → 2.123.2

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.123.0",
8
+ "version": "2.123.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Using bitcoin-inspired base58 encoding
3
+ * Primarily intended for UUID compression
4
+ * @param {Uint8Array} source
5
+ * @param {number} offset
6
+ * @param {number} byte_count
7
+ * @returns {string}
8
+ */
9
+ export function base58_encode(source: Uint8Array, offset: number, byte_count: number): string;
10
+ //# sourceMappingURL=base58_encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base58_encode.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/base58/base58_encode.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,sCALW,UAAU,UACV,MAAM,cACN,MAAM,GACJ,MAAM,CA0ElB"}
@@ -0,0 +1,87 @@
1
+ import { assert } from "../../assert.js";
2
+
3
+ const base58_alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
4
+
5
+ const scratch = new Uint8Array(256);
6
+
7
+ /**
8
+ * Using bitcoin-inspired base58 encoding
9
+ * Primarily intended for UUID compression
10
+ * @param {Uint8Array} source
11
+ * @param {number} offset
12
+ * @param {number} byte_count
13
+ * @returns {string}
14
+ */
15
+ export function base58_encode(
16
+ source,
17
+ offset,
18
+ byte_count
19
+ ) {
20
+
21
+ // ported from the bitcoin's C codebase: https://github.com/bitcoin/bitcoin/blob/08a7316c144f9f2516db8fa62400893f4358c5ae/src/base58.cpp#L71
22
+
23
+ if (byte_count === 0) {
24
+ return "";
25
+ }
26
+
27
+ // Skip & count leading zeroes.
28
+ let zeroes = 0
29
+ let length = 0
30
+ let pbegin = offset
31
+ const pend = offset + byte_count
32
+
33
+ while (pbegin !== pend && source[pbegin] === 0) {
34
+ pbegin++
35
+ zeroes++
36
+ }
37
+
38
+ // Allocate enough space in big-endian base58 representation.
39
+ const size = ((pend - pbegin) * 138 / 100 + 1) >>> 0; /// log(256) / log(58), rounded up.
40
+
41
+ // use scratch if possible to avoid allocation
42
+ const b58 = (size <= scratch.length) ? scratch : new Uint8Array(size);
43
+
44
+ // Process the bytes.
45
+ while (pbegin !== pend) {
46
+ let carry = source[pbegin]
47
+
48
+ // Apply "b58 = b58 * 256 + ch".
49
+ let i = 0
50
+
51
+ for (
52
+ let it1 = size - 1;
53
+ (carry !== 0 || i < length) && (it1 !== -1);
54
+ it1--, i++
55
+ ) {
56
+
57
+ carry += (256 * b58[it1]) >>> 0;
58
+ b58[it1] = (carry % 58) >>> 0;
59
+ carry = (carry / 58) >>> 0;
60
+
61
+ }
62
+
63
+ assert.equal(carry, 0, 'carry must be zero');
64
+
65
+ length = i;
66
+ pbegin++;
67
+ }
68
+
69
+ // Skip leading zeroes in base58 result.
70
+ let it2 = size - length
71
+ while (it2 !== size && b58[it2] === 0) {
72
+ it2++
73
+ }
74
+
75
+ // Translate the result into a string.
76
+ let str = base58_alphabet.charAt(0).repeat(zeroes)
77
+ for (; it2 < size; ++it2) {
78
+ str += base58_alphabet.charAt(b58[it2])
79
+ }
80
+
81
+ if (b58 === scratch) {
82
+ // clear out scratch
83
+ scratch.fill(0);
84
+ }
85
+
86
+ return str;
87
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Universally Unique Identifier
3
+ * The default is Nil UUID, where all bits are set to 0
3
4
  * @see IETF RFC 4122
4
- *
5
5
  */
6
6
  export class UUID {
7
7
  /**
@@ -10,13 +10,13 @@ export class UUID {
10
10
  */
11
11
  static v1(): UUID;
12
12
  /**
13
- *
13
+ * Variant 4 UUID generator (fully random)
14
14
  * @returns {UUID}
15
15
  */
16
16
  static v4(): UUID;
17
17
  /**
18
18
  * Shortcut to generate string-form ID
19
- * Uses v4 UUID
19
+ * Uses v4(random) UUID
20
20
  * @return {string}
21
21
  */
22
22
  static string(): string;
@@ -46,13 +46,15 @@ export class UUID {
46
46
  */
47
47
  v4(): void;
48
48
  /***
49
- * String in UUID format
50
- * @see https://github.com/uuidjs/uuid/blob/8f028c4ea42ce41a9a9dc5fa634abe525b2e2066/src/parse.js#L3
51
- * @param {string} string
49
+ * Parses standard UUID string of form AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
50
+ * @param {string} string String in UUID format
52
51
  */
53
52
  parse(string: string): void;
54
53
  /**
55
- * @see https://github.com/uuidjs/uuid/blob/8f028c4ea42ce41a9a9dc5fa634abe525b2e2066/src/stringify.js#L16
54
+ * Standard UUID string in from: AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
55
+ * Result is compatible with the {@link UUID.parse} method.
56
+ * @example
57
+ * a88bb73a-c89f-11ed-afa1-0242ac120002
56
58
  * @returns {string}
57
59
  */
58
60
  toString(): string;
@@ -68,11 +70,18 @@ export class UUID {
68
70
  */
69
71
  equals(other: UUID): boolean;
70
72
  /**
71
- * @returns {number}
73
+ * Compute hash sum
74
+ * @returns {number} 32bit integer value
72
75
  */
73
76
  hash(): number;
74
- toJSON(): string;
75
- fromJSON(v: any): void;
77
+ /**
78
+ * @readonly
79
+ */
80
+ readonly toJSON: () => string;
81
+ /**
82
+ * @readonly
83
+ */
84
+ readonly fromJSON: (string: string) => void;
76
85
  /**
77
86
  * @readonly
78
87
  * @type {boolean}
@@ -1 +1 @@
1
- {"version":3,"file":"UUID.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/guid/UUID.js"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH;IAiHI;;;OAGG;IACH,aAFY,IAAI,CAQf;IAED;;;OAGG;IACH,aAFa,IAAI,CAQhB;IAED;;;;OAIG;IACH,iBAFY,MAAM,CAIjB;IA0CD;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,CAQf;IAlMD;;;OAGG;IACH,gBAFW,MAAM,EAAE,GAAC,UAAU,GAAC,SAAS,CAAC,MAAM,CAAC,EAO/C;IAED;;;OAGG;IACH,YAFa,UAAU,CAItB;IAED;;;OAGG;IACH,WAsEC;IAED;;OAEG;IACH,WAUC;IAmCD;;;;OAIG;IACH,cAFW,MAAM,QAmChB;IAeD;;;OAGG;IACH,YAFa,MAAM,CA2BlB;IAED;;;OAGG;IACH,YAFW,IAAI,QAId;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAanB;IAED;;OAEG;IACH,QAFa,MAAM,CAWlB;IAED,iBAEC;IAED,uBAEC;IASL;;;OAGG;IACH,iBAFU,OAAO,CAEI;;CAZpB;;kBAIS,MAAM"}
1
+ {"version":3,"file":"UUID.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/guid/UUID.js"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH;IAiHI;;;OAGG;IACH,aAFY,IAAI,CAQf;IAED;;;OAGG;IACH,aAFa,IAAI,CAQhB;IAED;;;;OAIG;IACH,iBAFY,MAAM,CAIjB;IAyCD;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,CAQf;IAjMD;;;OAGG;IACH,gBAFW,MAAM,EAAE,GAAC,UAAU,GAAC,SAAS,CAAC,MAAM,CAAC,EAO/C;IAED;;;OAGG;IACH,YAFa,UAAU,CAItB;IAED;;;OAGG;IACH,WAsEC;IAED;;OAEG;IACH,WAUC;IAmCD;;;OAGG;IACH,cAFW,MAAM,QAmChB;IAeD;;;;;;OAMG;IACH,YAFa,MAAM,CA2BlB;IAED;;;OAGG;IACH,YAFW,IAAI,QAId;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAcnB;IAED;;;OAGG;IACH,QAFa,MAAM,CAYlB;IAIL;;OAEG;IACH,uBA7EiB,MAAM,CA6EF;IAErB;;OAEG;IACH,4BAzIe,MAAM,UAyIE;IAQvB;;;OAGG;IACH,iBAFU,OAAO,CAEI;;CAtBpB;;kBAcS,MAAM"}
@@ -1,5 +1,6 @@
1
1
  import { assert } from "../../../core/assert.js";
2
2
  import { dec2hex } from "../../../core/binary/dec2hex.js";
3
+ import { hex2dec } from "../../../core/binary/hex2dec.js";
3
4
  import { array_copy } from "../../../core/collection/array/array_copy.js";
4
5
  import { randomBytes } from "../../../core/math/random/randomBytes.js";
5
6
  import { randomUint8 } from "../../../core/math/random/randomUint8.js";
@@ -24,8 +25,8 @@ let _clockseq = ((randomUint8(random) << 8) | randomUint8(random)) & 0x3fff;
24
25
 
25
26
  /**
26
27
  * Universally Unique Identifier
28
+ * The default is Nil UUID, where all bits are set to 0
27
29
  * @see IETF RFC 4122
28
- *
29
30
  */
30
31
  export class UUID {
31
32
  #data = new Uint8Array(16);
@@ -153,7 +154,7 @@ export class UUID {
153
154
  }
154
155
 
155
156
  /**
156
- *
157
+ * Variant 4 UUID generator (fully random)
157
158
  * @returns {UUID}
158
159
  */
159
160
  static v4() {
@@ -166,7 +167,7 @@ export class UUID {
166
167
 
167
168
  /**
168
169
  * Shortcut to generate string-form ID
169
- * Uses v4 UUID
170
+ * Uses v4(random) UUID
170
171
  * @return {string}
171
172
  */
172
173
  static string() {
@@ -174,9 +175,8 @@ export class UUID {
174
175
  }
175
176
 
176
177
  /***
177
- * String in UUID format
178
- * @see https://github.com/uuidjs/uuid/blob/8f028c4ea42ce41a9a9dc5fa634abe525b2e2066/src/parse.js#L3
179
- * @param {string} string
178
+ * Parses standard UUID string of form AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
179
+ * @param {string} string String in UUID format
180
180
  */
181
181
  parse(string) {
182
182
  assert.isString(string, 'string');
@@ -186,26 +186,26 @@ export class UUID {
186
186
  const arr = this.#data;
187
187
 
188
188
  // Parse ########-....-....-....-............
189
- arr[0] = (v = parseInt(string.slice(0, 8), 16)) >>> 24;
189
+ arr[0] = (v = hex2dec(string.slice(0, 8))) >>> 24;
190
190
  arr[1] = (v >>> 16) & 0xff;
191
191
  arr[2] = (v >>> 8) & 0xff;
192
192
  arr[3] = v & 0xff;
193
193
 
194
194
  // Parse ........-####-....-....-............
195
- arr[4] = (v = parseInt(string.slice(9, 13), 16)) >>> 8;
195
+ arr[4] = (v = hex2dec(string.slice(9, 13))) >>> 8;
196
196
  arr[5] = v & 0xff;
197
197
 
198
198
  // Parse ........-....-####-....-............
199
- arr[6] = (v = parseInt(string.slice(14, 18), 16)) >>> 8;
199
+ arr[6] = (v = hex2dec(string.slice(14, 18))) >>> 8;
200
200
  arr[7] = v & 0xff;
201
201
 
202
202
  // Parse ........-....-....-####-............
203
- arr[8] = (v = parseInt(string.slice(19, 23), 16)) >>> 8;
203
+ arr[8] = (v = hex2dec(string.slice(19, 23))) >>> 8;
204
204
  arr[9] = v & 0xff;
205
205
 
206
206
  // Parse ........-....-....-....-############
207
207
  // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
208
- arr[10] = ((v = parseInt(string.slice(24, 36), 16)) / 0x10000000000) & 0xff;
208
+ arr[10] = ((v = hex2dec(string.slice(24, 36))) / 0x10000000000) & 0xff;
209
209
  arr[11] = (v / 0x100000000) & 0xff;
210
210
  arr[12] = (v >>> 24) & 0xff;
211
211
  arr[13] = (v >>> 16) & 0xff;
@@ -227,7 +227,10 @@ export class UUID {
227
227
  }
228
228
 
229
229
  /**
230
- * @see https://github.com/uuidjs/uuid/blob/8f028c4ea42ce41a9a9dc5fa634abe525b2e2066/src/stringify.js#L16
230
+ * Standard UUID string in from: AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
231
+ * Result is compatible with the {@link UUID.parse} method.
232
+ * @example
233
+ * a88bb73a-c89f-11ed-afa1-0242ac120002
231
234
  * @returns {string}
232
235
  */
233
236
  toString() {
@@ -271,6 +274,7 @@ export class UUID {
271
274
  * @returns {boolean}
272
275
  */
273
276
  equals(other) {
277
+
274
278
  const this_data = this.#data;
275
279
  const other_data = other.#data;
276
280
 
@@ -284,12 +288,14 @@ export class UUID {
284
288
  }
285
289
 
286
290
  /**
287
- * @returns {number}
291
+ * Compute hash sum
292
+ * @returns {number} 32bit integer value
288
293
  */
289
294
  hash() {
290
295
  const data = this.#data;
291
296
 
292
- // use some non-metadata bytes as a hash
297
+ // use some non-metadata bytes as a hash, favoring speed as this is expected to be used a lot
298
+
293
299
  return data[3] // low byte of "time_low", very likely to differ between two UUIDs
294
300
  | data[5] << 8 // low byte of "time_mid"
295
301
  | data[9] << 16 // "clock_seq_low"
@@ -297,15 +303,18 @@ export class UUID {
297
303
  ;
298
304
  }
299
305
 
300
- toJSON() {
301
- return this.toString();
302
- }
303
-
304
- fromJSON(v) {
305
- this.parse(v);
306
- }
307
306
  }
308
307
 
308
+ /**
309
+ * @readonly
310
+ */
311
+ UUID.prototype.toJSON = UUID.prototype.toString;
312
+
313
+ /**
314
+ * @readonly
315
+ */
316
+ UUID.prototype.fromJSON = UUID.prototype.parse;
317
+
309
318
  /**
310
319
  * @readonly
311
320
  * @type {string}