summaryrefslogtreecommitdiff
path: root/WebInterface/wasm/webhogg/src
diff options
context:
space:
mode:
Diffstat (limited to 'WebInterface/wasm/webhogg/src')
-rw-r--r--WebInterface/wasm/webhogg/src/canvas.rs36
-rw-r--r--WebInterface/wasm/webhogg/src/client_logger.rs47
-rw-r--r--WebInterface/wasm/webhogg/src/lib.rs44
-rw-r--r--WebInterface/wasm/webhogg/src/webhogg_exception.rs39
4 files changed, 0 insertions, 166 deletions
diff --git a/WebInterface/wasm/webhogg/src/canvas.rs b/WebInterface/wasm/webhogg/src/canvas.rs
deleted file mode 100644
index bc694ed..0000000
--- a/WebInterface/wasm/webhogg/src/canvas.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use web_sys::WebGl2RenderingContext as WebGl2;
-use wasm_bindgen::JsCast;
-use crate::webhogg_exception::WebhoggException;
-use web_sys::OffscreenCanvas as ECanvas;
-
-pub struct Canvas {
- ctx: WebGl2,
-}
-
-impl Canvas {
- 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()))?;
- info!("successfully obtained webgl2 context");
- ctx.clear_color(0.6, 0.0, 0.6, 1.0);
- ctx.clear(WebGl2::COLOR_BUFFER_BIT);
- Ok(Self {
- ctx,
- })
- }
-
- pub fn gl<'a>(&'a self) -> &'a WebGl2 {
- &self.ctx
- }
-
- pub fn gl_mut<'a>(&'a mut self) -> &'a mut WebGl2 {
- &mut self.ctx
- }
-}
diff --git a/WebInterface/wasm/webhogg/src/client_logger.rs b/WebInterface/wasm/webhogg/src/client_logger.rs
deleted file mode 100644
index f537631..0000000
--- a/WebInterface/wasm/webhogg/src/client_logger.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use wasm_bindgen::prelude::*;
-
-#[wasm_bindgen]
-extern "C" {
- #[wasm_bindgen(js_namespace=console, js_name=debug)]
- fn __console_debug_colored2(f: &str, c1: &str, c2: &str);
- #[wasm_bindgen(js_namespace=console, js_name=info)]
- fn __console_info_colored2(f: &str, c1: &str, c2: &str);
- #[wasm_bindgen(js_namespace=console, js_name=warn)]
- fn __console_warn_colored2(f: &str, c1: &str, c2: &str);
- #[wasm_bindgen(js_namespace=console, js_name=error)]
- fn __console_error_colored2(f: &str, c1: &str, c2: &str);
-}
-
-fn log(rec: &log::Record) {
- let log_fn = match rec.level() {
- log::Level::Trace | log::Level::Debug => __console_debug_colored2,
- log::Level::Info => __console_info_colored2,
- log::Level::Warn => __console_warn_colored2,
- log::Level::Error => __console_error_colored2,
- };
- log_fn(&format!("{}", rec.args()),
- &format!("color: {}", match rec.level() {
- log::Level::Trace => "violet",
- log::Level::Debug => "blue",
- log::Level::Info => "green",
- log::Level::Warn => "orange",
- log::Level::Error => "red"
- }), "");
-}
-
-pub fn init_logger() {
- fern::Dispatch::new().format(|out, message, record|{
- out.finish(format_args!(
- "%c{}%c |{}| {} > {}",
- record.level(),
- String::from(js_sys::Date::new_0().to_iso_string()),
- record.target(),
- message
- )
- )
- })
- .level(log::LevelFilter::Debug)
- .chain(fern::Output::call(log))
- .apply().unwrap();
-}
-
diff --git a/WebInterface/wasm/webhogg/src/lib.rs b/WebInterface/wasm/webhogg/src/lib.rs
deleted file mode 100644
index 6d9fca9..0000000
--- a/WebInterface/wasm/webhogg/src/lib.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-mod client_logger;
-mod webhogg_exception;
-mod canvas;
-
-use wasm_bindgen::prelude::*;
-use web_sys::Worker;
-use web_sys::OffscreenCanvas as ECanvas;
-
-#[macro_use]
-extern crate log;
-
-#[wasm_bindgen]
-pub fn game_logic_entry(worker: web_sys::Worker) {
- client_logger::init_logger();
-
- info!("hello from game logic wasm");
- worker.post_message(&wasm_bindgen::JsValue::from_str("premsg frm wasm_gLe"))
- .unwrap();
- info!("game logic terminated");
-}
-
-#[wasm_bindgen]
-pub fn graphics_entry(worker: web_sys::DedicatedWorkerGlobalScope,
- ecanvas: JsValue) {
- client_logger::init_logger();
-
- 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)));
-
- let canvas = canvas::Canvas::from_existing(&ecanvas)
- .map_err(|e| error!("{}", e))
- .unwrap();
-
- info!("graphics terminated");
-}
diff --git a/WebInterface/wasm/webhogg/src/webhogg_exception.rs b/WebInterface/wasm/webhogg/src/webhogg_exception.rs
deleted file mode 100644
index 46eedd6..0000000
--- a/WebInterface/wasm/webhogg/src/webhogg_exception.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-use std::error::Error;
-
-#[derive(Debug)]
-pub enum WebhoggException {
- DomError(String),
- WebGlContextError(String),
-}
-
-impl WebhoggException {
- fn err_name(&self) -> &str {
- match self {
- WebhoggException::DomError(_) => "DomError",
- WebhoggException::WebGlContextError(_) => "WebGlContextError",
- }
- }
-}
-
-impl Error for WebhoggException {
- fn description(&self) -> &str {
- match self {
- WebhoggException::DomError(desc) => desc,
- WebhoggException::WebGlContextError(desc) => desc,
- }
- }
-
- fn cause(&self) -> Option<&dyn Error> {
- self.source()
- }
-
- fn source(&self) -> Option<&(dyn Error + 'static)> {
- None
- }
-}
-
-impl std::fmt::Display for WebhoggException {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "WebhoggException::{} {}", self.err_name(), self.description())
- }
-}