From: Brendan Hansen Date: Sat, 24 Apr 2021 23:07:38 +0000 (-0500) Subject: removed stupid DOS line endings X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4286e8a5775be49f931cd780ca7b43a75f58ca7d;p=sand-toy.git removed stupid DOS line endings --- diff --git a/site/js/js_events.js b/site/js/js_events.js index 6d93929..df3bb83 100644 --- a/site/js/js_events.js +++ b/site/js/js_events.js @@ -1,67 +1,67 @@ -window.ONYX_MODULES = window.ONYX_MODULES || []; - -function push_event_to_buffer(esp, event_size, event_kind, data) { - let WASM_U32 = new Uint32Array(ONYX_MEMORY.buffer); - - if (WASM_U32[esp] >= WASM_U32[esp + 1]) { - console.log("Event buffer full!"); - return; - } - - WASM_U32[esp] += 1; - - let event_idx = esp + (WASM_U32[esp] - 1) * (event_size / 4) + 2; - WASM_U32[event_idx] = event_kind; - WASM_U32[event_idx + 1] = Date.now(); - - for (let i = 0; i < data.length; i++) { - WASM_U32[event_idx + 2 + i] = data[i]; - } -} - -window.ONYX_MODULES.push({ - module_name: "js_events", - - setup: function(esp, event_size) { - // Indicies into a Uint32Array are not based on bytes, - // but on the index. - esp /= 4; - - document.addEventListener("keydown", function (ev) { - if (ev.isComposing || ev.keyCode === 229) return; - push_event_to_buffer(esp, event_size, 0x04, [ ev.keyCode ]); - }); - - document.addEventListener("keyup", function (ev) { - if (ev.isComposing || ev.keyCode === 229) return; - push_event_to_buffer(esp, event_size, 0x05, [ ev.keyCode ]); - }); - - document.addEventListener("mousedown", function (ev) { - push_event_to_buffer(esp, event_size, 0x01, [ ev.clientX, ev.clientY, ev.button ]); - }); - - document.addEventListener("mouseup", function (ev) { - push_event_to_buffer(esp, event_size, 0x02, [ ev.clientX, ev.clientY, ev.button ]); - }); - - document.addEventListener("mousemove", function (ev) { - push_event_to_buffer(esp, event_size, 0x03, [ ev.clientX, ev.clientY, -1 ]); - }); - - document.addEventListener("wheel", function (ev) { - push_event_to_buffer(esp, event_size, 0x07, [ ev.clientX, ev.clientY, ev.deltaY >= 0 ? 0x04 : 0x03 ]); - }); - - window.addEventListener("resize", function (ev) { - push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]); - }); - - push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]); - - document.oncontextmenu = (e) => { - e.preventDefault = true; - return false; - }; - }, -}); +window.ONYX_MODULES = window.ONYX_MODULES || []; + +function push_event_to_buffer(esp, event_size, event_kind, data) { + let WASM_U32 = new Uint32Array(ONYX_MEMORY.buffer); + + if (WASM_U32[esp] >= WASM_U32[esp + 1]) { + console.log("Event buffer full!"); + return; + } + + WASM_U32[esp] += 1; + + let event_idx = esp + (WASM_U32[esp] - 1) * (event_size / 4) + 2; + WASM_U32[event_idx] = event_kind; + WASM_U32[event_idx + 1] = Date.now(); + + for (let i = 0; i < data.length; i++) { + WASM_U32[event_idx + 2 + i] = data[i]; + } +} + +window.ONYX_MODULES.push({ + module_name: "js_events", + + setup: function(esp, event_size) { + // Indicies into a Uint32Array are not based on bytes, + // but on the index. + esp /= 4; + + document.addEventListener("keydown", function (ev) { + if (ev.isComposing || ev.keyCode === 229) return; + push_event_to_buffer(esp, event_size, 0x04, [ ev.keyCode ]); + }); + + document.addEventListener("keyup", function (ev) { + if (ev.isComposing || ev.keyCode === 229) return; + push_event_to_buffer(esp, event_size, 0x05, [ ev.keyCode ]); + }); + + document.addEventListener("mousedown", function (ev) { + push_event_to_buffer(esp, event_size, 0x01, [ ev.clientX, ev.clientY, ev.button ]); + }); + + document.addEventListener("mouseup", function (ev) { + push_event_to_buffer(esp, event_size, 0x02, [ ev.clientX, ev.clientY, ev.button ]); + }); + + document.addEventListener("mousemove", function (ev) { + push_event_to_buffer(esp, event_size, 0x03, [ ev.clientX, ev.clientY, -1 ]); + }); + + document.addEventListener("wheel", function (ev) { + push_event_to_buffer(esp, event_size, 0x07, [ ev.clientX, ev.clientY, ev.deltaY >= 0 ? 0x04 : 0x03 ]); + }); + + window.addEventListener("resize", function (ev) { + push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]); + }); + + push_event_to_buffer(esp, event_size, 0x06, [ window.innerWidth, window.innerHeight ]); + + document.oncontextmenu = (e) => { + e.preventDefault = true; + return false; + }; + }, +}); diff --git a/site/js/onyx-loader.js b/site/js/onyx-loader.js index 6e643a8..a48a38a 100644 --- a/site/js/onyx-loader.js +++ b/site/js/onyx-loader.js @@ -1,47 +1,47 @@ - -window.ONYX_MODULES = window.ONYX_MODULES || []; -window.ONYX_MEMORY = null; -window.ONYX_INSTANCE = null; - -window.ONYX_MODULES.push({ - module_name: "host", - - print_str: function(ptr, len) { - var buffer = new Uint8Array(ONYX_MEMORY.buffer, ptr, len); - var string = new TextDecoder().decode(buffer); - console.log(string); - }, - - exit: function() { debugger; } -}); - -function launch_onyx_program(script_path, call_start) { - fetch(script_path) - .then(function(res) { return res.arrayBuffer(); }) - .then(function(wasm_code) { - var import_object = {}; - - for (var i = 0; i < window.ONYX_MODULES.length; i++) { - import_object[window.ONYX_MODULES[i].module_name] = window.ONYX_MODULES[i]; - } - - return WebAssembly.instantiate(wasm_code, import_object); - }) - .then(function(wasm_module) { - window.ONYX_MEMORY = wasm_module.instance.exports.memory; - window.ONYX_INSTANCE = wasm_module.instance; - - wasm_module.instance.exports._start(); - }); -} - -window.onload = function() { - var script_tags = document.getElementsByTagName("script"); - - for (var i = 0; i < script_tags.length; i++) { - if (script_tags[i].getAttribute("type") == "application/onyx") { - // @ROBUSTNESS: It should be configurable which function is called on start up of a Onyx WASM module. - launch_onyx_program(script_tags[i].getAttribute("src"), true); - } - } -}; + +window.ONYX_MODULES = window.ONYX_MODULES || []; +window.ONYX_MEMORY = null; +window.ONYX_INSTANCE = null; + +window.ONYX_MODULES.push({ + module_name: "host", + + print_str: function(ptr, len) { + var buffer = new Uint8Array(ONYX_MEMORY.buffer, ptr, len); + var string = new TextDecoder().decode(buffer); + console.log(string); + }, + + exit: function() { debugger; } +}); + +function launch_onyx_program(script_path, call_start) { + fetch(script_path) + .then(function(res) { return res.arrayBuffer(); }) + .then(function(wasm_code) { + var import_object = {}; + + for (var i = 0; i < window.ONYX_MODULES.length; i++) { + import_object[window.ONYX_MODULES[i].module_name] = window.ONYX_MODULES[i]; + } + + return WebAssembly.instantiate(wasm_code, import_object); + }) + .then(function(wasm_module) { + window.ONYX_MEMORY = wasm_module.instance.exports.memory; + window.ONYX_INSTANCE = wasm_module.instance; + + wasm_module.instance.exports._start(); + }); +} + +window.onload = function() { + var script_tags = document.getElementsByTagName("script"); + + for (var i = 0; i < script_tags.length; i++) { + if (script_tags[i].getAttribute("type") == "application/onyx") { + // @ROBUSTNESS: It should be configurable which function is called on start up of a Onyx WASM module. + launch_onyx_program(script_tags[i].getAttribute("src"), true); + } + } +}; diff --git a/site/sand_toy.wasm b/site/sand_toy.wasm index 4ed4bab..418522d 100644 Binary files a/site/sand_toy.wasm and b/site/sand_toy.wasm differ diff --git a/src/build.onyx b/src/build.onyx index 76f467b..7b376ee 100644 --- a/src/build.onyx +++ b/src/build.onyx @@ -1,3 +1,8 @@ + +#if (package runtime).Runtime != (package runtime).Runtime_Js { + #error "Please run with '-r js'." +} + #load "core/std" #load "modules/webgl2/module"