@woosh/meep-engine 2.42.5 → 2.42.7

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.
@@ -3,6 +3,7 @@ import { EnginePlugin } from "../../../../plugin/EnginePlugin.js";
3
3
  import { MaterialTransformer } from "./MaterialTransformer.js";
4
4
  import { Vector2 as ThreeVector2 } from "three";
5
5
 
6
+
6
7
  export class ForwardPlusRenderingPlugin extends EnginePlugin {
7
8
  constructor() {
8
9
  super();
@@ -16,6 +17,13 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
16
17
  light_manager: this.__light_manager,
17
18
  resolution: this.__resolution
18
19
  });
20
+
21
+ /**
22
+ * Track lifecycle state
23
+ * @type {boolean}
24
+ * @private
25
+ */
26
+ this.__state_is_running = false;
19
27
  }
20
28
 
21
29
  /**
@@ -36,6 +44,12 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
36
44
  }
37
45
 
38
46
  async startup() {
47
+ if (this.__state_is_running) {
48
+ throw new Error("Already running");
49
+ }
50
+
51
+ this.__state_is_running = true;
52
+
39
53
  const lm = this.__light_manager;
40
54
 
41
55
  lm.setTileMapResolution(16, 8, 8);
@@ -52,14 +66,23 @@ export class ForwardPlusRenderingPlugin extends EnginePlugin {
52
66
 
53
67
  this.updateResolution();
54
68
 
55
-
56
69
  await super.startup();
57
70
  }
58
71
 
59
72
  async shutdown() {
73
+ if (!this.__state_is_running) {
74
+ throw new Error("Not running");
75
+ }
76
+
77
+ this.__state_is_running = false;
78
+
60
79
  const graphics = this.engine.graphics;
61
80
 
62
- graphics.getMaterialManager().removeCompileStep(this.__material_transformer);
81
+ const is_material_removed = graphics.getMaterialManager().removeCompileStep(this.__material_transformer);
82
+
83
+ if (!is_material_removed) {
84
+ console.warn('Failed to remove material transformer');
85
+ }
63
86
 
64
87
  graphics.viewport.size.onChanged.remove(this.updateResolution, this);
65
88
  graphics.pixelRatio.onChanged.remove(this.updateResolution, this);
@@ -4,6 +4,7 @@ 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";
7
8
 
8
9
  export class EnginePluginManager extends BaseProcess {
9
10
  constructor() {
@@ -246,6 +247,11 @@ export class EnginePluginManager extends BaseProcess {
246
247
 
247
248
  ctx.dependency_references.addAll(dependency_refs);
248
249
 
250
+ // Sanity check
251
+ if (this.__plugins.has(PluginClass)) {
252
+ throw new IllegalStateException('Plugin was already instantiated during acquisition');
253
+ }
254
+
249
255
  // all dependencies acquired, register the plugin
250
256
  this.__plugins.set(PluginClass, ctx);
251
257
 
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.5",
8
+ "version": "2.42.7",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",