-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (31 loc) · 811 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"log"
"syscall/js"
"time"
"github.com/hulkholden/gowebgpu/client/examples/battle"
"github.com/mokiat/wasmgpu"
)
// waitForExports waits until the JS which initializes the globals has finished running.
func waitForExports() {
for {
if fn := js.Global().Get("getContext"); !fn.IsUndefined() {
return
}
log.Printf("getContext is still undefined")
// TODO: slower backoff.
time.Sleep(1 * time.Second)
}
}
func main() {
log.Println("Started client!")
waitForExports()
jsContext := js.Global().Call("getContext")
jsDevice := js.Global().Call("getDevice")
context := wasmgpu.NewCanvasContext(jsContext)
device := wasmgpu.NewDevice(jsDevice)
if err := battle.Run(device, context); err != nil {
log.Printf("runRender() failed: %v", err)
}
<-make(chan bool)
}