@woosh/meep-engine 2.43.4 → 2.43.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.
@@ -1,8 +1,20 @@
1
1
  import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
+ /**
4
+ * Wraps synchronous {@link Map}-implementing object
5
+ */
3
6
  export class AsyncMapWrapper extends AbstractAsyncMap {
4
- constructor(source) {
7
+ /**
8
+ *
9
+ * @param {Map} [source]
10
+ */
11
+ constructor(source = new Map()) {
5
12
  super();
13
+ /**
14
+ *
15
+ * @type {Map}
16
+ * @private
17
+ */
6
18
  this._source = source;
7
19
  }
8
20
 
@@ -1,10 +1,17 @@
1
1
  import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
+ /**
4
+ * Two-tier key-value storage. Intended to accelerate slow asynchronous
5
+ * storage with a fast but limited (in space and reliability) cache in front.
6
+ *
7
+ * First tier (volatile) is considered to be fast an unreliable,
8
+ * whereas second tier (persisted) is considered to be reliable, but slow.
9
+ */
3
10
  export class CachedAsyncMap extends AbstractAsyncMap {
4
11
  /**
5
12
  *
6
- * @param {AbstractAsyncMap} volatile
7
- * @param {AbstractAsyncMap} persisted
13
+ * @param {AbstractAsyncMap} volatile data here may be lost at any point, this is our "cache"
14
+ * @param {AbstractAsyncMap} persisted data here is stored reliably
8
15
  */
9
16
  constructor(volatile, persisted) {
10
17
  super();
@@ -0,0 +1,47 @@
1
+ import { CachedAsyncMap } from "./CachedAsyncMap.js";
2
+ import { AsyncMapWrapper } from "./AsyncMapWrapper.js";
3
+
4
+ test("'get' retrieves data if it is available in volatile level", async () => {
5
+
6
+ const first = new Map();
7
+
8
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(first), new AsyncMapWrapper());
9
+
10
+ first.set(1, 3);
11
+
12
+ expect(await sut.get(1)).toBe(3);
13
+ });
14
+
15
+ test("'get' retrieves data if it is available in persisted level", async () => {
16
+
17
+ const second = new Map();
18
+
19
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(), new AsyncMapWrapper(second));
20
+
21
+ second.set(1, 3);
22
+
23
+ expect(await sut.get(1)).toBe(3);
24
+ });
25
+
26
+ test("'set' propagates data into volatile level", async () => {
27
+
28
+ const first = new Map();
29
+
30
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(first), new AsyncMapWrapper());
31
+
32
+ await sut.set(1, 3);
33
+
34
+ expect(first.get(1)).toBe(3);
35
+ });
36
+
37
+
38
+ test("'set' propagates data into persisted level", async () => {
39
+
40
+ const second = new Map();
41
+
42
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(), new AsyncMapWrapper(second));
43
+
44
+ await sut.set(1, 3);
45
+
46
+ expect(second.get(1)).toBe(3);
47
+ });
@@ -143,6 +143,9 @@ export class GLTFAssetTransformer extends AssetTransformer {
143
143
  micron_geometry.proxy = geometry;
144
144
 
145
145
  geometry[MICRON_GEOMETRY_FIELD] = micron_geometry;
146
+
147
+ // push data into cache
148
+ this.__cache.set(geometry, micron_geometry);
146
149
  }
147
150
 
148
151
 
@@ -184,6 +187,7 @@ export class GLTFAssetTransformer extends AssetTransformer {
184
187
  const buffer = BinaryBuffer.fromArrayBuffer(micron_data.create());
185
188
 
186
189
  deserialize_geometry_collection(this.__active_mesh_micron_cache, buffer);
190
+
187
191
  }
188
192
 
189
193
 
@@ -89,7 +89,15 @@ export class MicronShadedGeometryRenderAdapter extends AbstractRenderAdapter {
89
89
 
90
90
  this.__geometry_building_promises.set(geometry_id, p);
91
91
 
92
- p.then(mg => this.__geometry_map.set(geometry_id, mg));
92
+ p.then(mg => {
93
+ if (mg !== undefined) {
94
+ this.__geometry_map.set(geometry_id, mg);
95
+ }
96
+ });
97
+
98
+ p.finally(() => {
99
+ this.__geometry_building_promises.delete(geometry_id);
100
+ });
93
101
  }
94
102
  return undefined;
95
103
  }
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.43.4",
8
+ "version": "2.43.6",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",