Simplify BSV code

This commit is contained in:
twinaphex 2019-06-17 02:22:49 +02:00
parent aec3bf41ae
commit ce51cf6b33
4 changed files with 31 additions and 47 deletions

View File

@ -661,25 +661,19 @@ void input_poll(void)
int16_t input_state(unsigned port, unsigned device,
unsigned idx, unsigned id)
{
int16_t bsv_result;
int16_t res = 0;
#ifdef HAVE_OVERLAY
int16_t res_overlay = 0;
#endif
/* used to reset input state of a button when the gamepad mapper
is in action for that button*/
bool reset_state = false;
device &= RETRO_DEVICE_MASK;
if (bsv_movie_is_playback_on())
{
int16_t bsv_result;
if (bsv_movie_get_input(&bsv_result))
return bsv_result;
bsv_movie_ctl(BSV_MOVIE_CTL_SET_END, NULL);
}
if (bsv_movie_get_input(&bsv_result))
return bsv_result;
if ( !input_driver_flushing_input
&& !input_driver_block_libretro_input)
@ -775,8 +769,7 @@ int16_t input_state(unsigned port, unsigned device,
}
}
if (bsv_movie_is_playback_off())
bsv_movie_ctl(BSV_MOVIE_CTL_SET_INPUT, &res);
bsv_movie_set_input(&res);
return res;
}

View File

@ -737,8 +737,7 @@ bool state_manager_check_rewind(bool pressed,
core_unserialize(&serial_info);
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
bsv_movie_ctl(BSV_MOVIE_CTL_FRAME_REWIND, NULL);
bsv_movie_frame_rewind();
}
else
{

View File

@ -538,8 +538,13 @@ error:
return NULL;
}
static void bsv_movie_frame_rewind(bsv_movie_t *handle)
void bsv_movie_frame_rewind(void)
{
bsv_movie_t *handle = bsv_movie_state_handle;
if (!handle)
return;
handle->did_rewind = true;
if ( (handle->frame_ptr <= 1)
@ -662,24 +667,31 @@ bool bsv_movie_init(void)
return true;
}
#define bsv_movie_is_playback_on() (bsv_movie_state_handle && bsv_movie_state.movie_playback)
#define bsv_movie_is_playback_off() (bsv_movie_state_handle && !bsv_movie_state.movie_playback)
bool bsv_movie_get_input(int16_t *bsv_data)
{
if (intfstream_read(bsv_movie_state_handle->file, bsv_data, 1) != 1)
if (!bsv_movie_is_playback_on())
return false;
if (intfstream_read(bsv_movie_state_handle->file, bsv_data, 1) != 1)
{
bsv_movie_state.movie_end = true;
return false;
}
*bsv_data = swap_if_big16(*bsv_data);
return true;
}
bool bsv_movie_is_playback_on(void)
void bsv_movie_set_input(int16_t *bsv_data)
{
return bsv_movie_state_handle && bsv_movie_state.movie_playback;
}
bool bsv_movie_is_playback_off(void)
{
return bsv_movie_state_handle && !bsv_movie_state.movie_playback;
if (bsv_data && bsv_movie_is_playback_off())
{
*bsv_data = swap_if_big16(*bsv_data);
intfstream_write(bsv_movie_state_handle->file, bsv_data, 1);
}
}
bool bsv_movie_ctl(enum bsv_ctl_state state, void *data)
@ -688,23 +700,6 @@ bool bsv_movie_ctl(enum bsv_ctl_state state, void *data)
{
case BSV_MOVIE_CTL_IS_INITED:
return (bsv_movie_state_handle != NULL);
case BSV_MOVIE_CTL_SET_END:
bsv_movie_state.movie_end = true;
break;
case BSV_MOVIE_CTL_UNSET_END:
bsv_movie_state.movie_end = false;
break;
case BSV_MOVIE_CTL_FRAME_REWIND:
bsv_movie_frame_rewind(bsv_movie_state_handle);
break;
case BSV_MOVIE_CTL_SET_INPUT:
{
int16_t *bsv_data = (int16_t*)data;
*bsv_data = swap_if_big16(*bsv_data);
intfstream_write(bsv_movie_state_handle->file, bsv_data, 1);
}
break;
case BSV_MOVIE_CTL_NONE:
default:
return false;

View File

@ -442,25 +442,22 @@ enum rarch_movie_type
enum bsv_ctl_state
{
BSV_MOVIE_CTL_NONE = 0,
BSV_MOVIE_CTL_IS_INITED,
BSV_MOVIE_CTL_SET_INPUT,
BSV_MOVIE_CTL_FRAME_REWIND,
BSV_MOVIE_CTL_SET_END,
BSV_MOVIE_CTL_UNSET_END
BSV_MOVIE_CTL_IS_INITED
};
void bsv_movie_deinit(void);
bool bsv_movie_init(void);
bool bsv_movie_is_playback_on(void);
bool bsv_movie_is_playback_off(void);
void bsv_movie_frame_rewind(void);
void bsv_movie_set_path(const char *path);
bool bsv_movie_get_input(int16_t *bsv_data);
void bsv_movie_set_input(int16_t *bsv_data);
bool bsv_movie_ctl(enum bsv_ctl_state state, void *data);
bool bsv_movie_check(void);