diff --git a/binaries/data/mods/official/gui/test/functions_page_pregame_load.js b/binaries/data/mods/official/gui/test/functions_page_pregame_load.js index 613fdc84ee..c59942d94d 100644 --- a/binaries/data/mods/official/gui/test/functions_page_pregame_load.js +++ b/binaries/data/mods/official/gui/test/functions_page_pregame_load.js @@ -136,9 +136,7 @@ function setupSession () // Select session peace track. curr_session_playlist_1 = newRandomSound("music", "peace"); // Fade out main theme and fade in session theme. - crossFade(curr_music, curr_session_playlist_1, 0.1); - // janwas: greatly accelerate this timesink; - // will be replaced soon by native version that doesn't block. + crossFade(curr_music, curr_session_playlist_1, 1); // Start refreshing the session controls. setInterval( snRefresh, 1, 100 ); @@ -160,12 +158,10 @@ function endSession (closeType) // Fade out current music and return to playing menu theme. curr_music = newRandomSound('music', 'menu'); - crossFade(curr_session_playlist_1, curr_music, 0.1); - // janwas: greatly accelerate this timesink; - // will be replaced soon by native version that doesn't block. + crossFade(curr_session_playlist_1, curr_music, 1); - // Stop refreshing the session controls. - cancelInterval(); + // Stop refreshing the session controls. + cancelInterval(); // Swap GUIs to display main menu. guiSwitch ("sn", "pg"); diff --git a/binaries/data/mods/official/gui/test/functions_utility_music.js b/binaries/data/mods/official/gui/test/functions_utility_music.js index e81c318e63..932ccd0101 100755 --- a/binaries/data/mods/official/gui/test/functions_utility_music.js +++ b/binaries/data/mods/official/gui/test/functions_utility_music.js @@ -64,57 +64,42 @@ function newRandomSound(soundType, soundSubType, soundPrePath) // ==================================================================== -function fadeOut (soundHandle, Rate) +function fadeOut (soundHandle, fadeDuration) { // Adjust the gain of a sound until it is zero. + // The sound is automatically freed when finished fading. + soundHandle.fade(-1, 0, fadeDuration) - // (This is a horrible hack, and needs to be replaced with a decent engine function.) - - for (fadeLoop = 1; fadeLoop > 0; fadeLoop = fadeLoop - Rate) - { - soundHandle.setGain(fadeLoop); - } - return true; } // ==================================================================== -function fadeIn (soundHandle, Gain, Rate) +function fadeIn (soundHandle, finalGain, fadeDuration) { // Adjust the gain of a sound from zero up to the given value. + soundHandle.fade(0, finalGain, fadeDuration) - // (This is a horrible hack, and needs to be replaced with a decent engine function.) - - for (fadeLoop = 0; fadeLoop < Gain; fadeLoop = fadeLoop + Rate) - { - soundHandle.setGain(fadeLoop); - } - return true; } // ==================================================================== -function crossFade (outHandle, inHandle, Rate) +function crossFade (outHandle, inHandle, fadeDuration) { - // Accepts two sound handles. Fades out the first and fades in the second at the specified rate. + // Accepts two sound handles. Over the given duration, + // fades out the first while fading in the second. // Note that it plays the in and frees the out while it's at it. - // (This is a horrible hack, and needs to be replaced with a decent engine function.) - if (outHandle) - fadeOut(outHandle, Rate); + fadeOut(outHandle, fadeDuration); if (inHandle) { inHandle.play(); - fadeIn(inHandle, 1, Rate); + fadeIn(inHandle, 1, fadeDuration); } - if (outHandle) - outHandle.free(); - return true; }