diff --git a/front/index.html b/front/index.html index f8cff3c..50709f7 100644 --- a/front/index.html +++ b/front/index.html @@ -5,7 +5,7 @@ -
+ diff --git a/front/index.js b/front/index.js index 947d1e6..40e2a25 100644 --- a/front/index.js +++ b/front/index.js @@ -1,6 +1,7 @@ var ctx; var image; var memory; +var exports; const width = 160; const height = 144; @@ -15,6 +16,18 @@ function blit_text(text, len, x, y, size) { ctx.fillText(decoded,x,y); } +function keyboard_callback(e) { + const keycode_address = exports.KEYCODE.value; + const value = new Uint8ClampedArray(exports.memory.buffer, keycode_address, 2); + + value[0] = e.keyCode; + console.log("thing" + value[0]); + console.log(keycode_address); + console.log(value[0]); + + exports.keyboard_input(); +} + async function init() { const canvas = document.getElementById("window"); canvas.width = width; @@ -33,6 +46,9 @@ async function init() { } ); + exports = instance.exports; + document.getElementById("body").onkeydown=keyboard_callback; + memory = instance.exports.memory const buffer_address = instance.exports.BUFFER.value; image = new ImageData( @@ -48,16 +64,11 @@ async function init() { ctx.textBaseline = 'top' ctx.textAlign = 'left'; - var frame = 1; const render = () => { - frame += 1; - console.log(frame); instance.exports.frame_entry(); requestAnimationFrame(render); } - canvas.onclick = render; - render(); } diff --git a/pirates/Cargo.lock b/pirates/Cargo.lock index add7169..119da1f 100644 --- a/pirates/Cargo.lock +++ b/pirates/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + [[package]] name = "approx" version = "0.5.1" @@ -11,18 +17,81 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arraydeque" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0ffd3d69bd89910509a5d31d1f1353f38ccffdd116dd0099bbd6627f7bd8ad8" + +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "keycode" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07873c3182aec8a0eb1a5a4e7b197d42e9d167ba78497a6ee932a82d94673ed" +dependencies = [ + "arraydeque", + "arrayvec", + "bitflags", + "keycode_macro", +] + +[[package]] +name = "keycode_macro" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e521ea802f5b3c7194e169d75cab431b0ff08d022f2b6047b08754b4988b89df" +dependencies = [ + "anyhow", + "heck", + "proc-macro2", + "quote", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] + [[package]] name = "libc" version = "0.2.147" @@ -35,6 +104,16 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "memory_units" version = "0.4.0" @@ -55,6 +134,12 @@ dependencies = [ "typenum", ] +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + [[package]] name = "num-complex" version = "0.4.4" @@ -101,15 +186,63 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pin-project" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pirates" version = "0.1.0" dependencies = [ + "keycode", + "lazy_static", "libm", "nalgebra", + "spin 0.9.8", + "thingbuf", "wee_alloc", ] +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "simba" version = "0.8.1" @@ -122,12 +255,59 @@ dependencies = [ "paste", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "syn" +version = "2.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thingbuf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4706f1bfb859af03f099ada2de3cea3e515843c2d3e93b7893f16d94a37f9415" +dependencies = [ + "pin-project", +] + [[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "wee_alloc" version = "0.4.5" diff --git a/pirates/Cargo.toml b/pirates/Cargo.toml index 99a95fc..4762e75 100644 --- a/pirates/Cargo.toml +++ b/pirates/Cargo.toml @@ -11,10 +11,21 @@ opt-level = 's' crate-type = ["cdylib"] [dependencies] +keycode = "0.4.0" libm = "0.2.7" +spin = "0.9.8" wee_alloc = "0.4.5" [dependencies.nalgebra] version = "0.32.3" default-features = false features = ["libm"] + +[dependencies.thingbuf] +version = "0.1.4" +default-features = false +features = ["static"] + +[dependencies.lazy_static] +version = "1.4.0" +features = ["spin_no_std"] diff --git a/pirates/src/lib.rs b/pirates/src/lib.rs index 16bb6a7..32da670 100644 --- a/pirates/src/lib.rs +++ b/pirates/src/lib.rs @@ -9,10 +9,15 @@ extern crate wee_alloc; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; +use lazy_static::lazy_static; +use noise::PerlinBuf; use core::sync::atomic::{AtomicU32, Ordering}; use libm::{self, Libm}; extern crate nalgebra as na; use nalgebra::{Vector2}; +use thingbuf::mpsc::{self, errors::TryRecvError}; +use spin::Mutex; +use keycode::KeyMap; mod sampler; mod noise; @@ -37,6 +42,12 @@ const HEIGHT: usize = 144; #[no_mangle] static mut BUFFER: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT]; +// hack, js -> rust ffi in weird shape without wasm_bindgen +#[no_mangle] +static mut KEYCODE: [u8; 2] = [0; 2]; + +static LAST_KEY: Mutex