@woosh/meep-engine 2.36.26 → 2.36.29

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.
Files changed (106) hide show
  1. package/core/bvh2/bvh3/{bvh_query_user_data_by_frustum.js → bvh_query_user_data_overlaps_frustum.js} +4 -5
  2. package/core/color/Color.js +54 -3
  3. package/core/color/hsv2rgb.js +3 -3
  4. package/core/color/kelvin_to_rgb.js +51 -0
  5. package/core/color/kelvin_to_rgb.spec.js +61 -0
  6. package/core/color/linear_to_sRGB.js +17 -0
  7. package/core/color/prototype_kelvin_to_rgb.js +44 -0
  8. package/core/color/rgb_to_kelvin.js +34 -0
  9. package/core/color/rgb_to_kelvin.spec.js +15 -0
  10. package/core/color/sRGB_to_linear.js +16 -0
  11. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +2 -2
  12. package/core/geom/LineSegment.js +2 -2
  13. package/core/geom/Vector3.js +14 -0
  14. package/core/math/DEG_TO_RAD.js +1 -0
  15. package/core/math/MathUtils.spec.js +0 -13
  16. package/core/math/RAD_TO_DEG.js +1 -0
  17. package/core/math/clamp01.js +15 -0
  18. package/core/math/fract.js +10 -0
  19. package/core/math/newton_solver_1d.js +21 -0
  20. package/core/math/smoothStep.js +3 -3
  21. package/core/math/solveQuadratic.js +32 -12
  22. package/core/math/solveQuadratic.spec.js +18 -0
  23. package/core/primitives/strings/StringUtils.js +10 -0
  24. package/core/process/task/TaskUtils.js +2 -2
  25. package/editor/view/ecs/components/color/GaugeView.js +2 -2
  26. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +5 -4
  27. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +5 -3
  28. package/engine/Clock.js +4 -0
  29. package/engine/UserController.js +2 -1
  30. package/engine/animation/behavior/animateProperty.js +6 -1
  31. package/engine/animation/keyed2/behavior/AnimationBehavior.js +0 -1
  32. package/engine/ecs/EntityBuilder.js +12 -1
  33. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -1
  34. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +2 -1
  35. package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +14 -11
  36. package/engine/ecs/systems/AimControllerSystem.js +3 -2
  37. package/engine/ecs/systems/RangedAttackSystem.js +3 -2
  38. package/engine/ecs/systems/SteeringSystem.js +3 -3
  39. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  40. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
  41. package/engine/graphics/GraphicsEngine.js +2 -1
  42. package/engine/graphics/camera/CameraShake.js +4 -4
  43. package/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +2 -2
  44. package/engine/graphics/ecs/camera/TiltCameraController.js +3 -2
  45. package/engine/graphics/ecs/compileAllMaterials.js +2 -2
  46. package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +14 -24
  47. package/engine/graphics/ecs/light/LightSystem.js +2 -3
  48. package/engine/graphics/ecs/mesh/createTaskWaitForMeshesToLoad.js +2 -2
  49. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  50. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +19 -0
  51. package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +4 -2
  52. package/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +9 -0
  53. package/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +11 -0
  54. package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +3 -0
  55. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +31 -0
  56. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -2
  57. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -82
  58. package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +28 -3
  59. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -3
  60. package/engine/graphics/render/gizmo/Gizmo.js +3 -0
  61. package/engine/graphics/render/gizmo/GizmoRenderingPlugin.js +5 -0
  62. package/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +91 -0
  63. package/engine/graphics/texture/sampler/Sampler2D.js +110 -18
  64. package/engine/graphics/three/OrbitControls.js +3 -2
  65. package/engine/graphics/trail/x/simulator/RibbonXFixedPhysicsSimulator.js +2 -2
  66. package/engine/graphics/util/makeMeshPreviewScene.js +11 -3
  67. package/engine/intelligence/behavior/Behavior.js +36 -17
  68. package/engine/intelligence/behavior/SelectorBehavior.js +6 -5
  69. package/engine/intelligence/behavior/composite/ParallelBehavior.js +0 -66
  70. package/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.js +63 -0
  71. package/engine/intelligence/behavior/composite/SequenceBehavior.js +36 -11
  72. package/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +0 -2
  73. package/engine/intelligence/behavior/decorator/IgnoreFailureBehavior.js +2 -4
  74. package/engine/intelligence/behavior/decorator/InverterBehavior.js +3 -3
  75. package/engine/intelligence/behavior/decorator/RepeatBehavior.js +0 -35
  76. package/engine/intelligence/behavior/decorator/RepeatBehavior.spec.js +0 -10
  77. package/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.js +37 -0
  78. package/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -3
  79. package/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.js +5 -10
  80. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +95 -7
  81. package/engine/intelligence/behavior/ecs/BehaviorComponentSerializationAdapter.js +15 -8
  82. package/engine/intelligence/behavior/ecs/BehaviorSystem.js +28 -37
  83. package/engine/intelligence/behavior/ecs/DieBehavior.js +2 -7
  84. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +2 -29
  85. package/engine/intelligence/behavior/ecs/WaitForEventBehaviorSerializationAdapter.js +29 -0
  86. package/engine/intelligence/behavior/primitive/ActionBehavior.js +6 -13
  87. package/engine/intelligence/behavior/primitive/FailingBehavior.js +1 -29
  88. package/engine/intelligence/behavior/primitive/FailingBehaviorSerializationAdapter.js +29 -0
  89. package/engine/intelligence/behavior/primitive/PromiseBehavior.js +15 -3
  90. package/engine/intelligence/behavior/selector/WeightedRandomBehavior.js +1 -5
  91. package/engine/intelligence/behavior/util/ConditionBehavior.js +1 -3
  92. package/engine/intelligence/behavior/util/ConditionBehavior.spec.js +1 -7
  93. package/engine/intelligence/behavior/util/ConditionalBehavior.js +3 -6
  94. package/engine/intelligence/behavior/util/DelayBehavior.js +2 -4
  95. package/engine/intelligence/behavior/util/SelectorBehavior.js +13 -12
  96. package/engine/intelligence/blackboard/AbstractBlackboard.js +16 -2
  97. package/engine/plugin/EnginePluginManager.js +4 -14
  98. package/engine/sound/ecs/emitter/SoundEmitter.js +3 -0
  99. package/generation/filtering/numeric/math/CellFilterSaturate.js +2 -2
  100. package/generation/grid/generation/GridTaskDensityMarkerDistribution.js +3 -2
  101. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +1 -1
  102. package/generation/rules/CellMatcherLayerBitMaskTest.js +3 -3
  103. package/package.json +1 -1
  104. package/view/elements/progress/SmoothProgressBar.js +2 -2
  105. package/view/elements/progress/segmented/SegmentedResourceBarView.js +3 -3
  106. package/view/elements/radial/RadialProgressView.js +2 -2
