refactor(vm, frontend): turns out that the serde_wasm_bindgen facilities of TSify are borken...
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement, query } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMActiveICMixin } from "virtual_machine/base_device";
|
||||
import { VMActiveICMixin } from "virtual_machine/baseDevice";
|
||||
|
||||
import SlSelect from "@shoelace-style/shoelace/dist/components/select/select.js";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { cache } from "lit/directives/cache.js";
|
||||
import { default as uFuzzy } from "@leeoniya/ufuzzy";
|
||||
import { when } from "lit/directives/when.js";
|
||||
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/baseDevice";
|
||||
import { LogicInfo, ObjectTemplate, StructureInfo } from "ic10emu_wasm";
|
||||
|
||||
type LogicableStrucutureTemplate = Extract<
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css, HTMLTemplateResult } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/baseDevice";
|
||||
import SlSelect from "@shoelace-style/shoelace/dist/components/select/select.component.js";
|
||||
import { parseIntWithHexOrBinary, parseNumber } from "utils";
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.component.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/baseDevice";
|
||||
import { displayNumber, parseNumber } from "utils";
|
||||
import type { LogicType } from "ic10emu_wasm";
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.component.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/baseDevice";
|
||||
import SlSelect from "@shoelace-style/shoelace/dist/components/select/select.component.js";
|
||||
import { ObjectID } from "ic10emu_wasm";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement, property} from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin, VMObjectMixin } from "virtual_machine/baseDevice";
|
||||
import {
|
||||
clamp,
|
||||
crc32,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/baseDevice";
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.component.js";
|
||||
import SlDialog from "@shoelace-style/shoelace/dist/components/dialog/dialog.component.js";
|
||||
import { VMDeviceCard } from "./card";
|
||||
|
||||
@@ -24,7 +24,7 @@ import { crc32, displayNumber, parseNumber } from "utils";
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.component.js";
|
||||
import SlSelect from "@shoelace-style/shoelace/dist/components/select/select.component.js";
|
||||
import { VMDeviceCard } from "./card";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/base_device";
|
||||
import { VMTemplateDBMixin } from "virtual_machine/baseDevice";
|
||||
|
||||
export interface SlotTemplate {
|
||||
typ: Class
|
||||
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
ObjectID,
|
||||
} from "ic10emu_wasm";
|
||||
import * as Comlink from "comlink";
|
||||
import "./base_device";
|
||||
import "./baseDevice";
|
||||
import "./device";
|
||||
import { App } from "app";
|
||||
import { structuralEqual, TypedEventTarget } from "utils";
|
||||
@@ -52,15 +52,24 @@ class VirtualMachine extends TypedEventTarget<VirtualMachineEventMap>() {
|
||||
constructor(app: App) {
|
||||
super();
|
||||
this.app = app;
|
||||
this.vm_worker = new Worker( new URL("./vm_worker.ts", import.meta.url));
|
||||
const vm = Comlink.wrap<VMRef>(this.vm_worker);
|
||||
this.ic10vm = vm;
|
||||
window.VM.set(this);
|
||||
|
||||
this._objects = new Map();
|
||||
this._circuitHolders = new Map();
|
||||
this._networks = new Map();
|
||||
|
||||
this.setupVM();
|
||||
}
|
||||
|
||||
async setupVM() {
|
||||
this.vm_worker = new Worker(new URL("./vmWorker.ts", import.meta.url));
|
||||
const loaded = (w: Worker) =>
|
||||
new Promise((r) => w.addEventListener("message", r, { once: true }));
|
||||
await Promise.all([loaded(this.vm_worker)]);
|
||||
console.info("VM Worker loaded");
|
||||
const vm = Comlink.wrap<VMRef>(this.vm_worker);
|
||||
this.ic10vm = vm;
|
||||
window.VM.set(this);
|
||||
|
||||
this.templateDBPromise = this.ic10vm.getTemplateDatabase();
|
||||
|
||||
this.templateDBPromise.then((db) => this.setupTemplateDatabase(db));
|
||||
|
||||
66639
www/src/ts/virtual_machine/prefabDatabase.ts
Normal file
66639
www/src/ts/virtual_machine/prefabDatabase.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMActiveICMixin } from "virtual_machine/base_device";
|
||||
import { VMActiveICMixin } from "virtual_machine/baseDevice";
|
||||
|
||||
import { RegisterSpec } from "ic10emu_wasm";
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html, css } from "lit";
|
||||
import { customElement } from "lit/decorators.js";
|
||||
import { BaseElement, defaultCss } from "components";
|
||||
import { VMActiveICMixin } from "virtual_machine/base_device";
|
||||
import { VMActiveICMixin } from "virtual_machine/baseDevice";
|
||||
|
||||
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js";
|
||||
import { displayNumber, parseNumber } from "utils";
|
||||
|
||||
1158
www/src/ts/virtual_machine/vmWorker.ts
Normal file
1158
www/src/ts/virtual_machine/vmWorker.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,47 +0,0 @@
|
||||
import { VMRef, init } from "ic10emu_wasm";
|
||||
import type { StationpediaPrefab, ObjectTemplate } from "ic10emu_wasm";
|
||||
|
||||
import * as Comlink from "comlink";
|
||||
|
||||
import * as json_database from "../../../data/database.json" with { type: "json" };
|
||||
|
||||
export interface PrefabDatabase {
|
||||
prefabs: { [key in StationpediaPrefab]: ObjectTemplate};
|
||||
reagents: {
|
||||
[key: string]: {
|
||||
Hash: number;
|
||||
Unit: string;
|
||||
Sources?: {
|
||||
[key in StationpediaPrefab]: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
prefabsByHash: {
|
||||
[key: number]: StationpediaPrefab;
|
||||
};
|
||||
structures: StationpediaPrefab[];
|
||||
devices: StationpediaPrefab[];
|
||||
items: StationpediaPrefab[];
|
||||
logicableItems: StationpediaPrefab[];
|
||||
suits: StationpediaPrefab[];
|
||||
circuitHolders: StationpediaPrefab[];
|
||||
}
|
||||
|
||||
const prefab_database = json_database as unknown as PrefabDatabase;
|
||||
|
||||
const vm: VMRef = init();
|
||||
|
||||
const template_database = new Map(
|
||||
Object.entries(prefab_database.prefabsByHash).map(([hash, name]) => {
|
||||
return [parseInt(hash), prefab_database.prefabs[name]];
|
||||
}),
|
||||
);
|
||||
|
||||
console.info("Loading Prefab Template Database into VM", template_database);
|
||||
const start_time = performance.now();
|
||||
vm.importTemplateDatabase(template_database);
|
||||
const now = performance.now();
|
||||
const time_elapsed = (now - start_time) / 1000;
|
||||
console.log(`Prefab Templat Database loaded in ${time_elapsed} seconds`);
|
||||
|
||||
Comlink.expose(vm);
|
||||
Reference in New Issue
Block a user