@woosh/meep-engine 2.47.15 → 2.47.16
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 +65 -62
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +65 -62
- package/package.json +1 -1
- package/src/core/IdPool.js +65 -62
- package/src/core/json/abstractJSONSerializer.js +24 -24
package/build/meep.module.js
CHANGED
|
@@ -117641,87 +117641,90 @@ class MaxRectanglesPacker {
|
|
|
117641
117641
|
*/
|
|
117642
117642
|
|
|
117643
117643
|
/**
|
|
117644
|
-
*
|
|
117645
|
-
*
|
|
117644
|
+
* Pool of unsigned integer IDs, useful when you don't want to just keep incrementing ID counter and want to re-use IDs after they are no longer needed
|
|
117645
|
+
* Main use case is when your IDs are array indices, having compact IDs lets you use fixed size array even as objects are added and removed as you're able to reuse slots in an efficient manner
|
|
117646
117646
|
*/
|
|
117647
|
-
|
|
117647
|
+
class IdPool {
|
|
117648
117648
|
/**
|
|
117649
117649
|
* @private
|
|
117650
117650
|
* @type {BitSet}
|
|
117651
117651
|
*/
|
|
117652
|
-
|
|
117653
|
-
}
|
|
117652
|
+
#set = new BitSet();
|
|
117654
117653
|
|
|
117655
|
-
/**
|
|
117656
|
-
|
|
117657
|
-
|
|
117658
|
-
|
|
117659
|
-
|
|
117660
|
-
|
|
117661
|
-
|
|
117662
|
-
}
|
|
117654
|
+
/**
|
|
117655
|
+
* Looks up next available ID without reserving it
|
|
117656
|
+
* If you want to also reserve the ID - use {@link get} instead
|
|
117657
|
+
* @returns {number}
|
|
117658
|
+
*/
|
|
117659
|
+
peek() {
|
|
117660
|
+
return this.#set.nextClearBit(0);
|
|
117661
|
+
}
|
|
117663
117662
|
|
|
117664
|
-
/**
|
|
117665
|
-
|
|
117666
|
-
|
|
117667
|
-
|
|
117668
|
-
|
|
117669
|
-
|
|
117663
|
+
/**
|
|
117664
|
+
*
|
|
117665
|
+
* @returns {number}
|
|
117666
|
+
*/
|
|
117667
|
+
get() {
|
|
117668
|
+
const id = this.peek();
|
|
117670
117669
|
|
|
117671
|
-
|
|
117670
|
+
this.#set.set(id, true);
|
|
117672
117671
|
|
|
117673
|
-
|
|
117674
|
-
}
|
|
117672
|
+
return id;
|
|
117673
|
+
}
|
|
117675
117674
|
|
|
117676
|
-
/**
|
|
117677
|
-
|
|
117678
|
-
|
|
117679
|
-
|
|
117680
|
-
|
|
117681
|
-
|
|
117682
|
-
|
|
117683
|
-
|
|
117675
|
+
/**
|
|
117676
|
+
* Attempt to request a specific ID from the pool.
|
|
117677
|
+
* @param {number} id
|
|
117678
|
+
* @return {boolean} true if request succeeds, false otherwise
|
|
117679
|
+
*/
|
|
117680
|
+
getSpecific(id) {
|
|
117681
|
+
if (this.isUsed(id)) {
|
|
117682
|
+
return false;
|
|
117683
|
+
}
|
|
117684
|
+
|
|
117685
|
+
this.#set.set(id, true);
|
|
117686
|
+
return true;
|
|
117684
117687
|
}
|
|
117685
117688
|
|
|
117686
|
-
|
|
117687
|
-
|
|
117688
|
-
}
|
|
117689
|
+
/**
|
|
117690
|
+
*
|
|
117691
|
+
* @param {number} id
|
|
117692
|
+
* @returns {boolean}
|
|
117693
|
+
*/
|
|
117694
|
+
isUsed(id) {
|
|
117695
|
+
return this.#set.get(id);
|
|
117696
|
+
}
|
|
117689
117697
|
|
|
117690
|
-
/**
|
|
117691
|
-
|
|
117692
|
-
|
|
117693
|
-
|
|
117694
|
-
|
|
117695
|
-
|
|
117696
|
-
return this.bitSet.get(id);
|
|
117697
|
-
};
|
|
117698
|
+
/**
|
|
117699
|
+
* Traverse all IDs currently in use
|
|
117700
|
+
* @param {function(id:number)} visitor
|
|
117701
|
+
*/
|
|
117702
|
+
traverseUsed(visitor) {
|
|
117703
|
+
assert.isFunction(visitor, "visitor");
|
|
117698
117704
|
|
|
117699
|
-
|
|
117700
|
-
* Traverse all IDs currently in use
|
|
117701
|
-
* @param {function(id:number)} visitor
|
|
117702
|
-
*/
|
|
117703
|
-
IdPool.prototype.traverseUsed = function (visitor) {
|
|
117704
|
-
assert.equal(typeof visitor, 'function', `visitor must be a function, instead was '${typeof visitor}'`);
|
|
117705
|
+
const set = this.#set;
|
|
117705
117706
|
|
|
117706
|
-
|
|
117707
|
+
for (let i = set.nextSetBit(0); i !== -1; i = set.nextSetBit(i + 1)) {
|
|
117708
|
+
visitor(i);
|
|
117709
|
+
}
|
|
117707
117710
|
|
|
117708
|
-
for (let i = bitSet.nextSetBit(0); i !== -1; i = bitSet.nextSetBit(i + 1)) {
|
|
117709
|
-
visitor(i);
|
|
117710
117711
|
}
|
|
117711
117712
|
|
|
117712
|
-
|
|
117713
|
-
|
|
117714
|
-
|
|
117715
|
-
|
|
117716
|
-
|
|
117717
|
-
|
|
117718
|
-
|
|
117719
|
-
this.bitSet.clear(id);
|
|
117720
|
-
};
|
|
117713
|
+
/**
|
|
117714
|
+
*
|
|
117715
|
+
* @param {number} id
|
|
117716
|
+
*/
|
|
117717
|
+
release(id) {
|
|
117718
|
+
this.#set.clear(id);
|
|
117719
|
+
}
|
|
117721
117720
|
|
|
117722
|
-
|
|
117723
|
-
|
|
117724
|
-
|
|
117721
|
+
/**
|
|
117722
|
+
* Release all used IDs
|
|
117723
|
+
*/
|
|
117724
|
+
reset() {
|
|
117725
|
+
this.#set.reset();
|
|
117726
|
+
}
|
|
117727
|
+
}
|
|
117725
117728
|
|
|
117726
117729
|
class AtlasPatch {
|
|
117727
117730
|
constructor() {
|
package/package.json
CHANGED
package/src/core/IdPool.js
CHANGED
|
@@ -7,86 +7,89 @@ import { assert } from "./assert.js";
|
|
|
7
7
|
import { BitSet } from "./binary/BitSet.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Pool of unsigned integer IDs, useful when you don't want to just keep incrementing ID counter and want to re-use IDs after they are no longer needed
|
|
11
|
+
* Main use case is when your IDs are array indices, having compact IDs lets you use fixed size array even as objects are added and removed as you're able to reuse slots in an efficient manner
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
class IdPool {
|
|
14
14
|
/**
|
|
15
15
|
* @private
|
|
16
16
|
* @type {BitSet}
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
}
|
|
18
|
+
#set = new BitSet();
|
|
20
19
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
20
|
+
/**
|
|
21
|
+
* Looks up next available ID without reserving it
|
|
22
|
+
* If you want to also reserve the ID - use {@link get} instead
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
peek() {
|
|
26
|
+
return this.#set.nextClearBit(0);
|
|
27
|
+
}
|
|
29
28
|
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
get() {
|
|
34
|
+
const id = this.peek();
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
this.#set.set(id, true);
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
}
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
41
40
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Attempt to request a specific ID from the pool.
|
|
43
|
+
* @param {number} id
|
|
44
|
+
* @return {boolean} true if request succeeds, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
getSpecific(id) {
|
|
47
|
+
if (this.isUsed(id)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.#set.set(id, true);
|
|
52
|
+
return true;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {number} id
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
*/
|
|
60
|
+
isUsed(id) {
|
|
61
|
+
return this.#set.get(id);
|
|
62
|
+
}
|
|
55
63
|
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return this.bitSet.get(id);
|
|
63
|
-
};
|
|
64
|
+
/**
|
|
65
|
+
* Traverse all IDs currently in use
|
|
66
|
+
* @param {function(id:number)} visitor
|
|
67
|
+
*/
|
|
68
|
+
traverseUsed(visitor) {
|
|
69
|
+
assert.isFunction(visitor, "visitor");
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
* Traverse all IDs currently in use
|
|
67
|
-
* @param {function(id:number)} visitor
|
|
68
|
-
*/
|
|
69
|
-
IdPool.prototype.traverseUsed = function (visitor) {
|
|
70
|
-
assert.equal(typeof visitor, 'function', `visitor must be a function, instead was '${typeof visitor}'`);
|
|
71
|
+
const set = this.#set;
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
for (let i = set.nextSetBit(0); i !== -1; i = set.nextSetBit(i + 1)) {
|
|
74
|
+
visitor(i);
|
|
75
|
+
}
|
|
73
76
|
|
|
74
|
-
for (let i = bitSet.nextSetBit(0); i !== -1; i = bitSet.nextSetBit(i + 1)) {
|
|
75
|
-
visitor(i);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.bitSet.clear(id);
|
|
86
|
-
};
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {number} id
|
|
82
|
+
*/
|
|
83
|
+
release(id) {
|
|
84
|
+
this.#set.clear(id);
|
|
85
|
+
}
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Release all used IDs
|
|
89
|
+
*/
|
|
90
|
+
reset() {
|
|
91
|
+
this.#set.reset();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
91
94
|
|
|
92
95
|
export default IdPool;
|
|
@@ -12,37 +12,37 @@ export function abstractJSONSerializer(source, serializers, classNames) {
|
|
|
12
12
|
return source;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// parameter is an object
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// extract type name
|
|
18
|
+
const Klass = source.constructor;
|
|
19
|
+
let typeName = classNames.get(Klass);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if (typeName === undefined) {
|
|
22
|
+
// try fallback to "typeName" field on constructor
|
|
23
|
+
typeName = Klass.typeName;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (typeName === undefined) {
|
|
27
|
+
throw new Error(`Failed to resolve type name. No name found in classNames registry and no .typeName field on the constructor {name: '${Klass.name}}'`);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
let serializer = serializers.get(typeName);
|
|
31
|
+
let serializerContext = undefined;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (serializer === undefined) {
|
|
34
|
+
serializer = source.toJSON;
|
|
35
|
+
serializerContext = source;
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (serializer === undefined) {
|
|
39
|
+
throw new Error(`Failed to resolve serializer for object type '${typeName}'. No serializer found in serializers registry and no .toJSON method on object itself`);
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
return {
|
|
43
|
+
type: typeName,
|
|
44
|
+
data: serializer.call(serializerContext, source)
|
|
45
|
+
};
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
}
|