diff -r 21ed7cec1fa2 -r 3deb9ff104da hedgewars/uSound.pas --- a/hedgewars/uSound.pas Thu Nov 05 20:40:31 2009 +0000 +++ b/hedgewars/uSound.pas Thu Nov 05 20:47:42 2009 +0000 @@ -31,6 +31,7 @@ procedure ReleaseSound; procedure SoundLoad; procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack); +procedure LoopSound(snd: TSound; voicepack: PVoicepack); procedure PlayMusic; procedure PauseMusic; procedure ResumeMusic; @@ -66,6 +67,7 @@ end; procedure InitSound; +var i: TSound; begin if not isSoundEnabled then exit; WriteToConsole('Init sound...'); @@ -77,6 +79,9 @@ Mix_AllocateChannels(Succ(chanTPU)); if isMusicEnabled then Mix_VolumeMusic(50); +for i:= Low(TSound) to High(TSound) do + lastChan[i]:= -1; + Volume:= 0; ChangeVolume(cInitVolume) end; @@ -105,7 +110,7 @@ defVoicepack:= AskForVoicepack('Default'); for i:= Low(TSound) to High(TSound) do - if Soundz[i].Path <> ptVoices then + if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then begin s:= Pathz[Soundz[i].Path] + '/' + Soundz[i].FileName; WriteToConsole(msgLoading + s + ' '); @@ -117,7 +122,7 @@ for t:= 0 to cMaxTeams do if voicepacks[t].name <> '' then for i:= Low(TSound) to High(TSound) do - if Soundz[i].Path = ptVoices then + 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 + ' '); @@ -144,11 +149,25 @@ lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1) end; +procedure LoopSound(snd: TSound; voicepack: PVoicepack); +begin +if (not isSoundEnabled) or fastUntilLag then exit; +if lastChan[snd] <> -1 then exit; + +if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then + lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) +else + lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1) +end; + procedure StopSound(snd: TSound); begin if not isSoundEnabled then exit; -if Mix_Playing(lastChan[snd]) <> 0 then - Mix_HaltChannel(lastChan[snd]) +if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then + begin + Mix_HaltChannel(lastChan[snd]); + lastChan[snd]:= -1; + end; end; procedure PlayMusic;