@woosh/meep-engine 2.47.31 → 2.47.32

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/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.31",
8
+ "version": "2.47.32",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,34 @@
1
+ import { BehaviorStatus } from "../BehaviorStatus.js";
2
+ import { assert } from "../../../../core/assert.js";
3
+
4
+ /**
5
+ * Synchronously executes behavior from start to finish, or throws if could not be completed within set number of ticks
6
+ * @template CTX
7
+ * @param {Behavior<CTX>} behavior
8
+ * @param {CTX} context behavior context, will be passed into behavior initialization
9
+ * @param {number} [tick_limit]
10
+ * @returns {BehaviorStatus} completion status
11
+ * @throws {Error} if can't complete within tick limit
12
+ */
13
+ export function syncExecuteBehaviorToCompletion({ behavior, context, tick_limit = 10000 }) {
14
+ assert.isNumber(tick_limit, 'tick_limit');
15
+ assert.notNaN(tick_limit, 'tick_limit');
16
+ assert.isNonNegativeInteger(tick_limit, 'tick_limit');
17
+
18
+ behavior.initialize(context);
19
+
20
+ let tick_count = 0;
21
+ let state;
22
+
23
+ do {
24
+ if (tick_count++ > tick_limit) {
25
+ throw new Error(`Failed to complete behavior, tick limit(${tick_limit}) reached. Behavior not finalized`);
26
+ }
27
+
28
+ state = behavior.tick(0);
29
+ } while (state === BehaviorStatus.Running);
30
+
31
+ behavior.finalize();
32
+
33
+ return state;
34
+ }