Skip to content

Commit

Permalink
Add Makefile to help build wasm target.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmcallister committed Feb 25, 2021
1 parent 9bdb48c commit e7920db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
html/*.wasm
html/*.js
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: wasm
wasm:
rm -f ./html/*.js ./html/*.wasm
cp $$(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
GOOS=js GOARCH=wasm go build -o ./html/main.wasm .

.PHONY: native
native:
go build -o ./build/doomfire .
16 changes: 16 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const go = new Go();
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
</script>
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (d *Doom) Draw(screen *ebiten.Image) {
}

// Layout takes the outside size (e.g., the window size) and returns the (logical) screen size.
func (d *Doom) Layout(outsideWidth, outsideHeight int) (int, int) {
func (d *Doom) Layout(_, _ int) (int, int) {
return d.width, d.height
}

Expand Down

0 comments on commit e7920db

Please sign in to comment.