init
This commit is contained in:
commit
66d2b43c6d
|
@ -0,0 +1,6 @@
|
||||||
|
/target
|
||||||
|
/bin
|
||||||
|
/pkg
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
|
wasm-pack.log
|
|
@ -0,0 +1,27 @@
|
||||||
|
[package]
|
||||||
|
name = "invaders"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["thetek <git@thetek.de>"]
|
||||||
|
description = "space invaders written using webassembly, rust and webgl"
|
||||||
|
repository = "https://git.tjdev.de/thetek/invaders"
|
||||||
|
license = "MIT"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wasm-bindgen = "0.2.84"
|
||||||
|
console_error_panic_hook = { version = "0.1.7", optional = true } # better debugging for errors, not great for code size
|
||||||
|
wee_alloc = { version = "0.4.5", optional = true } # smaller, but slower allocator
|
||||||
|
js-sys = "0.3.61"
|
||||||
|
|
||||||
|
[dependencies.web-sys]
|
||||||
|
version = "0.3.61"
|
||||||
|
features = ["Document", "Element", "HtmlCanvasElement", "WebGlBuffer", "WebGlProgram", "WebGl2RenderingContext", "WebGlShader", "WebGlVertexArrayObject", "Window"]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "s" # optimize for small code size
|
|
@ -0,0 +1,25 @@
|
||||||
|
Copyright (c) 2023 thetek <git@thetek.de>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any
|
||||||
|
person obtaining a copy of this software and associated
|
||||||
|
documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without
|
||||||
|
limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software
|
||||||
|
is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice
|
||||||
|
shall be included in all copies or substantial portions
|
||||||
|
of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||||
|
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,15 @@
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
#[cfg(feature = "wee_alloc")]
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn wasm_main() {
|
||||||
|
#[cfg(feature = "console_error_panic_hook")]
|
||||||
|
utils::set_panic_hook();
|
||||||
|
|
||||||
|
utils::alert("hello wasm!");
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
pub fn alert(s: &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_panic_hook() {
|
||||||
|
#[cfg(feature = "console_error_panic_hook")]
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
node_modules
|
||||||
|
dist
|
|
@ -0,0 +1,5 @@
|
||||||
|
// a dependency graph that contains any wasm must all be imported
|
||||||
|
// asynchronously. this `bootstrap.js` file does the single async import, so
|
||||||
|
// that no one else needs to worry about it again.
|
||||||
|
import('./index.js')
|
||||||
|
.catch(e => console.error('error importing `index.js`:', e))
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Invaders</title>
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
background-color: #111;
|
||||||
|
color: #bbb;
|
||||||
|
font-family: monospace;
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
margin: calc(50vh - 300px) auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>This page contains WebAssembly and JavaScript content, please enable JavaScript in your browser.</noscript>
|
||||||
|
<script src="./bootstrap.js"></script>
|
||||||
|
<canvas id="canvas" width="800" height="600">This page contains WebGL content, please enable WebGL in your browser.</canvas>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,3 @@
|
||||||
|
import * as wasm from 'invaders-wasm'
|
||||||
|
|
||||||
|
wasm.wasm_main()
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "invaders",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "space invaders written using webassembly, rust and webgl",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack --config webpack.config.js",
|
||||||
|
"start": "webpack serve"
|
||||||
|
},
|
||||||
|
"keywords": ["webassembly", "wasm", "rust", "webpack"],
|
||||||
|
"author": "thetek <git@thetek.de>",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"invaders-wasm": "file:../pkg"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"copy-webpack-plugin": "^11.0.0",
|
||||||
|
"webpack": "^5.76.2",
|
||||||
|
"webpack-cli": "^5.0.1",
|
||||||
|
"webpack-dev-server": "^4.13.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './bootstrap.js',
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'bootstrap.js',
|
||||||
|
},
|
||||||
|
mode: 'development',
|
||||||
|
plugins: [
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [{ from: 'index.html' }],
|
||||||
|
})
|
||||||
|
],
|
||||||
|
experiments: {
|
||||||
|
asyncWebAssembly: true,
|
||||||
|
syncWebAssembly: true,
|
||||||
|
},
|
||||||
|
devServer: {
|
||||||
|
static: {
|
||||||
|
directory: path.join(__dirname, "dist"),
|
||||||
|
},
|
||||||
|
compress: true,
|
||||||
|
port: 3000,
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue