@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.
@@ -117641,87 +117641,90 @@ class MaxRectanglesPacker {
117641
117641
  */
117642
117642
 
117643
117643
  /**
117644
- *
117645
- * @constructor
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
- function IdPool() {
117647
+ class IdPool {
117648
117648
  /**
117649
117649
  * @private
117650
117650
  * @type {BitSet}
117651
117651
  */
117652
- this.bitSet = new BitSet();
117653
- }
117652
+ #set = new BitSet();
117654
117653
 
117655
- /**
117656
- * Looks up next available ID without reserving it
117657
- * If you want to also reserve the ID - use {@link get} instead
117658
- * @returns {number}
117659
- */
117660
- IdPool.prototype.peek = function () {
117661
- return this.bitSet.nextClearBit(0);
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
- * @returns {number}
117667
- */
117668
- IdPool.prototype.get = function () {
117669
- const bitIndex = this.peek();
117663
+ /**
117664
+ *
117665
+ * @returns {number}
117666
+ */
117667
+ get() {
117668
+ const id = this.peek();
117670
117669
 
117671
- this.bitSet.set(bitIndex, true);
117670
+ this.#set.set(id, true);
117672
117671
 
117673
- return bitIndex;
117674
- };
117672
+ return id;
117673
+ }
117675
117674
 
117676
- /**
117677
- * Attempt to request a specific ID from the pool.
117678
- * @param {number} id
117679
- * @return {boolean} true if request succeeds, false otherwise
117680
- */
117681
- IdPool.prototype.getSpecific = function (id) {
117682
- if (this.isUsed(id)) {
117683
- return false;
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
- this.bitSet.set(id, true);
117687
- return true;
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
- * @param {number} id
117693
- * @returns {boolean}
117694
- */
117695
- IdPool.prototype.isUsed = function (id) {
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
- const bitSet = this.bitSet;
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
- * @param {number} id
117717
- */
117718
- IdPool.prototype.release = function (id) {
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
- IdPool.prototype.reset = function () {
117723
- this.bitSet.reset();
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
@@ -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.47.15",
8
+ "version": "2.47.16",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -7,86 +7,89 @@ import { assert } from "./assert.js";
7
7
  import { BitSet } from "./binary/BitSet.js";
8
8
 
9
9
  /**
10
- *
11
- * @constructor
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
- function IdPool() {
13
+ class IdPool {
14
14
  /**
15
15
  * @private
16
16
  * @type {BitSet}
17
17
  */
18
- this.bitSet = new BitSet();
19
- }
18
+ #set = new BitSet();
20
19
 
21
- /**
22
- * Looks up next available ID without reserving it
23
- * If you want to also reserve the ID - use {@link get} instead
24
- * @returns {number}
25
- */
26
- IdPool.prototype.peek = function () {
27
- return this.bitSet.nextClearBit(0);
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
- * @returns {number}
33
- */
34
- IdPool.prototype.get = function () {
35
- const bitIndex = this.peek();
29
+ /**
30
+ *
31
+ * @returns {number}
32
+ */
33
+ get() {
34
+ const id = this.peek();
36
35
 
37
- this.bitSet.set(bitIndex, true);
36
+ this.#set.set(id, true);
38
37
 
39
- return bitIndex;
40
- };
38
+ return id;
39
+ }
41
40
 
42
- /**
43
- * Attempt to request a specific ID from the pool.
44
- * @param {number} id
45
- * @return {boolean} true if request succeeds, false otherwise
46
- */
47
- IdPool.prototype.getSpecific = function (id) {
48
- if (this.isUsed(id)) {
49
- return false;
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
- this.bitSet.set(id, true);
53
- return true;
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
- * @param {number} id
59
- * @returns {boolean}
60
- */
61
- IdPool.prototype.isUsed = function (id) {
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
- const bitSet = this.bitSet;
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
- * @param {number} id
83
- */
84
- IdPool.prototype.release = function (id) {
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
- IdPool.prototype.reset = function () {
89
- this.bitSet.reset();
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
- // parameter is an object
15
+ // parameter is an object
16
16
 
17
- // extract type name
18
- const Klass = source.constructor;
19
- let typeName = classNames.get(Klass);
17
+ // extract type name
18
+ const Klass = source.constructor;
19
+ let typeName = classNames.get(Klass);
20
20
 
21
- if (typeName === undefined) {
22
- // try fallback to "typeName" field on constructor
23
- typeName = Klass.typeName;
24
- }
21
+ if (typeName === undefined) {
22
+ // try fallback to "typeName" field on constructor
23
+ typeName = Klass.typeName;
24
+ }
25
25
 
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`);
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
- let serializer = serializers.get(typeName);
31
- let serializerContext = undefined;
30
+ let serializer = serializers.get(typeName);
31
+ let serializerContext = undefined;
32
32
 
33
- if (serializer === undefined) {
34
- serializer = source.toJSON;
35
- serializerContext = source;
36
- }
33
+ if (serializer === undefined) {
34
+ serializer = source.toJSON;
35
+ serializerContext = source;
36
+ }
37
37
 
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
- }
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
- return {
43
- type: typeName,
44
- data: serializer.call(serializerContext, source)
45
- };
42
+ return {
43
+ type: typeName,
44
+ data: serializer.call(serializerContext, source)
45
+ };
46
46
 
47
47
 
48
48
  }