@woosh/meep-engine 2.119.102 → 2.119.104

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.
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.119.102",
8
+ "version": "2.119.104",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/core/process/worker/WorkerBuilder.js"],"names":[],"mappings":";AAQA;IAEI;;;OAGG;IACH,SAFU,MAAM,EAAE,CAEL;IACb,YAAa;IACb;;;OAGG;IACH,WAFU;QAAC,CAAC,WAAU;QAAC,IAAI,EAAC,MAAM,CAAA;KAAC,EAAE,CAEtB;IACf,sBAA6B;IAE7B;;;OAGG;IACH,cAFW,MAAM,QAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,UACN,WAAS,MAAM,QAIzB;IAED;;;;;OAKG;IACH,6CAKC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAMhB;IAED;;;OAGG;IACH,SAFa,WAAW,CAyGvB;CACJ;wBAzKuB,8BAA8B;wBAC9B,kBAAkB"}
1
+ {"version":3,"file":"WorkerBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/core/process/worker/WorkerBuilder.js"],"names":[],"mappings":";AAQA;IAEI;;;OAGG;IACH,SAFU,MAAM,EAAE,CAEL;IACb,YAAa;IACb;;;OAGG;IACH,WAFU;QAAC,CAAC,WAAU;QAAC,IAAI,EAAC,MAAM,CAAA;KAAC,EAAE,CAEtB;IACf,sBAA6B;IAE7B;;;OAGG;IACH,cAFW,MAAM,QAIhB;IAED;;;;OAIG;IACH,gBAHW,MAAM,UACN,WAAS,MAAM,QAIzB;IAED;;;;;OAKG;IACH,6CAKC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAMhB;IAED;;;OAGG;IACH,SAFa,WAAW,CA2HvB;CACJ;wBA3LuB,8BAA8B;wBAC9B,kBAAkB"}
@@ -116,6 +116,7 @@ class WorkerBuilder {
116
116
 
117
117
  //api handler
118
118
  Array.prototype.push.apply(codeLines, [
119
+ //language=js
119
120
  `function extractTransferables(obj, result) {
120
121
  if (typeof obj !== "object") {
121
122
  return; //not an object, skip
@@ -133,35 +134,52 @@ class WorkerBuilder {
133
134
  }
134
135
  }
135
136
  }`,
136
- 'globalScope.onmessage = function(event){',
137
- ' var eventData = event.data;',
138
- ' var requestId = eventData.id',
139
- ' var methodName = eventData.methodName;',
140
- ' var parameters = eventData.parameters;',
141
- ' var method = api[methodName];',
142
-
143
- ' function sendResult(result){',
144
- ' var transferables = [];',
145
- ' extractTransferables(result, transferables);',
146
- ' globalScope.postMessage({methodName: methodName, id: requestId, result: result}, transferables);',
147
- ' }',
148
-
149
- ' function sendError(error){',
150
- ' let stack = "";',
151
- ' try{stack = error.stack.split("\\n")}catch(e){}',
152
- ' globalScope.postMessage({methodName: methodName, id: requestId, error: {message: error.message, stack: stack }});',
153
- ' }',
154
-
155
- ' if(method === undefined){',
156
- ' sendError(new Error("API named \'"+methodName+"\' was not found."));',
157
- ' }else{',
158
- ' try{',
159
- ' method.apply(null,parameters).then(sendResult, sendError);',
160
- ' }catch(e){',
161
- ' sendError(e);',
162
- ' }',
163
- ' }',
164
- '};'
137
+ //language=js
138
+ `globalScope.onmessage = function (event) {
139
+ const eventData = event.data;
140
+ const requestId = eventData.id
141
+ const methodName = eventData.methodName;
142
+ const parameters = eventData.parameters;
143
+ const method = api[methodName];
144
+
145
+ function sendResult(result) {
146
+ const transferables = [];
147
+ extractTransferables(result, transferables);
148
+ globalScope.postMessage({ methodName: methodName, id: requestId, result: result }, transferables);
149
+ }
150
+
151
+ function sendError(error) {
152
+ let stack = "";
153
+ try {
154
+ stack = error.stack.split("\\n")
155
+ } catch (e) {
156
+ }
157
+ globalScope.postMessage({
158
+ methodName: methodName,
159
+ id: requestId,
160
+ error: { message: error.message, stack: stack }
161
+ });
162
+ }
163
+
164
+ if (method === undefined) {
165
+ sendError(new Error("API named \'" + methodName + "\' was not found."));
166
+ } else {
167
+ try {
168
+ const method_result = method.apply(null, parameters);
169
+
170
+ if(typeof method_result.then === "function"){
171
+ // thenable
172
+ method_result.then(sendResult, sendError);
173
+ }else{
174
+ // straight value
175
+ sendResult(method_result);
176
+ }
177
+
178
+ } catch (e) {
179
+ sendError(e);
180
+ }
181
+ }
182
+ };`
165
183
  ]);
166
184
 
167
185
  const code = codeLines.join("\n");
@@ -1,5 +1,9 @@
1
1
  export class ImageRGBADataLoader extends AssetLoader<any, any> {
2
- constructor();
2
+ /**
3
+ *
4
+ * @param {string} [worker_path] Path to decoder worker, allows flexibility in deployment
5
+ */
6
+ constructor({ worker_path }?: string);
3
7
  decoder: CodecWithFallback;
4
8
  link(assetManager: any, engine: any): Promise<void>;
5
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ImageRGBADataLoader.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/asset/loaders/image/ImageRGBADataLoader.js"],"names":[],"mappings":"AAYA;IACI,cAOC;IAJG,2BAGC;IAGL,oDAOC;IAED;;;;;;OAMG;IACH,4BASC;IAED;;;;;;OAMG;IACH,mBAoBC;IAED,6EAiCC;CACJ;4BA5G2B,mBAAmB;kCACb,8BAA8B"}
1
+ {"version":3,"file":"ImageRGBADataLoader.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/asset/loaders/image/ImageRGBADataLoader.js"],"names":[],"mappings":"AAYA;IACI;;;OAGG;IACH,8BAFW,MAAM,EAWhB;IAJG,2BAGC;IAGL,oDAOC;IAED;;;;;;OAMG;IACH,4BASC;IAED;;;;;;OAMG;IACH,mBAoBC;IAED,6EAiCC;CACJ;4BAlH2B,mBAAmB;kCACb,8BAA8B"}
@@ -11,11 +11,17 @@ import { ImageRGBADataAsset } from "./ImageRGBADataAsset.js";
11
11
  const ASSET_TYPE_ARRAY_BUFFER = "arraybuffer";
12
12
 
13
13
  export class ImageRGBADataLoader extends AssetLoader {
14
- constructor() {
14
+ /**
15
+ *
16
+ * @param {string} [worker_path] Path to decoder worker, allows flexibility in deployment
17
+ */
18
+ constructor({
19
+ worker_path
20
+ } = {}) {
15
21
  super();
16
22
 
17
23
  this.decoder = new CodecWithFallback(
18
- new ThreadedImageDecoder(),
24
+ new ThreadedImageDecoder({ worker_path }),
19
25
  new NativeImageDecoder()
20
26
  );
21
27
  }
@@ -1,4 +1,9 @@
1
1
  export class ThreadedImageDecoder extends Codec {
2
+ /**
3
+ *
4
+ * @param {string} [worker_path]
5
+ */
6
+ constructor({ worker_path }?: string);
2
7
  /**
3
8
  *
4
9
  * @type {OnDemandWorkerManager}
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadedImageDecoder.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/asset/loaders/image/codec/ThreadedImageDecoder.js"],"names":[],"mappings":"AAKA;IAYQ;;;OAGG;IACH,QAFU,qBAAqB,CAE+B;IAKlE,kCASC;IAED,gCAEC;CACJ;sBArCqB,YAAY;sCAHI,6DAA6D"}
1
+ {"version":3,"file":"ThreadedImageDecoder.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/asset/loaders/image/codec/ThreadedImageDecoder.js"],"names":[],"mappings":"AAKA;IACI;;;OAGG;IACH,8BAFW,MAAM,EAuBhB;IAPG;;;OAGG;IACH,QAFU,qBAAqB,CAE+B;IAKlE,kCASC;IAED,gCAEC;CACJ;sBA5CqB,YAAY;sCAHI,6DAA6D"}
@@ -4,12 +4,19 @@ import { PNG_HEADER_BYTES } from "../png/PNG_HEADER_BYTES.js";
4
4
  import { Codec } from "./Codec.js";
5
5
 
6
6
  export class ThreadedImageDecoder extends Codec {
7
- constructor() {
7
+ /**
8
+ *
9
+ * @param {string} [worker_path]
10
+ */
11
+ constructor({
12
+ worker_path = 'bundle-worker-image-decoder.js'
13
+ }={}) {
14
+
8
15
  super();
9
16
 
10
17
  const workerBuilder = new WorkerBuilder();
11
18
 
12
- workerBuilder.importScript('bundle-worker-image-decoder.js');
19
+ workerBuilder.importScript(worker_path);
13
20
 
14
21
  workerBuilder.addMethod('decode', function (data, type) {
15
22
  return Lib.decode(data, type);