Verifies during startup if the system can run the emulator

This check can be disabled with the emulator.failFast = false config option. Right now it checks SDL2 video context creation.
This commit is contained in:
sergystepanov 2025-06-20 18:12:47 +03:00 committed by sergystepanov
parent d8eed66a1d
commit 42b003db62
6 changed files with 27 additions and 0 deletions

View file

@ -137,6 +137,9 @@ emulator:
# path for storing emulator generated files
localPath: "./libretro"
# checks if the system supports running an emulator at startup
failFast: true
libretro:
# use zip compression for emulator save states
saveCompression: true

View file

@ -9,6 +9,7 @@ import (
)
type Emulator struct {
FailFast bool
Threads int
Storage string
LocalPath string

View file

@ -31,6 +31,13 @@ func (c *Caged) Init() error {
if err := manager.CheckCores(c.conf.Emulator, c.log); err != nil {
c.log.Warn().Err(err).Msgf("a Libretro cores sync fail")
}
if c.conf.Emulator.FailFast {
if err := c.IsSupported(); err != nil {
return err
}
}
return nil
}
@ -92,3 +99,4 @@ func (c *Caged) Start() { go c.Emulator.Start() }
func (c *Caged) SetSaveOnClose(v bool) { c.base.SaveOnClose = v }
func (c *Caged) SetSessionId(name string) { c.base.SetSessionId(name) }
func (c *Caged) Close() { c.Emulator.Close() }
func (c *Caged) IsSupported() error { return c.base.IsSupported() }

View file

@ -13,6 +13,7 @@ import (
"github.com/giongto35/cloud-game/v3/pkg/logger"
"github.com/giongto35/cloud-game/v3/pkg/os"
"github.com/giongto35/cloud-game/v3/pkg/worker/caged/app"
"github.com/giongto35/cloud-game/v3/pkg/worker/caged/libretro/graphics"
"github.com/giongto35/cloud-game/v3/pkg/worker/caged/libretro/nanoarch"
)
@ -422,6 +423,10 @@ func (f *Frontend) Load() error {
return nil
}
func (f *Frontend) IsSupported() error {
return graphics.TryInit()
}
func (f *Frontend) autosave(periodSec int) {
f.log.Info().Msgf("Autosave every [%vs]", periodSec)
ticker := time.NewTicker(time.Duration(periodSec) * time.Second)

View file

@ -76,6 +76,15 @@ func NewSDLContext(cfg Config, log *logger.Logger) (*SDL, error) {
return &display, nil
}
// TryInit check weather SDL context can be created on the system.
func TryInit() error {
if err := sdl.Init(sdl.INIT_VIDEO); err != nil {
return fmt.Errorf("SDL init fail: %w", err)
}
sdl.Quit()
return nil
}
// Deinit destroys SDL/OpenGL context.
// Uses main thread lock (see thread/mainthread).
func (s *SDL) Deinit() error {

View file

@ -414,6 +414,7 @@ func (n *Nanoarch) Run() {
}
}
func (n *Nanoarch) IsSupported() error { return graphics.TryInit() }
func (n *Nanoarch) IsGL() bool { return n.Video.gl.enabled }
func (n *Nanoarch) IsStopped() bool { return n.Stopped.Load() }
func (n *Nanoarch) InputRetropad(port int, data []byte) { n.retropad.Input(port, data) }