@@ -1,55 +1,74 @@
1
1
  import { BehaviorStatus } from "./BehaviorStatus.js";
2
- import { assert } from "../../../core/assert.js";
3
2
 
3
+ /**
4
+ * Base class of behavior tree implementation
5
+ */
4
6
  export class Behavior {
5
7
  constructor() {
6
8
  /**
7
- *
9
+ * Any internal state used by the behavior
8
10
  * @type {*}
9
11
  */
10
12
  this.context = null;
13
+ }
11
14
 
12
- /**
13
- *
14
- * @type {BehaviorStatus}
15
- * @protected
16
- */
17
- this.__status = BehaviorStatus.Initial;
15
+ /**
16
+ * @deprecated
17
+ * @private
18
+ * @returns {BehaviorStatus}
19
+ */
20
+ get __status() {
21
+ throw new Error('Deprecated');
18
22
  }
19
23
 
20
24
  /**
21
- *
25
+ * @deprecated
26
+ * @param {BehaviorStatus} v
27
+ * @private
28
+ */
29
+ set __status(v) {
30
+ throw new Error('Deprecated');
31
+ }
32
+
33
+ /**
34
+ * @deprecated
22
35
  * @returns {BehaviorStatus}
23
36
  */
24
37
  getStatus() {
25
- return this.__status;
38
+ throw new Error('Deprecated');
26
39
  }
27
40
 
28
41
  /**
29
- * NOTE: Be careful when setting this directly, make sure that finalization and initialization are handled properly
42
+ * @deprecated
30
43
  * @param {BehaviorStatus} s
31
44
  */
32
45
  setStatus(s) {
33
- assert.ok(Object.values(BehaviorStatus).includes(s), `'${s}' is not a valid BehaviorStatus`);
34
-
35
- this.__status = s;
46
+ throw new Error('Deprecated');
36
47
  }
37
48
 
38
49
  /**
39
- * @param {number} timeDelta
50
+ * Main update function
51
+ * @param {number} timeDelta time step in seconds
40
52
  * @returns {BehaviorStatus}
41
53
  */
42
54
  tick(timeDelta) {
43
55
  throw new Error('Abstract method, needs to be overridden');
44
56
  }
45
57
 
58
+ /**
59
+ * Called before behavior gets executed via {@link #tick} for the first time
60
+ * Used to prepare the behavior for execution
61
+ * @param {*} [context]
62
+ */
46
63
  initialize(context) {
47
64
  this.context = context;
48
- this.__status = BehaviorStatus.Running;
49
65
  }
50
66
 
67
+ /**
68
+ * Called when behavior is finished, or interrupted
69
+ * Used to clean up any resources
70
+ */
51
71
  finalize() {
52
- this.__status = BehaviorStatus.Initial;
53
72
  }
54
73
  }
