@woosh/meep-engine 2.42.4 → 2.42.6

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.
@@ -69,7 +69,7 @@ export class MaterialContext {
69
69
 
70
70
  const rewrite_material = this.adapter.rewriteMaterial.bind(this.adapter);
71
71
 
72
- if (material[MATERIAL_FLAG] === undefined) {
72
+ if (this.material[MATERIAL_FLAG] === undefined) {
73
73
  material.onBeforeCompile = composeCompile(this.material.onBeforeCompile, rewrite_material);
74
74
  material.needsUpdate = true;
75
75
 
@@ -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);
@@ -6,6 +6,12 @@ import { fp_build_fragment_shader } from "../materials/fp_build_fragment_shader.
6
6
  import { fp_build_vertex_shader } from "../materials/fp_build_vertex_shader.js";
7
7
  import { fp_build_vertex_lighting_shared } from "../materials/fp_build_vertex_lighting_shared.js";
8
8
 
9
+ /**
10
+ * @readonly
11
+ * @type {string}
12
+ */
13
+ const PROPERTY_TRANSFORMER_MARKER = '@forward-plus-material-transformer';
14
+
9
15
  export class MaterialTransformer extends AbstractMaterialTransformer {
10
16
 
11
17
  /**
@@ -88,6 +94,17 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
88
94
  }
89
95
 
90
96
  transform(source) {
97
+ if (source.hasOwnProperty(PROPERTY_TRANSFORMER_MARKER)) {
98
+ // already transformed
99
+
100
+ if (source[PROPERTY_TRANSFORMER_MARKER] !== this) {
101
+ throw new Error('The material is already transformed, but is associated with a different transformer instance');
102
+ } else {
103
+ return source;
104
+ }
105
+
106
+ }
107
+
91
108
  let result = source;
92
109
 
93
110
  if (isLitMaterial(source)) {
@@ -96,12 +113,16 @@ export class MaterialTransformer extends AbstractMaterialTransformer {
96
113
  // inherit uniforms directly
97
114
 
98
115
  if (source.isShaderMaterial) {
99
- result.uniforms = source.uniforms;
100
- result.defines = source.defines;
116
+ // TODO use Proxy
117
+ result.uniforms = Object.assign({}, source.uniforms);
118
+ result.defines = Object.assign({}, source.defines);
101
119
  }
102
120
 
103
121
  result.onBeforeCompile = composeCompile(source.onBeforeCompile, this.__on_before_compile);
104
122
 
123
+
124
+ result[PROPERTY_TRANSFORMER_MARKER] = this;
125
+
105
126
  }
106
127
 
107
128
  return result;
@@ -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.4",
8
+ "version": "2.42.6",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",