yohamta / donburi

Just another ECS library for Go/Ebitengine
https://pkg.go.dev/github.com/yohamta/donburi
Other
232 stars 21 forks source link

Headless/compile flag to disable rendering features #121

Closed imthatgin closed 4 months ago

imthatgin commented 4 months ago

I have a single go module which contains both client and server code. I want to be able to use the ECS, without necessarily running it in a window.

Therefore, I'd like to request the addition of a compile flag to disable the ebiten dependency if possible.

I get something like this, because the server does not have a display:


panic: NotInitialized: The GLFW library is not initialized

goroutine 1 [running]:
github.com/hajimehoshi/ebiten/v2/internal/cglfw.acceptError({0x0, 0x0, 0x10004?})
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/cglfw/error.go:184 +0x23c
github.com/hajimehoshi/ebiten/v2/internal/cglfw.panicError(...)
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/cglfw/error.go:195
github.com/hajimehoshi/ebiten/v2/internal/cglfw.WindowHint(0x0?, 0x0?)
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/cglfw/window.go:317 +0x34
github.com/hajimehoshi/ebiten/v2/internal/glfw.WindowHint(...)
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/glfw/glfw_cglfw.go:347
github.com/hajimehoshi/ebiten/v2/internal/ui.initialize()
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/ui/ui_glfw.go:174 +0x36
github.com/hajimehoshi/ebiten/v2/internal/ui.init.2()
        /config/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.6.5/internal/ui/ui_glfw.go:159 +0x13
exit status 2```
yohamta commented 4 months ago

Thanks for the great suggestion. The idea using ECS architecture in the server code sounds really interesting. I wanted to do some experiments.

Donburi uses ebitengine's *ebiten.Image in the ecs package. I think that all of those parameters of *ebiten.Image can be replaced with Generics type parameter. Then we can remove the dependency to ebitengine from go.mod. What do you think?

imthatgin commented 4 months ago

That sounds like a good solution! Would make the ECS system more capable for different contexts!

yohamta commented 4 months ago

Thanks! Let's do it.

imthatgin commented 4 months ago

Some places will be challenging to replace, as struct methods cannot have generic parameters. Do you have any ideas for any alternative solutions?

yohamta commented 4 months ago

I understand that it's a bit challenging, but still I think it's possible. Pls give me a moment to try it. --edit-- Hmm... it seems it's only possible via reflection or completely changing the interface of ecs package. Let me try with reflection.

yohamta commented 4 months ago

@im-gin I have just managed to remove the dependency to Ebitengine by using reflection, and tagged it as v1.3.13. Please let me know if you find any problems or further suggestions. Thanks!