@woosh/meep-engine 2.42.7 → 2.42.8

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.
@@ -17,13 +17,6 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
17
17
  light_manager: this.__light_manager,
18
18
  resolution: this.__resolution
19
19
  });
20
-
21
- /**
22
- * Track lifecycle state
23
- * @type {boolean}
24
- * @private
25
- */
26
- this.__state_is_running = false;
27
20
  }
28
21
 
29
22
  /**
@@ -44,12 +37,6 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
44
37
  }
45
38
 
46
39
  async startup() {
47
- if (this.__state_is_running) {
48
- throw new Error("Already running");
49
- }
50
-
51
- this.__state_is_running = true;
52
-
53
40
  const lm = this.__light_manager;
54
41
 
55
42
  lm.setTileMapResolution(16, 8, 8);
@@ -70,12 +57,6 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
70
57
  }
71
58
 
72
59
  async shutdown() {
73
- if (!this.__state_is_running) {
74
- throw new Error("Not running");
75
- }
76
-
77
- this.__state_is_running = false;
78
-
79
60
  const graphics = this.engine.graphics;
80
61
 
81
62
  const is_material_removed = graphics.getMaterialManager().removeCompileStep(this.__material_transformer);
@@ -4,7 +4,6 @@ import { EnginePlugin } from "./EnginePlugin.js";
4
4
  import { PluginReferenceContext } from "./PluginReferenceContext.js";
5
5
  import { isSubclassOf } from "./isSubclassOf.js";
6
6
  import { assert } from "../../core/assert.js";
7
- import { IllegalStateException } from "../../core/fsm/exceptions/IllegalStateException.js";
8
7
 
9
8
  export class EnginePluginManager extends BaseProcess {
10
9
  constructor() {
@@ -222,49 +221,51 @@ export class EnginePluginManager extends BaseProcess {
222
221
  }
223
222
 
224
223
  let ctx = this.__plugins.get(PluginClass);
224
+ let reference;
225
225
 
226
- if (ctx !== undefined) {
227
- return ctx.getReference();
228
- }
226
+ if (ctx === undefined) {
229
227
 
230
- this.__version++;
228
+ this.__version++;
231
229
 
232
- // context not found, create it
230
+ // context not found, create it
233
231
 
234
- const instance = new PluginClass();
232
+ const instance = new PluginClass();
235
233
 
236
- ctx = new PluginReferenceContext(instance, PluginClass);
234
+ ctx = new PluginReferenceContext(instance, PluginClass);
237
235
 
238
- // monitor the context
239
- ctx.on.lastReleased.add(this.__handle_last_plugin_reference_release, this);
236
+ // monitor the context
237
+ ctx.on.lastReleased.add(this.__handle_last_plugin_reference_release, this);
240
238
 
241
- // get reference to make sure that the context doesn't come up as having no references
242
- const reference = ctx.getReference();
239
+ // all dependencies acquired, register the plugin
240
+ this.__plugins.set(PluginClass, ctx);
243
241
 
244
- // TODO address cyclic dependencies, these can cause a deadlock
245
- // acquire dependencies
246
- const dependency_refs = await this.acquireMany(instance.dependencies);
242
+ // get reference to make sure that the context doesn't come up as having no references
243
+ reference = ctx.getReference();
247
244
 
248
- ctx.dependency_references.addAll(dependency_refs);
245
+ // TODO address cyclic dependencies, these can cause a deadlock
246
+ // acquire dependencies
247
+ const dependency_refs = await this.acquireMany(instance.dependencies);
248
+
249
+ ctx.dependency_references.addAll(dependency_refs);
249
250
 
250
- // Sanity check
251
- if (this.__plugins.has(PluginClass)) {
252
- throw new IllegalStateException('Plugin was already instantiated during acquisition');
253
- }
254
251
 
255
- // all dependencies acquired, register the plugin
256
- this.__plugins.set(PluginClass, ctx);
252
+ const manager_state_object = this.getState();
257
253
 
258
- const manager_state_object = this.getState();
259
254
 
255
+ const manager_state_value = manager_state_object.getValue();
260
256
 
261
- const manager_state_value = manager_state_object.getValue();
257
+ // bring the plugin into proper state
262
258
 
263
- // bring the plugin into proper state
259
+ const engine = this.engine;
264
260
 
265
- const engine = this.engine;
261
+ await ctx.transition(manager_state_value, engine);
262
+
263
+ } else {
264
+ reference = ctx.getReference();
265
+
266
+ await ctx.synchronize();
267
+ }
266
268
 
267
- await ctx.transition(manager_state_value, engine);
268
269
 
269
270
  return reference;
270
271
 
@@ -141,6 +141,15 @@ export class PluginReferenceContext {
141
141
  this.__transition = Promise.resolve();
142
142
  }
143
143
 
144
+ /**
145
+ * Returns promise to the latest transition, useful to synchronization
146
+ * @example await ctx.synchronize();
147
+ * @returns {Promise<void>}
148
+ */
149
+ synchronize() {
150
+ return this.__transition;
151
+ }
152
+
144
153
  /**
145
154
  *
146
155
  * @param {ProcessState} target_state
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.42.7",
8
+ "version": "2.42.8",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",