Skip to content

Commit

Permalink
New implementation of the savestate loaded at startup option.
Browse files Browse the repository at this point in the history
The savestate will be loaded on the first safe state interrupt instead of being loaded on the first frame.
  • Loading branch information
Gillou68310 committed Oct 19, 2016
1 parent 07dba79 commit 334db80
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main.c
Expand Up @@ -126,15 +126,6 @@ void DebugCallback(void *Context, int level, const char *message)

static void FrameCallback(unsigned int FrameIndex)
{
// load savestate at first frame if needed
if (l_SaveStatePath != NULL && FrameIndex == 0)
{
if ((*CoreDoCommand)(M64CMD_STATE_LOAD, 0, (void *) l_SaveStatePath) != M64ERR_SUCCESS)
{
DebugMessage(M64MSG_WARNING, "couldn't load state, rom will run normally.");
}
}

// take a screenshot if we need to
if (l_TestShotList != NULL)
{
Expand Down Expand Up @@ -769,12 +760,21 @@ int main(int argc, char *argv[])
}
}

/* set up Frame Callback if --testshots or --savestate is enabled */
if (l_TestShotList != NULL || l_SaveStatePath != NULL)
/* set up Frame Callback if --testshots is enabled */
if (l_TestShotList != NULL)
{
if ((*CoreDoCommand)(M64CMD_SET_FRAME_CALLBACK, 0, FrameCallback) != M64ERR_SUCCESS)
{
DebugMessage(M64MSG_WARNING, "couldn't set frame callback, --testshots and/or --savestate will not work.");
DebugMessage(M64MSG_WARNING, "couldn't set frame callback, --testshots will not work.");
}
}

/* load savestate at startup */
if (l_SaveStatePath != NULL)
{
if ((*CoreDoCommand)(M64CMD_STATE_LOAD, 0, (void *) l_SaveStatePath) != M64ERR_SUCCESS)
{
DebugMessage(M64MSG_WARNING, "couldn't load state, rom will run normally.");
}
}

Expand Down

2 comments on commit 334db80

@Narann
Copy link
Member

@Narann Narann commented on 334db80 Sep 22, 2017

Choose a reason for hiding this comment

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

@Gillou68310 @richard42

I know it's years after but I realize this break the possibility to use --savestates with --testshots because screenshots are taken before the save states is loaded.

What about also execute frame callback after the "first safe state interrupt"? This would guarantee the save states is loaded before take screenshots.

Any idea?

For information: My original attempt to fix the save state loading before frame was here: 7d5247b#diff-803c5170888b8642f2a97e5e9423d399, you can see the main.c history here: https://github.com/mupen64plus/mupen64plus-ui-console/commits/master/src/main.c

Yesterday I worked again on my regression test tool chain so I only see the problem now.

@richard42
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this change would prevent the screenshots from being taken after the state is loaded. The M64CMD_STATE_LOAD command just sets the savestate job to savestates_job_load. With the original code, this would get set during the first frame callback. With the new(er) code, it will get set just before starting the emulation running with M64CMD_EXECUTE. I presume the interrupt handler would get called before the first frame is rendered.

Please sign in to comment.