@woosh/meep-engine 2.85.0 → 2.85.2

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.
@@ -89385,6 +89385,7 @@ class GraphicsEngine {
89385
89385
  return intersectObject;
89386
89386
  })();
89387
89387
  }
89388
+
89388
89389
  /**
89389
89390
  *
89390
89391
  * @returns {MaterialManager}
@@ -89468,7 +89469,7 @@ class GraphicsEngine {
89468
89469
 
89469
89470
  start() {
89470
89471
  const canvas = document.createElement("canvas");
89471
- const context = canvas.getContext("webgl2", {antialias: false});
89472
+ const context = canvas.getContext("webgl2", { antialias: false });
89472
89473
 
89473
89474
  const rendererParameters = {
89474
89475
  antialias: true,
@@ -89665,6 +89666,10 @@ class GraphicsEngine {
89665
89666
  // TODO designate opaque output buffer
89666
89667
  const frameBuffer = buffers.getById(StandardFrameBuffers.ColorAndDepth);
89667
89668
 
89669
+ if (frameBuffer === undefined) {
89670
+ throw new Error(`No color-depth frame buffer`);
89671
+ }
89672
+
89668
89673
  renderTextureToScreenQuad(frameBuffer.renderTarget.texture, renderer);
89669
89674
 
89670
89675
  this.on.postOpaquePass.send0();
@@ -91074,7 +91079,21 @@ class StaticKnowledgeDatabase {
91074
91079
  * @private
91075
91080
  */
91076
91081
  __specs = [];
91077
-
91082
+
91083
+ /**
91084
+ *
91085
+ * @type {boolean}
91086
+ */
91087
+ #validation_enabled = false;
91088
+
91089
+ /**
91090
+ *
91091
+ * @param {boolean} v
91092
+ */
91093
+ set validation_enabled(v) {
91094
+ this.#validation_enabled = v;
91095
+ }
91096
+
91078
91097
 
91079
91098
  /**
91080
91099
  * Reset database, drop all table data
@@ -91317,7 +91336,7 @@ class StaticKnowledgeDatabase {
91317
91336
  return Promise.all(promises).then(() => {
91318
91337
  let p = this.link(am, executor);
91319
91338
 
91320
- if (!ENV_PRODUCTION) {
91339
+ if (this.#validation_enabled) {
91321
91340
  p = p.then(() => this.validate(executor));
91322
91341
  }
91323
91342
 
@@ -103164,14 +103183,16 @@ class Engine {
103164
103183
  *
103165
103184
  * @param {EnginePlatform} platform
103166
103185
  * @param {EntityManager} [entityManager]
103167
- * @param enableGraphics
103168
- * @param enableAudio
103186
+ * @param {boolean} [enableGraphics]
103187
+ * @param {boolean} [enableAudio]
103188
+ * @param {boolean} [validation]
103169
103189
  * @constructor
103170
103190
  */
