@woosh/meep-engine 2.123.1 → 2.123.4
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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IAEI;;;;OAIG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC
|
|
1
|
+
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IAEI;;;;OAIG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;;;;;;;OASG;IACH,2BAAkC;IAElC;;;;;OAKG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;OAGG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,MAAM,CAAC,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,MAAM,CAEe;IAG/B;;;;OAIG;IACH,+BAA4B;IAE5B;;;;OAIG;IACH,kCAA+B;IAE/B;;;OAGG;IACH,kBAAe;IAGf;;;;;;OAMG;IACH,iBALa,CAAC,EAAE,CAAC,UACN,GAAG,iBACH,CAAC,GACC,OAAO,CAAC,CAAC,CAAC,CAoCtB;IAED;;;;;OAKG;IACH,sBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAqDnB;IAED;;;;;OAKG;IACH,yBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAuDnB;IAED;;;OAGG;IACH,kBAFa,M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,aACN,MAAM,YACN,SAAU,YACV,GAAC,QA8BX;IAED;;;;;;;;OAQG;IACH,kCAPW,MAAM,aACN,MAAM,gCAEN,GAAC,GAEC,OAAO,CAwCnB;IAED;;;;;OAKG;IACH,2DAeC;IAED;;;;OAIG;IACH,iCAHW,MAAM,GACJ,OAAO,CAenB;IAED;;OAEG;IACH,cAMC;IAED;;;OAGG;IACH,iBAYC;IAED;;;;OAIG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,cAAU,KAAK,CAAC,CAAC,CAAC,CAYlC;IAED;;;;OAIG;IACH,mBAFW,sBAAsB,iCA6DhC;IAED;;;;OAIG;IACH,+EAiDC;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,8CAFW,GAAC,QAgBX;IAGL;;;OAGG;IACH,mCAFU,OAAO,CAEwC;CANxD;mBA15DkB,oCAAoC"}
|
|
@@ -161,12 +161,20 @@ export class EntityComponentDataset {
|
|
|
161
161
|
entityGeneration = new Uint32Array(0);
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
+
* Bit table, if a bit is set - that means component is present.
|
|
165
|
+
* The format is
|
|
166
|
+
* entity_0: [component_0, component_1, ... component_n]
|
|
167
|
+
* entity_1: [component_0, component_1, ... component_n]
|
|
168
|
+
* ...
|
|
169
|
+
* entity_n: [component_0, component_1, ... component_n]
|
|
164
170
|
* @private
|
|
165
171
|
* @type {BitSet}
|
|
166
172
|
*/
|
|
167
173
|
componentOccupancy = new BitSet();
|
|
168
174
|
|
|
169
175
|
/**
|
|
176
|
+
* Do not modify directly.
|
|
177
|
+
* Use {@link setComponentTypeMap} instead.
|
|
170
178
|
* @private
|
|
171
179
|
* @type {Class[]}
|
|
172
180
|
*/
|
|
@@ -425,7 +433,7 @@ export class EntityComponentDataset {
|
|
|
425
433
|
/**
|
|
426
434
|
* Convenience method for retrieving a collection of components for a given entity
|
|
427
435
|
* @param {number} entity ID of the entity
|
|
428
|
-
* @param {
|
|
436
|
+
* @param {[]} componentClasses Classes of components to extract
|
|
429
437
|
* @returns {Array}
|
|
430
438
|
*/
|
|
431
439
|
getComponents(entity, componentClasses) {
|
|
@@ -495,6 +503,7 @@ export class EntityComponentDataset {
|
|
|
495
503
|
/**
|
|
496
504
|
* Modify dataset component mapping. Algorithm will attempt to mutate dataset even if entities exist, however, it will not remove component classes for which instances exist in the dataset.
|
|
497
505
|
* @param {Class[]} map collection of component classes
|
|
506
|
+
* @returns {void}
|
|
498
507
|
* @throws Error when attempting to remove component classes with live instances
|
|
499
508
|
*/
|
|
500
509
|
setComponentTypeMap(map) {
|
|
@@ -598,6 +607,8 @@ export class EntityComponentDataset {
|
|
|
598
607
|
for (i = 0, l = typesToAdd.length; i < l; i++) {
|
|
599
608
|
const type = typesToAdd[i];
|
|
600
609
|
|
|
610
|
+
assert.defined(type, 'type');
|
|
611
|
+
|
|
601
612
|
const newIndex = map.indexOf(type);
|
|
602
613
|
|
|
603
614
|
//initialize component store
|
|
@@ -683,10 +694,13 @@ export class EntityComponentDataset {
|
|
|
683
694
|
/**
|
|
684
695
|
*
|
|
685
696
|
* @param {Class[]} types
|
|
686
|
-
* @returns {boolean}
|
|
697
|
+
* @returns {boolean} true if all types are present, false otherwise
|
|
687
698
|
*/
|
|
688
699
|
areComponentTypesRegistered(types) {
|
|
689
|
-
|
|
700
|
+
assert.isArray(types, 'types');
|
|
701
|
+
|
|
702
|
+
const count = types.length;
|
|
703
|
+
for (let i = 0; i < count; i++) {
|
|
690
704
|
const type = types[i];
|
|
691
705
|
|
|
692
706
|
if (!this.isComponentTypeRegistered(type)) {
|
|
@@ -704,6 +718,9 @@ export class EntityComponentDataset {
|
|
|
704
718
|
* @return {boolean}
|
|
705
719
|
*/
|
|
706
720
|
isComponentTypeRegistered(type) {
|
|
721
|
+
assert.defined(type, 'type');
|
|
722
|
+
assert.notNull(type, 'type');
|
|
723
|
+
|
|
707
724
|
const componentTypeMap = this.getComponentTypeMap();
|
|
708
725
|
|
|
709
726
|
return componentTypeMap.indexOf(type) !== -1;
|
|
@@ -762,7 +779,8 @@ export class EntityComponentDataset {
|
|
|
762
779
|
* @returns {boolean} true iff component is removed, false if it was not registered
|
|
763
780
|
*/
|
|
764
781
|
unregisterComponentType(type) {
|
|
765
|
-
|
|
782
|
+
|
|
783
|
+
if (!this.isComponentTypeRegistered(type)) {
|
|
766
784
|
// not registered
|
|
767
785
|
return false;
|
|
768
786
|
}
|
|
@@ -806,7 +824,7 @@ export class EntityComponentDataset {
|
|
|
806
824
|
*/
|
|
807
825
|
getEntityGeneration(entity_id) {
|
|
808
826
|
assert.isNonNegativeInteger(entity_id, 'entity_id');
|
|
809
|
-
assert.ok(this.entityExists(entity_id)
|
|
827
|
+
assert.ok(this.entityExists(entity_id), `Entity ${entity_id} does not exist`);
|
|
810
828
|
|
|
811
829
|
return this.entityGeneration[entity_id];
|
|
812
830
|
}
|
|
@@ -1003,10 +1021,13 @@ export class EntityComponentDataset {
|
|
|
1003
1021
|
|
|
1004
1022
|
/**
|
|
1005
1023
|
*
|
|
1006
|
-
* @param klass
|
|
1024
|
+
* @param {Function|Class} klass
|
|
1007
1025
|
* @returns {number}
|
|
1008
1026
|
*/
|
|
1009
1027
|
computeComponentTypeIndex(klass) {
|
|
1028
|
+
assert.defined(klass, "klass");
|
|
1029
|
+
assert.notNull(klass, "klass");
|
|
1030
|
+
|
|
1010
1031
|
const idx = this.__type_to_index_map.get(klass);
|
|
1011
1032
|
|
|
1012
1033
|
if (idx === undefined) {
|
|
@@ -1399,13 +1420,15 @@ export class EntityComponentDataset {
|
|
|
1399
1420
|
traverseComponentsByIndex(componentTypeIndex, visitor, thisArg) {
|
|
1400
1421
|
|
|
1401
1422
|
assert.isNumber(componentTypeIndex, "componentTypeIndex");
|
|
1423
|
+
assert.isNonNegativeInteger(componentTypeIndex, "componentTypeIndex");
|
|
1402
1424
|
assert.isFunction(visitor, "visitor");
|
|
1403
1425
|
|
|
1404
1426
|
this.__traverseComponentsByIndex_via_property(componentTypeIndex, visitor, thisArg);
|
|
1405
1427
|
}
|
|
1406
1428
|
|
|
1407
1429
|
/**
|
|
1408
|
-
*
|
|
1430
|
+
* Alternative to {@link __traverseComponentsByIndex_via_property} as of 2020, appears to be significantly slower on Chrome with larger datasets
|
|
1431
|
+
* @private
|
|
1409
1432
|
* @param {number} componentTypeIndex
|
|
1410
1433
|
* @param {function} visitor
|
|
1411
1434
|
* @param {*} [thisArg]
|
|
@@ -1438,7 +1461,7 @@ export class EntityComponentDataset {
|
|
|
1438
1461
|
}
|
|
1439
1462
|
|
|
1440
1463
|
/**
|
|
1441
|
-
*
|
|
1464
|
+
* @private
|
|
1442
1465
|
* @param {number} componentTypeIndex
|
|
1443
1466
|
* @param {function} visitor
|
|
1444
1467
|
* @param {*} [thisArg]
|
|
@@ -1574,6 +1597,9 @@ export class EntityComponentDataset {
|
|
|
1574
1597
|
* @returns {boolean}
|
|
1575
1598
|
*/
|
|
1576
1599
|
removeAnyEventListener(entity, listener, thisArg) {
|
|
1600
|
+
assert.isNonNegativeInteger(entity, "entity");
|
|
1601
|
+
assert.isFunction(listener, "listener");
|
|
1602
|
+
|
|
1577
1603
|
const evl = this.__entityAnyEventListeners;
|
|
1578
1604
|
|
|
1579
1605
|
let handlers = evl[entity];
|
|
@@ -1609,7 +1635,7 @@ export class EntityComponentDataset {
|
|
|
1609
1635
|
* @param {*} [thisArg]
|
|
1610
1636
|
*/
|
|
1611
1637
|
addEntityEventListener(entity, eventName, listener, thisArg) {
|
|
1612
|
-
|
|
1638
|
+
assert.isNonNegativeInteger(entity, "entity");
|
|
1613
1639
|
assert.isString(eventName, "eventName");
|
|
1614
1640
|
assert.isFunction(listener, "listener");
|
|
1615
1641
|
|
|
@@ -1648,6 +1674,10 @@ export class EntityComponentDataset {
|
|
|
1648
1674
|
* @returns {boolean}
|
|
1649
1675
|
*/
|
|
1650
1676
|
removeEntityEventListener(entity, eventName, listener, thisArg) {
|
|
1677
|
+
assert.isNonNegativeInteger(entity, "entity");
|
|
1678
|
+
assert.isString(eventName, "eventName");
|
|
1679
|
+
assert.isFunction(listener, "listener");
|
|
1680
|
+
|
|
1651
1681
|
const evl = this.__entityEventListeners;
|
|
1652
1682
|
|
|
1653
1683
|
const hash = evl[entity];
|
|
@@ -20,12 +20,6 @@ export class UUID {
|
|
|
20
20
|
* @return {string}
|
|
21
21
|
*/
|
|
22
22
|
static string(): string;
|
|
23
|
-
/**
|
|
24
|
-
* Shortcut to generate 22-character base58 string
|
|
25
|
-
* Uses v4(random) UUID
|
|
26
|
-
* @return {string}
|
|
27
|
-
*/
|
|
28
|
-
static base58(): string;
|
|
29
23
|
/**
|
|
30
24
|
*
|
|
31
25
|
* @param {string} string
|
|
@@ -56,10 +50,6 @@ export class UUID {
|
|
|
56
50
|
* @param {string} string String in UUID format
|
|
57
51
|
*/
|
|
58
52
|
parse(string: string): void;
|
|
59
|
-
/**
|
|
60
|
-
* Use base58 encoding to represent UUID as a 22 character string
|
|
61
|
-
*/
|
|
62
|
-
get base58(): string;
|
|
63
53
|
/**
|
|
64
54
|
* Standard UUID string in from: AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
|
|
65
55
|
* Result is compatible with the {@link UUID.parse} method.
|
|
@@ -80,11 +70,18 @@ export class UUID {
|
|
|
80
70
|
*/
|
|
81
71
|
equals(other: UUID): boolean;
|
|
82
72
|
/**
|
|
83
|
-
*
|
|
73
|
+
* Compute hash sum
|
|
74
|
+
* @returns {number} 32bit integer value
|
|
84
75
|
*/
|
|
85
76
|
hash(): number;
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @readonly
|
|
79
|
+
*/
|
|
80
|
+
readonly toJSON: () => string;
|
|
81
|
+
/**
|
|
82
|
+
* @readonly
|
|
83
|
+
*/
|
|
84
|
+
readonly fromJSON: (string: string) => void;
|
|
88
85
|
/**
|
|
89
86
|
* @readonly
|
|
90
87
|
* @type {boolean}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { assert } from "../../../core/assert.js";
|
|
2
|
-
import { base58_encode } from "../../../core/binary/base58/base58_encode.js";
|
|
3
2
|
import { dec2hex } from "../../../core/binary/dec2hex.js";
|
|
3
|
+
import { hex2dec } from "../../../core/binary/hex2dec.js";
|
|
4
4
|
import { array_copy } from "../../../core/collection/array/array_copy.js";
|
|
5
5
|
import { randomBytes } from "../../../core/math/random/randomBytes.js";
|
|
6
6
|
import { randomUint8 } from "../../../core/math/random/randomUint8.js";
|
|
@@ -174,15 +174,6 @@ export class UUID {
|
|
|
174
174
|
return UUID.v4().toString();
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
/**
|
|
178
|
-
* Shortcut to generate 22-character base58 string
|
|
179
|
-
* Uses v4(random) UUID
|
|
180
|
-
* @return {string}
|
|
181
|
-
*/
|
|
182
|
-
static base58() {
|
|
183
|
-
return UUID.v4().base58;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
177
|
/***
|
|
187
178
|
* Parses standard UUID string of form AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
|
|
188
179
|
* @param {string} string String in UUID format
|
|
@@ -195,26 +186,26 @@ export class UUID {
|
|
|
195
186
|
const arr = this.#data;
|
|
196
187
|
|
|
197
188
|
// Parse ########-....-....-....-............
|
|
198
|
-
arr[0] = (v =
|
|
189
|
+
arr[0] = (v = hex2dec(string.slice(0, 8))) >>> 24;
|
|
199
190
|
arr[1] = (v >>> 16) & 0xff;
|
|
200
191
|
arr[2] = (v >>> 8) & 0xff;
|
|
201
192
|
arr[3] = v & 0xff;
|
|
202
193
|
|
|
203
194
|
// Parse ........-####-....-....-............
|
|
204
|
-
arr[4] = (v =
|
|
195
|
+
arr[4] = (v = hex2dec(string.slice(9, 13))) >>> 8;
|
|
205
196
|
arr[5] = v & 0xff;
|
|
206
197
|
|
|
207
198
|
// Parse ........-....-####-....-............
|
|
208
|
-
arr[6] = (v =
|
|
199
|
+
arr[6] = (v = hex2dec(string.slice(14, 18))) >>> 8;
|
|
209
200
|
arr[7] = v & 0xff;
|
|
210
201
|
|
|
211
202
|
// Parse ........-....-....-####-............
|
|
212
|
-
arr[8] = (v =
|
|
203
|
+
arr[8] = (v = hex2dec(string.slice(19, 23))) >>> 8;
|
|
213
204
|
arr[9] = v & 0xff;
|
|
214
205
|
|
|
215
206
|
// Parse ........-....-....-....-############
|
|
216
207
|
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
|
217
|
-
arr[10] = ((v =
|
|
208
|
+
arr[10] = ((v = hex2dec(string.slice(24, 36))) / 0x10000000000) & 0xff;
|
|
218
209
|
arr[11] = (v / 0x100000000) & 0xff;
|
|
219
210
|
arr[12] = (v >>> 24) & 0xff;
|
|
220
211
|
arr[13] = (v >>> 16) & 0xff;
|
|
@@ -235,13 +226,6 @@ export class UUID {
|
|
|
235
226
|
return r;
|
|
236
227
|
}
|
|
237
228
|
|
|
238
|
-
/**
|
|
239
|
-
* Use base58 encoding to represent UUID as a 22 character string
|
|
240
|
-
*/
|
|
241
|
-
get base58() {
|
|
242
|
-
return base58_encode(this.#data, 0, 16);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
229
|
/**
|
|
246
230
|
* Standard UUID string in from: AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE
|
|
247
231
|
* Result is compatible with the {@link UUID.parse} method.
|
|
@@ -290,6 +274,7 @@ export class UUID {
|
|
|
290
274
|
* @returns {boolean}
|
|
291
275
|
*/
|
|
292
276
|
equals(other) {
|
|
277
|
+
|
|
293
278
|
const this_data = this.#data;
|
|
294
279
|
const other_data = other.#data;
|
|
295
280
|
|
|
@@ -303,12 +288,14 @@ export class UUID {
|
|
|
303
288
|
}
|
|
304
289
|
|
|
305
290
|
/**
|
|
306
|
-
*
|
|
291
|
+
* Compute hash sum
|
|
292
|
+
* @returns {number} 32bit integer value
|
|
307
293
|
*/
|
|
308
294
|
hash() {
|
|
309
295
|
const data = this.#data;
|
|
310
296
|
|
|
311
|
-
// 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
|
+
|
|
312
299
|
return data[3] // low byte of "time_low", very likely to differ between two UUIDs
|
|
313
300
|
| data[5] << 8 // low byte of "time_mid"
|
|
314
301
|
| data[9] << 16 // "clock_seq_low"
|
|
@@ -316,15 +303,18 @@ export class UUID {
|
|
|
316
303
|
;
|
|
317
304
|
}
|
|
318
305
|
|
|
319
|
-
toJSON() {
|
|
320
|
-
return this.toString();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
fromJSON(v) {
|
|
324
|
-
this.parse(v);
|
|
325
|
-
}
|
|
326
306
|
}
|
|
327
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
|
+
|
|
328
318
|
/**
|
|
329
319
|
* @readonly
|
|
330
320
|
* @type {string}
|