mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 02:34:42 +00:00
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:
parent
d8eed66a1d
commit
42b003db62
6 changed files with 27 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type Emulator struct {
|
||||
FailFast bool
|
||||
Threads int
|
||||
Storage string
|
||||
LocalPath string
|
||||
|
|
|
|||
|
|
@ -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() }
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue