summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-31 05:26:50 +0200
committernatrixaeria <janng@gmx.de>2019-05-31 05:26:50 +0200
commitb5ec9c693f3abfe36d6d1e4dbf86e084872a4676 (patch)
treea6595027e8ee7f97b6d6406cb1cb18e876e437a9
parent43f14444fa6f4756aaac255e9c1b47b756d0ecd5 (diff)
Split into two entry points
-rw-r--r--WebInterface/wasm/webhogg/loader.js10
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs17
-rw-r--r--WebInterface/wasm/webhogg/webhogg.js117
3 files changed, 140 insertions, 4 deletions
diff --git a/WebInterface/wasm/webhogg/loader.js b/WebInterface/wasm/webhogg/loader.js
index 81ecbc7..50bf69d 100644
--- a/WebInterface/wasm/webhogg/loader.js
+++ b/WebInterface/wasm/webhogg/loader.js
@@ -1,2 +1,8 @@
-import {default as init} from './pkg/webhogg.js'
-init('./pkg/webhogg_bg.wasm');
+import {default as init_r} from './webhogg.js'
+import {init_x} from './webhogg.js'
+
+let m1 = init_r('./pkg/webhogg_bg.wasm');
+let m2 = init_r('./pkg/webhogg_bg.wasm');
+
+init_x(m1, 1);
+init_x(m2, 2);
diff --git a/WebInterface/wasm/webhogg/src/lib.rs b/WebInterface/wasm/webhogg/src/lib.rs
index 81a3237..2812ed9 100644
--- a/WebInterface/wasm/webhogg/src/lib.rs
+++ b/WebInterface/wasm/webhogg/src/lib.rs
@@ -17,8 +17,21 @@ fn run_application() {
}
}
-#[wasm_bindgen(start)]
-pub fn entry() {
+#[wasm_bindgen]
+pub fn game_logic_entry() {
+ client_logger::init_logger();
+
+ info!("game logic initialisation");
+}
+
+#[wasm_bindgen]
+pub fn graphics_entry() {
+ client_logger::init_logger();
+
+ info!("graphics initialisation");
+}
+
+pub fn entry2() {
client_logger::init_logger();
info!("begin running wasm application");
diff --git a/WebInterface/wasm/webhogg/webhogg.js b/WebInterface/wasm/webhogg/webhogg.js
new file mode 100644
index 0000000..1011eef
--- /dev/null
+++ b/WebInterface/wasm/webhogg/webhogg.js
@@ -0,0 +1,117 @@
+
+const __exports = {};
+let wasm;
+
+let cachedTextDecoder = new TextDecoder('utf-8');
+
+let cachegetUint8Memory = null;
+function getUint8Memory() {
+ if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
+ cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
+ }
+ return cachegetUint8Memory;
+}
+
+function getStringFromWasm(ptr, len) {
+ return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
+}
+
+function __wbg_debug_eacd5b227c4c01c7(arg0, arg1, arg2, arg3, arg4, arg5) {
+ let varg0 = getStringFromWasm(arg0, arg1);
+ let varg2 = getStringFromWasm(arg2, arg3);
+ let varg4 = getStringFromWasm(arg4, arg5);
+ console.debug(varg0, varg2, varg4);
+}
+__exports.__wbg_debug_eacd5b227c4c01c7 = __wbg_debug_eacd5b227c4c01c7
+
+function __wbg_info_be654745b6a55079(arg0, arg1, arg2, arg3, arg4, arg5) {
+ let varg0 = getStringFromWasm(arg0, arg1);
+ let varg2 = getStringFromWasm(arg2, arg3);
+ let varg4 = getStringFromWasm(arg4, arg5);
+ console.info(varg0, varg2, varg4);
+}
+__exports.__wbg_info_be654745b6a55079 = __wbg_info_be654745b6a55079
+
+function __wbg_warn_804a0523852c6d10(arg0, arg1, arg2, arg3, arg4, arg5) {
+ let varg0 = getStringFromWasm(arg0, arg1);
+ let varg2 = getStringFromWasm(arg2, arg3);
+ let varg4 = getStringFromWasm(arg4, arg5);
+ console.warn(varg0, varg2, varg4);
+}
+__exports.__wbg_warn_804a0523852c6d10 = __wbg_warn_804a0523852c6d10
+
+function __wbg_error_56a861ecc80f27e1(arg0, arg1, arg2, arg3, arg4, arg5) {
+ let varg0 = getStringFromWasm(arg0, arg1);
+ let varg2 = getStringFromWasm(arg2, arg3);
+ let varg4 = getStringFromWasm(arg4, arg5);
+ console.error(varg0, varg2, varg4);
+}
+__exports.__wbg_error_56a861ecc80f27e1 = __wbg_error_56a861ecc80f27e1
+/**
+* @returns {void}
+*/
+export function game_logic_entry() {
+ return wasm.game_logic_entry();
+}
+__exports.game_logic_entry = game_logic_entry
+
+/**
+* @returns {void}
+*/
+export function graphics_entry() {
+ return wasm.graphics_entry();
+}
+__exports.graphics_entry = graphics_entry
+
+function __wbindgen_throw(ptr, len) {
+ throw new Error(getStringFromWasm(ptr, len));
+}
+__exports.__wbindgen_throw = __wbindgen_throw
+
+function init_r(module) {
+ let result;
+ const imports = { './webhogg': __exports };
+
+ if (module instanceof URL || typeof module === 'string' || module instanceof Request) {
+
+ const response = fetch(module);
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
+ result = WebAssembly.instantiateStreaming(response, imports)
+ .catch(e => {
+ console.warn("`WebAssembly.instantiateStreaming` failed. Assuming this is because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
+ return response
+ .then(r => r.arrayBuffer())
+ .then(bytes => WebAssembly.instantiate(bytes, imports));
+ });
+ } else {
+ result = response
+ .then(r => r.arrayBuffer())
+ .then(bytes => WebAssembly.instantiate(bytes, imports));
+ }
+ } else {
+
+ result = WebAssembly.instantiate(module, imports)
+ .then(result => {
+ if (result instanceof WebAssembly.Instance) {
+ return { instance: result, module };
+ } else {
+ return result;
+ }
+ });
+ }
+ return result;
+}
+
+function _init_x(result, bx) {
+ return result.then(({instance, module}) => {
+ wasm = instance.exports;
+ if (bx == 1) wasm.game_logic_entry();
+ else wasm.graphics_entry();
+ //init_r.__wbindgen_wasm_module = module;
+ //wasm.__wbindgen_start();
+ return wasm;
+ });
+}
+
+export default init_r;
+export var init_x = _init_x;