From c72400573c6c7f67165cd492a615cb5c2fc18f9f Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 13 May 2024 00:04:44 -0500 Subject: [PATCH] perf: Enable ebiten single thread mode --- .github/workflows/build.yml | 7 ++++--- cmd/gones/cmd.go | 8 +++++++- cmd/gones/get_icons.go | 5 ++--- cmd/gones/window_icon.go | 11 ----------- hack/build-darwin.sh | 2 +- hack/build-windows.sh | 2 +- 6 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 cmd/gones/window_icon.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bcd11322..f9dc0c4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,7 @@ env: libxinerama-dev libxrandr-dev libxxf86vm-dev + BUILD_TAGS: gzip,ebitenginesinglethread jobs: lint: @@ -133,7 +134,7 @@ jobs: - name: Build env: CGO_ENABLED: "1" - run: go build -ldflags='-w -s' -trimpath -tags gzip -o dist/gones + run: go build -ldflags='-w -s' -trimpath -tags "${{ env.BUILD_TAGS }}" -o dist/gones - name: Compress run: tar -cvf gones_linux_amd64.tar.gz -C dist . - name: Upload Artifact @@ -176,7 +177,7 @@ jobs: -v "$(go env GOMODCACHE):/go/pkg/mod" \ -v "$PWD:/app" \ builder \ - go build -ldflags='-w -s' -trimpath -tags gzip -o dist/gones + go build -ldflags='-w -s' -trimpath -tags "${{ env.BUILD_TAGS }}" -o dist/gones - name: Compress run: tar -cvf gones_linux_arm64.tar.gz -C dist . - name: Upload Artifact @@ -202,7 +203,7 @@ jobs: env: GOOS: js GOARCH: wasm - run: go build -ldflags='-w -s' -trimpath -tags gzip -o web/src/assets/gones.wasm + run: go build -ldflags='-w -s' -trimpath -tags "${{ env.BUILD_TAGS }}" -o web/src/assets/gones.wasm - name: Set up Node uses: actions/setup-node@v4 with: diff --git a/cmd/gones/cmd.go b/cmd/gones/cmd.go index 4882de12..500e8468 100644 --- a/cmd/gones/cmd.go +++ b/cmd/gones/cmd.go @@ -4,6 +4,7 @@ import ( "errors" "os" "os/signal" + "runtime" "github.com/gabe565/gones/internal/config" "github.com/gabe565/gones/internal/console" @@ -67,12 +68,17 @@ func run(cmd *cobra.Command, args []string) error { ebiten.SetFullscreen(conf.UI.Fullscreen) ebiten.SetScreenClearedEveryFrame(false) ebiten.SetRunnableOnUnfocused(!conf.UI.PauseUnfocused) + if runtime.GOOS != "darwin" { + ebiten.SetWindowIcon(getWindowIcons()) + } if name := c.Cartridge.Name(); name != "" { ebiten.SetWindowTitle(name + " | GoNES") } - if err := ebiten.RunGame(c); err != nil && !errors.Is(err, console.ErrExit) { + if err := ebiten.RunGameWithOptions(c, &ebiten.RunGameOptions{ + SingleThread: true, + }); err != nil && !errors.Is(err, console.ErrExit) { return err } diff --git a/cmd/gones/get_icons.go b/cmd/gones/get_icons.go index c9985b70..7ea70fae 100644 --- a/cmd/gones/get_icons.go +++ b/cmd/gones/get_icons.go @@ -12,7 +12,7 @@ import ( func getWindowIcons() []image.Image { icons := make([]image.Image, 0, 3) - err := fs.WalkDir(assets.Icons, ".", func(path string, d fs.DirEntry, err error) error { + if err := fs.WalkDir(assets.Icons, ".", func(path string, d fs.DirEntry, err error) error { if err != nil || d.IsDir() { return err } @@ -34,8 +34,7 @@ func getWindowIcons() []image.Image { icons = append(icons, icon) return nil - }) - if err != nil { + }); err != nil { log.Err(err).Msg("Failed to load icons") } diff --git a/cmd/gones/window_icon.go b/cmd/gones/window_icon.go deleted file mode 100644 index d5ffc521..00000000 --- a/cmd/gones/window_icon.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build freebsd || linux || netbsd || openbsd || windows - -package gones - -import "github.com/hajimehoshi/ebiten/v2" - -func init() { //nolint:all - go func() { - ebiten.SetWindowIcon(getWindowIcons()) - }() -} diff --git a/hack/build-darwin.sh b/hack/build-darwin.sh index 662fa223..18a37e1f 100755 --- a/hack/build-darwin.sh +++ b/hack/build-darwin.sh @@ -29,7 +29,7 @@ go generate export GOOS=darwin CGO_ENABLED=1 for ARCH in amd64 arm64; do echo Build "$BINARY_NAME-$ARCH" - GOARCH="$ARCH" go build -ldflags='-w -s' -trimpath -tags gzip -o "dist/$BINARY_NAME-$ARCH" . + GOARCH="$ARCH" go build -ldflags='-w -s' -trimpath -tags gzip,ebitenginesinglethread -o "dist/$BINARY_NAME-$ARCH" . done # Merge binaries diff --git a/hack/build-windows.sh b/hack/build-windows.sh index ce27b7c1..6c5adc05 100755 --- a/hack/build-windows.sh +++ b/hack/build-windows.sh @@ -26,5 +26,5 @@ go generate export GOOS=windows CGO_ENABLED=1 for ARCH in amd64 arm64; do echo Build "$BINARY_NAME-$ARCH.exe" - GOARCH="$ARCH" go build -ldflags='-w -s -H=windowsgui' -trimpath -tags gzip -o "dist/$BINARY_NAME-$ARCH.exe" . + GOARCH="$ARCH" go build -ldflags='-w -s -H=windowsgui' -trimpath -tags gzip,ebitenginesinglethread -o "dist/$BINARY_NAME-$ARCH.exe" . done