@woosh/meep-engine 2.47.14 → 2.47.15

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.
@@ -117652,12 +117652,21 @@ function IdPool() {
117652
117652
  this.bitSet = new BitSet();
117653
117653
  }
117654
117654
 
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
+ };
117663
+
117655
117664
  /**
117656
117665
  *
117657
117666
  * @returns {number}
117658
117667
  */
117659
117668
  IdPool.prototype.get = function () {
117660
- const bitIndex = this.bitSet.nextClearBit(0);
117669
+ const bitIndex = this.peek();
117661
117670
 
117662
117671
  this.bitSet.set(bitIndex, true);
117663
117672
 
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.14",
8
+ "version": "2.47.15",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -18,12 +18,21 @@ function IdPool() {
18
18
  this.bitSet = new BitSet();
19
19
  }
20
20
 
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
+ }
29
+
21
30
  /**
22
31
  *
23
32
  * @returns {number}
24
33
  */
25
34
  IdPool.prototype.get = function () {
26
- const bitIndex = this.bitSet.nextClearBit(0);
35
+ const bitIndex = this.peek();
27
36
 
28
37
  this.bitSet.set(bitIndex, true);
29
38
 
@@ -127,6 +127,7 @@ export class NodeGraph {
127
127
  * Merge foreign nodes and associated connections into this graph
128
128
  * New node instances and connections will be created to reflect these inside this graph
129
129
  * NOTE: parameters on merged nodes are shallow copies
130
+ * NOTE: if IDs are available - copied nodes will have the same IDs as the originals
130
131
  * @param {NodeInstance[]} nodes
131
132
  * @param {Connection[]} [connections]
132
133
  * @returns {{connections:Connection[], nodes:NodeInstance[]}} local created instances
@@ -147,12 +148,28 @@ export class NodeGraph {
147
148
  for (let i = 0; i < additional_node_count; i++) {
148
149
  const other_node = nodes[i];
149
150
 
150
- const this_node_id = this.createNode(other_node.description);
151
- this_nodes[other_node.id] = this_node_id;
151
+ const other_node_id = other_node.id;
152
152
 
153
- // copy parameters
154
- const this_node = this.getNode(this_node_id);
153
+ const this_node = new NodeInstance();
154
+ this_node.setDescription(other_node.description);
155
+
156
+
157
+ // attempt to gain the same ID
158
+ const can_use_same_id = this.__idpNodes.isUsed(other_node_id);
159
+
160
+ let this_node_id;
161
+ if (can_use_same_id) {
162
+ this_node_id = other_node_id;
163
+ } else {
164
+ this_node_id = this.__idpNodes.peek();
165
+ }
155
166
 
167
+ this.addNode(this_node);
168
+
169
+
170
+ this_nodes[other_node_id] = this_node_id;
171
+
172
+ // copy parameters
156
173
  this_node.setParameters(other_node.parameters);
157
174
 
158
175
  }
@@ -376,13 +393,13 @@ export class NodeGraph {
376
393
  createNode(node) {
377
394
  const nodeInstance = new NodeInstance();
378
395
 
379
- const id = this.__idpNodes.get();
396
+ const id = this.__idpNodes.peek();
380
397
 
381
398
  nodeInstance.id = id;
382
399
  nodeInstance.setDescription(node);
383
400
 
384
401
  //record the node
385
- this.nodes.add(nodeInstance);
402
+ this.addNode(nodeInstance);
386
403
 
387
404
  return id;
388
405
  }
@@ -11,4 +11,8 @@ export class NodeInstance {
11
11
  readonly endpoints: NodeInstancePortReference[]
12
12
 
13
13
  readonly connections: List<Connection>
14
+
15
+ setDescription(d: NodeDescription): void
16
+
17
+ setParameters(hash: { [key: string]: any }): void
14
18
  }