Files
KSP-MGA-Planner/dist/dedicated-workers/libs/common.js
Krafpy 8da935b047 2D physics fix and error handling consistency
- Reimplemented 2D orbital mechanics functions in physics-2d.ts
and encaspulated inside a `Physics2D` namespace.
- Deleted physics.ts and moved the required functions into physics-3d.ts
Further cleaning and reimplemntation will be done on the physics-3d.ts
content.
- Forced consistency on error handling : every raised error throws
an `Error` object.
- Commented sections relative to 2D physics and sequence generation.
2021-12-19 17:19:30 +01:00

46 lines
1.3 KiB
JavaScript

"use strict";
class WorkerEnvironment {
onWorkerInitialize(data) { }
onWorkerRun(input) { }
onWorkerContinue(input) { }
onWorkerStop() { }
onWorkerDataPass(data) { }
}
function postMessageSafe(msg) {
postMessage(msg);
}
function sendProgress(progress, data) {
postMessageSafe({ label: "progress", progress, data });
}
function debug(...data) {
postMessageSafe({ label: "debug", data: data });
}
function sendResult(result) {
postMessageSafe({ label: "complete", result: result });
}
function initWorker(Env) {
const env = new Env();
onmessage = ({ data }) => {
switch (data.label) {
case "initialize":
env.onWorkerInitialize(data.config);
postMessageSafe({ label: "initialized" });
break;
case "run":
env.onWorkerRun(data.input);
break;
case "continue":
env.onWorkerContinue();
break;
case "stop":
env.onWorkerStop();
postMessageSafe({ label: "stopped" });
break;
case "pass":
env.onWorkerDataPass(data.data);
postMessageSafe({ label: "received" });
break;
}
};
}