rename to maxwell

This commit is contained in:
Magnus Ulimoen 2019-09-09 18:27:54 +02:00
parent 3513cc496a
commit 8a8e2fefec
5 changed files with 55 additions and 24 deletions

View File

@ -1,11 +1,11 @@
[package]
name = "webgl"
version = "0.1.0"
name = "maxwell"
version = "0.1.1"
authors = ["Magnus Ulimoen <flymagnus@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook", "wee_alloc"]

View File

@ -5,7 +5,7 @@
<meta charset="utf-8" />
<meta name="generator" content="by-hand" />
<meta name="viewpost" context="width=device-width, inital-scale=1.0, user-scalable=yes" />
<title>WebGL waves</title>
<title>Maxwell waves</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script async type="module" src="main.js"></script>
</head>

View File

@ -1,7 +1,7 @@
import { Universe, set_panic_hook, default as init } from "./webgl.js";
import { Universe, set_panic_hook, default as init } from "./maxwell.js";
async function run() {
let wasm = await init("./webgl_bg.wasm");
let wasm = await init("./maxwell_bg.wasm");
set_panic_hook();
const canvas = document.getElementById("glCanvas");

View File

@ -3,31 +3,63 @@
from argparse import ArgumentParser
from subprocess import check_call
from shutil import copyfile
import tempfile
import pathlib
if __name__ == "__main__":
parser = ArgumentParser(description="Build js and wasm")
parser.add_argument("-r", help="Build release type",
dest="release", action="store_true")
parser.add_argument(
"-r", help="Build release type", dest="release", action="store_true"
)
parser.add_argument(
"--destdir",
default=pathlib.Path("publish"),
type=pathlib.Path,
help="Destination suitable for being copied directly to the webserver",
)
args = parser.parse_args()
if args.release:
check_call(["cargo", "build", "--release",
"--target", "wasm32-unknown-unknown"])
target = "target/wasm32-unknown-unknown/release/webgl.wasm"
else:
check_call(["cargo", "build",
"--target", "wasm32-unknown-unknown"])
target = "target/wasm32-unknown-unknown/debug/webgl.wasm"
publish = args.destdir
publish.mkdir(exist_ok=True)
check_call(["wasm-bindgen", target, "--out-dir", ".",
"--no-typescript", "--target", "web"])
target_triple = "wasm32-unknown-unknown"
command = ["cargo", "build", "--target", target_triple]
target = (
pathlib.Path("target")
.joinpath(target_triple)
.joinpath("release" if args.release else "debug")
.joinpath("maxwell.wasm")
)
if args.release:
command.append("--release")
check_call(command)
assert target.exists()
check_call(
[
"wasm-bindgen",
str(target),
"--out-dir",
str(publish),
"--no-typescript",
"--target",
"web",
]
)
if args.release:
try:
copyfile("webgl_bg.wasm", "before-wasm-opt.wasm")
check_call(["wasm-opt", "-O4", "before-wasm-opt.wasm",
"-o", "webgl_bg.wasm"])
with tempfile.TemporaryDirectory() as d_:
d = pathlib.Path(d_)
wasm_bg = publish.joinpath("maxwell_bg.wasm")
wasm_to_opt = d.joinpath("before-wasm-opt.wasm")
copyfile(wasm_bg, wasm_to_opt)
check_call(["wasm-opt", "-O4", str(wasm_to_opt), "-o", str(wasm_bg)])
except FileNotFoundError:
print("wasm-opt not found, not optimising further")
pass
for f in ["index.html", "main.js", "style.css"]:
copyfile(f, publish.joinpath(f))

View File

@ -2,8 +2,7 @@ use wasm_bindgen::prelude::*;
mod maxwell;
mod operators;
use maxwell::{System, WorkBuffers};
use operators::Upwind4;
pub use crate::maxwell::{System, WorkBuffers};
#[cfg(feature = "wee_alloc")]
#[global_allocator]
@ -35,7 +34,7 @@ impl Universe {
}
pub fn advance(&mut self, dt: f32) {
System::advance::<Upwind4>(&self.sys.0, &mut self.sys.1, dt, Some(&mut self.wb));
System::advance::<operators::Upwind4>(&self.sys.0, &mut self.sys.1, dt, Some(&mut self.wb));
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
}