Ikemen-GO
Ikemen-GO copied to clipboard
Porting to wasm/js/webgl using Gopherjs
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:
- identify external modules that are not Gopherjs-compatible
- when sensible, isolate code that uses these modules in specific files
- find acceptable replacements for the incompatible modules
- 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:
- https://github.com/goxjs/glfw
- https://github.com/goxjs/gl
OpenAL can probably be replaced with Oto, which is already pulled as a dependency by the Beep module :
- https://github.com/hajimehoshi/oto
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.
I have some updates on this. The GopherJS port went pretty well, and I have now switched to WASM instead because GopherJS does not really support unsafe.Pointer
. Here is a summary of the changes:
Changes to Ikemen GO
- use https://github.com/fyne-io/gl-js instead of https://github.com/go-gl/gl
- use https://github.com/fyne-io/glfw-js instead of https://github.com/go-gl/glfw/v3.3/glfw
- disable writing to files (
cfgPath
,stats.json
,Ikemen.log
) -
external/scrip/motif.lua
: do not useOpen_Sans.def
(usearcade.def
instead) - use https://github.com/jvilk/BrowserFS for filesystem access
Changes to Elecbyte Screenpack
-
data/system.def
: do not useOpen_Sans.def
(usearcade.def
instead)
Changes to gl-gs
Pull requests sent here: https://github.com/fyne-io/gl-js/pulls?q=is%3Apr+author%3Asamhocevar
Changes to glfw-js
All pull requests have been accepted by the fyne-io authors: https://github.com/fyne-io/glfw-js/pulls?q=is%3Apr+author%3Asamhocevar
Changes to BrowserFS
- make sure
atimeMs
,mtimeMs
,ctimeMs
are properly initialised inStats()
Changes to Go
- in
c:/Program Files/Go/src/syscall/fs_js.go
, replace!jsErr.IsNull()
with!jsErr.IsUndefined() && !jsErr.IsNull()
- no pull request yet
- the same fix was sent to the GopherJS project https://github.com/gopherjs/gopherjs/pull/1118
It is really pretty excited to see this port !!!!
Here’s how it looks like so far: http://sam.hocevar.net/projects/ikemen/
Yes I found it !!! Pretty awesome :)
Great work :) was thinking about this myself - we really need a web version of this engine.