@woosh/meep-engine 2.42.3 → 2.42.4
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.
|
@@ -8,6 +8,12 @@ export class ManagedMaterial {
|
|
|
8
8
|
* @param {Material} m
|
|
9
9
|
*/
|
|
10
10
|
constructor(m) {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {Material|null}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
this.__source = null;
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
*
|
|
@@ -30,6 +36,10 @@ export class ManagedMaterial {
|
|
|
30
36
|
this.onLastReleased = new Signal();
|
|
31
37
|
}
|
|
32
38
|
|
|
39
|
+
getSource() {
|
|
40
|
+
return this.__source;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
/**
|
|
34
44
|
*
|
|
35
45
|
* @returns {Material}
|
|
@@ -8,7 +8,7 @@ export class MaterialManager {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Stores links from uncompiled (source) materials to managed containers
|
|
12
12
|
* @type {HashMap<Material, ManagedMaterial>}
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
@@ -29,6 +29,17 @@ export class MaterialManager {
|
|
|
29
29
|
maxWeight: 100
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Stores links from compiled materials back to the container
|
|
34
|
+
* @type {HashMap<Material, ManagedMaterial>}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
this.__reverse_library = new HashMap({
|
|
38
|
+
keyHashFunction: computeMaterialHash,
|
|
39
|
+
keyEqualityFunction: computeMaterialEquality,
|
|
40
|
+
capacity: 1024
|
|
41
|
+
});
|
|
42
|
+
|
|
32
43
|
this.__cache.onEvicted.add(this.__dispose_material, this);
|
|
33
44
|
|
|
34
45
|
/**
|
|
@@ -55,13 +66,15 @@ export class MaterialManager {
|
|
|
55
66
|
* @private
|
|
56
67
|
*/
|
|
57
68
|
__handle_last_reference_removed(material) {
|
|
58
|
-
const
|
|
69
|
+
const compiled_material = material.getMaterial();
|
|
59
70
|
|
|
60
71
|
// remove from library
|
|
61
|
-
|
|
72
|
+
const source = material.getSource();
|
|
73
|
+
this.__library.delete(source);
|
|
74
|
+
this.__reverse_library.delete(compiled_material);
|
|
62
75
|
|
|
63
76
|
// put material into cache
|
|
64
|
-
this.__cache.put(
|
|
77
|
+
this.__cache.put(source, material);
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -118,7 +131,16 @@ export class MaterialManager {
|
|
|
118
131
|
* @returns {Reference<Material>}
|
|
119
132
|
*/
|
|
120
133
|
obtain(source) {
|
|
121
|
-
|
|
134
|
+
// reverse check to see if this is actually an already compiled/managed material
|
|
135
|
+
let material = this.__reverse_library.get(source);
|
|
136
|
+
|
|
137
|
+
if (material !== undefined) {
|
|
138
|
+
// already compiled material
|
|
139
|
+
return material.getRef();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// forward check
|
|
143
|
+
material = this.__library.get(source);
|
|
122
144
|
|
|
123
145
|
if (material === undefined) {
|
|
124
146
|
// not found in library, check cache
|
|
@@ -138,6 +160,7 @@ export class MaterialManager {
|
|
|
138
160
|
material.onLastReleased.addOne(this.__handle_last_reference_removed, this);
|
|
139
161
|
|
|
140
162
|
this.__library.set(source, material);
|
|
163
|
+
this.__reverse_library.set(material.getMaterial(), material);
|
|
141
164
|
}
|
|
142
165
|
|
|
143
166
|
return material.getRef();
|
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.
|
|
8
|
+
"version": "2.42.4",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|