Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize details of ispx #816

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/ispx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/goplus/builder/ispx
go 1.21

require (
github.com/goplus/igop v0.27.0
github.com/goplus/igop v0.27.1
github.com/goplus/reflectx v1.2.2
github.com/goplus/spx v1.0.1-0.20240828022121-d1b083ef69a3
github.com/hajimehoshi/ebiten/v2 v2.7.8
Expand Down
2 changes: 2 additions & 0 deletions tools/ispx/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ github.com/goplus/gop v1.2.6 h1:kog3c5Js+8EopqmI4+CwueXsqibnBwYVt5q5N7juRVY=
github.com/goplus/gop v1.2.6/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
github.com/goplus/igop v0.27.0 h1:4Wk5CIdm3FI1w6d0Y8GO2IC9sgs4wwYdpizCgRdcfYs=
github.com/goplus/igop v0.27.0/go.mod h1:V8Kf/b4nrw0OPPodwnOYZPCpXvU+hqzuhSAXIToT0ME=
github.com/goplus/igop v0.27.1 h1:nLfk+2a8TZ1XvMb6XZnD6f1DlJ6Owj5We1gt6BMKqaI=
github.com/goplus/igop v0.27.1/go.mod h1:V8Kf/b4nrw0OPPodwnOYZPCpXvU+hqzuhSAXIToT0ME=
github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE=
github.com/goplus/mod v0.13.10/go.mod h1:HDuPZgpWiaTp3PUolFgsiX+Q77cbUWB/mikVHfYND3c=
github.com/goplus/reflectx v1.2.2 h1:T1p20OIH/HcnAvQQNnDLwl6AZOjU34icsfc6migD6L8=
Expand Down
16 changes: 10 additions & 6 deletions tools/ispx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"archive/zip"
"bytes"
"log"
"reflect"
"syscall/js"

_ "github.com/goplus/builder/ispx/pkg/github.com/goplus/spx"
Expand Down Expand Up @@ -48,6 +47,9 @@

var mode igop.Mode
ctx := igop.NewContext(mode)

// Register patch for spx to support functions with generic type like `Gopt_Game_Gopx_GetWidget`.
// See details in https://github.com/goplus/builder/issues/765#issuecomment-2313915805
err = gopbuild.RegisterPackagePatch(ctx, "github.com/goplus/spx", `
package spx

Expand All @@ -67,13 +69,15 @@
if err != nil {
log.Fatalln("Failed to register package patch:", err)
}

source, err := gopbuild.BuildFSDir(ctx, fs, "")
if err != nil {
log.Fatalln("Failed to build Go+ source:", err)
}

// Definition of `Gamer` here should be the same as `Gamer` in `github.com/goplus/spx`
// otherwise, it produces: "fatal error: unreachable method called. linker bug?"
// TODO: consider better solution to avoid replacing `Gopy_Game_Main` and `Gopy_Game_Run`, see details in https://github.com/goplus/builder/issues/824

Check warning on line 80 in tools/ispx/main.go

View check run for this annotation

qiniu-x / note-check

tools/ispx/main.go#L80

A Note is recommended to use "MARKER(uid): note body" format.
type Gamer interface {
initGame(sprites []spx.Spriter) *spx.Game
}
Expand All @@ -84,15 +88,15 @@
}

igop.RegisterExternal("github.com/goplus/spx.Gopt_Game_Main", func(game Gamer, sprites ...spx.Spriter) {
g := game.initGame(sprites)
game.initGame(sprites)
if me, ok := game.(interface{ MainEntry() }); ok {
me.MainEntry()
}
v := reflect.ValueOf(g).Elem().FieldByName("isRunned")
if v.IsValid() && v.Bool() {
return
if me, ok := game.(interface{ IsRunned() bool }); ok {
if !me.IsRunned() {
gameRun(game.(spx.Gamer), "assets")
}
}
gameRun(game.(spx.Gamer), "assets")
})

igop.RegisterExternal("github.com/goplus/spx.Gopt_Game_Run", gameRun)
Expand Down
Loading