103171
103191
  constructor(platform, {
103172
103192
  entityManager,
103173
103193
  enableGraphics = true,
103174
- enableAudio = true
103194
+ enableAudio = true,
103195
+ validation = true
103175
103196
  } = {}) {
103176
103197
 
103177
103198
  /**
@@ -103185,6 +103206,7 @@ class Engine {
103185
103206
  * @type {StaticKnowledgeDatabase}
103186
103207
  */
103187
103208
  this.staticKnowledge = new StaticKnowledgeDatabase();
103209
+ this.staticKnowledge.validation_enabled = validation;
103188
103210
 
103189
103211
  /**
103190
103212
  *
@@ -103346,7 +103368,7 @@ class Engine {
103346
103368
  try {
103347
103369
  graphicsEngine.start();
103348
103370
  } catch (e) {
103349
- logger.info("Failed to start GraphicEngine: ", e);
103371
+ logger.error(`Failed to start GraphicEngine: ${e}`);
103350
103372
  }
103351
103373
 
103352
103374
  } else {
@@ -103578,7 +103600,7 @@ class Engine {
103578
103600
  requestAnimationFrame(this.#animation_frame);
103579
103601
 
103580
103602
  //start simulation
103581
- this.ticker.start({maxTimeout: 200});
103603
+ this.ticker.start({ maxTimeout: 200 });
103582
103604
  //self.uiController.init(self);
103583
103605
 
103584
103606
  //load options
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.85.0",
8
+ "version": "2.85.2",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -148,16 +148,17 @@ export class LoadingCache {
148
148
 
149
149
  this.#internal.put(key, record);
150
150
 
151
- promise.then((value) => {
152
- // re-score value based on actual data
153
- record.weight = this.#value_weigher(value);
154
- this.#internal.updateElementWeight(key);
155
- });
156
-
157
- promise.catch(() => {
158
- // mark as failure
159
- record.failed = true;
160
- });
151
+ promise.then(
152
+ (value) => {
153
+ // re-score value based on actual data
154
+ record.weight = this.#value_weigher(value);
155
+ this.#internal.updateElementWeight(key);
156
+ },
157
+ () => {
158
+ // mark as failure
159
+ record.failed = true;
160
+ }
161
+ );
161
162
 
162
163
  return record;
163
164
  }
@@ -1,26 +1,27 @@
1
- import { delay } from "../process/delay.js";
2
1
  import { LoadingCache } from "./LoadingCache.js";
3
2
 
4
- test("successful load", async () => {
3
+ jest.useFakeTimers();
4
+
5
+ test("successful load", () => {
5
6
  const cache = new LoadingCache({
6
7
  async load(key) {
7
8
  return 17;
8
9
  }
9
10
  });
10
11
 
11
- expect(await cache.get(1)).toEqual(17);
12
+ expect( cache.get(1)).resolves.toEqual(17);
12
13
  });
13
14
 
14
- test("when loader throws an exception, we should get a failed promise", async () => {
15
+ test("when loader throws an exception, we should get a failed promise", () => {
15
16
  const cache = new LoadingCache({
16
17
  load(key) {
17
- throw 1;
18
+ throw "Designed Thrown Thing";
18
19
  }
19
20
  });
20
21
 
21
22
  const promise = cache.get("a");
22
23
 
23
- await expect(promise).rejects.toEqual(1);
24
+ expect(promise).rejects.toEqual("Designed Thrown Thing");
24
25
  });
25
26
 
26
27
  test("record reuse", async () => {
@@ -30,8 +31,8 @@ test("record reuse", async () => {
30
31
  load
31
32
  });
32
33
 
33
- expect(await cache.get(1)).toEqual(17);
34
- expect(await cache.get(1)).toEqual(17);
34
+ await expect(cache.get(1)).resolves.toEqual(17);
35
+ await expect(cache.get(1)).resolves.toEqual(17);
35
36
 
36
37
  expect(load).toHaveBeenCalledTimes(1);
37
38
  });
@@ -44,47 +45,23 @@ test("timeout reload reuse", async () => {
44
45
 
45
46
  const cache = new LoadingCache({
46
47
  load,
47
- timeToLive: 0.0000001
48
+ timeToLive: 0.00000001
48
49
  });
49
50
 
50
51
  const request_1 = await cache.get(1);
51
52
  expect(request_1).toEqual(11);
52
53
 
53
- await delay(2);
54
+ jest.advanceTimersByTime(1);
54
55
 
55
56
  const request_2 = await cache.get(1);
56
57
  expect(request_2).toEqual(5);
57
58
 
58
- await delay(2);
59
+ jest.advanceTimersByTime(1);
59
60
 
60
61
  const request_3 = await cache.get(1);
61
62
  expect(request_3).toEqual(3);
62
63
  });
63
64
 
64
- test("insert element directly", async () => {
65
-
66
- const cache = new LoadingCache({
67
- load: async () => 3
68
- });
69
-
70
- cache.put("x", 1);
71
-
72
- expect(await cache.get("x")).toEqual(1);
73
- });
74
-
75
- test("clear", async () => {
76
-
77
- const cache = new LoadingCache({
78
- load: async () => 3
79
- });
80
-
81
- cache.put("x", 1);
82
-
83
- cache.clear();
84
-
85
- expect(await cache.get("x")).toEqual(3);
86
- });
87
-
88
65
  test("eviction", async () => {
89
66
 
90
67
  /**
@@ -116,4 +93,28 @@ test("eviction", async () => {
116
93
  expect(cache.contains(3)).toBe(true);
117
94
  expect(cache.contains(4)).toBe(true);
118
95
 
119
- });
96
+ });
97
+
98
+ test("insert element directly", async () => {
99
+
100
+ const cache = new LoadingCache({
101
+ load: async () => 3
102
+ });
103
+
104
+ cache.put("x", 1);
105
+
106
+ expect(await cache.get("x")).toEqual(1);
107
+ });
108
+
109
+ test("clear", async () => {
110
+
111
+ const cache = new LoadingCache({
112
+ load: async () => 3
113
+ });
114
+
115
+ cache.put("x", 1);
116
+
117
+ cache.clear();
118
+
119
+ expect(await cache.get("x")).toEqual(3);
120
+ });
@@ -1,20 +1,21 @@
1
- import {EnginePlatform} from "./platform/EnginePlatform";
2
- import SceneManager from "./scene/SceneManager";
1
+ import ConcurrentExecutor from "../core/process/executor/ConcurrentExecutor";
2
+ import View from "../view/View";
3
+ import {AssetManager} from "./asset/AssetManager";
4
+ import {EntityManager} from "./ecs/EntityManager";
3
5
  import {GraphicsEngine} from "./graphics/GraphicsEngine";
4
- import SoundEngine from "./sound/SoundEngine";
5
6
  import KeyboardDevice from "./input/devices/KeyboardDevice";
6
7
  import {PointerDevice} from "./input/devices/PointerDevice";
7
- import {AssetManager} from "./asset/AssetManager";
8
- import {EntityManager} from "./ecs/EntityManager";
9
- import View from "../view/View";
10
- import Ticker from "./simulation/Ticker";
8
+ import {EnginePlatform} from "./platform/EnginePlatform";
11
9
  import {EnginePluginManager} from "./plugin/EnginePluginManager";
12
- import ConcurrentExecutor from "../core/process/executor/ConcurrentExecutor";
10
+ import SceneManager from "./scene/SceneManager";
11
+ import Ticker from "./simulation/Ticker";
12
+ import SoundEngine from "./sound/SoundEngine";
13
13
 
14
14
  export interface IEngineInitializationOptions {
15
15
  entityManager?: EntityManager,
16
16
  enableAudio?: boolean
17
17
  enableGraphics?: boolean
18
+ validation?:boolean
18
19
  }
19
20
 
20
21
  export default class Engine {
@@ -2,30 +2,30 @@
2
2
  *
3
3
  */
4
4
 
5
- import {PerspectiveCamera as ThreePerspectiveCamera} from 'three';
6
- import {assert} from "../core/assert.js";
5
+ import { PerspectiveCamera as ThreePerspectiveCamera } from 'three';
6
+ import { assert } from "../core/assert.js";
7
7
  import Vector1 from "../core/geom/Vector1.js";
8
- import {Localization} from "../core/localization/Localization.js";
9
- import {ModuleRegistry} from "../core/model/ModuleRegistry.js";
8
+ import { Localization } from "../core/localization/Localization.js";
9
+ import { ModuleRegistry } from "../core/model/ModuleRegistry.js";
10
10
  import ObservedBoolean from "../core/model/ObservedBoolean.js";
11
11
  import ConcurrentExecutor from '../core/process/executor/ConcurrentExecutor.js';
12
12
  import EmptyView from "../view/elements/EmptyView.js";
13
- import {ViewStack} from "../view/elements/navigation/ViewStack.js";
13
+ import { ViewStack } from "../view/elements/navigation/ViewStack.js";
14
14
 
15
- import {AssetManager} from './asset/AssetManager.js';
15
+ import { AssetManager } from './asset/AssetManager.js';
16
16
  import Preloader from "./asset/preloader/Preloader.js";
17
- import {MetricCollection} from "./development/performance/MetricCollection.js";
18
- import {MetricStatistics} from "./development/performance/MetricStatistics.js";
19
- import {PeriodicConsolePrinter} from "./development/performance/monitor/PeriodicConsolePrinter.js";
20
- import {EntityManager} from "./ecs/EntityManager.js";
21
- import {BinarySerializationRegistry} from "./ecs/storage/binary/BinarySerializationRegistry.js";
22
- import {GraphicsEngine} from './graphics/GraphicsEngine.js';
17
+ import { MetricCollection } from "./development/performance/MetricCollection.js";
18
+ import { MetricStatistics } from "./development/performance/MetricStatistics.js";
19
+ import { PeriodicConsolePrinter } from "./development/performance/monitor/PeriodicConsolePrinter.js";
20
+ import { EntityManager } from "./ecs/EntityManager.js";
21
+ import { BinarySerializationRegistry } from "./ecs/storage/binary/BinarySerializationRegistry.js";
22
+ import { GraphicsEngine } from './graphics/GraphicsEngine.js';
23
23
  import KeyboardDevice from "./input/devices/KeyboardDevice.js";
24
- import {PointerDevice} from "./input/devices/PointerDevice.js";
25
- import {StaticKnowledgeDatabase} from "./knowledge/database/StaticKnowledgeDatabase.js";
26
- import {logger} from "./logging/GlobalLogger.js";
27
- import {OptionGroup} from "./options/OptionGroup.js";
28
- import {EnginePluginManager} from "./plugin/EnginePluginManager.js";
24
+ import { PointerDevice } from "./input/devices/PointerDevice.js";
25
+ import { StaticKnowledgeDatabase } from "./knowledge/database/StaticKnowledgeDatabase.js";
26
+ import { logger } from "./logging/GlobalLogger.js";
27
+ import { OptionGroup } from "./options/OptionGroup.js";
28
+ import { EnginePluginManager } from "./plugin/EnginePluginManager.js";
29
29
  import SceneManager from "./scene/SceneManager.js";
30
30
  import Ticker from "./simulation/Ticker.js";
31
31
  import SoundEngine from './sound/SoundEngine.js';
@@ -52,14 +52,16 @@ class Engine {
52
52
  *
53
53
  * @param {EnginePlatform} platform
54
54
  * @param {EntityManager} [entityManager]
55
- * @param enableGraphics
56
- * @param enableAudio
55
+ * @param {boolean} [enableGraphics]
56
+ * @param {boolean} [enableAudio]
57
+ * @param {boolean} [validation]
57
58
  * @constructor
58
59
  */
59
60
  constructor(platform, {
60
61
  entityManager,
61
62
  enableGraphics = true,
62
- enableAudio = true
63
+ enableAudio = true,
64
+ validation = true
63
65
  } = {}) {
64
66
  assert.defined(platform, 'platform');
65
67
 
@@ -74,6 +76,7 @@ class Engine {
74
76
  * @type {StaticKnowledgeDatabase}
75
77
  */
76
78
  this.staticKnowledge = new StaticKnowledgeDatabase();
79
+ this.staticKnowledge.validation_enabled = validation;
77
80
 
78
81
  /**
79
82
  *
@@ -235,7 +238,7 @@ class Engine {
235
238
  try {
236
239
  graphicsEngine.start();
237
240
  } catch (e) {
238
- logger.info("Failed to start GraphicEngine: ", e);
241
+ logger.error(`Failed to start GraphicEngine: ${e}`);
239
242
  }
240
243
 
241
244
  } else {
@@ -468,7 +471,7 @@ class Engine {
468
471
  requestAnimationFrame(this.#animation_frame);
469
472
 
470
473
  //start simulation
471
- this.ticker.start({maxTimeout: 200});
474
+ this.ticker.start({ maxTimeout: 200 });
472
475
  //self.uiController.init(self);
473
476
 
474
477
  //load options
@@ -232,6 +232,7 @@ export class GraphicsEngine {
232
232
  return intersectObject;
233
233
  })();
234
234
  }
235
+
235
236
  /**
236
237
  *
237
238
  * @returns {MaterialManager}
@@ -315,7 +316,7 @@ export class GraphicsEngine {
315
316
 
316
317
  start() {
317
318
  const canvas = document.createElement("canvas");
318
- const context = canvas.getContext("webgl2", {antialias: false});
319
+ const context = canvas.getContext("webgl2", { antialias: false });
319
320
 
320
321
  const rendererParameters = {
321
322
  antialias: true,
@@ -519,6 +520,10 @@ export class GraphicsEngine {
519
520
  // TODO designate opaque output buffer
520
521
  const frameBuffer = buffers.getById(StandardFrameBuffers.ColorAndDepth);
521
522
 
523
+ if (frameBuffer === undefined) {
524
+ throw new Error(`No color-depth frame buffer`);
525
+ }
526
+
522
527
  renderTextureToScreenQuad(frameBuffer.renderTarget.texture, renderer);
523
528
 
524
529
  this.on.postOpaquePass.send0();
@@ -1,10 +1,10 @@
1
+ import { IllegalStateException } from "../../../core/fsm/exceptions/IllegalStateException.js";
2
+ import { objectKeyByValue } from "../../../core/model/object/objectKeyByValue.js";
1
3
  import ObservedEnum from "../../../core/model/ObservedEnum.js";
2
- import { GameAssetType } from "../../asset/GameAssetType.js";
3
- import TaskGroup from "../../../core/process/task/TaskGroup.js";
4
4
  import Task from "../../../core/process/task/Task.js";
5
+ import TaskGroup from "../../../core/process/task/TaskGroup.js";
6
+ import { GameAssetType } from "../../asset/GameAssetType.js";
5
7
  import { StaticKnowledgeDataTableDescriptor } from "./StaticKnowledgeDataTableDescriptor.js";
6
- import { IllegalStateException } from "../../../core/fsm/exceptions/IllegalStateException.js";
7
- import { objectKeyByValue } from "../../../core/model/object/objectKeyByValue.js";
8
8
 
9
9
  /**
10
10
  * @readonly
@@ -32,7 +32,21 @@ export class StaticKnowledgeDatabase {
32
32
  * @private
33
33
  */
34
34
  __specs = [];
35
-
35
+
36
+ /**
37
+ *
38
+ * @type {boolean}
39
+ */
40
+ #validation_enabled = false;
41
+
42
+ /**
43
+ *
44
+ * @param {boolean} v
45
+ */
46
+ set validation_enabled(v) {
47
+ this.#validation_enabled = v;
48
+ }
49
+
36
50
 
37
51
  /**
38
52
  * Reset database, drop all table data
@@ -279,7 +293,7 @@ export class StaticKnowledgeDatabase {
279
293
  return Promise.all(promises).then(() => {
280
294
  let p = this.link(am, executor);
281
295
 
282
- if (!ENV_PRODUCTION) {
296
+ if (this.#validation_enabled) {
283
297
  p = p.then(() => this.validate(executor));
284
298
  }
285
299