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

Allow combining saves in content dir with save sorting #16369

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

BryanJacobs
Copy link
Contributor

Description

Background: save files are usually compatible between cores, but save states basically never are. Retroarch currently has three settings for each of (savestate, savefile):

  • "Put X in content directory"
  • "Sort X into folders by core name"
  • "Sort X into folders by the content directory"

Currently, turning on the first option overrides the later two, and save(files|states) will be placed directly into the content directory.

This isn't a great experience because it means that if you put save states into the content directory, and then change the core you're using for the content, you'll get a save state that's invalid for the current core.

I thought it might be better if the options instead stacked. The logic would be:

  • Start with the retroarch default dir
  • If "put X in content directory" is set, replace that with the content base dir
  • If "sort X into folders by core name" is set, append core-name directory
  • If "sort X into folders by content directory" is set, append content directory

So if you have content in /roms, and you use core X and core Y, with both the content-dir and sort-by-core-name options enabled you'll end up with saves in /roms/X and /roms/Y.

To me this is more useful because it allows doing a cross-device sync of the content directory and carrying everything - save files, save states, whatever - while still not risking trying to load an incompatible save state on the wrong core. It feels like this better respects what the user is asking for when they toggle both options.

What do you think? PR attached as an example of one potential way to do this.

@@ -7956,114 +7958,112 @@ void runloop_path_set_redirect(settings_t *settings,
runloop_st->runtime_content_path_basename,
sizeof(content_dir_name));

if (sysinfo && !string_is_empty(sysinfo->library_name))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved pretty much unmodified below.

@LibretroAdmin
Copy link
Contributor

Any reason for that new string when it will get overwritten at the end anyway? Can't you just make do with the string variable that already exists? I think it would be prudent to not require too many additional extra strings for local stack if we can help it.

@BryanJacobs
Copy link
Contributor Author

Any reason for that new string when it will get overwritten at the end anyway? Can't you just make do with the string variable that already exists? I think it would be prudent to not require too many additional extra strings for local stack if we can help it.

Yes, the codepath on line 8022/8055 where we fall back on failing to create the desired directory.

If we don't have the intermediate string, we would fall back to putting the saves in the libretro config directory, when really we should fall back to putting them in the content directory IMO.

It's possible to avoid this with less stack memory and more code by trying to create the directory, then if that fails chopping it back down (or redoing the setup). I thought 8k of momentary stack memory usage during setup (not emulator execution) wouldn't be noticed even on extremely constrained targets, but it's your call.

@LibretroAdmin
Copy link
Contributor

Alright, I guess I shouldn't make a big deal about it. I guess we can merge this then.

@LibretroAdmin
Copy link
Contributor

One last thing before merge that would be nice -

we try to do 3 space indents, without tabs. I think another contributor noticed some mixing of tabs for indents and 4 space indents. If you could change all of that to 3 space indents, then we could merge it.

@BryanJacobs
Copy link
Contributor Author

Okay, I'll update the whitespace in here. Sorry about that.

This is a Breaking Change (TM), but I think that it's okay because the old behavior can be restored by turning off the "saves sorted by blah" setting.

@BryanJacobs
Copy link
Contributor Author

I did an autoformat pass, this function is now consistently three-space indents. The code now matches the (very loose) .editorconfig file in the project.

Feel free to test+merge if you're okay with this.

@LibretroAdmin
Copy link
Contributor

LibretroAdmin commented Mar 19, 2024

Hmm, not that much of a fan of the autoformat pass to be honest, I'd prefer if you just rolled that back that and instead just manuallymade sure that when you do indents, you do it with 3 spaces instead of with tabs or with 4 spaces.

LIke the way the variables were formatted previously was deliberate for readability purposes.

You can read about these guidelines here
https://docs.libretro.com/development/coding-standards/#indentation

@BryanJacobs
Copy link
Contributor Author

Hmm, not that much of a fan of the autoformat pass to be honest, I'd prefer if you just rolled that back that and instead just manuallymade sure that when you do indents, you do it with 3 spaces instead of with tabs or with 4 spaces.

LIke the way the variables were formatted previously was deliberate for readability purposes.

You can read about these guidelines here https://docs.libretro.com/development/coding-standards/#indentation

Pushed a change manually re-aligning the variable assignments.

I've had a read through the guidelines and, after I corrected one incorrectly indented following argument from before my change, it looks like this function now complies with them. Personally, I find it easier to be consistent if the computer does it for me via an in-repository clangformat or similar than if I have to remember what each of twenty different software projects chooses, you know?

Let me know if there are other problems, formatting or otherwise.

@LibretroAdmin
Copy link
Contributor

Alright, it's good to go now. Sorry for putting you through this ordeal, it might seem nitpicky but I'd figure it was best to just ask you directly to make these changes rather than me making manual edits afterwards.

@LibretroAdmin LibretroAdmin merged commit 338c9a4 into libretro:master Mar 19, 2024
27 checks passed
@BryanJacobs
Copy link
Contributor Author

Alright, it's good to go now. Sorry for putting you through this ordeal, it might seem nitpicky but I'd figure it was best to just ask you directly to make these changes rather than me making manual edits afterwards.

Absolutely no problem, glad to help. I hope it ends up working well for users!

@BryanJacobs
Copy link
Contributor Author

This has been released in retroarch 1.18.0 (currently available as a flatpak on flathub) and appears to work just fine. Save states go into per-core subdirectories of the content root when both options are set.

Sunderland93 pushed a commit to Sunderland93/RetroArch that referenced this pull request Dec 26, 2024
* Allow combining saves in content dir with save sorting

* Formatting

* Realign var assignments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants