mirror of
https://github.com/libretro/RetroArch
synced 2024-12-26 21:29:08 +00:00
Move global->autosave to autosave.c
This commit is contained in:
parent
30ed8b750b
commit
5d70131ce1
73
autosave.c
73
autosave.c
@ -22,9 +22,19 @@
|
||||
|
||||
#include <rthreads/rthreads.h>
|
||||
|
||||
#include "general.h"
|
||||
#include "autosave.h"
|
||||
#include "configuration.h"
|
||||
#include "msg_hash.h"
|
||||
#include "runloop.h"
|
||||
#include "verbosity.h"
|
||||
|
||||
/* Autosave support. */
|
||||
struct autosave_st
|
||||
{
|
||||
autosave_t **list;
|
||||
unsigned num;
|
||||
};
|
||||
|
||||
struct autosave
|
||||
{
|
||||
volatile bool quit;
|
||||
@ -41,6 +51,8 @@ struct autosave
|
||||
unsigned interval;
|
||||
};
|
||||
|
||||
static struct autosave_st autosave_state;
|
||||
|
||||
/**
|
||||
* autosave_lock:
|
||||
* @handle : pointer to autosave object
|
||||
@ -197,12 +209,11 @@ void autosave_free(autosave_t *handle)
|
||||
void lock_autosave(void)
|
||||
{
|
||||
unsigned i;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
for (i = 0; i < global->autosave.num; i++)
|
||||
for (i = 0; i < autosave_state.num; i++)
|
||||
{
|
||||
if (global->autosave.list[i])
|
||||
autosave_lock(global->autosave.list[i]);
|
||||
if (autosave_state.list[i])
|
||||
autosave_lock(autosave_state.list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,13 +225,57 @@ void lock_autosave(void)
|
||||
void unlock_autosave(void)
|
||||
{
|
||||
unsigned i;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
for (i = 0; i < global->autosave.num; i++)
|
||||
for (i = 0; i < autosave_state.num; i++)
|
||||
{
|
||||
if (global->autosave.list[i])
|
||||
autosave_unlock(global->autosave.list[i]);
|
||||
if (autosave_state.list[i])
|
||||
autosave_unlock(autosave_state.list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void autosave_event_init(void)
|
||||
{
|
||||
unsigned i;
|
||||
settings_t *settings = config_get_ptr();
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (settings->autosave_interval < 1 || !global->savefiles)
|
||||
return;
|
||||
|
||||
if (!(autosave_state.list = (autosave_t**)calloc(global->savefiles->size,
|
||||
sizeof(*autosave_state.list))))
|
||||
return;
|
||||
|
||||
autosave_state.num = global->savefiles->size;
|
||||
|
||||
for (i = 0; i < global->savefiles->size; i++)
|
||||
{
|
||||
const char *path = global->savefiles->elems[i].data;
|
||||
unsigned type = global->savefiles->elems[i].attr.i;
|
||||
|
||||
if (core.retro_get_memory_size(type) <= 0)
|
||||
continue;
|
||||
|
||||
autosave_state.list[i] = autosave_new(path,
|
||||
core.retro_get_memory_data(type),
|
||||
core.retro_get_memory_size(type),
|
||||
settings->autosave_interval);
|
||||
|
||||
if (!autosave_state.list[i])
|
||||
RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED));
|
||||
}
|
||||
}
|
||||
|
||||
void autosave_event_deinit(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < autosave_state.num; i++)
|
||||
autosave_free(autosave_state.list[i]);
|
||||
|
||||
if (autosave_state.list)
|
||||
free(autosave_state.list);
|
||||
|
||||
autosave_state.list = NULL;
|
||||
autosave_state.num = 0;
|
||||
}
|
||||
|
@ -62,6 +62,10 @@ void lock_autosave(void);
|
||||
**/
|
||||
void unlock_autosave(void);
|
||||
|
||||
void autosave_event_init(void);
|
||||
|
||||
void autosave_event_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "command_event.h"
|
||||
|
||||
#include "audio/audio_driver.h"
|
||||
#include "autosave.h"
|
||||
#include "general.h"
|
||||
#include "performance.h"
|
||||
#include "dynamic.h"
|
||||
@ -91,56 +92,6 @@ static void event_init_remote(void)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_THREADS)
|
||||
static void event_init_autosave(void)
|
||||
{
|
||||
unsigned i;
|
||||
settings_t *settings = config_get_ptr();
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (settings->autosave_interval < 1 || !global->savefiles)
|
||||
return;
|
||||
|
||||
if (!(global->autosave.list = (autosave_t**)calloc(global->savefiles->size,
|
||||
sizeof(*global->autosave.list))))
|
||||
return;
|
||||
|
||||
global->autosave.num = global->savefiles->size;
|
||||
|
||||
for (i = 0; i < global->savefiles->size; i++)
|
||||
{
|
||||
const char *path = global->savefiles->elems[i].data;
|
||||
unsigned type = global->savefiles->elems[i].attr.i;
|
||||
|
||||
if (core.retro_get_memory_size(type) <= 0)
|
||||
continue;
|
||||
|
||||
global->autosave.list[i] = autosave_new(path,
|
||||
core.retro_get_memory_data(type),
|
||||
core.retro_get_memory_size(type),
|
||||
settings->autosave_interval);
|
||||
|
||||
if (!global->autosave.list[i])
|
||||
RARCH_WARN("%s\n", msg_hash_to_str(MSG_AUTOSAVE_FAILED));
|
||||
}
|
||||
}
|
||||
|
||||
static void event_deinit_autosave(void)
|
||||
{
|
||||
unsigned i;
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
for (i = 0; i < global->autosave.num; i++)
|
||||
autosave_free(global->autosave.list[i]);
|
||||
|
||||
if (global->autosave.list)
|
||||
free(global->autosave.list);
|
||||
|
||||
global->autosave.list = NULL;
|
||||
global->autosave.num = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void event_save_files(void)
|
||||
{
|
||||
unsigned i;
|
||||
@ -1270,13 +1221,13 @@ bool event_command(enum event_command cmd)
|
||||
break;
|
||||
case EVENT_CMD_AUTOSAVE_DEINIT:
|
||||
#ifdef HAVE_THREADS
|
||||
event_deinit_autosave();
|
||||
autosave_event_deinit();
|
||||
#endif
|
||||
break;
|
||||
case EVENT_CMD_AUTOSAVE_INIT:
|
||||
event_command(EVENT_CMD_AUTOSAVE_DEINIT);
|
||||
#ifdef HAVE_THREADS
|
||||
event_init_autosave();
|
||||
autosave_event_init();
|
||||
#endif
|
||||
break;
|
||||
case EVENT_CMD_AUTOSAVE_STATE:
|
||||
|
@ -32,6 +32,7 @@
|
||||
#ifdef HAVE_CHEEVOS
|
||||
#include "cheevos.h"
|
||||
#endif
|
||||
#include "autosave.h"
|
||||
#include "configuration.h"
|
||||
#include "performance.h"
|
||||
#include "retroarch.h"
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "core_options.h"
|
||||
#include "driver.h"
|
||||
#include "rewind.h"
|
||||
#include "autosave.h"
|
||||
#include "movie.h"
|
||||
#include "cheats.h"
|
||||
#include "dynamic.h"
|
||||
@ -228,13 +227,6 @@ typedef struct global
|
||||
bool use;
|
||||
} sram;
|
||||
|
||||
/* Autosave support. */
|
||||
struct
|
||||
{
|
||||
autosave_t **list;
|
||||
unsigned num;
|
||||
} autosave;
|
||||
|
||||
#ifdef HAVE_NETPLAY
|
||||
/* Netplay. */
|
||||
struct
|
||||
|
Loading…
Reference in New Issue
Block a user