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

Quick Resume Mode #15

Draft
wants to merge 9 commits into
base: knulli
Choose a base branch
from

Conversation

t0b10-r3tr0
Copy link

@t0b10-r3tr0 t0b10-r3tr0 commented Jan 2, 2025

These components implement a Quick Resume Mode. This implementation mostly

leverages existing Batocera features such as the Launch This Game on Startup feature. This component automates the management of global.bootgame.cmd and global.bootgame.path settings within the batocera.conf configuration file.

Description from the ES settings menu:

Boots directly from the last played game if shutdown during gameplay. Works with auto save/load. Reduces boot time by scanning games, laoding ES, after game exit.

When in this mode, if you power down from ES, you will boot back in to ES. When booting a game in this mode, WIFI and Bluetooth are restored prior to game load which means RetroAchievements is supported.

The following script quick_resume_mode.sh needs to reside in userdata/system/scripts in order for this feature to work:

#!/bin/bash

# Set all constants before anything else.
logfile=/userdata/system/logs/quick_resume_mode.log
rm -rf $logfile
touch $logfile

# Case selection for first parameter parsed, our event.
case $1 in
    gameStart)
        # Commands in here will be executed on the start of any game.
        echo "gameStart event complete." >> $logfile
        echo "$@" >> $logfile
    ;;
    gameStop)
        # Commands here will be executed on the stop of every game.
        quick_resume_mode=$(batocera-settings-get global.quickresumemode)
        if [ "$quick_resume_mode" -eq 1 ]; then
            (sleep 5 && batocera-settings-set global.bootgame.cmd "" && batocera-settings-set global.bootgame.path "" && echo "Cleared bootgame settings from batocera.conf!" >> $logfile) &
        fi
        echo "gameStop event complete." >> $logfile
        echo "$@" >> $logfile
    ;;
esac

knulli-screenshot

knulli-quickmode.mp4

… toggle. Added logic to manage bootgame settings in conf if mode is enabled.
{
SystemConf::getInstance()->set("global.bootgame.path", getFullPath());
SystemConf::getInstance()->set("global.bootgame.cmd", quickResumeCommand);
SystemConf::getInstance()->saveSystemConf();
Copy link

@Mikhailzrick Mikhailzrick Jan 3, 2025

Choose a reason for hiding this comment

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

I don't think it's a good idea to use batocera.conf for storing what is essentially temp data in this way. I think it would be a better approach to store the data in files. Maybe "quickresume_path" and "quickresume_cmd"?

maybe something like:

std::string quickResumePathFile = "/userdata/system/quickresume_path";
std::string quickResumeCmdFile = "/userdata/system/quickresume_cmd";

std::ofstream pathFile(quickResumePathFile, std::ios::out | std::ios::trunc);
if (pathFile.is_open())
{
    pathFile << getFullPath();
    pathFile.close();
}

std::ofstream cmdFile(quickResumeCmdFile, std::ios::out | std::ios::trunc);
if (cmdFile.is_open())
{
    cmdFile << quickResumeCommand;
    cmdFile.close();
}

@Mikhailzrick
Copy link

Mikhailzrick commented Jan 3, 2025

What about this script for the gamestop logic?

#!/bin/bash

# Set all constants before anything else.
logfile=/userdata/system/logs/quick_resume.log
rm -rf $logfile
touch $logfile

# Case selection for first parameter parsed, our event.
case $1 in
    gameStart)
        # Commands in here will be executed on the start of any game.
        echo "gameStart event complete." >> $logfile
        echo "$@" >> $logfile
    ;;
    gameStop)
        # Commands here will be executed on the stop of every game.
        quick_resume=$(batocera-settings-get global.quickresume)
        if [ "$quick_resume" -eq 1 ]; then
            LOCK_FILE="/var/run/power-button-script.lock"
            PATH_FILE="/userdata/system/quickresume_path"
            CMD_FILE="/userdata/system/quickresume_cmd"
            
            exec 200>"${LOCK_FILE}"
            
            # Use lock file to check if power button(shutdown) is reason for emulator exit, if not clear the quickresume data
            if flock -n 200; then
                if [ -f "$PATH_FILE" ] && [ -f "$CMD_FILE" ]; then
                    > "$PATH_FILE"
                    > "$CMD_FILE"
                    echo "Cleared $PATH_FILE and $CMD_FILE" >> $logfile
                fi
            fi
        echo "gameStop event complete." >> $logfile
        echo "$@" >> $logfile
    ;;
esac

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