@woosh/meep-engine 2.85.0 → 2.85.1

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.
@@ -91074,7 +91074,21 @@ class StaticKnowledgeDatabase {
91074
91074
  * @private
91075
91075
  */
91076
91076
  __specs = [];
91077
-
91077
+
91078
+ /**
91079
+ *
91080
+ * @type {boolean}
91081
+ */
91082
+ #validation_enabled = false;
91083
+
91084
+ /**
91085
+ *
91086
+ * @param {boolean} v
91087
+ */
91088
+ set validation_enabled(v) {
91089
+ this.#validation_enabled = v;
91090
+ }
91091
+
91078
91092
 
91079
91093
  /**
91080
91094
  * Reset database, drop all table data
@@ -91317,7 +91331,7 @@ class StaticKnowledgeDatabase {
91317
91331
  return Promise.all(promises).then(() => {
91318
91332
  let p = this.link(am, executor);
91319
91333
 
91320
- if (!ENV_PRODUCTION) {
91334
+ if (this.#validation_enabled) {
91321
91335
  p = p.then(() => this.validate(executor));
91322
91336
  }
91323
91337
 
@@ -103164,14 +103178,16 @@ class Engine {
103164
103178
  *
103165
103179
  * @param {EnginePlatform} platform
103166
103180
  * @param {EntityManager} [entityManager]
103167
- * @param enableGraphics
103168
- * @param enableAudio
103181
+ * @param {boolean} [enableGraphics]
103182
+ * @param {boolean} [enableAudio]
103183
+ * @param {boolean} [validation]
103169
103184
  * @constructor
103170
103185
  */
103171
103186
  constructor(platform, {
103172
103187
  entityManager,
103173
103188
  enableGraphics = true,
103174
- enableAudio = true
103189
+ enableAudio = true,
103190
+ validation = true
103175
103191
  } = {}) {
103176
103192
 
103177
103193
  /**
@@ -103185,6 +103201,7 @@ class Engine {
103185
103201
  * @type {StaticKnowledgeDatabase}
103186
103202
  */
103187
103203
  this.staticKnowledge = new StaticKnowledgeDatabase();
103204
+ this.staticKnowledge.validation_enabled = validation;
103188
103205
 
103189
103206
  /**
103190
103207
  *
@@ -103578,7 +103595,7 @@ class Engine {
103578
103595
  requestAnimationFrame(this.#animation_frame);
103579
103596
 
103580
103597
  //start simulation
103581
- this.ticker.start({maxTimeout: 200});
103598
+ this.ticker.start({ maxTimeout: 200 });
103582
103599
  //self.uiController.init(self);
103583
103600
 
103584
103601
  //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.1",
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
  *
@@ -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
@@ -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