rename to maxwell
This commit is contained in:
parent
3513cc496a
commit
8a8e2fefec
|
@ -1,11 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "webgl"
|
name = "maxwell"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Magnus Ulimoen <flymagnus@gmail.com>"]
|
authors = ["Magnus Ulimoen <flymagnus@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["console_error_panic_hook", "wee_alloc"]
|
default = ["console_error_panic_hook", "wee_alloc"]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="generator" content="by-hand" />
|
<meta name="generator" content="by-hand" />
|
||||||
<meta name="viewpost" context="width=device-width, inital-scale=1.0, user-scalable=yes" />
|
<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">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
<script async type="module" src="main.js"></script>
|
<script async type="module" src="main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
4
main.js
4
main.js
|
@ -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() {
|
async function run() {
|
||||||
let wasm = await init("./webgl_bg.wasm");
|
let wasm = await init("./maxwell_bg.wasm");
|
||||||
set_panic_hook();
|
set_panic_hook();
|
||||||
|
|
||||||
const canvas = document.getElementById("glCanvas");
|
const canvas = document.getElementById("glCanvas");
|
||||||
|
|
62
make_wasm.py
62
make_wasm.py
|
@ -3,31 +3,63 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
import tempfile
|
||||||
|
import pathlib
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = ArgumentParser(description="Build js and wasm")
|
parser = ArgumentParser(description="Build js and wasm")
|
||||||
parser.add_argument("-r", help="Build release type",
|
parser.add_argument(
|
||||||
dest="release", action="store_true")
|
"-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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.release:
|
publish = args.destdir
|
||||||
check_call(["cargo", "build", "--release",
|
publish.mkdir(exist_ok=True)
|
||||||
"--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"
|
|
||||||
|
|
||||||
check_call(["wasm-bindgen", target, "--out-dir", ".",
|
target_triple = "wasm32-unknown-unknown"
|
||||||
"--no-typescript", "--target", "web"])
|
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:
|
if args.release:
|
||||||
try:
|
try:
|
||||||
copyfile("webgl_bg.wasm", "before-wasm-opt.wasm")
|
with tempfile.TemporaryDirectory() as d_:
|
||||||
check_call(["wasm-opt", "-O4", "before-wasm-opt.wasm",
|
d = pathlib.Path(d_)
|
||||||
"-o", "webgl_bg.wasm"])
|
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:
|
except FileNotFoundError:
|
||||||
print("wasm-opt not found, not optimising further")
|
print("wasm-opt not found, not optimising further")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
for f in ["index.html", "main.js", "style.css"]:
|
||||||
|
copyfile(f, publish.joinpath(f))
|
||||||
|
|
|
@ -2,8 +2,7 @@ use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
mod maxwell;
|
mod maxwell;
|
||||||
mod operators;
|
mod operators;
|
||||||
use maxwell::{System, WorkBuffers};
|
pub use crate::maxwell::{System, WorkBuffers};
|
||||||
use operators::Upwind4;
|
|
||||||
|
|
||||||
#[cfg(feature = "wee_alloc")]
|
#[cfg(feature = "wee_alloc")]
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
@ -35,7 +34,7 @@ impl Universe {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance(&mut self, dt: f32) {
|
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);
|
std::mem::swap(&mut self.sys.0, &mut self.sys.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue