Skip to content

Commit 32dd839

Browse files
committed
guard statestream related code on ifdefs
1 parent 80d8a43 commit 32dd839

8 files changed

Lines changed: 71 additions & 5 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
HAVE_FILE_LOGGER=1
2+
HAVE_STATESTREAM?=1
23
NEED_CXX_LINKER?=0
34
NEED_GOLD_LINKER?=0
45
MISSING_DECLS =0

Makefile.common

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ ifeq ($(HAVE_SAPI), 1)
2525
LIBS += sapi.dll
2626
endif
2727

28+
ifeq ($(HAVE_STATESTREAM), 1)
29+
DEF_FLAGS += -DHAVE_STATESTREAM
30+
endif
31+
2832
ifeq ($(HAVE_GL_CONTEXT),)
2933
HAVE_GL_CONTEXT = 0
3034
HAVE_GL_MODERN = 0

Makefile.emscripten

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ OBJ :=
1414
DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN -DEMSCRIPTEN
1515
DEFINES += -DHAVE_FILTERS_BUILTIN -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORE_INFO
1616

17+
HAVE_STATESTREAM ?= 1
1718
HAVE_PATCH = 1
1819
HAVE_DSP_FILTER = 1
1920
HAVE_VIDEO_FILTER = 1

input/bsv/bsvmovie.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
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
@@ -48,20 +50,27 @@
4850

4951
/* Forward declarations */
5052
void bsv_movie_free(bsv_movie_t*);
53+
54+
#ifdef HAVE_STATESTREAM
5155
int64_t bsv_movie_write_deduped_state(bsv_movie_t *movie, uint8_t *state, size_t state_size, uint8_t *output, size_t output_capacity);
5256
bool bsv_movie_read_deduped_state(bsv_movie_t *movie,
5357
uint8_t *encoded, size_t encoded_size, bool output);
58+
#endif
5459

5560
bool 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
10951124
int64_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

input/bsv/uint32s_index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef HAVE_STATESTREAM
12
#include "uint32s_index.h"
23
#include <string.h>
34
#include <array/rhmap.h>
@@ -363,3 +364,4 @@ void uint32s_index_print_count_data(uint32s_index_t *index)
363364
}
364365
}
365366
#endif
367+
#endif

input/bsv/uint32s_index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef __UINT32S_INDEX__H
22
#define __UINT32S_INDEX__H
3-
3+
#ifdef HAVE_STATESTREAM
44
#include <stdint.h>
55
#include <stdlib.h>
66
#include <stddef.h>
@@ -66,5 +66,5 @@ uint32_t uint32s_index_count(uint32s_index_t *index);
6666
void uint32s_index_print_count_data(uint32s_index_t *index);
6767
#endif
6868
RETRO_END_DECLS
69-
69+
#endif
7070
#endif /* __UINT32S_INDEX__H */

input/input_driver.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,15 @@ struct bsv_movie
261261
bool first_rewind;
262262
bool did_rewind;
263263

264+
#ifdef HAVE_STATESTREAM
264265
/* Block index and superblock index for incremental checkpoints */
265266
uint32s_index_t *superblocks;
266267
uint32s_index_t *blocks;
267268
uint32_t *superblock_seq;
268269
uint8_t commit_interval, commit_threshold;
270+
#endif
269271

270-
uint8_t checkpoint_compression;
272+
uint8_t checkpoint_compression, checkpoint_encoding;
271273

272274
uint8_t *last_save, *cur_save;
273275
size_t last_save_size, cur_save_size;

tasks/task_movie.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "../input/input_driver.h"
4646
#include "../input/bsv/bsvmovie.h"
4747

48+
#ifdef HAVE_STATESTREAM
4849
#if DEBUG
4950
#include "input/bsv/uint32s_index.h"
5051
#endif
@@ -60,6 +61,8 @@
6061
#define SMALL_SUPERBLOCK_SIZE 16 /* measured in blocks */
6162
#define SMALL_BLOCK_SIZE 128 /* measured in bytes */
6263

