77#include "../../tasks/task_content.h"
88#include "../../libretro-db/rmsgpack.h"
99#include "../../libretro-db/rmsgpack_dom.h"
10+ #ifdef HAVE_STATESTREAM
1011#include "input/bsv/uint32s_index.h"
12+ #endif
1113#include "libretro.h"
1214#include "streams/interface_stream.h"
1315#ifdef HAVE_CHEEVOS
4850
4951/* Forward declarations */
5052void bsv_movie_free (bsv_movie_t * );
53+
54+ #ifdef HAVE_STATESTREAM
5155int64_t bsv_movie_write_deduped_state (bsv_movie_t * movie , uint8_t * state , size_t state_size , uint8_t * output , size_t output_capacity );
5256bool bsv_movie_read_deduped_state (bsv_movie_t * movie ,
5357 uint8_t * encoded , size_t encoded_size , bool output );
58+ #endif
5459
5560bool bsv_movie_reset_recording (bsv_movie_t * handle )
5661{
5762 retro_ctx_serialize_info_t serial_info ;
5863 size_t state_size , state_size_ ;
5964 uint8_t compression = handle -> checkpoint_compression ;
65+ #if HAVE_STATESTREAM
6066 uint8_t encoding = REPLAY_CHECKPOINT2_ENCODING_STATESTREAM ;
6167 /* If recording, we simply reset
6268 * the starting point. Nice and easy. */
6369 uint32s_index_clear (handle -> superblocks );
6470 uint32s_index_clear (handle -> blocks );
71+ #else
72+ uint8_t encoding = REPLAY_CHECKPOINT2_ENCODING_RAW ;
73+ #endif
6574
6675 intfstream_seek (handle -> file , REPLAY_HEADER_LEN_BYTES , SEEK_SET );
6776 intfstream_truncate (handle -> file , REPLAY_HEADER_LEN_BYTES );
@@ -123,8 +132,10 @@ void bsv_movie_frame_rewind()
123132 handle -> frame_counter = 0 ;
124133 intfstream_seek (handle -> file , (int )handle -> min_file_pos , SEEK_SET );
125134 /* clear incremental checkpoint table data. We do this both on recording and playback for simplicity. */
135+ #ifdef HAVE_STATESTREAM
126136 uint32s_index_remove_after (handle -> superblocks , 0 );
127137 uint32s_index_remove_after (handle -> blocks , 0 );
138+ #endif
128139 if (recording )
129140 intfstream_truncate (handle -> file , (int )handle -> min_file_pos );
130141 else
@@ -143,8 +154,10 @@ void bsv_movie_frame_rewind()
143154 handle -> frame_counter -= delta ;
144155 else
145156 handle -> frame_counter = 0 ;
157+ #ifdef HAVE_STATESTREAM
146158 uint32s_index_remove_after (handle -> superblocks , handle -> frame_counter );
147159 uint32s_index_remove_after (handle -> blocks , handle -> frame_counter );
160+ #endif
148161 RARCH_LOG ("[REPLAY] rewound to %d\n" , handle -> frame_counter );
149162 intfstream_seek (handle -> file , (int )handle -> frame_pos [handle -> frame_counter & handle -> frame_mask ], SEEK_SET );
150163 if (recording )
@@ -160,8 +173,10 @@ void bsv_movie_frame_rewind()
160173 if (handle -> playback )
161174 {
162175 intfstream_seek (handle -> file , (int )handle -> min_file_pos , SEEK_SET );
176+ #ifdef HAVE_STATESTREAM
163177 uint32s_index_remove_after (handle -> superblocks , 0 );
164178 uint32s_index_remove_after (handle -> blocks , 0 );
179+ #endif
165180 bsv_movie_read_next_events (handle , false);
166181 }
167182 else
@@ -356,6 +371,7 @@ bool bsv_movie_load_checkpoint(bsv_movie_t *handle, uint8_t compression, uint8_t
356371 else
357372 encoded_data = NULL ;
358373 break ;
374+ #ifdef HAVE_STATESTREAM
359375 case REPLAY_CHECKPOINT2_ENCODING_STATESTREAM :
360376 if (!bsv_movie_read_deduped_state (handle , encoded_data , encoded_size , !just_update_structures ))
361377 {
@@ -364,6 +380,7 @@ bool bsv_movie_load_checkpoint(bsv_movie_t *handle, uint8_t compression, uint8_t
364380 goto exit ;
365381 }
366382 break ;
383+ #endif
367384 default :
368385 RARCH_WARN ("[Replay] Unrecognized encoding scheme %d\n" , encoding );
369386 ret = false;
@@ -373,6 +390,7 @@ bool bsv_movie_load_checkpoint(bsv_movie_t *handle, uint8_t compression, uint8_t
373390 goto exit ;
374391 serial_info .data_const = handle -> cur_save ;
375392 serial_info .size = size ;
393+ /* TODO: should this happen at the end of the current frame, or at the beginning before inputs have been polled/etc? FCEUMM and PPSSPP have some jankiness here */
376394 if (!core_unserialize (& serial_info ))
377395 {
378396 abort ();
@@ -419,12 +437,14 @@ int64_t bsv_movie_write_checkpoint(bsv_movie_t *handle, uint8_t compression, uin
419437 encoded_size = serial_info .size ;
420438 encoded_data = serial_info .data ;
421439 break ;
440+ #ifdef HAVE_STATESTREAM
422441 case REPLAY_CHECKPOINT2_ENCODING_STATESTREAM :
423442 encoded_size = serial_info .size + serial_info .size / 2 ;
424443 encoded_data = malloc (encoded_size );
425444 owns_encoded = true;
426445 encoded_size = bsv_movie_write_deduped_state (handle , serial_info .data , serial_info .size , encoded_data , encoded_size );
427446 break ;
447+ #endif
428448 default :
429449 RARCH_ERR ("[Replay] Unrecognized encoding scheme %d\n" , encoding );
430450 ret = -1 ;
@@ -702,7 +722,11 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
702722 uint8_t frame_tok = REPLAY_TOKEN_CHECKPOINT2_FRAME ;
703723 retro_ctx_serialize_info_t serial_info ;
704724 uint8_t compression = handle -> checkpoint_compression ;
725+ #if HAVE_STATESTREAM
705726 uint8_t encoding = REPLAY_CHECKPOINT2_ENCODING_STATESTREAM ;
727+ #else
728+ uint8_t encoding = REPLAY_CHECKPOINT2_ENCODING_RAW ;
729+ #endif
706730 /* "next frame is a checkpoint" */
707731 intfstream_write (handle -> file , (uint8_t * )(& frame_tok ), sizeof (uint8_t ));
708732 /* compression and encoding schemes */
@@ -1001,8 +1025,10 @@ bool replay_set_serialized_data(void* buf)
10011025 MESSAGE_QUEUE_ICON_DEFAULT , MESSAGE_QUEUE_CATEGORY_WARNING );
10021026 RARCH_WARN ("[Replay] %s.\n" , _msg );
10031027 }
1028+ #ifdef HAVE_STATESTREAM
10041029 uint32s_index_remove_after (handle -> superblocks , 0 );
10051030 uint32s_index_remove_after (handle -> blocks , 0 );
1031+ #endif
10061032 intfstream_rewind (handle -> file );
10071033 intfstream_write (handle -> file , header , loaded_len );
10081034 /* also need to update/reinit frame_pos,
@@ -1014,8 +1040,10 @@ bool replay_set_serialized_data(void* buf)
10141040 }
10151041 else
10161042 {
1043+ #ifdef HAVE_STATESTREAM
10171044 uint32s_index_remove_after (handle -> superblocks , 0 );
10181045 uint32s_index_remove_after (handle -> blocks , 0 );
1046+ #endif
10191047 intfstream_seek (handle -> file , loaded_len , SEEK_SET );
10201048 /* TODO: in the future, don't clear indices above and only
10211049 update frame counter and remove index entries after the
@@ -1092,6 +1120,7 @@ int16_t bsv_movie_read_state(input_driver_state_t *input_st,
10921120 return 0 ;
10931121}
10941122
1123+ #ifdef HAVE_STATESTREAM
10951124int64_t bsv_movie_write_deduped_state (bsv_movie_t * movie , uint8_t * state , size_t state_size , uint8_t * output , size_t output_capacity )
10961125{
10971126 static uint32_t skipped_blocks = 0 ;
@@ -1415,3 +1444,4 @@ bool bsv_movie_read_deduped_state(bsv_movie_t *movie,
14151444 RARCH_DBG ("[STATESTREAM] Total statestream decodes %d ; net time (secs): %f\n" , total_decode_count , (double )total_decode_micros / (1000000.0 ));
14161445 return ret ;
14171446}
1447+ #endif
0 commit comments