This commit is contained in:
twinaphex 2017-01-09 02:49:39 +01:00
parent 80bc91477a
commit dfec7a44ca
3 changed files with 48 additions and 22 deletions

View File

@ -1994,15 +1994,19 @@ bool command_event(enum event_command cmd, void *data)
break; break;
case CMD_EVENT_REWIND_INIT: case CMD_EVENT_REWIND_INIT:
{ {
#ifdef HAVE_CHEEVOS
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
#ifdef HAVE_CHEEVOS
if (settings->cheevos.hardcore_mode_enable) if (settings->cheevos.hardcore_mode_enable)
return false; return false;
#endif #endif
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL)) if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
#endif #endif
state_manager_event_init(); {
if (settings->rewind_enable)
state_manager_event_init();
}
} }
break; break;
case CMD_EVENT_REWIND_TOGGLE: case CMD_EVENT_REWIND_TOGGLE:

View File

@ -17,7 +17,6 @@
#include <string.h> #include <string.h>
#include <file/config_file.h> #include <file/config_file.h>
#include <lists/dir_list.h>
#include <lists/string_list.h> #include <lists/string_list.h>
#include <compat/posix_string.h> #include <compat/posix_string.h>
#include <compat/strl.h> #include <compat/strl.h>

View File

@ -299,50 +299,70 @@ static void state_manager_free(state_manager_t *state)
if (!state) if (!state)
return; return;
free(state->data); if (state->data)
free(state->thisblock); free(state->data);
free(state->nextblock); if (state->thisblock)
free(state->thisblock);
if (state->nextblock)
free(state->nextblock);
#if STRICT_BUF_SIZE #if STRICT_BUF_SIZE
free(state->debugblock); if (state->debugblock)
free(state->debugblock);
state->debugblock = NULL;
#endif #endif
free(state); state->data = NULL;
state->thisblock = NULL;
state->nextblock = NULL;
} }
static state_manager_t *state_manager_new(size_t state_size, size_t buffer_size) static state_manager_t *state_manager_new(size_t state_size, size_t buffer_size)
{ {
size_t max_comp_size, block_size;
uint8_t *next_block = NULL;
uint8_t *this_block = NULL;
uint8_t *state_data = NULL;
state_manager_t *state = (state_manager_t*)calloc(1, sizeof(*state)); state_manager_t *state = (state_manager_t*)calloc(1, sizeof(*state));
if (!state) if (!state)
return NULL; return NULL;
state->blocksize = (state_size + sizeof(uint16_t) - 1) & -sizeof(uint16_t); block_size = (state_size + sizeof(uint16_t) - 1) & -sizeof(uint16_t);
/* the compressed data is surrounded by pointers to the other side */ /* the compressed data is surrounded by pointers to the other side */
state->maxcompsize = state_manager_raw_maxsize(state_size) + sizeof(size_t) * 2; max_comp_size = state_manager_raw_maxsize(state_size) + sizeof(size_t) * 2;
state->data = (uint8_t*)malloc(buffer_size); state_data = (uint8_t*)malloc(buffer_size);
if (!state->data) if (!state_data)
goto error; goto error;
state->thisblock = (uint8_t*)state_manager_raw_alloc(state_size, 0); this_block = (uint8_t*)state_manager_raw_alloc(state_size, 0);
state->nextblock = (uint8_t*)state_manager_raw_alloc(state_size, 1); next_block = (uint8_t*)state_manager_raw_alloc(state_size, 1);
if (!state->thisblock || !state->nextblock) if (!this_block || !next_block)
goto error; goto error;
state->capacity = buffer_size; state->blocksize = block_size;
state->maxcompsize = max_comp_size;
state->data = state_data;
state->thisblock = this_block;
state->nextblock = next_block;
state->capacity = buffer_size;
state->head = state->data + sizeof(size_t); state->head = state->data + sizeof(size_t);
state->tail = state->data + sizeof(size_t); state->tail = state->data + sizeof(size_t);
#if STRICT_BUF_SIZE #if STRICT_BUF_SIZE
state->debugsize = state_size; state->debugsize = state_size;
state->debugblock = (uint8_t*)malloc(state_size); state->debugblock = (uint8_t*)malloc(state_size);
#endif #endif
return state; return state;
error: error:
if (state_data)
free(state_data);
state_manager_free(state); state_manager_free(state);
free(state);
return NULL; return NULL;
} }
@ -491,7 +511,7 @@ void state_manager_event_init(void)
void *state = NULL; void *state = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!settings->rewind_enable || rewind_state.state) if (rewind_state.state)
return; return;
if (audio_driver_has_callback()) if (audio_driver_has_callback())
@ -545,7 +565,10 @@ static void state_manager_set_frame_is_reversed(bool value)
void state_manager_event_deinit(void) void state_manager_event_deinit(void)
{ {
if (rewind_state.state) if (rewind_state.state)
{
state_manager_free(rewind_state.state); state_manager_free(rewind_state.state);
free(rewind_state.state);
}
rewind_state.state = NULL; rewind_state.state = NULL;
rewind_state.size = 0; rewind_state.size = 0;
} }
@ -559,7 +582,6 @@ void state_manager_event_deinit(void)
void state_manager_check_rewind(bool pressed) void state_manager_check_rewind(bool pressed)
{ {
static bool first = true; static bool first = true;
settings_t *settings = config_get_ptr();
if (state_manager_frame_is_reversed()) if (state_manager_frame_is_reversed())
{ {
@ -609,6 +631,7 @@ void state_manager_check_rewind(bool pressed)
else else
{ {
static unsigned cnt = 0; static unsigned cnt = 0;
settings_t *settings = config_get_ptr();
cnt = (cnt + 1) % (settings->rewind_granularity ? cnt = (cnt + 1) % (settings->rewind_granularity ?
settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */ settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */