@woosh/meep-engine 2.31.4 → 2.31.5
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.
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
import { convertPathToURL } from "../../../engine/network/convertPathToURL.js";
|
|
7
7
|
import WorkerProxy from "./WorkerProxy.js";
|
|
8
|
-
import
|
|
8
|
+
import LineBuilder from "../../codegen/LineBuilder.js";
|
|
9
9
|
|
|
10
10
|
const RxMatchFunctionName = /(function\s*)([a-zA-Z0-9_]+)?(\s*\([^\]]*\)\s*\{.*)/g;
|
|
11
11
|
|
|
12
|
-
const builtin_functions = [{
|
|
13
|
-
f: extractTransferables,
|
|
14
|
-
name: 'extractTransferables'
|
|
15
|
-
}];
|
|
16
|
-
|
|
17
12
|
const WorkerBuilder = function () {
|
|
18
13
|
this.imports = [];
|
|
19
14
|
this.methods = {};
|
|
20
15
|
this.functions = [];
|
|
16
|
+
this.preable = new LineBuilder();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
WorkerBuilder.prototype.addCode = function (code) {
|
|
20
|
+
this.preable.add(code);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -78,8 +78,10 @@ WorkerBuilder.prototype.build = function () {
|
|
|
78
78
|
codeLines.push("globalScope.importScripts('" + url + "');");
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
codeLines.push(this.preable.build());
|
|
82
|
+
|
|
81
83
|
//handle functions
|
|
82
|
-
|
|
84
|
+
this.functions.forEach(function (spec) {
|
|
83
85
|
const f = spec.f;
|
|
84
86
|
|
|
85
87
|
const function_string = f.toString();
|
|
@@ -102,7 +104,23 @@ WorkerBuilder.prototype.build = function () {
|
|
|
102
104
|
|
|
103
105
|
//api handler
|
|
104
106
|
Array.prototype.push.apply(codeLines, [
|
|
105
|
-
|
|
107
|
+
`function extractTransferables(obj, result) {
|
|
108
|
+
if (typeof obj !== "object") {
|
|
109
|
+
return; //not an object, skip
|
|
110
|
+
} else if (obj instanceof ArrayBuffer) {
|
|
111
|
+
result.push(obj);
|
|
112
|
+
} else if (obj.buffer instanceof ArrayBuffer) {
|
|
113
|
+
result.push(obj.buffer);
|
|
114
|
+
} else if (obj instanceof ImageBitmap) {
|
|
115
|
+
result.push(obj);
|
|
116
|
+
} else {
|
|
117
|
+
for (var i in obj) {
|
|
118
|
+
if (obj.hasOwnProperty(i)) {
|
|
119
|
+
extractTransferables(obj[i], result);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}`,
|
|
106
124
|
'globalScope.onmessage = function(event){',
|
|
107
125
|
' var eventData = event.data;',
|
|
108
126
|
' var requestId = eventData.id',
|
|
@@ -8,19 +8,19 @@ export function makeTerrainWorkerProxy() {
|
|
|
8
8
|
const workerBuilder = new WorkerBuilder();
|
|
9
9
|
workerBuilder.importScript('bundle-worker-terrain.js');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (globalScope.useSampleCallbacks === undefined) {
|
|
16
|
-
globalScope.useSampleCallbacks = [callback];
|
|
11
|
+
workerBuilder.addCode(`
|
|
12
|
+
function useSampler(callback) {
|
|
13
|
+
if (globalScope.samplerHeight !== undefined) {
|
|
14
|
+
callback(globalScope.samplerHeight);
|
|
17
15
|
} else {
|
|
18
|
-
globalScope.useSampleCallbacks
|
|
16
|
+
if (globalScope.useSampleCallbacks === undefined) {
|
|
17
|
+
globalScope.useSampleCallbacks = [callback];
|
|
18
|
+
} else {
|
|
19
|
+
globalScope.useSampleCallbacks.push(callback);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
workerBuilder.importFunction('useSampler', useSampler);
|
|
23
|
+
`);
|
|
24
24
|
|
|
25
25
|
workerBuilder.addMethod('computeHeightRange', function () {
|
|
26
26
|
return new Promise(function (resolve, reject) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"productName": "Meep",
|
|
5
5
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
6
6
|
"author": "Alexander Goldring",
|
|
7
|
-
"version": "2.31.
|
|
7
|
+
"version": "2.31.5",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"fast-levenshtein": "2.0.6",
|
|
10
10
|
"opentype.js": "1.3.3",
|