summaryrefslogtreecommitdiff
path: root/WebInterface/wasm/webhogg/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'WebInterface/wasm/webhogg/src/lib.rs')
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs36
1 files changed, 13 insertions, 23 deletions
diff --git a/WebInterface/wasm/webhogg/src/lib.rs b/WebInterface/wasm/webhogg/src/lib.rs
index 2ee7267..6d9fca9 100644
--- a/WebInterface/wasm/webhogg/src/lib.rs
+++ b/WebInterface/wasm/webhogg/src/lib.rs
@@ -1,54 +1,44 @@
mod client_logger;
mod webhogg_exception;
-mod page;
mod canvas;
-mod app;
use wasm_bindgen::prelude::*;
-use app::WebhoggApplication as App;
use web_sys::Worker;
+use web_sys::OffscreenCanvas as ECanvas;
#[macro_use]
extern crate log;
-fn run_application() {
- match App::new().and_then(|app| app.run()) {
- Ok(_) => info!("program terminated successfully"),
- Err(e) => error!("program terminated with failure > {}", e)
- }
-}
-
#[wasm_bindgen]
pub fn game_logic_entry(worker: web_sys::Worker) {
client_logger::init_logger();
info!("hello from game logic wasm");
- info!("begin long calculation in game logic thread");
worker.post_message(&wasm_bindgen::JsValue::from_str("premsg frm wasm_gLe"))
.unwrap();
- info!("killed game logic");
+ info!("game logic terminated");
}
#[wasm_bindgen]
pub fn graphics_entry(worker: web_sys::DedicatedWorkerGlobalScope,
- canvas: web_sys::OffscreenCanvas) {
+ ecanvas: JsValue) {
client_logger::init_logger();
- info!("hello from graphics wasm {:?}", canvas);
+ let ecanvas: ECanvas = js_sys::Reflect::get(&ecanvas,
+ &wasm_bindgen::JsValue::from_str("canvas"))
+ .map_err(|e| error!("could not load canvas"))
+ .unwrap().into();
+
+ info!("hello from graphics wasm {:?}", ecanvas);
let handler = wasm_bindgen::closure::Closure::once_into_js(
(|e: web_sys::MessageEvent| {
info!("things are getting wired: {:?}", e.data());
}));
-
worker.set_onmessage(Some(&js_sys::Function::from(handler)));
- entry2();
- info!("killed graphics");
-}
-
-pub fn entry2() {
- // client_logger::init_logger();
- info!("begin running wasm application");
+ let canvas = canvas::Canvas::from_existing(&ecanvas)
+ .map_err(|e| error!("{}", e))
+ .unwrap();
- run_application()
+ info!("graphics terminated");
}