From 78da8bb8161c47348371a7dfd6990c9204eaea02 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 4 Apr 2024 05:10:27 -0700 Subject: [PATCH] ACS: add Music_Dim function, API to g_musicfade --- src/acs/call-funcs.cpp | 31 +++++++++++++++++++++++++++++++ src/acs/call-funcs.hpp | 1 + src/acs/environment.cpp | 1 + 3 files changed, 33 insertions(+) diff --git a/src/acs/call-funcs.cpp b/src/acs/call-funcs.cpp index 17e6474f7..020771a14 100644 --- a/src/acs/call-funcs.cpp +++ b/src/acs/call-funcs.cpp @@ -2399,6 +2399,37 @@ bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM:: return false; } +/*-------------------------------------------------- + bool CallFunc_MusicDim(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC) + + Fade level music into or out of silence. +--------------------------------------------------*/ +bool CallFunc_MusicDim(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC) +{ + // 0: int fade time (tics) - time to fade between full volume and silence + // 1: [int duration (tics)] - silent duration (not including fade in and fade out), -1 = infinite (default if omitted) + + // If a dim is ongoing, do not interrupt it + if (g_musicfade.start < leveltime && g_musicfade.end < leveltime) + { + g_musicfade.start = leveltime; + } + + tic_t fade = argV[0]; + tic_t duration = INFTICS; + + if (argC > 1 && argV[1] >= 0) + { + duration = argV[1]; + } + + g_musicfade.end = duration != INFTICS ? leveltime + duration + 2*fade : INFTICS; + g_musicfade.fade = fade; + g_musicfade.ticked = false; + + return false; +} + /*-------------------------------------------------- bool CallFunc_Freeze(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC) diff --git a/src/acs/call-funcs.hpp b/src/acs/call-funcs.hpp index 8ad5df737..8d304f558 100644 --- a/src/acs/call-funcs.hpp +++ b/src/acs/call-funcs.hpp @@ -103,6 +103,7 @@ bool CallFunc_ExitLevel(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::W bool CallFunc_MusicPlay(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); bool CallFunc_MusicStopAll(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); bool CallFunc_MusicRemap(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); +bool CallFunc_MusicDim(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); bool CallFunc_DialogueSetSpeaker(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); bool CallFunc_DialogueSetCustomSpeaker(ACSVM::Thread *thread, const ACSVM::Word *argV, ACSVM::Word argC); diff --git a/src/acs/environment.cpp b/src/acs/environment.cpp index 5c6a4ffd8..43fb3be97 100644 --- a/src/acs/environment.cpp +++ b/src/acs/environment.cpp @@ -187,6 +187,7 @@ Environment::Environment() addFuncDataACS0( 509, addCallFunc(CallFunc_MusicStopAll)); addFuncDataACS0( 510, addCallFunc(CallFunc_MusicRemap)); addFuncDataACS0( 511, addCallFunc(CallFunc_Freeze)); + addFuncDataACS0( 512, addCallFunc(CallFunc_MusicDim)); addFuncDataACS0( 600, addCallFunc(CallFunc_DialogueSetSpeaker)); addFuncDataACS0( 601, addCallFunc(CallFunc_DialogueSetCustomSpeaker));