mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-09 08:55:32 +00:00
update JS code to use new fade code. fix some indentation.
This was SVN commit r3242.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user