55
74
 
@@ -21,20 +21,23 @@ export class SelectorBehavior extends CompositeBehavior {
21
21
  }
22
22
 
23
23
  tick(timeDelta) {
24
+ if (this.__children.length < 1) {
25
+ // no options, nothing chosen
26
+ return BehaviorStatus.Failed;
27
+ }
28
+
24
29
  //keep going until a child behavior says it's running
25
- for (;;) {
30
+ for (; ;) {
26
31
  const s = this.__currentBehaviour.tick(timeDelta);
27
32
 
28
33
  //if child succeeds or keeps running, do the same
29
34
  if (s !== BehaviorStatus.Failed) {
30
- this.__status = s;
31
35
  return s;
32
36
  }
33
37
 
34
38
  //Continue search for a fallback until the last child
35
39
  const children = this.__children;
36
40
  if (this.__currentBehaviourIndex + 1 >= children.length) {
37
- this.__status = BehaviorStatus.Failed;
38
41
  return BehaviorStatus.Failed;
39
42
  }
40
43
 
@@ -48,7 +51,5 @@ export class SelectorBehavior extends CompositeBehavior {
48
51
  this.__currentBehaviour = this.__children[0];
49
52
 
50
53
  this.__currentBehaviour.initialize();
51
-
52
- this.__status = BehaviorStatus.Running;
53
54
  }
54
55
  }
@@ -1,7 +1,6 @@
1
1
  import { CompositeBehavior } from "./CompositeBehavior.js";
2
2
  import { BehaviorStatus } from "../BehaviorStatus.js";
3
3
  import { BitSet } from "../../../../core/binary/BitSet.js";
4
- import { ObjectBasedClassSerializationAdapter } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
5
4
 
6
5
  /**
7
6
  *
@@ -122,7 +121,6 @@ export class ParallelBehavior extends CompositeBehavior {
122
121
 
123
122
  this.__finalizeActiveChildren();
124
123
 
125
- this.__status = BehaviorStatus.Succeeded;
126
124
  return BehaviorStatus.Succeeded;
127
125
 
128
126
  }
@@ -138,14 +136,12 @@ export class ParallelBehavior extends CompositeBehavior {
138
136
 
139
137
  this.__finalizeActiveChildren();
140
138
 
141
- this.__status = BehaviorStatus.Failed;
142
139
  return BehaviorStatus.Failed;
143
140
 
144
141
  } else if (this.successPolicy === ParallelBehaviorPolicy.RequireAll) {
145
142
 
146
143
  this.__finalizeActiveChildren();
147
144
 
148
- this.__status = BehaviorStatus.Failed;
149
145
  return BehaviorStatus.Failed;
150
146
 
151
147
  }
@@ -155,22 +151,18 @@ export class ParallelBehavior extends CompositeBehavior {
155
151
 
156
152
  if (this.successCount === numChildren && this.successPolicy === ParallelBehaviorPolicy.RequireAll) {
157
153
 
158
- this.__status = BehaviorStatus.Succeeded;
159
154
  return BehaviorStatus.Succeeded;
160
155
 
161
156
  } else if (this.failureCount === numChildren && this.failurePolicy === ParallelBehaviorPolicy.RequireAll) {
162
157
 
163
- this.__status = BehaviorStatus.Failed;
164
158
  return BehaviorStatus.Failed;
165
159
 
166
160
  } else if ((this.failureCount + this.successCount) === numChildren) {
167
161
 
168
- this.__status = BehaviorStatus.Failed;
169
162
  return BehaviorStatus.Failed;
170
163
 
171
164
  } else {
172
165
 
173
- this.__status = BehaviorStatus.Running;
174
166
  return BehaviorStatus.Running;
175
167
 
176
168
  }
@@ -236,61 +228,3 @@ export class ParallelBehavior extends CompositeBehavior {
236
228
 
237
229
  ParallelBehavior.typeName = "ParallelBehavior";
238
230
 
239
- export class ParallelBehaviorSerializationAdapter extends ObjectBasedClassSerializationAdapter {
240
- constructor() {
241
- super();
242
-
243
- this.klass = ParallelBehavior;
244
- this.version = 0;
245
- }
246
-
247
- /**
248
- *
249
- * @param {BinaryBuffer} buffer
250
- * @param {ParallelBehavior} value
251
- */
252
- serialize(buffer, value) {
253
-
254
- buffer.writeUint8(value.getSuccessPolicy());
255
- buffer.writeUint8(value.getFailurePolicy());
256
-
257
- const children = value.getChildren();
258
-
259
- const n = children.length;
260
-
261
- buffer.writeUintVar(n);
262
-
263
- for (let i = 0; i < n; i++) {
264
- const behavior = children[i];
265
-
266
- this.objectAdapter.serialize(buffer, behavior);
267
- }
268
- }
269
-
270
- /**
271
- *
272
- * @param {BinaryBuffer} buffer
273
- * @param {ParallelBehavior} value
274
- */
275
- deserialize(buffer, value) {
276
- const successPolicy = buffer.readUint8();
277
- const failurePolicy = buffer.readUint8();
278
-
279
- const count = buffer.readUintVar();
280
-
281
- value.clearChildren();
282
-
283
- for (let i = 0; i < count; i++) {
284
- /**
285
- *
286
- * @type {Behavior}
287
- */
288
- const child = this.objectAdapter.deserialize(buffer);
289
-
290
- value.addChild(child);
291
- }
292
-
293
- value.setFailurePolicy(failurePolicy);
294
- value.setSuccessPolicy(successPolicy);
295
- }
296
- }
@@ -0,0 +1,63 @@
1
+ import {
2
+ ObjectBasedClassSerializationAdapter
3
+ } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
4
+ import { ParallelBehavior } from "./ParallelBehavior.js";
5
+
6
+ export class ParallelBehaviorSerializationAdapter extends ObjectBasedClassSerializationAdapter {
7
+ constructor() {
8
+ super();
9
+
10
+ this.klass = ParallelBehavior;
11
+ this.version = 0;
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param {BinaryBuffer} buffer
17
+ * @param {ParallelBehavior} value
18
+ */
19
+ serialize(buffer, value) {
20
+
21
+ buffer.writeUint8(value.getSuccessPolicy());
22
+ buffer.writeUint8(value.getFailurePolicy());
23
+
24
+ const children = value.getChildren();
25
+
26
+ const n = children.length;
27
+
28
+ buffer.writeUintVar(n);
29
+
30
+ for (let i = 0; i < n; i++) {
31
+ const behavior = children[i];
32
+
33
+ this.objectAdapter.serialize(buffer, behavior);
34
+ }
35
+ }
36
+
37
+ /**
38
+ *
39
+ * @param {BinaryBuffer} buffer
40
+ * @param {ParallelBehavior} value
41
+ */
42
+ deserialize(buffer, value) {
43
+ const successPolicy = buffer.readUint8();
44
+ const failurePolicy = buffer.readUint8();
45
+
46
+ const count = buffer.readUintVar();
47
+
48
+ value.clearChildren();
49
+
50
+ for (let i = 0; i < count; i++) {
51
+ /**
52
+ *
53
+ * @type {Behavior}
54
+ */
55
+ const child = this.objectAdapter.deserialize(buffer);
56
+
57
+ value.addChild(child);
58
+ }
59
+
60
+ value.setFailurePolicy(failurePolicy);
61
+ value.setSuccessPolicy(successPolicy);
62
+ }
63
+ }
@@ -1,7 +1,10 @@
1
1
  import { Behavior } from "../Behavior.js";
2
2
  import { CompositeBehavior } from "./CompositeBehavior.js";
3
3
  import { BehaviorStatus } from "../BehaviorStatus.js";
4
- import { ObjectBasedClassSerializationAdapter } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
4
+ import {
5
+ ObjectBasedClassSerializationAdapter
6
+ } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
7
+ import { assert } from "../../../../core/assert.js";
5
8
 
6
9
  export class SequenceBehavior extends CompositeBehavior {
7
10
  constructor() {
@@ -13,6 +16,12 @@ export class SequenceBehavior extends CompositeBehavior {
13
16
  * @protected
14
17
  */
15
18
  this.__currentBehaviourIndex = -1;
19
+ /**
20
+ *
21
+ * @type {BehaviorStatus|number}
22
+ * @private
23
+ */
24
+ this.__currentBehaviourState = BehaviorStatus.Initial;
16
25
 
17
26
  /**
18
27
  *
@@ -23,32 +32,41 @@ export class SequenceBehavior extends CompositeBehavior {
23
32
  }
24
33
 
25
34
  initialize(context) {
26
-
35
+ // console.log('+ SequenceBehavior');
27
36
  super.initialize(context);
28
37
 
29
38
  this.__currentBehaviourIndex = 0;
30
- this.__currentBehaviour = this.__children[this.__currentBehaviourIndex];
39
+ this.__currentBehaviour = this.__children[0];
31
40
 
32
41
  //initialize first behaviour
33
42
  this.__currentBehaviour.initialize(context);
34
43
 
44
+ this.__currentBehaviourState = BehaviorStatus.Running;
35
45
  }
36
46
 
47
+
37
48
  /**
38
49
  *
39
50
  * @param {number} timeDelta
40
51
  * @returns {BehaviorStatus}
41
52
  */
42
53
  tick(timeDelta) {
43
- const s = this.__currentBehaviour.tick(timeDelta);
54
+ assert.isNonNegativeInteger(this.__currentBehaviourIndex, 'child index');
55
+
56
+ const currentBehaviour = this.__currentBehaviour;
57
+
58
+ const s = currentBehaviour.tick(timeDelta);
59
+
60
+ this.__currentBehaviourState = s;
44
61
 
45
62
  if (s !== BehaviorStatus.Succeeded) {
46
63
  return s;
47
64
  }
48
65
 
49
66
  //current behaviour succeeded, move onto the next one
50
- this.__currentBehaviour.finalize();
67
+ currentBehaviour.finalize();
51
68
 
69
+ this.__currentBehaviourState = BehaviorStatus.Initial;
52
70
  this.__currentBehaviourIndex++;
53
71
 
54
72
  if (this.__currentBehaviourIndex < this.__children.length) {
@@ -56,24 +74,31 @@ export class SequenceBehavior extends CompositeBehavior {
56
74
 
57
75
  this.__currentBehaviour.initialize(this.context);
58
76
 
77
+ this.__currentBehaviourState = BehaviorStatus.Running;
78
+
59
79
  return BehaviorStatus.Running;
60
80
  } else {
61
- this.__status = BehaviorStatus.Succeeded;
62
-
63
81
  //all behaviours completed
64
- return this.__status;
82
+ return BehaviorStatus.Succeeded;
65
83
  }
66
84
  }
67
85
 
68
86
  finalize() {
69
- if (this.__currentBehaviourIndex !== this.__children.length) {
87
+
88
+ const child_count = this.__children.length;
89
+
90
+ if (this.__currentBehaviourIndex !== child_count) {
70
91
  //sequence has not been finished
71
92
 
72
- if (this.__currentBehaviour !== undefined && this.__currentBehaviour.getStatus() !== BehaviorStatus.Initial) {
93
+ if (this.__currentBehaviour !== undefined && this.__currentBehaviourState !== BehaviorStatus.Initial) {
73
94
  this.__currentBehaviour.finalize();
74
95
  }
75
96
  }
76
- this.__status = BehaviorStatus.Initial;
97
+
98
+ this.__currentBehaviour = undefined;
99
+ this.__currentBehaviourIndex = child_count;
100
+
101
+ // console.warn('- SequenceBehavior');
77
102
  }
78
103
 
79
104
  /**
@@ -36,8 +36,6 @@ export class AbstractDecoratorBehavior extends Behavior {
36
36
  initialize(context) {
37
37
  super.initialize(context);
38
38
  this.__source.initialize(context);
39
-
40
- this.__status = this.__source.getStatus();
41
39
  }
42
40
 
43
41
  finalize() {
@@ -19,11 +19,9 @@ export class IgnoreFailureBehavior extends AbstractDecoratorBehavior {
19
19
  const behaviorStatus = this.__source.tick(timeDelta);
20
20
 
21
21
  if (behaviorStatus === BehaviorStatus.Failed) {
22
- this.setStatus(BehaviorStatus.Succeeded);
23
- } else {
24
- this.setStatus(behaviorStatus);
22
+ return BehaviorStatus.Succeeded;
25
23
  }
26
24
 
27
- return this.getStatus();
25
+ return behaviorStatus;
28
26
  }
29
27
  }
@@ -1,6 +1,8 @@
1
1
  import { Behavior } from "../Behavior.js";
2
2
  import { BehaviorStatus } from "../BehaviorStatus.js";
3
- import { ObjectBasedClassSerializationAdapter } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
3
+ import {
4
+ ObjectBasedClassSerializationAdapter
5
+ } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
4
6
  import { AbstractDecoratorBehavior } from "./AbstractDecoratorBehavior.js";
5
7
 
6
8
  /**
@@ -37,8 +39,6 @@ export class InverterBehavior extends AbstractDecoratorBehavior {
37
39
  r = BehaviorStatus.Succeeded;
38
40
  }
39
41
 
40
- this.__status = r;
41
-
42
42
  return r;
43
43
  }
44
44
  }
@@ -1,6 +1,5 @@
1
1
  import { Behavior } from "../Behavior.js";
2
2
  import { BehaviorStatus } from "../BehaviorStatus.js";
3
- import { ObjectBasedClassSerializationAdapter } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
4
3
  import { AbstractDecoratorBehavior } from "./AbstractDecoratorBehavior.js";
5
4
  import { assert } from "../../../../core/assert.js";
6
5
 
@@ -65,7 +64,6 @@ export class RepeatBehavior extends AbstractDecoratorBehavior {
65
64
  assert.enum(s, BehaviorStatus, 'status');
66
65
 
67
66
  if (s !== BehaviorStatus.Succeeded && s !== BehaviorStatus.Failed) {
68
- this.__status = s;
69
67
  return s;
70
68
  }
71
69
 
@@ -73,7 +71,6 @@ export class RepeatBehavior extends AbstractDecoratorBehavior {
73
71
  this.__iterator++;
74
72
 
75
73
  if (this.__iterator >= this.__limit) {
76
- this.__status = BehaviorStatus.Succeeded;
77
74
 
78
75
  return BehaviorStatus.Succeeded;
79
76
  } else {
@@ -87,35 +84,3 @@ export class RepeatBehavior extends AbstractDecoratorBehavior {
87
84
 
88
85
  RepeatBehavior.typeName = "RepeatBehavior";
89
86
 
90
- export class RepeatBehaviorSerializationAdapter extends ObjectBasedClassSerializationAdapter {
91
- constructor() {
92
- super();
93
-
94
- this.klass = RepeatBehavior;
95
- this.version = 0;
96
- }
97
-
98
- /**
99
- *
100
- * @param {BinaryBuffer} buffer
101
- * @param {RepeatBehavior} value
102
- */
103
- serialize(buffer, value) {
104
- buffer.writeUintVar(value.getCount());
105
-
106
- this.objectAdapter.serialize(buffer, value.getSource());
107
- }
108
-
109
- /**
110
- *
111
- * @param {BinaryBuffer} buffer
112
- * @param {RepeatBehavior} value
113
- */
114
- deserialize(buffer, value) {
115
- const count = buffer.readUintVar();
116
- const source = this.objectAdapter.deserialize(buffer);
117
-
118
- value.setCount(count);
119
- value.setSource(source);
120
- }
121
- }
@@ -6,11 +6,7 @@ import { jest } from '@jest/globals';
6
6
  test("initialization", () => {
7
7
  const b = new RepeatBehavior(new SucceedingBehavior(), 1);
8
8
 
9
- expect(b.getStatus()).toBe(BehaviorStatus.Initial);
10
-
11
9
  b.initialize();
12
-
13
- expect(b.getStatus()).toBe(BehaviorStatus.Running);
14
10
  });
15
11
 
16
12
  test('2 successful repetitions', () => {
@@ -23,12 +19,8 @@ test('2 successful repetitions', () => {
23
19
 
24
20
  b.initialize();
25
21
 
26
- expect(b.getStatus()).toBe(BehaviorStatus.Running);
27
-
28
22
  expect(b.tick(3)).toBe(BehaviorStatus.Running);
29
23
 
30
- expect(b.getStatus()).toBe(BehaviorStatus.Running);
31
-
32
24
  expect(tickSpy).toHaveBeenCalledTimes(1);
33
25
  expect(tickSpy).toHaveBeenCalledWith(3);
34
26
 
@@ -37,6 +29,4 @@ test('2 successful repetitions', () => {
37
29
 
38
30
  expect(tickSpy).toHaveBeenCalledTimes(2);
39
31
  expect(tickSpy).toHaveBeenLastCalledWith(7);
40
-
41
- expect(b.getStatus()).toBe(BehaviorStatus.Succeeded);
42
32
  });
@@ -0,0 +1,37 @@
1
+ import {
2
+ ObjectBasedClassSerializationAdapter
3
+ } from "../../../ecs/storage/binary/object/ObjectBasedClassSerializationAdapter.js";
4
+ import { RepeatBehavior } from "./RepeatBehavior.js";
5
+
6
+ export class RepeatBehaviorSerializationAdapter extends ObjectBasedClassSerializationAdapter {
7
+ constructor() {
8
+ super();
9
+
10
+ this.klass = RepeatBehavior;
11
+ this.version = 0;
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param {BinaryBuffer} buffer
17
+ * @param {RepeatBehavior} value
18
+ */
19
+ serialize(buffer, value) {
20
+ buffer.writeUintVar(value.getCount());
21
+
22
+ this.objectAdapter.serialize(buffer, value.getSource());
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {BinaryBuffer} buffer
28
+ * @param {RepeatBehavior} value
29
+ */
30
+ deserialize(buffer, value) {
31
+ const count = buffer.readUintVar();
32
+ const source = this.objectAdapter.deserialize(buffer);
33
+
34
+ value.setCount(count);
35
+ value.setSource(source);
36
+ }
37
+ }
@@ -51,8 +51,6 @@ export class RepeatUntilFailureBehavior extends AbstractDecoratorBehavior {
51
51
 
52
52
  if (s !== BehaviorStatus.Succeeded) {
53
53
 
54
- this.__status = s;
55
-
56
54
  return s;
57
55
 
58
56
  }
@@ -60,7 +58,6 @@ export class RepeatUntilFailureBehavior extends AbstractDecoratorBehavior {
60
58
  this.__iterator++;
61
59
 
62
60
  if (this.__iterator >= this.__limit) {
63
- this.__status = BehaviorStatus.Succeeded;
64
61
 
65
62
  return BehaviorStatus.Succeeded;
66
63
  } else {
@@ -40,10 +40,10 @@ export class RepeatUntilSuccessBehavior extends AbstractDecoratorBehavior {
40
40
  * @return {RepeatUntilSuccessBehavior}
41
41
  */
42
42
  static from(source, limit = Infinity) {
43
- const r = new RepeatUntilSuccessBehavior();
44
-
45
- r.setSource(source);
46
- r.__limit = limit;
43
+ const r = new RepeatUntilSuccessBehavior(
44
+ source,
45
+ limit
46
+ );
47
47
 
48
48
  return r;
49
49
  }
@@ -52,9 +52,6 @@ export class RepeatUntilSuccessBehavior extends AbstractDecoratorBehavior {
52
52
  const s = this.__source.tick(timeDelta);
53
53
 
54
54
  if (s === BehaviorStatus.Succeeded) {
55
-
56
- this.__status = s;
57
-
58
55
  return s;
59
56
 
60
57
  } else if (s === BehaviorStatus.Running) {
@@ -64,9 +61,7 @@ export class RepeatUntilSuccessBehavior extends AbstractDecoratorBehavior {
64
61
  this.__iterator++;
65
62
 
66
63
  if (this.__iterator >= this.__limit) {
67
- this.__status = BehaviorStatus.Failed;
68
-
69
- return this.__status;
64
+ return BehaviorStatus.Failed;
70
65
  } else {
71
66
  //re-initialize the source behavior
72
67
  this.__source.initialize(this.context);