Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the uniqueSaveDir option #470

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cd/cloudretro.io/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ emulator:
logLevel: 1
cores:
list:
dos:
uniqueSaveDir: true
mame:
options:
"fbneo-diagnostic-input": "Hold Start"
nes:
scale: 2
pcsx:
altRepo: true
snes:
scale: 2
2 changes: 2 additions & 0 deletions pkg/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ emulator:
# - skip_hw_context_destroy -- don't destroy OpenGL context during Libretro core deinit.
# May help with crashes, for example, with PPSSPP.
# - skip_same_thread_save -- skip thread lock save (used with PPSSPP).
# - uniqueSaveDir (bool) -- needed only for cores (like DosBox) that persist their state into one shared file.
# This will allow for concurrent reading and saving of current states.
list:
gba:
lib: mgba_libretro
Expand Down
1 change: 1 addition & 0 deletions pkg/config/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type LibretroCoreConfig struct {
Options4rom map[string]map[string]string // <(^_^)>
Roms []string
Scale float64
UniqueSaveDir bool
UsesLibCo bool
VFR bool
Width int
Expand Down
4 changes: 4 additions & 0 deletions pkg/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ func StatSize(path string) (int64, error) {
}
return fi.Size(), nil
}

func RemoveAll(path string) error {
return os.RemoveAll(path)
}
13 changes: 13 additions & 0 deletions pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Frontend struct {

DisableCanvasPool bool
SaveOnClose bool
UniqueSaveDir bool
}

type Device byte
Expand Down Expand Up @@ -153,6 +154,11 @@ func (f *Frontend) LoadCore(emu string) {
KbMouseSupport: conf.KbMouseSupport,
}
f.mu.Lock()
if conf.UniqueSaveDir {
f.UniqueSaveDir = true
f.nano.SetSaveDirSuffix(f.storage.MainPath())
f.log.Debug().Msgf("Using unique dir for saves: %v", f.storage.MainPath())
}
scale := 1.0
if conf.Scale > 1 {
scale = conf.Scale
Expand Down Expand Up @@ -336,6 +342,13 @@ func (f *Frontend) Close() {

f.mui.Lock()
f.nano.Close()

if f.UniqueSaveDir && !f.HasSave() {
if err := f.nano.DeleteSaveDir(); err != nil {
f.log.Error().Msgf("couldn't delete save dir: %v", err)
}
}

f.mui.Unlock()
f.log.Debug().Msgf("frontend closed")
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ func (n *Nanoarch) WaitReady() { <-n.reserved }
func (n *Nanoarch) Close() { n.Stopped.Store(true); n.reserved <- struct{}{} }
func (n *Nanoarch) SetLogger(log *logger.Logger) { n.log = log }
func (n *Nanoarch) SetVideoDebounce(t time.Duration) { n.limiter = NewLimit(t) }
func (n *Nanoarch) SetSaveDirSuffix(sx string) {
if n.cSaveDirectory != nil {
C.free(unsafe.Pointer(n.cSaveDirectory))
}
dir := C.GoString(n.cSaveDirectory) + "/" + sx
_ = os.CheckCreateDir(dir)
n.cSaveDirectory = C.CString(dir)
}
func (n *Nanoarch) DeleteSaveDir() error {
if n.cSaveDirectory == nil {
return nil
}

dir := C.GoString(n.cSaveDirectory)
return os.RemoveAll(dir)
}

func (n *Nanoarch) CoreLoad(meta Metadata) {
var err error
Expand Down
2 changes: 2 additions & 0 deletions pkg/worker/caged/libretro/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type (
Storage interface {
MainPath() string
GetSavePath() string
GetSRAMPath() string
SetMainSaveName(name string)
Expand All @@ -32,6 +33,7 @@ type (
}
)

func (s *StateStorage) MainPath() string { return s.MainSave }
func (s *StateStorage) SetMainSaveName(name string) { s.MainSave = name }
func (s *StateStorage) SetNonBlocking(v bool) { s.NonBlock = v }
func (s *StateStorage) GetSavePath() string { return filepath.Join(s.Path, s.MainSave+".dat") }
Expand Down
Loading