decomp: improve cutscene syncing

This commit is contained in:
Marcin Kurczewski 2024-05-04 23:35:21 +02:00
parent 1ada84cf51
commit b16027d4c8
No known key found for this signature in database
GPG Key ID: CC65E6FD28CAE42A
4 changed files with 14 additions and 8 deletions

View File

@ -1070,7 +1070,8 @@ int32_t __cdecl Game_Cutscene_Control(const int32_t nframes)
HairControl(1);
Camera_UpdateCutscene();
if (++g_CineFrameIdx >= g_NumCineFrames) {
g_CineFrameIdx++;
if (g_CineFrameIdx >= g_NumCineFrames) {
return 1;
}
@ -1081,7 +1082,14 @@ int32_t __cdecl Game_Cutscene_Control(const int32_t nframes)
}
}
g_CineFrameCurrent = Music_GetFrames() * 4 / 5;
if (Music_GetTimestamp() < 0.0) {
g_CineFrameCurrent++;
} else {
// sync with music
g_CineFrameCurrent =
Music_GetTimestamp() * FRAMES_PER_SECOND * TICKS_PER_FRAME / 1000.0;
}
return 0;
}

View File

@ -7,5 +7,5 @@ void __cdecl Music_Shutdown(void);
void __cdecl Music_Play(int16_t track_id, bool is_looped);
void __cdecl Music_Stop(void);
bool __cdecl Music_PlaySynced(int16_t track_id);
uint32_t __cdecl Music_GetFrames(void);
double __cdecl Music_GetTimestamp(void);
void __cdecl Music_SetVolume(int32_t volume);

View File

@ -164,13 +164,12 @@ bool __cdecl Music_PlaySynced(int16_t track_id)
return true;
}
uint32_t __cdecl Music_GetFrames(void)
double __cdecl Music_GetTimestamp(void)
{
if (m_AudioStreamID < 0) {
return 0;
return -1.0;
}
return Audio_Stream_GetTimestamp(m_AudioStreamID) * FRAMES_PER_SECOND
* TICKS_PER_FRAME / 1000.0;
return Audio_Stream_GetTimestamp(m_AudioStreamID);
}
void __cdecl Music_SetVolume(int32_t volume)

View File

@ -293,7 +293,6 @@ static void Inject_Music(const bool enable)
INJECT(enable, 0x00455500, Music_Play);
INJECT(enable, 0x00455570, Music_Stop);
INJECT(enable, 0x004555B0, Music_PlaySynced);
INJECT(enable, 0x00455640, Music_GetFrames);
INJECT(enable, 0x004556B0, Music_SetVolume);
}