64+
#endif
65+
6366
/* Forward declaration */
6467
bool content_load_state_in_progress(void* data);
6568

@@ -71,8 +74,10 @@ static bool bsv_movie_init_playback(bsv_movie_t *handle, const char *path)
7174
uint32_t state_size = 0;
7275
uint32_t header[REPLAY_HEADER_LEN] = {0};
7376
uint32_t vsn = 0;
77+
#ifdef HAVE_STATESTREAM
7478
uint32_t superblock_size = DEFAULT_SUPERBLOCK_SIZE,
7579
block_size = DEFAULT_BLOCK_SIZE/4;
80+
#endif
7681
intfstream_t *file = intfstream_open_file(path,
7782
RETRO_VFS_FILE_ACCESS_READ,
7883
RETRO_VFS_FILE_ACCESS_HINT_NONE);
@@ -137,6 +142,7 @@ static bool bsv_movie_init_playback(bsv_movie_t *handle, const char *path)
137142
{
138143
retro_ctx_serialize_info_t serial_info;
139144
uint8_t compression, encoding;
145+
#ifdef HAVE_STATESTREAM
140146
uint32_t commit_settings = header[REPLAY_HEADER_CHECKPOINT_CONFIG_INDEX];
141147
superblock_size = swap_if_big32(header[REPLAY_HEADER_SUPERBLOCK_SIZE_INDEX]);
142148
block_size = swap_if_big32(header[REPLAY_HEADER_BLOCK_SIZE_INDEX]);
@@ -145,6 +151,7 @@ static bool bsv_movie_init_playback(bsv_movie_t *handle, const char *path)
145151
handle->checkpoint_compression = (commit_settings >> 8) & 0x000000FF;
146152
handle->superblocks = uint32s_index_new(superblock_size,handle->commit_interval,handle->commit_threshold);
147153
handle->blocks = uint32s_index_new(block_size/4,handle->commit_interval,handle->commit_threshold);
154+
#endif
148155

149156
if (intfstream_read(handle->file, &(compression), sizeof(uint8_t)) != sizeof(uint8_t) ||
150157
intfstream_read(handle->file, &(encoding), sizeof(uint8_t)) != sizeof(uint8_t))
@@ -172,10 +179,12 @@ static bool bsv_movie_init_record(
172179
intfstream_t *file = intfstream_open_file(path,
173180
RETRO_VFS_FILE_ACCESS_WRITE | RETRO_VFS_FILE_ACCESS_READ,
174181
RETRO_VFS_FILE_ACCESS_HINT_NONE);
182+
settings_t *settings = config_get_ptr();
183+
#ifdef HAVE_STATESTREAM
175184
bool is_small = false;
176185
uint32_t superblock_size;
177186
uint32_t block_size;
178-
settings_t *settings = config_get_ptr();
187+
#endif
179188

180189
if (!file)
181190
{
@@ -185,8 +194,10 @@ static bool bsv_movie_init_record(
185194

186195
handle->file = file;
187196
handle->version = REPLAY_FORMAT_VERSION;
197+
#ifdef HAVE_STATESTREAM
188198
handle->commit_interval = REPLAY_DEFAULT_COMMIT_INTERVAL;
189199
handle->commit_threshold = REPLAY_DEFAULT_COMMIT_THRESHOLD;
200+
#endif
190201
handle->checkpoint_compression = REPLAY_CHECKPOINT2_COMPRESSION_NONE;
191202
if (settings->bools.savestate_file_compression)
192203
#if defined(HAVE_ZSTD)
@@ -205,23 +216,32 @@ static bool bsv_movie_init_record(
205216

206217
info_size = core_serialize_size();
207218
state_size = (unsigned)info_size;
219+
#ifdef HAVE_STATESTREAM
208220
is_small = info_size < SMALL_STATE_THRESHOLD;
209221
superblock_size = is_small ? SMALL_SUPERBLOCK_SIZE : DEFAULT_SUPERBLOCK_SIZE;
210222
block_size = is_small ? SMALL_BLOCK_SIZE : DEFAULT_BLOCK_SIZE;
223+
#endif
211224
header[REPLAY_HEADER_STATE_SIZE_INDEX] = 0; /* Will fill this in later */
212225
header[REPLAY_HEADER_FRAME_COUNT_INDEX] = 0;
226+
#ifdef HAVE_STATESTREAM
213227
header[REPLAY_HEADER_BLOCK_SIZE_INDEX] = swap_if_big32(block_size);
214228
header[REPLAY_HEADER_SUPERBLOCK_SIZE_INDEX] = swap_if_big32(superblock_size);
215229
header[REPLAY_HEADER_CHECKPOINT_CONFIG_INDEX] = (((uint32_t)handle->commit_interval) << 24) |
216230
((uint32_t)handle->commit_threshold << 16) |
217231
(((uint32_t)handle->checkpoint_compression) << 8);
232+
#else
233+
header[REPLAY_HEADER_BLOCK_SIZE_INDEX] = 0;
234+
header[REPLAY_HEADER_SUPERBLOCK_SIZE_INDEX] = 0;
235+
header[REPLAY_HEADER_CHECKPOINT_CONFIG_INDEX] = 0;
236+
#endif
218237
handle->identifier = (int64_t)t;
219238
*((int64_t *)(header+REPLAY_HEADER_IDENTIFIER_INDEX)) = time_lil;
220239
intfstream_write(handle->file, header, REPLAY_HEADER_LEN_BYTES);
221240

241+
#ifdef HAVE_STATESTREAM
222242
handle->superblocks = uint32s_index_new(superblock_size, handle->commit_interval, handle->commit_threshold);
223243
handle->blocks = uint32s_index_new(block_size/4, handle->commit_interval, handle->commit_threshold);
224-
244+
#endif
225245
if (state_size)
226246
return bsv_movie_reset_recording(handle);
227247

@@ -237,9 +257,11 @@ void bsv_movie_free(bsv_movie_t *handle)
237257

238258
free(handle->frame_pos);
239259

260+
#ifdef HAVE_STATESTREAM
240261
uint32s_index_free(handle->superblocks);
241262
uint32s_index_free(handle->blocks);
242263
free(handle->superblock_seq);
264+
#endif
243265
if (handle->last_save)
244266
free(handle->last_save);
245267
if (handle->cur_save)
@@ -408,11 +430,13 @@ bool movie_stop_playback(input_driver_state_t *input_st)
408430
/* Checks if movie is being played back. */
409431
if (!(input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK))
410432
return false;
433+
#ifdef HAVE_STATESTREAM
411434
#if DEBUG
412435
RARCH_DBG("[Replay] superblock histogram\n");
413436
uint32s_index_print_count_data(input_st->bsv_movie_state_handle->superblocks);
414437
RARCH_DBG("[Replay] block histogram\n");
415438
uint32s_index_print_count_data(input_st->bsv_movie_state_handle->blocks);
439+
#endif
416440
#endif
417441
_msg = msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED);
418442
runloop_msg_queue_push(_msg, strlen(_msg), 2, 180, false, NULL,
@@ -437,11 +461,13 @@ bool movie_stop_record(input_driver_state_t *input_st)
437461
runloop_msg_queue_push(_msg, strlen(_msg), 2, 180, true, NULL,
438462
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
439463
RARCH_LOG("[Replay] %s\n", _msg);
464+
#ifdef HAVE_STATESTREAM
440465
#if DEBUG
441466
RARCH_DBG("[Replay] superblock histogram\n");
442467
uint32s_index_print_count_data(movie->superblocks);
443468
RARCH_DBG("[Replay] block histogram\n");
444469
uint32s_index_print_count_data(movie->blocks);
470+
#endif
445471
#endif
446472
frame_count = swap_if_big32(movie->frame_counter);
447473
intfstream_seek(movie->file, REPLAY_HEADER_FRAME_COUNT_INDEX*sizeof(uint32_t), SEEK_SET);

0 commit comments

Comments
 (0)