Skip to content

Commit

Permalink
fix timestamp save and load, and remove debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Jul 27, 2023
1 parent 33779bd commit 39084b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
30 changes: 10 additions & 20 deletions src/game/savegame/savegame_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/specific/s_audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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(
Expand Down

0 comments on commit 39084b5

Please sign in to comment.