summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--WebInterface/wasm/webhogg/game_logic.js79
-rw-r--r--WebInterface/wasm/webhogg/graphics.js79
-rw-r--r--WebInterface/wasm/webhogg/src/app.rs22
-rw-r--r--WebInterface/wasm/webhogg/src/canvas.rs24
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs36
-rw-r--r--WebInterface/wasm/webhogg/src/page.rs26
6 files changed, 82 insertions, 184 deletions
diff --git a/WebInterface/wasm/webhogg/game_logic.js b/WebInterface/wasm/webhogg/game_logic.js
index d023228..fad5d82 100644
--- a/WebInterface/wasm/webhogg/game_logic.js
+++ b/WebInterface/wasm/webhogg/game_logic.js
@@ -28,11 +28,11 @@ __exports.game_logic_entry = game_logic_entry
/**
* @param {any} worker
-* @param {any} canvas
+* @param {any} ecanvas
* @returns {void}
*/
-function graphics_entry(worker, canvas) {
- return wasm.graphics_entry(addHeapObject(worker), addHeapObject(canvas));
+function graphics_entry(worker, ecanvas) {
+ return wasm.graphics_entry(addHeapObject(worker), addHeapObject(ecanvas));
}
__exports.graphics_entry = graphics_entry
@@ -89,21 +89,14 @@ function __widl_f_set_onmessage_DedicatedWorkerGlobalScope(arg0, arg1) {
}
__exports.__widl_f_set_onmessage_DedicatedWorkerGlobalScope = __widl_f_set_onmessage_DedicatedWorkerGlobalScope
-function isLikeNone(x) {
- return x === undefined || x === null;
+function __widl_f_data_MessageEvent(arg0) {
+ return addHeapObject(getObject(arg0).data);
}
+__exports.__widl_f_data_MessageEvent = __widl_f_data_MessageEvent
-function __widl_f_get_element_by_id_Document(arg0, arg1, arg2) {
- let varg1 = getStringFromWasm(arg1, arg2);
-
- const val = getObject(arg0).getElementById(varg1);
- return isLikeNone(val) ? 0 : addHeapObject(val);
-
+function isLikeNone(x) {
+ return x === undefined || x === null;
}
-__exports.__widl_f_get_element_by_id_Document = __widl_f_get_element_by_id_Document
-
-function __widl_instanceof_HTMLCanvasElement(idx) { return getObject(idx) instanceof HTMLCanvasElement ? 1 : 0; }
-__exports.__widl_instanceof_HTMLCanvasElement = __widl_instanceof_HTMLCanvasElement
let cachegetUint32Memory = null;
function getUint32Memory() {
@@ -119,7 +112,7 @@ function handleError(exnptr, e) {
view[exnptr / 4 + 1] = addHeapObject(e);
}
-function __widl_f_get_context_HTMLCanvasElement(arg0, arg1, arg2, exnptr) {
+function __widl_f_get_context_OffscreenCanvas(arg0, arg1, arg2, exnptr) {
let varg1 = getStringFromWasm(arg1, arg2);
try {
@@ -130,26 +123,20 @@ function __widl_f_get_context_HTMLCanvasElement(arg0, arg1, arg2, exnptr) {
handleError(exnptr, e);
}
}
-__exports.__widl_f_get_context_HTMLCanvasElement = __widl_f_get_context_HTMLCanvasElement
-
-function __widl_f_data_MessageEvent(arg0) {
- return addHeapObject(getObject(arg0).data);
-}
-__exports.__widl_f_data_MessageEvent = __widl_f_data_MessageEvent
+__exports.__widl_f_get_context_OffscreenCanvas = __widl_f_get_context_OffscreenCanvas
function __widl_instanceof_WebGL2RenderingContext(idx) { return getObject(idx) instanceof WebGL2RenderingContext ? 1 : 0; }
__exports.__widl_instanceof_WebGL2RenderingContext = __widl_instanceof_WebGL2RenderingContext
-function __widl_instanceof_Window(idx) { return getObject(idx) instanceof Window ? 1 : 0; }
-__exports.__widl_instanceof_Window = __widl_instanceof_Window
-
-function __widl_f_document_Window(arg0) {
-
- const val = getObject(arg0).document;
- return isLikeNone(val) ? 0 : addHeapObject(val);
+function __widl_f_clear_WebGL2RenderingContext(arg0, arg1) {
+ getObject(arg0).clear(arg1 >>> 0);
+}
+__exports.__widl_f_clear_WebGL2RenderingContext = __widl_f_clear_WebGL2RenderingContext
+function __widl_f_clear_color_WebGL2RenderingContext(arg0, arg1, arg2, arg3, arg4) {
+ getObject(arg0).clearColor(arg1, arg2, arg3, arg4);
}
-__exports.__widl_f_document_Window = __widl_f_document_Window
+__exports.__widl_f_clear_color_WebGL2RenderingContext = __widl_f_clear_color_WebGL2RenderingContext
function __widl_f_post_message_Worker(arg0, arg1, exnptr) {
try {
@@ -160,21 +147,6 @@ function __widl_f_post_message_Worker(arg0, arg1, exnptr) {
}
__exports.__widl_f_post_message_Worker = __widl_f_post_message_Worker
-function __wbg_newnoargs_a172f39151049128(arg0, arg1) {
- let varg0 = getStringFromWasm(arg0, arg1);
- return addHeapObject(new Function(varg0));
-}
-__exports.__wbg_newnoargs_a172f39151049128 = __wbg_newnoargs_a172f39151049128
-
-function __wbg_call_8a9c8b0a32a202ff(arg0, arg1, exnptr) {
- try {
- return addHeapObject(getObject(arg0).call(getObject(arg1)));
- } catch (e) {
- handleError(exnptr, e);
- }
-}
-__exports.__wbg_call_8a9c8b0a32a202ff = __wbg_call_8a9c8b0a32a202ff
-
function __wbg_new0_b4c0f6100aa61878() {
return addHeapObject(new Date());
}
@@ -185,6 +157,15 @@ function __wbg_toISOString_580e1bcc780bf968(arg0) {
}
__exports.__wbg_toISOString_580e1bcc780bf968 = __wbg_toISOString_580e1bcc780bf968
+function __wbg_get_48d637c66043532c(arg0, arg1, exnptr) {
+ try {
+ return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
+ } catch (e) {
+ handleError(exnptr, e);
+ }
+}
+__exports.__wbg_get_48d637c66043532c = __wbg_get_48d637c66043532c
+
function __wbindgen_string_new(p, l) { return addHeapObject(getStringFromWasm(p, l)); }
__exports.__wbindgen_string_new = __wbindgen_string_new
@@ -360,9 +341,9 @@ function __wbindgen_throw(ptr, len) {
}
__exports.__wbindgen_throw = __wbindgen_throw
-function __wbindgen_closure_wrapper59(a, b, _ignored) {
- const f = wasm.__wbg_function_table.get(25);
- const d = wasm.__wbg_function_table.get(26);
+function __wbindgen_closure_wrapper55(a, b, _ignored) {
+ const f = wasm.__wbg_function_table.get(23);
+ const d = wasm.__wbg_function_table.get(24);
const cb = function(arg0) {
this.cnt++;
let a = this.a;
@@ -383,7 +364,7 @@ function __wbindgen_closure_wrapper59(a, b, _ignored) {
real.original = cb;
return addHeapObject(real);
}
-__exports.__wbindgen_closure_wrapper59 = __wbindgen_closure_wrapper59
+__exports.__wbindgen_closure_wrapper55 = __wbindgen_closure_wrapper55
function __wbindgen_object_clone_ref(idx) {
return addHeapObject(getObject(idx));
diff --git a/WebInterface/wasm/webhogg/graphics.js b/WebInterface/wasm/webhogg/graphics.js
index 5f817fd..11ddf89 100644
--- a/WebInterface/wasm/webhogg/graphics.js
+++ b/WebInterface/wasm/webhogg/graphics.js
@@ -28,11 +28,11 @@ __exports.game_logic_entry = game_logic_entry
/**
* @param {any} worker
-* @param {any} canvas
+* @param {any} ecanvas
* @returns {void}
*/
-function graphics_entry(worker, canvas) {
- return wasm.graphics_entry(addHeapObject(worker), addHeapObject(canvas));
+function graphics_entry(worker, ecanvas) {
+ return wasm.graphics_entry(addHeapObject(worker), addHeapObject(ecanvas));
}
__exports.graphics_entry = graphics_entry
@@ -89,21 +89,14 @@ function __widl_f_set_onmessage_DedicatedWorkerGlobalScope(arg0, arg1) {
}
__exports.__widl_f_set_onmessage_DedicatedWorkerGlobalScope = __widl_f_set_onmessage_DedicatedWorkerGlobalScope
-function isLikeNone(x) {
- return x === undefined || x === null;
+function __widl_f_data_MessageEvent(arg0) {
+ return addHeapObject(getObject(arg0).data);
}
+__exports.__widl_f_data_MessageEvent = __widl_f_data_MessageEvent
-function __widl_f_get_element_by_id_Document(arg0, arg1, arg2) {
- let varg1 = getStringFromWasm(arg1, arg2);
-
- const val = getObject(arg0).getElementById(varg1);
- return isLikeNone(val) ? 0 : addHeapObject(val);
-
+function isLikeNone(x) {
+ return x === undefined || x === null;
}
-__exports.__widl_f_get_element_by_id_Document = __widl_f_get_element_by_id_Document
-
-function __widl_instanceof_HTMLCanvasElement(idx) { return getObject(idx) instanceof HTMLCanvasElement ? 1 : 0; }
-__exports.__widl_instanceof_HTMLCanvasElement = __widl_instanceof_HTMLCanvasElement
let cachegetUint32Memory = null;
function getUint32Memory() {
@@ -119,7 +112,7 @@ function handleError(exnptr, e) {
view[exnptr / 4 + 1] = addHeapObject(e);
}
-function __widl_f_get_context_HTMLCanvasElement(arg0, arg1, arg2, exnptr) {
+function __widl_f_get_context_OffscreenCanvas(arg0, arg1, arg2, exnptr) {
let varg1 = getStringFromWasm(arg1, arg2);
try {
@@ -130,26 +123,20 @@ function __widl_f_get_context_HTMLCanvasElement(arg0, arg1, arg2, exnptr) {
handleError(exnptr, e);
}
}
-__exports.__widl_f_get_context_HTMLCanvasElement = __widl_f_get_context_HTMLCanvasElement
-
-function __widl_f_data_MessageEvent(arg0) {
- return addHeapObject(getObject(arg0).data);
-}
-__exports.__widl_f_data_MessageEvent = __widl_f_data_MessageEvent
+__exports.__widl_f_get_context_OffscreenCanvas = __widl_f_get_context_OffscreenCanvas
function __widl_instanceof_WebGL2RenderingContext(idx) { return getObject(idx) instanceof WebGL2RenderingContext ? 1 : 0; }
__exports.__widl_instanceof_WebGL2RenderingContext = __widl_instanceof_WebGL2RenderingContext
-function __widl_instanceof_Window(idx) { return getObject(idx) instanceof Window ? 1 : 0; }
-__exports.__widl_instanceof_Window = __widl_instanceof_Window
-
-function __widl_f_document_Window(arg0) {
-
- const val = getObject(arg0).document;
- return isLikeNone(val) ? 0 : addHeapObject(val);
+function __widl_f_clear_WebGL2RenderingContext(arg0, arg1) {
+ getObject(arg0).clear(arg1 >>> 0);
+}
+__exports.__widl_f_clear_WebGL2RenderingContext = __widl_f_clear_WebGL2RenderingContext
+function __widl_f_clear_color_WebGL2RenderingContext(arg0, arg1, arg2, arg3, arg4) {
+ getObject(arg0).clearColor(arg1, arg2, arg3, arg4);
}
-__exports.__widl_f_document_Window = __widl_f_document_Window
+__exports.__widl_f_clear_color_WebGL2RenderingContext = __widl_f_clear_color_WebGL2RenderingContext
function __widl_f_post_message_Worker(arg0, arg1, exnptr) {
try {
@@ -160,21 +147,6 @@ function __widl_f_post_message_Worker(arg0, arg1, exnptr) {
}
__exports.__widl_f_post_message_Worker = __widl_f_post_message_Worker
-function __wbg_newnoargs_a172f39151049128(arg0, arg1) {
- let varg0 = getStringFromWasm(arg0, arg1);
- return addHeapObject(new Function(varg0));
-}
-__exports.__wbg_newnoargs_a172f39151049128 = __wbg_newnoargs_a172f39151049128
-
-function __wbg_call_8a9c8b0a32a202ff(arg0, arg1, exnptr) {
- try {
- return addHeapObject(getObject(arg0).call(getObject(arg1)));
- } catch (e) {
- handleError(exnptr, e);
- }
-}
-__exports.__wbg_call_8a9c8b0a32a202ff = __wbg_call_8a9c8b0a32a202ff
-
function __wbg_new0_b4c0f6100aa61878() {
return addHeapObject(new Date());
}
@@ -185,6 +157,15 @@ function __wbg_toISOString_580e1bcc780bf968(arg0) {
}
__exports.__wbg_toISOString_580e1bcc780bf968 = __wbg_toISOString_580e1bcc780bf968
+function __wbg_get_48d637c66043532c(arg0, arg1, exnptr) {
+ try {
+ return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
+ } catch (e) {
+ handleError(exnptr, e);
+ }
+}
+__exports.__wbg_get_48d637c66043532c = __wbg_get_48d637c66043532c
+
function __wbindgen_string_new(p, l) { return addHeapObject(getStringFromWasm(p, l)); }
__exports.__wbindgen_string_new = __wbindgen_string_new
@@ -360,9 +341,9 @@ function __wbindgen_throw(ptr, len) {
}
__exports.__wbindgen_throw = __wbindgen_throw
-function __wbindgen_closure_wrapper59(a, b, _ignored) {
- const f = wasm.__wbg_function_table.get(25);
- const d = wasm.__wbg_function_table.get(26);
+function __wbindgen_closure_wrapper55(a, b, _ignored) {
+ const f = wasm.__wbg_function_table.get(23);
+ const d = wasm.__wbg_function_table.get(24);
const cb = function(arg0) {
this.cnt++;
let a = this.a;
@@ -383,7 +364,7 @@ function __wbindgen_closure_wrapper59(a, b, _ignored) {
real.original = cb;
return addHeapObject(real);
}
-__exports.__wbindgen_closure_wrapper59 = __wbindgen_closure_wrapper59
+__exports.__wbindgen_closure_wrapper55 = __wbindgen_closure_wrapper55
function __wbindgen_object_clone_ref(idx) {
return addHeapObject(getObject(idx));
diff --git a/WebInterface/wasm/webhogg/src/app.rs b/WebInterface/wasm/webhogg/src/app.rs
deleted file mode 100644
index 7931418..0000000
--- a/WebInterface/wasm/webhogg/src/app.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-use crate::webhogg_exception::WebhoggException;
-use crate::page::Page;
-use crate::canvas::Canvas;
-
-pub(crate) struct WebhoggApplication {
- page: Page,
- canvas: Canvas,
-}
-
-impl WebhoggApplication {
- pub fn new() -> Result<Self, WebhoggException> {
- let page = Page::obtain()?;
- let canvas = Canvas::from_existing("canvas", &page)?;
- Ok(Self {
- page, canvas,
- })
- }
-
- pub fn run(self) -> Result<(), WebhoggException> {
- Ok(())
- }
-}
diff --git a/WebInterface/wasm/webhogg/src/canvas.rs b/WebInterface/wasm/webhogg/src/canvas.rs
index a0ef7d1..5f819e9 100644
--- a/WebInterface/wasm/webhogg/src/canvas.rs
+++ b/WebInterface/wasm/webhogg/src/canvas.rs
@@ -1,32 +1,26 @@
use web_sys::WebGl2RenderingContext as WebGl2;
use wasm_bindgen::JsCast;
use crate::webhogg_exception::WebhoggException;
-use crate::page::Page;
+use web_sys::OffscreenCanvas as ECanvas;
pub struct Canvas {
ctx: WebGl2,
}
impl Canvas {
- pub fn from_existing(id: &str, page: &Page) -> Result<Self, WebhoggException> {
- let canvas_element = page.get_element(id)
- .ok_or(WebhoggException::DomError(
- "could not obtain canvas element (id=canvas)"
- .to_string()))?;
- let canvas_element = canvas_element
- .dyn_into::<web_sys::HtmlCanvasElement>()
- .map_err(|_| WebhoggException::DomError(
- "id=canvas is not a canvas element".to_string()))?;
- debug!("successfully obtained canvas element");
- let ctx = canvas_element.get_context("webgl2")
- .map_err(|_| WebhoggException::WebGlContextError(
- "obtained invalid webgl2 context js value".to_string()))?
+ pub fn from_existing(canvas: &ECanvas) -> Result<Self, WebhoggException> {
+ info!("messages lol");
+ let ctx = canvas.get_context("webgl2")
+ .map_err(|x| WebhoggException::WebGlContextError(
+ format!("obtained invalid webgl2 context js value: {:?}", x)))?
.ok_or(WebhoggException::WebGlContextError(
"could not obtaine webgl2 context".to_string()))?
.dyn_into::<WebGl2>()
.map_err(|_| WebhoggException::WebGlContextError(
"obtained invalid webgl2 context js object".to_string()))?;
- debug!("successfully obtained webgl2 context");
+ info!("successfully obtained webgl2 context");
+ ctx.clear_color(1.0, 0.0, 0.0, 1.0);
+ ctx.clear(WebGl2::COLOR_BUFFER_BIT);
Ok(Self {
ctx,
})
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");
}
diff --git a/WebInterface/wasm/webhogg/src/page.rs b/WebInterface/wasm/webhogg/src/page.rs
deleted file mode 100644
index cb9ee3f..0000000
--- a/WebInterface/wasm/webhogg/src/page.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-use web_sys;
-
-use crate::webhogg_exception::WebhoggException;
-
-pub struct Page {
- window: web_sys::Window,
- document: web_sys::Document,
-}
-
-impl Page {
- pub fn obtain() -> Result<Self, WebhoggException> {
- let window = web_sys::window()
- .ok_or(WebhoggException::DomError("could not obtain window".to_string()))?;
- let document = window.document()
- .ok_or(WebhoggException::DomError("could not obtain document".to_string()))?;
- debug!("initialised page");
- Ok(Self {
- window,
- document,
- })
- }
-
- pub fn get_element(&self, id: &str) -> Option<web_sys::Element> {
- self.document.get_element_by_id(id)
- }
-}