diff -r a8c673657b79 -r 0e968ba12a84 hedgewars/uSound.pas --- a/hedgewars/uSound.pas Fri Jun 18 14:45:05 2010 +0200 +++ b/hedgewars/uSound.pas Mon Jun 21 16:08:24 2010 +0200 @@ -40,8 +40,8 @@ procedure PlaySound(snd: TSound; keepPlaying: boolean); procedure PlaySound(snd: TSound; voicepack: PVoicepack); procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); -function LoopSound(snd: TSound): LongInt; -function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; +function LoopSound(snd: TSound): LongInt; +function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; procedure PlayMusic; procedure PauseMusic; procedure ResumeMusic; @@ -65,14 +65,14 @@ var i: Longword; begin i:= 0; -while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do + while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do begin - inc(i); - TryDo(i <= cMaxTeams, 'Engine bug: AskForVoicepack i > cMaxTeams', true) + inc(i); + TryDo(i <= cMaxTeams, 'Engine bug: AskForVoicepack i > cMaxTeams', true) end; -voicepacks[i].name:= name; -AskForVoicepack:= @voicepacks[i] + voicepacks[i].name:= name; + AskForVoicepack:= @voicepacks[i] end; procedure InitSound; @@ -110,22 +110,22 @@ var i: TSound; t: Longword; begin -for t:= 0 to cMaxTeams do - if voicepacks[t].name <> '' then - for i:= Low(TSound) to High(TSound) do - if voicepacks[t].chunks[i] <> nil then - Mix_FreeChunk(voicepacks[t].chunks[i]); + for t:= 0 to cMaxTeams do + if voicepacks[t].name <> '' then + for i:= Low(TSound) to High(TSound) do + if voicepacks[t].chunks[i] <> nil then + Mix_FreeChunk(voicepacks[t].chunks[i]); -if Mus <> nil then - Mix_FreeMusic(Mus); + if Mus <> nil then + Mix_FreeMusic(Mus); {$IFDEF SDL_MIXER_NEWER} -// make sure all instances of sdl_mixer are unloaded before continuing -while Mix_Init(0) <> 0 do - Mix_Quit(); + // make sure all instances of sdl_mixer are unloaded before continuing + while Mix_Init(0) <> 0 do + Mix_Quit(); {$ENDIF} -Mix_CloseAudio(); + Mix_CloseAudio(); end; procedure SoundLoad; @@ -137,28 +137,28 @@ defVoicepack:= AskForVoicepack('Default'); -for i:= Low(TSound) to High(TSound) do - if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then + for i:= Low(TSound) to High(TSound) do + if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then begin - s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; - WriteToConsole(msgLoading + s + ' '); - defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); - TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); - WriteLnToConsole(msgOK); + s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; + WriteToConsole(msgLoading + s + ' '); + defVoicepack^.chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); + TryDo(defVoicepack^.chunks[i] <> nil, msgFailed, true); + WriteLnToConsole(msgOK); end; -for t:= 0 to cMaxTeams do - if voicepacks[t].name <> '' then - for i:= Low(TSound) to High(TSound) do - if (Soundz[i].Path = ptVoices) and (Soundz[i].FileName <> '') then + for t:= 0 to cMaxTeams do + if voicepacks[t].name <> '' then + for i:= Low(TSound) to High(TSound) do + if (Soundz[i].Path = ptVoices) and (Soundz[i].FileName <> '') then begin - s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; - WriteToConsole(msgLoading + s + ' '); - voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); - if voicepacks[t].chunks[i] = nil then - WriteLnToConsole(msgFailed) - else - WriteLnToConsole(msgOK) + s:= Pathz[Soundz[i].Path] + '/' + voicepacks[t].name + '/' + Soundz[i].FileName; + WriteToConsole(msgLoading + s + ' '); + voicepacks[t].chunks[i]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); + if voicepacks[t].chunks[i] = nil then + WriteLnToConsole(msgFailed) + else + WriteLnToConsole(msgOK) end; end; @@ -179,15 +179,16 @@ procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); begin -if (not isSoundEnabled) or fastUntilLag then exit; - -if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then - exit; + if (not isSoundEnabled) or fastUntilLag then + exit; -if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then - lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1) -else - lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1) + if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then + exit; + + if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then + lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1) + else + lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1) end; function LoopSound(snd: TSound): LongInt; @@ -197,76 +198,79 @@ function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; begin -if (not isSoundEnabled) or fastUntilLag then + if (not isSoundEnabled) or fastUntilLag then begin - LoopSound:= -1; - exit + LoopSound:= -1; + exit end; -if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then - LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) -else - LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1) + if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then + LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) + else + LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1) end; procedure StopSound(snd: TSound); begin -if not isSoundEnabled then exit; -if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then + if not isSoundEnabled then exit; + if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then begin - Mix_HaltChannel(lastChan[snd]); - lastChan[snd]:= -1; + Mix_HaltChannel(lastChan[snd]); + lastChan[snd]:= -1; end; end; procedure StopSound(chn: LongInt); begin -if not isSoundEnabled then exit; -if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_HaltChannel(chn); + if not isSoundEnabled then exit; + + if (chn <> -1) and (Mix_Playing(chn) <> 0) then + Mix_HaltChannel(chn); end; procedure PlayMusic; var s: shortstring; begin -if (not isSoundEnabled) - or (MusicFN = '') - or (not isMusicEnabled) then exit; + if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then + exit; + + s:= PathPrefix + '/Music/' + MusicFN; + WriteToConsole(msgLoading + s + ' '); -s:= PathPrefix + '/Music/' + MusicFN; -WriteToConsole(msgLoading + s + ' '); + Mus:= Mix_LoadMUS(Str2PChar(s)); + TryDo(Mus <> nil, msgFailed, false); + WriteLnToConsole(msgOK); -Mus:= Mix_LoadMUS(Str2PChar(s)); -TryDo(Mus <> nil, msgFailed, false); -WriteLnToConsole(msgOK); - -SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false) + SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false) end; function ChangeVolume(voldelta: LongInt): LongInt; begin -if not isSoundEnabled then - exit(0); + if not isSoundEnabled then + exit(0); -inc(Volume, voldelta); -if Volume < 0 then Volume:= 0; -Mix_Volume(-1, Volume); -Volume:= Mix_Volume(-1, -1); -if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); -ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME + inc(Volume, voldelta); + if Volume < 0 then Volume:= 0; + Mix_Volume(-1, Volume); + Volume:= Mix_Volume(-1, -1); + if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); + ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME end; procedure PauseMusic; begin -if (MusicFN = '') or (not isMusicEnabled) then exit; + if (MusicFN = '') or (not isMusicEnabled) then + exit; -Mix_PauseMusic(Mus); + Mix_PauseMusic(Mus); end; procedure ResumeMusic; begin -if (MusicFN = '') or (not isMusicEnabled) then exit; + if (MusicFN = '') or (not isMusicEnabled) then + exit; -Mix_ResumeMusic(Mus); + Mix_ResumeMusic(Mus); end; procedure initModule;