Skip to content

Porting to wasm/js/webgl using Gopherjs #485

Description

@samhocevar

I would like to build a web version of an Ikemen GO game, and from my understanding of the codebase this will not be trivial and I’d like to discuss a few changes I am willing to contribute. Here is my proposed roadmap:

  1. identify external modules that are not Gopherjs-compatible
  2. when sensible, isolate code that uses these modules in specific files
  3. find acceptable replacements for the incompatible modules
  4. when not possible, just disable these modules

1. Modules that are not Gopherjs-compatible

  • github.com/faiface/beep ✔️ (pure Go implementation)
  • github.com/flopp/go-findfont ❌
  • github.com/go-gl/gl ❌ (alternative available, see below)
  • github.com/go-gl/glfw/v3.3/glfw ❌ (alternative available, see below)
  • github.com/ikemen-engine/glfont ❌
  • github.com/ikemen-engine/go-openal ❌
  • github.com/sqweek/dialog ❌
  • github.com/yuin/gopher-lua ✔️ (pure Go implementation)

2. Isolate incompatible code

Here is an example of how code could be isolated: this commit moves all the code from font.go that uses glfont and go-findfont into a separate font_ttf.go file. When built with go build -tags nottf, this file is ignored and another file, font_nottf.go, is built instead. Right now the implementation is empty and just panics, but there could be a smarter implementation or at least more forgiving error handling.

3. Propose acceptable replacements

OpenGL code is far too entangled in the codebase for a refactor like above. However, the following two libraries appear to work with GopherJS and may work as replacements, with minimal changes:

OpenAL can probably be replaced with Oto, which is already pulled as a dependency by the Beep module :

Note that @hajimehoshi is a game developer and has provided the Go community with great tools for porting Go games to Wasm (as well as other platforms thanks to some impressive work, see https://ebiten.org/blog/native_compiling_for_nintendo_switch.html)

4. Make the rest optional

It’ll probably be tricky to replace glfont in the short term, but I think it’s an acceptable loss. Also the dialog module has no replacement, but a Wasm program can directly call a JavaScript function such as alert() so I don’t see a real problem here either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions