@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.
- package/core/bvh2/bvh3/{bvh_query_user_data_by_frustum.js → bvh_query_user_data_overlaps_frustum.js} +4 -5
- package/core/color/Color.js +54 -3
- package/core/color/hsv2rgb.js +3 -3
- package/core/color/kelvin_to_rgb.js +51 -0
- package/core/color/kelvin_to_rgb.spec.js +61 -0
- package/core/color/linear_to_sRGB.js +17 -0
- package/core/color/prototype_kelvin_to_rgb.js +44 -0
- package/core/color/rgb_to_kelvin.js +34 -0
- package/core/color/rgb_to_kelvin.spec.js +15 -0
- package/core/color/sRGB_to_linear.js +16 -0
- package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +2 -2
- package/core/geom/LineSegment.js +2 -2
- package/core/geom/Vector3.js +14 -0
- package/core/math/DEG_TO_RAD.js +1 -0
- package/core/math/MathUtils.spec.js +0 -13
- package/core/math/RAD_TO_DEG.js +1 -0
- package/core/math/clamp01.js +15 -0
- package/core/math/fract.js +10 -0
- package/core/math/newton_solver_1d.js +21 -0
- package/core/math/smoothStep.js +3 -3
- package/core/math/solveQuadratic.js +32 -12
- package/core/math/solveQuadratic.spec.js +18 -0
- package/core/primitives/strings/StringUtils.js +10 -0
- package/core/process/task/TaskUtils.js +2 -2
- package/editor/view/ecs/components/color/GaugeView.js +2 -2
- package/editor/view/ecs/components/particles/ColorParameterLUTController.js +5 -4
- package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +5 -3
- package/engine/Clock.js +4 -0
- package/engine/UserController.js +2 -1
- package/engine/animation/behavior/animateProperty.js +6 -1
- package/engine/animation/keyed2/behavior/AnimationBehavior.js +0 -1
- package/engine/ecs/EntityBuilder.js +12 -1
- package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -1
- package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +2 -1
- package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +14 -11
- package/engine/ecs/systems/AimControllerSystem.js +3 -2
- package/engine/ecs/systems/RangedAttackSystem.js +3 -2
- package/engine/ecs/systems/SteeringSystem.js +3 -3
- package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
- package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
- package/engine/graphics/GraphicsEngine.js +2 -1
- package/engine/graphics/camera/CameraShake.js +4 -4
- package/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +2 -2
- package/engine/graphics/ecs/camera/TiltCameraController.js +3 -2
- package/engine/graphics/ecs/compileAllMaterials.js +2 -2
- package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +14 -24
- package/engine/graphics/ecs/light/LightSystem.js +2 -3
- package/engine/graphics/ecs/mesh/createTaskWaitForMeshesToLoad.js +2 -2
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +19 -0
- package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +4 -2
- package/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +9 -0
- package/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +11 -0
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +3 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +31 -0
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -2
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -82
- package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +28 -3
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -3
- package/engine/graphics/render/gizmo/Gizmo.js +3 -0
- package/engine/graphics/render/gizmo/GizmoRenderingPlugin.js +5 -0
- package/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +91 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +110 -18
- package/engine/graphics/three/OrbitControls.js +3 -2
- package/engine/graphics/trail/x/simulator/RibbonXFixedPhysicsSimulator.js +2 -2
- package/engine/graphics/util/makeMeshPreviewScene.js +11 -3
- package/engine/intelligence/behavior/Behavior.js +36 -17
- package/engine/intelligence/behavior/SelectorBehavior.js +6 -5
- package/engine/intelligence/behavior/composite/ParallelBehavior.js +0 -66
- package/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.js +63 -0
- package/engine/intelligence/behavior/composite/SequenceBehavior.js +36 -11
- package/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +0 -2
- package/engine/intelligence/behavior/decorator/IgnoreFailureBehavior.js +2 -4
- package/engine/intelligence/behavior/decorator/InverterBehavior.js +3 -3
- package/engine/intelligence/behavior/decorator/RepeatBehavior.js +0 -35
- package/engine/intelligence/behavior/decorator/RepeatBehavior.spec.js +0 -10
- package/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.js +37 -0
- package/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -3
- package/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.js +5 -10
- package/engine/intelligence/behavior/ecs/BehaviorComponent.js +95 -7
- package/engine/intelligence/behavior/ecs/BehaviorComponentSerializationAdapter.js +15 -8
- package/engine/intelligence/behavior/ecs/BehaviorSystem.js +28 -37
- package/engine/intelligence/behavior/ecs/DieBehavior.js +2 -7
- package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +2 -29
- package/engine/intelligence/behavior/ecs/WaitForEventBehaviorSerializationAdapter.js +29 -0
- package/engine/intelligence/behavior/primitive/ActionBehavior.js +6 -13
- package/engine/intelligence/behavior/primitive/FailingBehavior.js +1 -29
- package/engine/intelligence/behavior/primitive/FailingBehaviorSerializationAdapter.js +29 -0
- package/engine/intelligence/behavior/primitive/PromiseBehavior.js +15 -3
- package/engine/intelligence/behavior/selector/WeightedRandomBehavior.js +1 -5
- package/engine/intelligence/behavior/util/ConditionBehavior.js +1 -3
- package/engine/intelligence/behavior/util/ConditionBehavior.spec.js +1 -7
- package/engine/intelligence/behavior/util/ConditionalBehavior.js +3 -6
- package/engine/intelligence/behavior/util/DelayBehavior.js +2 -4
- package/engine/intelligence/behavior/util/SelectorBehavior.js +13 -12
- package/engine/intelligence/blackboard/AbstractBlackboard.js +16 -2
- package/engine/plugin/EnginePluginManager.js +4 -14
- package/engine/sound/ecs/emitter/SoundEmitter.js +3 -0
- package/generation/filtering/numeric/math/CellFilterSaturate.js +2 -2
- package/generation/grid/generation/GridTaskDensityMarkerDistribution.js +3 -2
- package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +1 -1
- package/generation/rules/CellMatcherLayerBitMaskTest.js +3 -3
- package/package.json +1 -1
- package/view/elements/progress/SmoothProgressBar.js +2 -2
- package/view/elements/progress/segmented/SegmentedResourceBarView.js +3 -3
- package/view/elements/radial/RadialProgressView.js +2 -2
|
@@ -2,18 +2,15 @@ import { assert } from "../../../../core/assert.js";
|
|
|
2
2
|
import { ClockChannelType } from "./ClockChannelType.js";
|
|
3
3
|
import { RepeatBehavior } from "../decorator/RepeatBehavior.js";
|
|
4
4
|
import { ActionBehavior } from "../primitive/ActionBehavior.js";
|
|
5
|
+
import { SequenceBehavior } from "../composite/SequenceBehavior.js";
|
|
5
6
|
|
|
6
7
|
export const BehaviorComponentFlag = {
|
|
7
|
-
AllowSleep: 1
|
|
8
|
+
AllowSleep: 1,
|
|
9
|
+
Resolved: 2
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
export class BehaviorComponent {
|
|
11
13
|
constructor() {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @type {Behavior[]}
|
|
15
|
-
*/
|
|
16
|
-
this.list = [];
|
|
17
14
|
|
|
18
15
|
/**
|
|
19
16
|
*
|
|
@@ -26,6 +23,97 @@ export class BehaviorComponent {
|
|
|
26
23
|
* @type {number}
|
|
27
24
|
*/
|
|
28
25
|
this.flags = 0;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @type {Behavior|null}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
this.__behavior = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {number|BehaviorComponentFlag} flag
|
|
38
|
+
* @returns {void}
|
|
39
|
+
*/
|
|
40
|
+
setFlag(flag) {
|
|
41
|
+
this.flags |= flag;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {number|BehaviorComponentFlag} flag
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
clearFlag(flag) {
|
|
50
|
+
this.flags &= ~flag;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param {number|BehaviorComponentFlag} flag
|
|
56
|
+
* @param {boolean} value
|
|
57
|
+
*/
|
|
58
|
+
writeFlag(flag, value) {
|
|
59
|
+
if (value) {
|
|
60
|
+
this.setFlag(flag);
|
|
61
|
+
} else {
|
|
62
|
+
this.clearFlag(flag);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param {number|BehaviorComponentFlag} flag
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
getFlag(flag) {
|
|
72
|
+
return (this.flags & flag) === flag;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @returns {Behavior|null}
|
|
78
|
+
*/
|
|
79
|
+
get behavior() {
|
|
80
|
+
return this.__behavior;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {Behavior} v
|
|
86
|
+
*/
|
|
87
|
+
set behavior(v) {
|
|
88
|
+
this.__behavior = v;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated
|
|
93
|
+
* @returns {Readonly<Behavior[]>}
|
|
94
|
+
*/
|
|
95
|
+
get list() {
|
|
96
|
+
if (this.__behavior !== null) {
|
|
97
|
+
return [this.__behavior];
|
|
98
|
+
} else {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated
|
|
105
|
+
* @param {Behavior[]} v
|
|
106
|
+
*/
|
|
107
|
+
set list(v) {
|
|
108
|
+
console.warn('.list is deprecated, use SequenceBehavior instead');
|
|
109
|
+
if (v.length > 1) {
|
|
110
|
+
console.warn('.list is deprecated, converting to sequence instead');
|
|
111
|
+
this.__behavior = SequenceBehavior.from(v);
|
|
112
|
+
} else if (v.length === 1) {
|
|
113
|
+
this.__behavior = v[0];
|
|
114
|
+
} else {
|
|
115
|
+
this.__behavior = null;
|
|
116
|
+
}
|
|
29
117
|
}
|
|
30
118
|
|
|
31
119
|
|
|
@@ -53,7 +141,7 @@ export class BehaviorComponent {
|
|
|
53
141
|
|
|
54
142
|
const result = new BehaviorComponent();
|
|
55
143
|
|
|
56
|
-
result.
|
|
144
|
+
result.__behavior = b;
|
|
57
145
|
|
|
58
146
|
return result;
|
|
59
147
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
2
|
import { BehaviorComponent } from "./BehaviorComponent.js";
|
|
3
|
+
import { SequenceBehavior } from "../composite/SequenceBehavior.js";
|
|
4
|
+
import { SucceedingBehavior } from "../primitive/SucceedingBehavior.js";
|
|
3
5
|
|
|
4
6
|
export class BehaviorComponentSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
5
7
|
constructor() {
|
|
@@ -33,15 +35,13 @@ export class BehaviorComponentSerializationAdapter extends BinaryClassSerializat
|
|
|
33
35
|
buffer.writeUint8(value.clock);
|
|
34
36
|
buffer.writeUint8(value.flags);
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
buffer.writeUintVar(n);
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < n; i++) {
|
|
41
|
-
const behavior = behaviors[i];
|
|
38
|
+
if (value.behavior !== null) {
|
|
39
|
+
buffer.writeUintVar(1);
|
|
42
40
|
|
|
43
41
|
//write single behavior
|
|
44
|
-
this.objectAdapter.serialize(buffer, behavior);
|
|
42
|
+
this.objectAdapter.serialize(buffer, value.behavior);
|
|
43
|
+
} else {
|
|
44
|
+
buffer.writeUintVar(0);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -71,6 +71,13 @@ export class BehaviorComponentSerializationAdapter extends BinaryClassSerializat
|
|
|
71
71
|
//write object fields
|
|
72
72
|
value.clock = clock;
|
|
73
73
|
value.flags = flags;
|
|
74
|
-
|
|
74
|
+
|
|
75
|
+
if (behaviors.length > 1) {
|
|
76
|
+
value.behavior = SequenceBehavior.from(behaviors);
|
|
77
|
+
} else if (behaviors.length === 1) {
|
|
78
|
+
value.behavior = behaviors[0];
|
|
79
|
+
} else {
|
|
80
|
+
value.behavior = SucceedingBehavior.from(0);
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
83
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { System } from "../../../ecs/System.js";
|
|
2
|
-
import { BehaviorComponent } from "./BehaviorComponent.js";
|
|
2
|
+
import { BehaviorComponent, BehaviorComponentFlag } from "./BehaviorComponent.js";
|
|
3
3
|
import { BehaviorStatus } from "../BehaviorStatus.js";
|
|
4
4
|
import Clock from "../../../Clock.js";
|
|
5
5
|
import { ClockChannelType } from "./ClockChannelType.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {Behavior} behavior
|
|
10
10
|
* @param {number} timeDelta
|
|
11
|
+
* @returns {BehaviorStatus}
|
|
11
12
|
*/
|
|
12
13
|
function updateBehavior(behavior, timeDelta) {
|
|
13
14
|
|
|
14
15
|
try {
|
|
15
|
-
behavior.tick(timeDelta);
|
|
16
|
+
return behavior.tick(timeDelta);
|
|
16
17
|
} catch (e) {
|
|
17
18
|
console.error('Behavior threw an exception', e);
|
|
18
19
|
|
|
19
20
|
// Transition behavior into failed state
|
|
20
|
-
|
|
21
|
+
return BehaviorStatus.Failed;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export class BehaviorSystem extends System {
|
|
@@ -60,24 +60,18 @@ export class BehaviorSystem extends System {
|
|
|
60
60
|
* @param {number} entity
|
|
61
61
|
*/
|
|
62
62
|
link(component, entity) {
|
|
63
|
+
const behavior = component.behavior;
|
|
64
|
+
component.clearFlag(BehaviorComponentFlag.Resolved);
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
const l = list.length;
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < l; i++) {
|
|
68
|
-
const behavior = list[i];
|
|
69
|
-
|
|
70
|
-
if (behavior.getStatus() === BehaviorStatus.Initial) {
|
|
71
|
-
// initialize behavior
|
|
72
|
-
const dataset = this.entityManager.dataset;
|
|
66
|
+
if (behavior !== null) {
|
|
73
67
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} catch (e) {
|
|
77
|
-
console.warn('Behavior initialization failed:', e);
|
|
68
|
+
// initialize behavior
|
|
69
|
+
const dataset = this.entityManager.dataset;
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
}
|
|
71
|
+
try {
|
|
72
|
+
behavior.initialize({ entity, ecd: dataset, engine: this.engine });
|
|
73
|
+
} catch (e) {
|
|
74
|
+
console.warn('Behavior initialization failed:', e);
|
|
81
75
|
}
|
|
82
76
|
}
|
|
83
77
|
}
|
|
@@ -88,17 +82,12 @@ export class BehaviorSystem extends System {
|
|
|
88
82
|
* @param {number} entity
|
|
89
83
|
*/
|
|
90
84
|
unlink(component, entity) {
|
|
85
|
+
const behavior = component.behavior;
|
|
91
86
|
|
|
92
|
-
|
|
93
|
-
const l = list.length;
|
|
94
|
-
|
|
95
|
-
for (let i = 0; i < l; i++) {
|
|
96
|
-
const behavior = list[i];
|
|
87
|
+
if (behavior !== null) {
|
|
97
88
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
behavior.finalize();
|
|
101
|
-
}
|
|
89
|
+
// finalize behavior
|
|
90
|
+
behavior.finalize();
|
|
102
91
|
}
|
|
103
92
|
}
|
|
104
93
|
|
|
@@ -118,8 +107,9 @@ export class BehaviorSystem extends System {
|
|
|
118
107
|
* @param {number} entity
|
|
119
108
|
*/
|
|
120
109
|
function visitBehavior(b, entity) {
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
if (b.getFlag(BehaviorComponentFlag.Resolved)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
123
113
|
|
|
124
114
|
let td;
|
|
125
115
|
|
|
@@ -131,15 +121,16 @@ export class BehaviorSystem extends System {
|
|
|
131
121
|
td = systemDelta;
|
|
132
122
|
}
|
|
133
123
|
|
|
134
|
-
|
|
135
|
-
const behavior = list[i];
|
|
124
|
+
const behavior = b.behavior;
|
|
136
125
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
126
|
+
if (behavior !== null) {
|
|
127
|
+
const state = updateBehavior(behavior, td);
|
|
140
128
|
|
|
141
|
-
|
|
129
|
+
if (state === BehaviorStatus.Failed || state === BehaviorStatus.Succeeded) {
|
|
130
|
+
b.setFlag(BehaviorComponentFlag.Resolved);
|
|
131
|
+
}
|
|
142
132
|
}
|
|
133
|
+
|
|
143
134
|
}
|
|
144
135
|
|
|
145
136
|
dataset.traverseComponents(BehaviorComponent, visitBehavior);
|
|
@@ -16,16 +16,11 @@ export class DieBehavior extends EntityBehavior {
|
|
|
16
16
|
if (!ecd.entityExists(entity)) {
|
|
17
17
|
//entity doesn't exist, count as success
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return this.__status;
|
|
19
|
+
return BehaviorStatus.Succeeded;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
ecd.removeEntity(entity);
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return this.__status;
|
|
29
|
-
|
|
24
|
+
return BehaviorStatus.Succeeded;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EntityBehavior } from "./EntityBehavior.js";
|
|
2
2
|
import { BehaviorStatus } from "../BehaviorStatus.js";
|
|
3
|
-
import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
4
3
|
import { assert } from "../../../../core/assert.js";
|
|
5
4
|
|
|
6
5
|
export class WaitForEventBehavior extends EntityBehavior {
|
|
@@ -48,10 +47,10 @@ export class WaitForEventBehavior extends EntityBehavior {
|
|
|
48
47
|
|
|
49
48
|
tick(timeDelta) {
|
|
50
49
|
if (this.detected) {
|
|
51
|
-
|
|
50
|
+
return BehaviorStatus.Succeeded;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
return
|
|
53
|
+
return BehaviorStatus.Running;
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
|
@@ -89,29 +88,3 @@ export class WaitForEventBehavior extends EntityBehavior {
|
|
|
89
88
|
*/
|
|
90
89
|
WaitForEventBehavior.typeName = "WaitForEventBehavior";
|
|
91
90
|
|
|
92
|
-
export class WaitForEventBehaviorSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
93
|
-
constructor() {
|
|
94
|
-
super();
|
|
95
|
-
|
|
96
|
-
this.klass = WaitForEventBehavior;
|
|
97
|
-
this.version = 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {BinaryBuffer} buffer
|
|
103
|
-
* @param {WaitForEventBehavior} value
|
|
104
|
-
*/
|
|
105
|
-
serialize(buffer, value) {
|
|
106
|
-
buffer.writeUTF8String(value.event);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
* @param {BinaryBuffer} buffer
|
|
112
|
-
* @param {WaitForEventBehavior} value
|
|
113
|
-
*/
|
|
114
|
-
deserialize(buffer, value) {
|
|
115
|
-
value.event = buffer.readUTF8String();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
|
+
import { WaitForEventBehavior } from "./WaitForEventBehavior.js";
|
|
3
|
+
|
|
4
|
+
export class WaitForEventBehaviorSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
|
|
8
|
+
this.klass = WaitForEventBehavior;
|
|
9
|
+
this.version = 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {BinaryBuffer} buffer
|
|
15
|
+
* @param {WaitForEventBehavior} value
|
|
16
|
+
*/
|
|
17
|
+
serialize(buffer, value) {
|
|
18
|
+
buffer.writeUTF8String(value.event);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {BinaryBuffer} buffer
|
|
24
|
+
* @param {WaitForEventBehavior} value
|
|
25
|
+
*/
|
|
26
|
+
deserialize(buffer, value) {
|
|
27
|
+
value.event = buffer.readUTF8String();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -19,24 +19,17 @@ export class ActionBehavior extends Behavior {
|
|
|
19
19
|
|
|
20
20
|
tick(timeDelta) {
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
try {
|
|
23
|
+
this.__action.call(this.__context, timeDelta);
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
this.__action.call(this.__context, timeDelta);
|
|
25
|
+
return BehaviorStatus.Succeeded;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
} catch (e) {
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
console.warn(e);
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.setStatus(BehaviorStatus.Failed);
|
|
34
|
-
|
|
35
|
-
}
|
|
31
|
+
return BehaviorStatus.Failed;
|
|
36
32
|
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return this.__status;
|
|
41
34
|
}
|
|
42
35
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Behavior } from "../Behavior.js";
|
|
2
2
|
import { BehaviorStatus } from "../BehaviorStatus.js";
|
|
3
|
-
import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
4
3
|
|
|
5
4
|
export class FailingBehavior extends Behavior {
|
|
6
5
|
constructor(delayTicks = 0) {
|
|
@@ -9,9 +8,8 @@ export class FailingBehavior extends Behavior {
|
|
|
9
8
|
this.delayTicks = delayTicks;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
tick() {
|
|
11
|
+
tick(td) {
|
|
13
12
|
if (this.delayTicks === 0) {
|
|
14
|
-
this.__status = BehaviorStatus.Failed;
|
|
15
13
|
|
|
16
14
|
return BehaviorStatus.Failed;
|
|
17
15
|
} else {
|
|
@@ -24,29 +22,3 @@ export class FailingBehavior extends Behavior {
|
|
|
24
22
|
|
|
25
23
|
FailingBehavior.typeName = "FailingBehavior";
|
|
26
24
|
|
|
27
|
-
export class FailingBehaviorSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
28
|
-
constructor() {
|
|
29
|
-
super();
|
|
30
|
-
|
|
31
|
-
this.klass = FailingBehavior;
|
|
32
|
-
this.version = 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param {BinaryBuffer} buffer
|
|
38
|
-
* @param {FailingBehavior} value
|
|
39
|
-
*/
|
|
40
|
-
serialize(buffer, value) {
|
|
41
|
-
buffer.writeUintVar(value.delayTicks);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {BinaryBuffer} buffer
|
|
47
|
-
* @param {FailingBehavior} value
|
|
48
|
-
*/
|
|
49
|
-
deserialize(buffer, value) {
|
|
50
|
-
value.delayTicks = buffer.readUintVar();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
|
+
import { FailingBehavior } from "./FailingBehavior.js";
|
|
3
|
+
|
|
4
|
+
export class FailingBehaviorSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
|
|
8
|
+
this.klass = FailingBehavior;
|
|
9
|
+
this.version = 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {BinaryBuffer} buffer
|
|
15
|
+
* @param {FailingBehavior} value
|
|
16
|
+
*/
|
|
17
|
+
serialize(buffer, value) {
|
|
18
|
+
buffer.writeUintVar(value.delayTicks);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {BinaryBuffer} buffer
|
|
24
|
+
* @param {FailingBehavior} value
|
|
25
|
+
*/
|
|
26
|
+
deserialize(buffer, value) {
|
|
27
|
+
value.delayTicks = buffer.readUintVar();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -2,30 +2,42 @@ import { Behavior } from "../Behavior.js";
|
|
|
2
2
|
import { BehaviorStatus } from "../BehaviorStatus.js";
|
|
3
3
|
|
|
4
4
|
export class PromiseBehavior extends Behavior {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {()=>Promise} factory
|
|
8
|
+
*/
|
|
5
9
|
constructor(factory) {
|
|
6
10
|
super();
|
|
7
11
|
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @type {function(): Promise}
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
8
17
|
this.__factory = factory;
|
|
9
18
|
|
|
10
19
|
this.__promise = null;
|
|
20
|
+
|
|
21
|
+
this.__promise_state = BehaviorStatus.Running;
|
|
11
22
|
}
|
|
12
23
|
|
|
13
24
|
initialize(context) {
|
|
14
25
|
super.initialize(context);
|
|
15
26
|
|
|
16
27
|
this.__promise = this.__factory();
|
|
28
|
+
this.__promise_state = BehaviorStatus.Running;
|
|
17
29
|
|
|
18
30
|
this.__promise.then(
|
|
19
31
|
() => {
|
|
20
|
-
this.
|
|
32
|
+
this.__promise_state = BehaviorStatus.Succeeded;
|
|
21
33
|
},
|
|
22
34
|
() => {
|
|
23
|
-
this.
|
|
35
|
+
this.__promise_state = BehaviorStatus.Failed;
|
|
24
36
|
}
|
|
25
37
|
);
|
|
26
38
|
}
|
|
27
39
|
|
|
28
40
|
tick(timeDelta) {
|
|
29
|
-
return this.
|
|
41
|
+
return this.__promise_state;
|
|
30
42
|
}
|
|
31
43
|
}
|
|
@@ -5,8 +5,6 @@ test('initialize', () => {
|
|
|
5
5
|
const b = new ConditionBehavior(() => true);
|
|
6
6
|
|
|
7
7
|
b.initialize();
|
|
8
|
-
|
|
9
|
-
expect(b.getStatus()).toBe(BehaviorStatus.Running);
|
|
10
8
|
});
|
|
11
9
|
|
|
12
10
|
test('positive', () => {
|
|
@@ -15,8 +13,6 @@ test('positive', () => {
|
|
|
15
13
|
b.initialize();
|
|
16
14
|
|
|
17
15
|
expect(b.tick(0)).toBe(BehaviorStatus.Succeeded);
|
|
18
|
-
|
|
19
|
-
expect(b.getStatus()).toBe(BehaviorStatus.Succeeded);
|
|
20
16
|
});
|
|
21
17
|
|
|
22
18
|
test('negative', () => {
|
|
@@ -25,6 +21,4 @@ test('negative', () => {
|
|
|
25
21
|
b.initialize();
|
|
26
22
|
|
|
27
23
|
expect(b.tick(0)).toBe(BehaviorStatus.Failed);
|
|
28
|
-
|
|
29
|
-
expect(b.getStatus()).toBe(BehaviorStatus.Failed);
|
|
30
|
-
});
|
|
24
|
+
});
|
|
@@ -33,19 +33,18 @@ export class ConditionalBehavior extends AbstractDecoratorBehavior {
|
|
|
33
33
|
|
|
34
34
|
const s1 = this.__source.tick(timeDelta);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
return s1;
|
|
37
37
|
|
|
38
38
|
} else if (s === BehaviorStatus.Failed) {
|
|
39
39
|
condition.finalize();
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
return s;
|
|
42
42
|
|
|
43
43
|
} else {
|
|
44
44
|
//waiting?
|
|
45
|
-
|
|
45
|
+
return s;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return this.__status;
|
|
49
48
|
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -54,9 +53,7 @@ export class ConditionalBehavior extends AbstractDecoratorBehavior {
|
|
|
54
53
|
|
|
55
54
|
const condition = this.condition;
|
|
56
55
|
|
|
57
|
-
if (condition.getStatus() === BehaviorStatus.Running) {
|
|
58
56
|
condition.finalize();
|
|
59
|
-
}
|
|
60
57
|
}
|
|
61
58
|
|
|
62
59
|
/**
|
|
@@ -52,8 +52,6 @@ export class DelayBehavior extends Behavior {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
initialize() {
|
|
55
|
-
super.initialize();
|
|
56
|
-
|
|
57
55
|
this.elapsed = 0;
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -61,9 +59,9 @@ export class DelayBehavior extends Behavior {
|
|
|
61
59
|
this.elapsed += timeDelta;
|
|
62
60
|
|
|
63
61
|
if (this.elapsed >= this.value) {
|
|
64
|
-
|
|
62
|
+
return BehaviorStatus.Succeeded;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
return
|
|
65
|
+
return BehaviorStatus.Running;
|
|
68
66
|
}
|
|
69
67
|
}
|