@woosh/meep-engine 2.43.39 → 2.43.42
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/core/binary/BitSet.js +4 -18
- package/core/color/Color.js +1 -1
- package/core/geom/ConicRay.js +1 -1
- package/core/geom/Quaternion.js +1 -1
- package/core/geom/Vector1.js +1 -1
- package/core/geom/Vector3.js +1 -1
- package/core/geom/Vector4.js +1 -1
- package/core/math/hash/computeHashFloatArray.js +1 -1
- package/core/math/hash/computeObjectHash.js +1 -1
- package/core/math/interval/NumericInterval.js +1 -1
- package/core/model/BoundedValue.js +1 -1
- package/core/model/node-graph/Connection.js +47 -6
- package/core/model/node-graph/Connection.spec.js +21 -0
- package/core/model/node-graph/DataType.js +36 -13
- package/core/model/node-graph/DataType.spec.js +28 -0
- package/core/model/node-graph/NodeGraph.js +46 -12
- package/core/model/node-graph/node/NodeDescription.js +26 -16
- package/core/model/node-graph/node/NodeDescription.spec.js +14 -0
- package/core/model/node-graph/node/NodeInstance.js +10 -4
- package/core/model/node-graph/node/NodeInstancePortReference.js +18 -0
- package/core/model/node-graph/node/NodeRegistry.js +36 -10
- package/core/model/node-graph/node/NodeRegistry.spec.js +25 -0
- package/core/model/node-graph/node/Port.js +12 -1
- package/core/model/node-graph/node/PortDirection.js +1 -1
- package/core/model/node-graph/node/parameter/NodeParameterDescription.js +1 -1
- package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
- package/core/model/stat/LinearModifier.js +1 -1
- package/core/{math/hash → primitives/numbers}/computeHashFloat.js +0 -0
- package/core/{math/hash → primitives/numbers}/computeHashFloat.spec.js +0 -0
- package/engine/asset/loaders/material/computeMaterialHash.js +1 -1
- package/engine/asset/loaders/material/computeTextureHash.js +1 -1
- package/engine/ecs/animation/Animation.js +1 -1
- package/engine/ecs/animation/InverseKinematics.js +1 -1
- package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
- package/engine/ecs/gui/position/ViewportPosition.js +1 -1
- package/engine/graphics/ecs/animation/animator/AnimationClip.js +1 -1
- package/engine/graphics/ecs/animation/animator/AnimationNotification.js +1 -1
- package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +1 -1
- package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +1 -1
- package/engine/graphics/ecs/highlight/HighlightDefinition.js +1 -1
- package/engine/graphics/ecs/mesh/Mesh.js +1 -1
- package/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +1 -1
- package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
- package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +1 -1
- package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +1 -1
- package/engine/graphics/render/frame_graph/RenderGraph.js +5 -1
- package/engine/intelligence/behavior/SelectorBehavior.js +3 -1
- package/engine/intelligence/behavior/behavior_to_dot.js +251 -0
- package/engine/intelligence/behavior/behavior_to_dot.prototype.js +55 -0
- package/engine/intelligence/behavior/composite/CompositeBehavior.js +6 -0
- package/engine/intelligence/behavior/composite/ParallelBehavior.js +10 -0
- package/engine/intelligence/behavior/composite/SequenceBehavior.js +6 -50
- package/engine/intelligence/behavior/composite/SequenceBehaviorSerializationAdapter.js +52 -0
- package/engine/intelligence/behavior/selector/WeightedElement.js +1 -1
- package/engine/intelligence/blackboard/Blackboard.js +26 -14
- package/engine/intelligence/blackboard/Blackboard.spec.js +62 -0
- package/engine/intelligence/blackboard/{Blacboard.spec.js → BlackboardSerializationAdapter.spec.js} +1 -1
- package/engine/intelligence/mcts/README.md +7 -0
- package/engine/intelligence/optimization/RandomOptimizer.js +2 -1
- package/engine/intelligence/resource/ResourceAllocationBid.js +3 -3
- package/engine/intelligence/resource/ResourceAllocationSolver.js +1 -1
- package/engine/intelligence/resource/StrategicResourceAllocator.js +6 -4
- package/engine/intelligence/resource/TacticalModule.js +7 -0
- package/engine/knowledge/database/StaticKnowledgeDataTableDescriptor.js +5 -5
- package/engine/navigation/grid/GridField.js +1 -0
- package/engine/notify/NotificationLog.js +2 -2
- package/engine/sound/ecs/emitter/SoundEmitter.js +1 -1
- package/engine/sound/ecs/emitter/SoundTrack.js +1 -1
- package/package.json +1 -1
package/core/binary/BitSet.js
CHANGED
|
@@ -86,7 +86,6 @@ function BitSet() {
|
|
|
86
86
|
this.__data_uint32 = new Uint32Array(this.__capacity >> 5);
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
89
|
* @type {number}
|
|
91
90
|
*/
|
|
92
91
|
this.__shrinkFactor = SHRINK_FACTOR;
|
|
@@ -201,7 +200,7 @@ BitSet.prototype.__setLength = function (new_length) {
|
|
|
201
200
|
* @returns {int} Index of previous set bit, or -1 if no set bit found
|
|
202
201
|
*/
|
|
203
202
|
BitSet.prototype.previousSetBit = function (fromIndex) {
|
|
204
|
-
assert.
|
|
203
|
+
assert.isNonNegativeInteger(fromIndex, `fromIndex`);
|
|
205
204
|
|
|
206
205
|
const index = min2(fromIndex, this.__length - 1);
|
|
207
206
|
|
|
@@ -354,21 +353,6 @@ BitSet.prototype.nextClearBit = function (fromIndex) {
|
|
|
354
353
|
return set_length;
|
|
355
354
|
};
|
|
356
355
|
|
|
357
|
-
/**
|
|
358
|
-
* Slow method for scanning through bitset, used for debugging
|
|
359
|
-
* @param {BitSet} set
|
|
360
|
-
* @returns {number}
|
|
361
|
-
*/
|
|
362
|
-
function scanToFirstClearBit(set) {
|
|
363
|
-
for (let i = 0; i <= set.size(); i++) {
|
|
364
|
-
if (set.get(i) === false) {
|
|
365
|
-
return i;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return -1;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
356
|
/**
|
|
373
357
|
*
|
|
374
358
|
* @param {int} bitIndex
|
|
@@ -443,7 +427,9 @@ BitSet.prototype.setRange = function (startIndex, endIndex) {
|
|
|
443
427
|
* @param {number} endIndex clear up to here, excluding this position
|
|
444
428
|
*/
|
|
445
429
|
BitSet.prototype.clearRange = function (startIndex, endIndex) {
|
|
446
|
-
|
|
430
|
+
assert.greaterThanOrEqual(startIndex, 0, "invalid start index");
|
|
431
|
+
assert.greaterThanOrEqual(endIndex, 0, "invalid end index");
|
|
432
|
+
|
|
447
433
|
for (let i = startIndex; i < endIndex; i++) {
|
|
448
434
|
this.set(i, false);
|
|
449
435
|
}
|
package/core/color/Color.js
CHANGED
|
@@ -5,7 +5,7 @@ import { min2 } from "../math/min2.js";
|
|
|
5
5
|
import { max2 } from "../math/max2.js";
|
|
6
6
|
import { min3 } from "../math/min3.js";
|
|
7
7
|
import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
|
|
8
|
-
import { computeHashFloat } from "../
|
|
8
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
9
9
|
import { rgb2hsv } from "./rgb2hsv.js";
|
|
10
10
|
import { rgb2uint24 } from "./rgb2uint24.js";
|
|
11
11
|
import { clamp01 } from "../math/clamp01.js";
|
package/core/geom/ConicRay.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert } from "../assert.js";
|
|
2
2
|
import Vector3 from "./Vector3.js";
|
|
3
3
|
import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
|
|
4
|
-
import { computeHashFloat } from "../
|
|
4
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
5
5
|
import { epsilonEquals } from "../math/epsilonEquals.js";
|
|
6
6
|
import { EPSILON } from "../math/EPSILON.js";
|
|
7
7
|
|
package/core/geom/Quaternion.js
CHANGED
|
@@ -11,7 +11,7 @@ import { lerp } from "../math/lerp.js";
|
|
|
11
11
|
import Vector3 from "./Vector3.js";
|
|
12
12
|
import { v3_dot } from "./v3_dot.js";
|
|
13
13
|
import { min2 } from "../math/min2.js";
|
|
14
|
-
import { computeHashFloat } from "../
|
|
14
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
15
15
|
import { epsilonEquals } from "../math/epsilonEquals.js";
|
|
16
16
|
import { EPSILON } from "../math/EPSILON.js";
|
|
17
17
|
|
package/core/geom/Vector1.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { assert } from "../assert.js";
|
|
7
7
|
import Signal from "../events/signal/Signal.js";
|
|
8
8
|
import { clamp } from "../math/clamp.js";
|
|
9
|
-
import { computeHashFloat } from "../
|
|
9
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Vector1 extends Number {
|
package/core/geom/Vector3.js
CHANGED
|
@@ -13,7 +13,7 @@ import { v3_length } from "./v3_length.js";
|
|
|
13
13
|
import { v3_angle_between } from "./v3_angle_between.js";
|
|
14
14
|
import { v3_lerp } from "./v3_lerp.js";
|
|
15
15
|
import { v3_slerp } from "./v3_slerp.js";
|
|
16
|
-
import { computeHashFloat } from "../
|
|
16
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
17
17
|
import { epsilonEquals } from "../math/epsilonEquals.js";
|
|
18
18
|
import { EPSILON } from "../math/EPSILON.js";
|
|
19
19
|
|
package/core/geom/Vector4.js
CHANGED
|
@@ -6,7 +6,7 @@ import { assert } from "../assert.js";
|
|
|
6
6
|
import { Signal } from "../events/signal/Signal.js";
|
|
7
7
|
import { lerp } from "../math/lerp.js";
|
|
8
8
|
import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
|
|
9
|
-
import { computeHashFloat } from "../
|
|
9
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computeStringHash } from "../../primitives/strings/computeStringHash.js";
|
|
2
|
-
import { computeHashFloat } from "
|
|
2
|
+
import { computeHashFloat } from "../../primitives/numbers/computeHashFloat.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Recursively computes object hash
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { assert } from "../../assert.js";
|
|
8
8
|
import Signal from "../../events/signal/Signal.js";
|
|
9
9
|
import { inverseLerp } from "../inverseLerp.js";
|
|
10
|
-
import { computeHashFloat } from "
|
|
10
|
+
import { computeHashFloat } from "../../primitives/numbers/computeHashFloat.js";
|
|
11
11
|
|
|
12
12
|
export class NumericInterval {
|
|
13
13
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import Signal from "../events/signal/Signal.js";
|
|
7
7
|
import { inverseLerp } from "../math/inverseLerp.js";
|
|
8
|
-
import { computeHashFloat } from "../
|
|
8
|
+
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -3,13 +3,26 @@ import { noop } from "../../function/Functions.js";
|
|
|
3
3
|
import { objectKeyByValue } from "../object/objectKeyByValue.js";
|
|
4
4
|
import { PortDirection } from "./node/PortDirection.js";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type {number}
|
|
9
|
+
*/
|
|
10
|
+
let id_counter = 0;
|
|
11
|
+
|
|
6
12
|
export class Connection {
|
|
7
13
|
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* @readonly
|
|
16
|
+
* @type {number}
|
|
17
|
+
*/
|
|
18
|
+
this.id = id_counter++;
|
|
19
|
+
|
|
8
20
|
/**
|
|
9
21
|
*
|
|
10
22
|
* @type {NodeInstancePortReference}
|
|
11
23
|
*/
|
|
12
24
|
this.source = null;
|
|
25
|
+
|
|
13
26
|
/**
|
|
14
27
|
*
|
|
15
28
|
* @type {NodeInstancePortReference}
|
|
@@ -65,8 +78,8 @@ export class Connection {
|
|
|
65
78
|
* @param {NodeInstancePortReference} endpoint
|
|
66
79
|
*/
|
|
67
80
|
setSource(endpoint) {
|
|
68
|
-
assert.
|
|
69
|
-
assert.
|
|
81
|
+
assert.defined(endpoint, 'endpoint');
|
|
82
|
+
assert.notNull(endpoint, 'endpoint');
|
|
70
83
|
|
|
71
84
|
this.source = endpoint;
|
|
72
85
|
}
|
|
@@ -76,8 +89,8 @@ export class Connection {
|
|
|
76
89
|
* @param {NodeInstancePortReference} endpoint
|
|
77
90
|
*/
|
|
78
91
|
setTarget(endpoint) {
|
|
79
|
-
assert.
|
|
80
|
-
assert.
|
|
92
|
+
assert.defined(endpoint, 'endpoint');
|
|
93
|
+
assert.notNull(endpoint, 'endpoint');
|
|
81
94
|
|
|
82
95
|
this.target = endpoint;
|
|
83
96
|
}
|
|
@@ -88,9 +101,37 @@ export class Connection {
|
|
|
88
101
|
* @returns {boolean}
|
|
89
102
|
*/
|
|
90
103
|
isAttachedToNode(id) {
|
|
91
|
-
assert.
|
|
92
|
-
assert.
|
|
104
|
+
assert.isNumber(id, 'id');
|
|
105
|
+
assert.isInteger(id, 'id');
|
|
93
106
|
|
|
94
107
|
return this.source.instance.id === id || this.target.instance.id === id;
|
|
95
108
|
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @param {Connection} other
|
|
113
|
+
* @returns {boolean}
|
|
114
|
+
*/
|
|
115
|
+
equals(other) {
|
|
116
|
+
return this.target === other.target
|
|
117
|
+
&& this.source === other.source
|
|
118
|
+
;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
hash() {
|
|
122
|
+
const source_hash = this.source !== null ? this.source.id : 0;
|
|
123
|
+
const target_hash = this.target !== null ? this.target.id : 0;
|
|
124
|
+
|
|
125
|
+
// shuffle bits a bit to get better spread
|
|
126
|
+
return ((source_hash << 16) | (source_hash >>> 16))
|
|
127
|
+
^ (target_hash)
|
|
128
|
+
;
|
|
129
|
+
}
|
|
96
130
|
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @readonly
|
|
135
|
+
* @type {boolean}
|
|
136
|
+
*/
|
|
137
|
+
Connection.prototype.isConnection = true;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Connection } from "./Connection.js";
|
|
2
|
+
|
|
3
|
+
test("stable hash", () => {
|
|
4
|
+
const a = new Connection();
|
|
5
|
+
const b = new Connection();
|
|
6
|
+
|
|
7
|
+
expect(a.hash()).toEqual(b.hash());
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("equality of fresh instances", () => {
|
|
11
|
+
const a = new Connection();
|
|
12
|
+
const b = new Connection();
|
|
13
|
+
|
|
14
|
+
expect(a.equals(b)).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("equality on self", () => {
|
|
18
|
+
const thing = new Connection();
|
|
19
|
+
|
|
20
|
+
expect(thing.equals(thing)).toBe(true);
|
|
21
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
|
|
1
3
|
export class DataType {
|
|
2
4
|
constructor() {
|
|
3
5
|
/**
|
|
@@ -14,7 +16,15 @@ export class DataType {
|
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
toString() {
|
|
17
|
-
return
|
|
19
|
+
return `{DataType: id=${this.id}, name='${this.name}' }`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @return {number}
|
|
25
|
+
*/
|
|
26
|
+
hash() {
|
|
27
|
+
return this.id;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
/**
|
|
@@ -25,18 +35,31 @@ export class DataType {
|
|
|
25
35
|
equals(other) {
|
|
26
36
|
return this.id === other.id && this.name === other.name;
|
|
27
37
|
}
|
|
28
|
-
}
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @param {string} name
|
|
34
|
-
*/
|
|
35
|
-
DataType.from = function (id, name) {
|
|
36
|
-
const r = new DataType();
|
|
39
|
+
toJSON() {
|
|
40
|
+
return { ...this };
|
|
41
|
+
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
fromJSON({ id, name }) {
|
|
44
|
+
assert.isNonNegativeInteger(id, 'id');
|
|
45
|
+
assert.isString(name, 'name');
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
this.id = id;
|
|
48
|
+
this.name = name;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {number} id
|
|
54
|
+
* @param {string} name
|
|
55
|
+
* @returns {DataType}
|
|
56
|
+
*/
|
|
57
|
+
static from(id, name) {
|
|
58
|
+
const r = new DataType();
|
|
59
|
+
|
|
60
|
+
r.id = id;
|
|
61
|
+
r.name = name;
|
|
62
|
+
|
|
63
|
+
return r;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataType } from "./DataType.js";
|
|
2
|
+
|
|
3
|
+
test('to/from json', () => {
|
|
4
|
+
const a = DataType.from(7, 'kitty');
|
|
5
|
+
|
|
6
|
+
const b = new DataType();
|
|
7
|
+
|
|
8
|
+
b.fromJSON(a.toJSON());
|
|
9
|
+
|
|
10
|
+
expect(b.id).toBe(a.id);
|
|
11
|
+
expect(b.name).toBe(a.name);
|
|
12
|
+
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('equals', () => {
|
|
16
|
+
const a = DataType.from(7, 'kitty');
|
|
17
|
+
const b = DataType.from(7, 'kitty');
|
|
18
|
+
const c = DataType.from(7, 'fluffy');
|
|
19
|
+
const d = DataType.from(9, 'kitty');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
expect(a.equals(b)).toBe(true);
|
|
23
|
+
|
|
24
|
+
expect(a.equals(c)).toBe(false);
|
|
25
|
+
expect(a.equals(d)).toBe(false);
|
|
26
|
+
|
|
27
|
+
expect(c.equals(d)).toBe(false);
|
|
28
|
+
});
|
|
@@ -43,7 +43,7 @@ export class NodeGraph {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
*
|
|
46
|
-
* @param {function(NodeInstance)} visitor
|
|
46
|
+
* @param {function(NodeInstance):*} visitor
|
|
47
47
|
* @param [thisArg]
|
|
48
48
|
*/
|
|
49
49
|
traverseNodes(visitor, thisArg) {
|
|
@@ -52,7 +52,7 @@ export class NodeGraph {
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
55
|
-
* @param {function(Connection)} visitor
|
|
55
|
+
* @param {function(Connection):*} visitor
|
|
56
56
|
* @param [thisArg]
|
|
57
57
|
*/
|
|
58
58
|
traverseConnections(visitor, thisArg) {
|
|
@@ -62,34 +62,61 @@ export class NodeGraph {
|
|
|
62
62
|
/**
|
|
63
63
|
*
|
|
64
64
|
* @param {number} id
|
|
65
|
-
* @returns {NodeInstance}
|
|
65
|
+
* @returns {NodeInstance|undefined}
|
|
66
66
|
*/
|
|
67
67
|
getNode(id) {
|
|
68
|
-
|
|
68
|
+
const nodes = this.nodes;
|
|
69
|
+
const n = nodes.length;
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < n; i++) {
|
|
72
|
+
const node = nodes[i];
|
|
73
|
+
|
|
74
|
+
if (node.id === id) {
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// node not found, return undefined
|
|
80
|
+
return undefined;
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
/**
|
|
72
84
|
*
|
|
73
85
|
* @param {number} id
|
|
74
|
-
* @returns {Connection}
|
|
86
|
+
* @returns {Connection|undefined}
|
|
75
87
|
*/
|
|
76
88
|
getConnection(id) {
|
|
77
|
-
|
|
89
|
+
const connections = this.connections;
|
|
90
|
+
const n = connections.length;
|
|
91
|
+
|
|
92
|
+
for (let i = 0; i < n; i++) {
|
|
93
|
+
const connection = connections[i];
|
|
94
|
+
|
|
95
|
+
if (connection.id === id) {
|
|
96
|
+
return connection;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// nothing found, undefined will be returned
|
|
101
|
+
return undefined;
|
|
78
102
|
}
|
|
79
103
|
|
|
80
104
|
/**
|
|
81
105
|
*
|
|
82
106
|
* @param {number} node_id
|
|
83
107
|
* @param {number} port_id
|
|
84
|
-
* @returns {NodeInstancePortReference}
|
|
108
|
+
* @returns {NodeInstancePortReference|undefined}
|
|
85
109
|
*/
|
|
86
110
|
getConnectionEndpoint(node_id, port_id) {
|
|
87
111
|
|
|
88
112
|
const nodeInstance = this.getNode(node_id);
|
|
89
113
|
|
|
90
|
-
|
|
114
|
+
if (nodeInstance === undefined) {
|
|
115
|
+
// no node
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
91
118
|
|
|
92
|
-
return
|
|
119
|
+
return nodeInstance.getEndpoint(port_id);
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
/**
|
|
@@ -123,7 +150,7 @@ export class NodeGraph {
|
|
|
123
150
|
|
|
124
151
|
const id_obtained = this.__idpNodes.getSpecific(node.id);
|
|
125
152
|
|
|
126
|
-
if (
|
|
153
|
+
if (id_obtained === false) {
|
|
127
154
|
throw new Error(`Node with id '${node.id}' already exists`);
|
|
128
155
|
}
|
|
129
156
|
|
|
@@ -195,13 +222,13 @@ export class NodeGraph {
|
|
|
195
222
|
//get endpoints
|
|
196
223
|
const sourceEndpoint = sourceNodeInstance.getEndpoint(sourcePort);
|
|
197
224
|
|
|
198
|
-
if (sourceEndpoint ===
|
|
225
|
+
if (sourceEndpoint === undefined) {
|
|
199
226
|
throw new Error(`Source port '${sourcePort}' not found`);
|
|
200
227
|
}
|
|
201
228
|
|
|
202
229
|
const targetEndpoint = targetNodeInstance.getEndpoint(targetPort);
|
|
203
230
|
|
|
204
|
-
if (targetEndpoint ===
|
|
231
|
+
if (targetEndpoint === undefined) {
|
|
205
232
|
throw new Error(`Target port '${targetPort}' not found`);
|
|
206
233
|
}
|
|
207
234
|
|
|
@@ -241,6 +268,7 @@ export class NodeGraph {
|
|
|
241
268
|
*
|
|
242
269
|
* @param {number} id
|
|
243
270
|
* @param {number[]} result IDs of attached connections
|
|
271
|
+
* @returns {number} number of found connections
|
|
244
272
|
*/
|
|
245
273
|
getConnectionsAttachedToNode(id, result) {
|
|
246
274
|
let count = 0;
|
|
@@ -262,3 +290,9 @@ export class NodeGraph {
|
|
|
262
290
|
return count;
|
|
263
291
|
}
|
|
264
292
|
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @readonly
|
|
296
|
+
* @type {boolean}
|
|
297
|
+
*/
|
|
298
|
+
NodeGraph.prototype.isNodeGraph = true;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assert } from "../../../assert.js";
|
|
2
|
-
import { BitSet } from "../../../binary/BitSet.js";
|
|
3
2
|
import { NodeParameterDataType } from "./parameter/NodeParameterDataType.js";
|
|
4
3
|
import { NodeParameterDescription } from "./parameter/NodeParameterDescription.js";
|
|
5
4
|
import { Port } from "./Port.js";
|
|
@@ -11,17 +10,22 @@ import { Port } from "./Port.js";
|
|
|
11
10
|
* @returns {number}
|
|
12
11
|
*/
|
|
13
12
|
function pickNewSetId(things) {
|
|
14
|
-
const ids = new BitSet();
|
|
15
13
|
|
|
16
|
-
things.forEach((v, id) => ids.set(id, true));
|
|
17
14
|
|
|
18
|
-
const
|
|
15
|
+
const n = things.length;
|
|
16
|
+
|
|
17
|
+
let r = n;
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < n; i++) {
|
|
20
|
+
|
|
21
|
+
if (things[i] === undefined) {
|
|
22
|
+
r = i;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
19
25
|
|
|
20
|
-
if (id === -1) {
|
|
21
|
-
return 0;
|
|
22
|
-
} else {
|
|
23
|
-
return id;
|
|
24
26
|
}
|
|
27
|
+
|
|
28
|
+
return r;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export class NodeDescription {
|
|
@@ -61,22 +65,22 @@ export class NodeDescription {
|
|
|
61
65
|
createParameter(name, type, defaultValue) {
|
|
62
66
|
|
|
63
67
|
assert.typeOf(name, 'string', 'name');
|
|
64
|
-
assert.
|
|
68
|
+
assert.enum(type, NodeParameterDataType, 'type');
|
|
65
69
|
|
|
70
|
+
let _default = defaultValue;
|
|
66
71
|
|
|
67
72
|
//if default value is not given, pick one
|
|
68
|
-
if (
|
|
73
|
+
if (_default === undefined) {
|
|
69
74
|
switch (type) {
|
|
70
|
-
case NodeParameterDataType.Integer:
|
|
71
75
|
//intended fallthrough
|
|
72
|
-
case NodeParameterDataType.
|
|
73
|
-
|
|
76
|
+
case NodeParameterDataType.Number:
|
|
77
|
+
_default = 0;
|
|
74
78
|
break;
|
|
75
79
|
case NodeParameterDataType.Boolean:
|
|
76
|
-
|
|
80
|
+
_default = false;
|
|
77
81
|
break;
|
|
78
82
|
case NodeParameterDataType.String:
|
|
79
|
-
|
|
83
|
+
_default = "";
|
|
80
84
|
break;
|
|
81
85
|
default:
|
|
82
86
|
throw new Error(`Unknown data type '${type}'`);
|
|
@@ -90,7 +94,7 @@ export class NodeDescription {
|
|
|
90
94
|
|
|
91
95
|
pd.name = name;
|
|
92
96
|
pd.type = type;
|
|
93
|
-
pd.defaultValue =
|
|
97
|
+
pd.defaultValue = _default;
|
|
94
98
|
pd.id = id;
|
|
95
99
|
|
|
96
100
|
assert.ok(pd.validate(console.error), 'parameter is not valid');
|
|
@@ -185,3 +189,9 @@ export class NodeDescription {
|
|
|
185
189
|
return this.ports
|
|
186
190
|
}
|
|
187
191
|
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @readonly
|
|
195
|
+
* @type {boolean}
|
|
196
|
+
*/
|
|
197
|
+
NodeDescription.prototype.isNodeDescription = true;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NodeDescription } from "./NodeDescription.js";
|
|
2
|
+
import { DataType } from "../DataType.js";
|
|
3
|
+
import { PortDirection } from "./PortDirection.js";
|
|
4
|
+
|
|
5
|
+
const DUMMY_TYPE = DataType.from(0, 'dummy');
|
|
6
|
+
|
|
7
|
+
test('ports are assigned unique IDs', () => {
|
|
8
|
+
const node = new NodeDescription();
|
|
9
|
+
|
|
10
|
+
const id_a = node.createPort(DUMMY_TYPE, 'a', PortDirection.Unspecified);
|
|
11
|
+
const id_b = node.createPort(DUMMY_TYPE, 'b', PortDirection.Unspecified);
|
|
12
|
+
|
|
13
|
+
expect(id_a).not.toEqual(id_b);
|
|
14
|
+
});
|
|
@@ -4,13 +4,19 @@ import { NodeInstancePortReference } from "./NodeInstancePortReference.js";
|
|
|
4
4
|
import { PortDirection } from "./PortDirection.js";
|
|
5
5
|
import { isArrayEqual } from "../../../collection/array/isArrayEqual.js";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {number}
|
|
10
|
+
*/
|
|
11
|
+
let id_counter = 0;
|
|
12
|
+
|
|
7
13
|
export class NodeInstance {
|
|
8
14
|
constructor() {
|
|
9
15
|
/**
|
|
10
16
|
*
|
|
11
17
|
* @type {number}
|
|
12
18
|
*/
|
|
13
|
-
this.id =
|
|
19
|
+
this.id = id_counter++;
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
22
|
*
|
|
@@ -148,8 +154,8 @@ export class NodeInstance {
|
|
|
148
154
|
|
|
149
155
|
/**
|
|
150
156
|
*
|
|
151
|
-
* @param {number} port Port
|
|
152
|
-
* @returns {
|
|
157
|
+
* @param {number} port Port ID
|
|
158
|
+
* @returns {NodeInstancePortReference|undefined}
|
|
153
159
|
*/
|
|
154
160
|
getEndpoint(port) {
|
|
155
161
|
const endpoints = this.endpoints;
|
|
@@ -161,7 +167,7 @@ export class NodeInstance {
|
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
//not found
|
|
164
|
-
return
|
|
170
|
+
return undefined;
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
hash() {
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { assert } from "../../../assert.js";
|
|
2
2
|
import { computeHashIntegerArray } from "../../../collection/array/computeHashIntegerArray.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @type {number}
|
|
7
|
+
*/
|
|
8
|
+
let id_counter = 0;
|
|
9
|
+
|
|
4
10
|
/**
|
|
5
11
|
* Reference for a port of a node instance
|
|
6
12
|
*/
|
|
7
13
|
export class NodeInstancePortReference {
|
|
8
14
|
|
|
9
15
|
constructor() {
|
|
16
|
+
/**
|
|
17
|
+
* @readonly
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
this.id = id_counter++;
|
|
21
|
+
|
|
10
22
|
/**
|
|
11
23
|
*
|
|
12
24
|
* @type {NodeInstance}
|
|
@@ -75,3 +87,9 @@ export class NodeInstancePortReference {
|
|
|
75
87
|
;
|
|
76
88
|
}
|
|
77
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @readonly
|
|
93
|
+
* @type {boolean}
|
|
94
|
+
*/
|
|
95
|
+
NodeInstancePortReference.prototype.isNodeInstancePortReference = true;
|