Skip to content

Commit

Permalink
Unroll this
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Jan 13, 2019
1 parent cb596ae commit 5b88685
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 50 deletions.
45 changes: 1 addition & 44 deletions movie.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <rhash.h>
#include <compat/strl.h>
#include <retro_endianness.h>
#include <streams/interface_stream.h>

#include "configuration.h"
#include "movie.h"
Expand All @@ -34,26 +33,6 @@
#include "command.h"
#include "file_path_special.h"

struct bsv_movie
{
intfstream_t *file;

/* A ring buffer keeping track of positions
* in the file for each frame. */
size_t *frame_pos;
size_t frame_mask;
size_t frame_ptr;

size_t min_file_pos;

size_t state_size;
uint8_t *state;

bool playback;
bool first_rewind;
bool did_rewind;
};

struct bsv_state
{
bool movie_start_recording;
Expand All @@ -68,7 +47,7 @@ struct bsv_state
char movie_start_path[PATH_MAX_LENGTH];
};

static bsv_movie_t *bsv_movie_state_handle = NULL;
bsv_movie_t *bsv_movie_state_handle = NULL;
static struct bsv_state bsv_movie_state;

static bool bsv_movie_init_playback(bsv_movie_t *handle, const char *path)
Expand Down Expand Up @@ -259,28 +238,6 @@ static bsv_movie_t *bsv_movie_init_internal(const char *path,
return NULL;
}

/* Used for rewinding while playback/record. */
void bsv_movie_set_frame_start(void)
{
if (bsv_movie_state_handle)
bsv_movie_state_handle->frame_pos[bsv_movie_state_handle->frame_ptr]
= intfstream_tell(bsv_movie_state_handle->file);
}

void bsv_movie_set_frame_end(void)
{
if (!bsv_movie_state_handle)
return;

bsv_movie_state_handle->frame_ptr =
(bsv_movie_state_handle->frame_ptr + 1)
& bsv_movie_state_handle->frame_mask;

bsv_movie_state_handle->first_rewind =
!bsv_movie_state_handle->did_rewind;
bsv_movie_state_handle->did_rewind = false;
}

static void bsv_movie_frame_rewind(bsv_movie_t *handle)
{
handle->did_rewind = true;
Expand Down
27 changes: 23 additions & 4 deletions movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boolean.h>
#include <retro_common_api.h>
#include <streams/interface_stream.h>

RETRO_BEGIN_DECLS

Expand Down Expand Up @@ -56,6 +57,26 @@ enum bsv_ctl_state
BSV_MOVIE_CTL_UNSET_END
};

struct bsv_movie
{
intfstream_t *file;

/* A ring buffer keeping track of positions
* in the file for each frame. */
size_t *frame_pos;
size_t frame_mask;
size_t frame_ptr;

size_t min_file_pos;

size_t state_size;
uint8_t *state;

bool playback;
bool first_rewind;
bool did_rewind;
};

void bsv_movie_deinit(void);

bool bsv_movie_init(void);
Expand All @@ -68,10 +89,6 @@ void bsv_movie_set_path(const char *path);

void bsv_movie_set_start_path(const char *path);

void bsv_movie_set_frame_start(void);

void bsv_movie_set_frame_end(void);

bool bsv_movie_get_input(int16_t *bsv_data);

bool bsv_movie_is_end_of_file(void);
Expand All @@ -82,6 +99,8 @@ bool bsv_movie_check(void);

bool bsv_movie_init_handle(const char *path, enum rarch_movie_type type);

extern bsv_movie_t *bsv_movie_state_handle;

RETRO_END_DECLS

#endif
16 changes: 14 additions & 2 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3594,7 +3594,10 @@ int runloop_iterate(unsigned *sleep_ms)
if (runloop_autosave)
autosave_lock();

bsv_movie_set_frame_start();
/* Used for rewinding while playback/record. */
if (bsv_movie_state_handle)
bsv_movie_state_handle->frame_pos[bsv_movie_state_handle->frame_ptr]
= intfstream_tell(bsv_movie_state_handle->file);

camera_driver_poll();

Expand Down Expand Up @@ -3661,7 +3664,16 @@ int runloop_iterate(unsigned *sleep_ms)
input_pop_analog_dpad(auto_binds);
}

bsv_movie_set_frame_end();
if (bsv_movie_state_handle)
{
bsv_movie_state_handle->frame_ptr =
(bsv_movie_state_handle->frame_ptr + 1)
& bsv_movie_state_handle->frame_mask;

bsv_movie_state_handle->first_rewind =
!bsv_movie_state_handle->did_rewind;
bsv_movie_state_handle->did_rewind = false;
}

if (runloop_autosave)
autosave_unlock();
Expand Down

0 comments on commit 5b88685

Please sign in to comment.