This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a way to start an example in the browser.
- Loading branch information
1 parent
ce0c752
commit a59366f
Showing
16 changed files
with
654 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode/* | ||
*.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
fileData, err := os.ReadFile("turtle.png") | ||
if err != nil { | ||
panic(err) | ||
} | ||
result := base64.StdEncoding.EncodeToString(fileData) | ||
fmt.Printf("var turtleImage string = \"%s\"\n", result) | ||
|
||
fileData, err = os.ReadFile("arrow.png") | ||
if err != nil { | ||
panic(err) | ||
} | ||
result = base64.StdEncoding.EncodeToString(fileData) | ||
fmt.Printf("var arrowImage string = \"%s\"\n", result) | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Run Example In Browser | ||
|
||
## Info | ||
|
||
Based on info from: <https://ebitengine.org/en/documents/webassembly.html> | ||
|
||
## Run | ||
|
||
```bash | ||
. ./cmd/runinweb/build.sh ./examples/fallingturtles/ | ||
``` | ||
|
||
Then open: <http://localhost:3000/game.html> | ||
|
||
OR: <http://localhost:3000/main.html> for an iframe. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
echo $1 | ||
cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./cmd/runinweb/ | ||
env GOOS=js GOARCH=wasm go build -o ./cmd/runinweb/yourGame.wasm $1 | ||
go run ./cmd/runinweb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("yourGame.wasm"), go.importObject).then(result => { | ||
go.run(result.instance); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
http.Handle("/", http.FileServer(http.Dir("./cmd/runinweb"))) | ||
fmt.Println("Golang: Serving directory") | ||
log.Fatal(http.ListenAndServe(":3000", nil)) | ||
} | ||
|
||
// http://localhost:3000/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<div>Example Golang Scratch game running in the browser as WASM.</div> | ||
<iframe src="game.html" width="1000" height="1000" scrolling="no"></iframe> |
Oops, something went wrong.