From 39084b5a8200b4e7398989e52a24b1e49270bbd6 Mon Sep 17 00:00:00 2001 From: walkawayy <81546780+walkawayy@users.noreply.github.com> Date: Wed, 26 Jul 2023 20:01:15 -0400 Subject: [PATCH] fix timestamp save and load, and remove debug logs --- src/game/savegame/savegame_bson.c | 30 ++++++++++-------------------- src/specific/s_audio_stream.c | 4 ---- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/game/savegame/savegame_bson.c b/src/game/savegame/savegame_bson.c index 8e3283bfe..16b087d0a 100644 --- a/src/game/savegame/savegame_bson.c +++ b/src/game/savegame/savegame_bson.c @@ -1211,7 +1211,7 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) if (header.version >= VERSION_2) { if (!SaveGame_BSON_LoadFx(json_object_get_array(root_obj, "fx"))) { - goto cleanup; + goto cleanup; } } @@ -1221,19 +1221,13 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) } int16_t load_track = json_object_get_int(root_obj, "music_track", -1); - - int64_t timestamp_arr[2]; + int32_t timestamp_arr[2]; timestamp_arr[0] = json_object_get_int(root_obj, "music_timestamp1", -1); timestamp_arr[1] = json_object_get_int(root_obj, "music_timestamp2", -1); - LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]); - LOG_DEBUG("music_timestamp2 %d", timestamp_arr[1]); - int64_t load_timestamp = *(int64_t *)timestamp_arr; - LOG_DEBUG("load_timestamp %d", load_timestamp); - LOG_DEBUG("load_track %d", load_track); - + int64_t *music_timestamp = (int64_t *) timestamp_arr; if (load_track) { Music_Play(load_track); - Music_SeekTimestamp(load_track, load_timestamp); + Music_SeekTimestamp(load_track, *music_timestamp); } ret = true; @@ -1303,19 +1297,15 @@ void Savegame_BSON_SaveToFile(MYFILE *fp, GAME_INFO *game_info) json_object_append_array(root_obj, "fx", SaveGame_BSON_DumpFx()); json_object_append_object( root_obj, "lara", Savegame_BSON_DumpLara(&g_Lara)); - int16_t save_track = Music_CurrentTrack(); - json_object_append_int(root_obj, "music_track", save_track); - int64_t save_timestamp = 0; - if (save_track) { - save_timestamp = Music_GetTimestamp(Music_CurrentTrack()); + int16_t music_track = Music_CurrentTrack(); + json_object_append_int(root_obj, "music_track", music_track); + int64_t music_timestamp = 0; + if (music_track) { + music_timestamp = Music_GetTimestamp(Music_CurrentTrack()); } - int64_t *timestamp_arr = (int64_t *)&save_timestamp; + int32_t *timestamp_arr = (int32_t *) &music_timestamp; json_object_append_int(root_obj, "music_timestamp1", timestamp_arr[0]); json_object_append_int(root_obj, "music_timestamp2", timestamp_arr[1]); - LOG_DEBUG("save_timestamp %d", save_timestamp); - LOG_DEBUG("music_timestamp1 %d", timestamp_arr[0]); - LOG_DEBUG("music_timestamp2 %d", timestamp_arr[1]); - LOG_DEBUG("save_track %d", save_track); struct json_value_s *root = json_value_from_object(root_obj); SaveGame_BSON_SaveRaw(fp, root, SAVEGAME_CURRENT_VERSION); diff --git a/src/specific/s_audio_stream.c b/src/specific/s_audio_stream.c index f2296b4f2..dd096a010 100644 --- a/src/specific/s_audio_stream.c +++ b/src/specific/s_audio_stream.c @@ -141,7 +141,6 @@ static bool S_Audio_StreamSoundEnqueueFrame(AUDIO_STREAM_SOUND *stream) } stream->timestamp = stream->av.frame->best_effort_timestamp; - LOG_DEBUG("Enqueue timestamp: %d.", stream->timestamp); av_frame_unref(stream->av.frame); } @@ -531,11 +530,9 @@ int64_t S_Audio_StreamGetTimestamp(int sound_id) } if (m_StreamSounds[sound_id].is_playing) { - LOG_DEBUG("Getting timestamp for sound_id %d.", sound_id); SDL_LockAudioDevice(g_AudioDeviceID); AUDIO_STREAM_SOUND *stream = &m_StreamSounds[sound_id]; int64_t timestamp = stream->timestamp; - LOG_DEBUG("Timestamp: %d.", timestamp); SDL_UnlockAudioDevice(g_AudioDeviceID); return timestamp; } @@ -551,7 +548,6 @@ bool S_Audio_StreamSeekTimestamp(int sound_id, int64_t timestamp) } if (m_StreamSounds[sound_id].is_playing) { - LOG_DEBUG("Seeking timestamp %d on sound_id %d.", timestamp, sound_id); SDL_LockAudioDevice(g_AudioDeviceID); AUDIO_STREAM_SOUND *stream = &m_StreamSounds[sound_id]; av_seek_frame(