Skip to content

Commit

Permalink
Merge branch 'savestate' of github.com:libretro/libretro-chailove int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
RobLoach committed Sep 20, 2018
2 parents 028a578 + 0bd94ce commit e4aa141
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_modules
*.srm.*
*.srm1.*
/package.json
/.bsv
/*.mkv
51 changes: 24 additions & 27 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,33 @@ FLAGS += -I$(CORE_DIR)/vendor/filesystem

# libretro-common
FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include

# libretro-common audio
SOURCES_C += $(wildcard \
$(CORE_DIR)/vendor/libretro-common/audio/audio_mix.c \
$(CORE_DIR)/vendor/libretro-common/audio/audio_mixer.c \
$(CORE_DIR)/vendor/libretro-common/audio/conversion/*.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/audio_resampler.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/null_resampler.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/sinc_resampler.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_posix_string.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_strcasestr.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_strl.c \
$(CORE_DIR)/vendor/libretro-common/compat/fopen_utf8.c \
$(CORE_DIR)/vendor/libretro-common/encodings/encoding_utf.c \
$(CORE_DIR)/vendor/libretro-common/features/features_cpu.c \
$(CORE_DIR)/vendor/libretro-common/file/config_file.c \
$(CORE_DIR)/vendor/libretro-common/file/config_file_userdata.c \
$(CORE_DIR)/vendor/libretro-common/file/file_path.c \
$(CORE_DIR)/vendor/libretro-common/formats/wav/rwav.c \
$(CORE_DIR)/vendor/libretro-common/lists/string_list.c \
$(CORE_DIR)/vendor/libretro-common/memmap/memalign.c \
$(CORE_DIR)/vendor/libretro-common/streams/file_stream.c \
$(CORE_DIR)/vendor/libretro-common/vfs/*.c \
)
# Only compile nearest_resampler when not STATIC_LINKING
# Only compile libretro-common when not STATIC_LINKING
ifneq ($(STATIC_LINKING), 1)
SOURCES_C += $(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/nearest_resampler.c
SOURCES_C += $(wildcard \
$(CORE_DIR)/vendor/libretro-common/audio/audio_mix.c \
$(CORE_DIR)/vendor/libretro-common/audio/audio_mixer.c \
$(CORE_DIR)/vendor/libretro-common/audio/conversion/*.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/audio_resampler.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/nearest_resampler.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/null_resampler.c \
$(CORE_DIR)/vendor/libretro-common/audio/resampler/drivers/sinc_resampler.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_posix_string.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_strcasestr.c \
$(CORE_DIR)/vendor/libretro-common/compat/compat_strl.c \
$(CORE_DIR)/vendor/libretro-common/compat/fopen_utf8.c \
$(CORE_DIR)/vendor/libretro-common/encodings/encoding_utf.c \
$(CORE_DIR)/vendor/libretro-common/features/features_cpu.c \
$(CORE_DIR)/vendor/libretro-common/file/config_file.c \
$(CORE_DIR)/vendor/libretro-common/file/config_file_userdata.c \
$(CORE_DIR)/vendor/libretro-common/file/file_path.c \
$(CORE_DIR)/vendor/libretro-common/formats/wav/rwav.c \
$(CORE_DIR)/vendor/libretro-common/lists/string_list.c \
$(CORE_DIR)/vendor/libretro-common/memmap/memalign.c \
$(CORE_DIR)/vendor/libretro-common/streams/file_stream.c \
$(CORE_DIR)/vendor/libretro-common/vfs/*.c \
)
endif


# stb_vorbis
#SOURCES_C += $(CORE_DIR)/vendor/stb/stb_vorbis.c
FLAGS += -DHAVE_STB_VORBIS
Expand Down
14 changes: 6 additions & 8 deletions src/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ void retro_set_controller_port_device(unsigned port, unsigned device) {
* libretro callback; Return the amount of bytes required to save a state.
*/
size_t retro_serialize_size(void) {
// Save states will be 10 kilobytes.
return 10000;
// Save states will be 5 kilobytes.
return 5000;
}

/**
Expand All @@ -235,7 +235,6 @@ bool retro_serialize(void *data, size_t size) {
if (!ChaiLove::hasInstance()) {
return false;
}
std::cout << "[ChaiLove] retro_serialize" << std::endl;

// Ask ChaiLove for save data.
ChaiLove* app = ChaiLove::getInstance();
Expand All @@ -244,9 +243,9 @@ bool retro_serialize(void *data, size_t size) {
return false;
}

// Encode the JSON state data.
// Encode the JSON state data. Disabled for speed.
// state = app->data.encode("string", "base64", state);
state = app->data.compress(state);
// state = app->data.compress(state);

// Save the information to the state data.
std::copy(state.begin(), state.end(), reinterpret_cast<char*>(data));
Expand All @@ -260,7 +259,6 @@ bool retro_unserialize(const void *data, size_t size) {
if (!ChaiLove::hasInstance() || size <= 0) {
return false;
}
std::cout << "[ChaiLove] retro_unserialize" << std::endl;

// Create a string stream from the data.
std::stringstream ss(std::string(
Expand All @@ -273,9 +271,9 @@ bool retro_unserialize(const void *data, size_t size) {
// Pass the string to the script.
ChaiLove* app = ChaiLove::getInstance();

// Decompress the state data.
// Decompress the state data. Disabled for speed.
// loadData = app->data.decode("string", "base64", loadData);
loadData = app->data.decompress(loadData);
// loadData = app->data.decompress(loadData);

// Finally, load the string.
return app->loadstate(loadData);
Expand Down

0 comments on commit e4aa141

Please sign in to comment.