hedgewars/uSound.pas
branchwebgl
changeset 8096 453917e94e55
parent 8026 4a4f21070479
parent 8046 4d3415927d2c
child 8330 aaefa587e277
equal deleted inserted replaced
8053:2e836bebb518 8096:453917e94e55
   104 // Returns a pointer to the voicepack with the given name.
   104 // Returns a pointer to the voicepack with the given name.
   105 function  AskForVoicepack(name: shortstring): Pointer;
   105 function  AskForVoicepack(name: shortstring): Pointer;
   106 
   106 
   107 
   107 
   108 implementation
   108 implementation
   109 uses uVariables, uConsole, uUtils, uCommands, uDebug;
   109 uses uVariables, uConsole, uUtils, uCommands, uDebug, uPhysFSLayer;
   110 
   110 
   111 const chanTPU = 32;
   111 const chanTPU = 32;
   112 var Volume: LongInt;
   112 var Volume: LongInt;
   113     cInitVolume: LongInt;
   113     cInitVolume: LongInt;
   114     previousVolume: LongInt; // cached volume value
   114     previousVolume: LongInt; // cached volume value
   129 i:= 0;
   129 i:= 0;
   130     // First, attempt to locate a localised version of the voice
   130     // First, attempt to locate a localised version of the voice
   131     if cLocale <> 'en' then
   131     if cLocale <> 'en' then
   132         begin
   132         begin
   133         locName:= name+'_'+cLocale;
   133         locName:= name+'_'+cLocale;
   134         path:= UserPathz[ptVoices] + '/' + locName;
   134         path:= cPathz[ptVoices] + '/' + locName;
   135         if DirectoryExists(path) then
   135         if DirectoryExists(path) then
   136             name:= locName
   136             name:= locName
   137         else
   137         else
   138             begin
   138             if Length(cLocale) > 3 then
   139             path:= Pathz[ptVoices] + '/' + locName;
       
   140             if DirectoryExists(path) then
       
   141                 name:= locName
       
   142             else if Length(cLocale) > 3
       
   143                 then
       
   144                 begin
   139                 begin
   145                 locName:= name+'_'+Copy(cLocale,1,2);
   140                 locName:= name+'_'+Copy(cLocale,1,2);
   146                 path:= UserPathz[ptVoices] + '/' + locName;
   141                 path:= cPathz[ptVoices] + '/' + locName;
   147                 if DirectoryExists(path) then
   142                 if DirectoryExists(path) then
   148                     name:= locName
   143                     name:= locName
   149                 else
       
   150                     begin
       
   151                     path:= Pathz[ptVoices] + '/' + locName;
       
   152                     if DirectoryExists(path) then
       
   153                         name:= locName
       
   154                     end
       
   155                 end
   144                 end
   156             end
       
   157         end;
   145         end;
   158 
   146 
   159     // If that fails, use the unmodified one
   147     // If that fails, use the unmodified one
   160     while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do
   148     while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do
   161         begin
   149         begin
   265 
   253 
   266     if (voicepack <> nil) then
   254     if (voicepack <> nil) then
   267         begin
   255         begin
   268         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   256         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   269             begin
   257             begin
   270             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   258             s:= cPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   271             if not FileExists(s) then
       
   272                 s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
       
   273             if (not FileExists(s)) and (snd in [sndFirePunch2, sndFirePunch3, sndFirePunch4, sndFirePunch5, sndFirePunch6]) then
   259             if (not FileExists(s)) and (snd in [sndFirePunch2, sndFirePunch3, sndFirePunch4, sndFirePunch5, sndFirePunch6]) then
   274                 s:= Pathz[Soundz[sndFirePunch1].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   260                 s:= cPathz[Soundz[sndFirePunch1].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   275             WriteToConsole(msgLoading + s + ' ');
   261             WriteToConsole(msgLoading + s + ' ');
   276             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), _P'rb'), 1);
   262             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   277             if voicepack^.chunks[snd] = nil then
   263             if voicepack^.chunks[snd] = nil then
   278                 WriteLnToConsole(msgFailed)
   264                 WriteLnToConsole(msgFailed)
   279             else
   265             else
   280                 WriteLnToConsole(msgOK)
   266                 WriteLnToConsole(msgOK)
   281             end;
   267             end;
   283         end
   269         end
   284     else
   270     else
   285         begin
   271         begin
   286         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   272         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   287             begin
   273             begin
   288             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   274             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   289             if not FileExists(s) then
       
   290                 s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
       
   291             WriteToConsole(msgLoading + s + ' ');
   275             WriteToConsole(msgLoading + s + ' ');
   292             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), _P'rb'), 1);
   276             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   293             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   277             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   294             WriteLnToConsole(msgOK);
   278             WriteLnToConsole(msgOK);
   295             end;
   279             end;
   296         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   280         lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   297         end;
   281         end;
   367 
   351 
   368     if (voicepack <> nil) then
   352     if (voicepack <> nil) then
   369         begin
   353         begin
   370         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   354         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
   371            begin
   355            begin
   372             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   356             s:= cPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
   373             if not FileExists(s) then
       
   374                 s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
       
   375             WriteToConsole(msgLoading + s + ' ');
   357             WriteToConsole(msgLoading + s + ' ');
   376             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), _P'rb'), 1);
   358             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   377             if voicepack^.chunks[snd] = nil then
   359             if voicepack^.chunks[snd] = nil then
   378                 WriteLnToConsole(msgFailed)
   360                 WriteLnToConsole(msgFailed)
   379             else
   361             else
   380                 WriteLnToConsole(msgOK)
   362                 WriteLnToConsole(msgOK)
   381             end;
   363             end;
   383         end
   365         end
   384     else
   366     else
   385         begin
   367         begin
   386         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   368         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
   387             begin
   369             begin
   388             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   370             s:= cPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
   389             if not FileExists(s) then
       
   390                 s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
       
   391             WriteToConsole(msgLoading + s + ' ');
   371             WriteToConsole(msgLoading + s + ' ');
   392             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), _P'rb'), 1);
   372             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(rwopsOpenRead(s), 1);
   393             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   373             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
   394             WriteLnToConsole(msgOK);
   374             WriteLnToConsole(msgOK);
   395             end;
   375             end;
   396         if fadems > 0 then
   376         if fadems > 0 then
   397             LoopSoundV:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1)
   377             LoopSoundV:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1)
   434 var s: shortstring;
   414 var s: shortstring;
   435 begin
   415 begin
   436     if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then
   416     if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then
   437         exit;
   417         exit;
   438 
   418 
   439     s:= UserPathPrefix + '/Data/Music/' + MusicFN;
   419     s:= '/Music/' + MusicFN;
   440     if not FileExists(s) then
       
   441         s:= PathPrefix + '/Music/' + MusicFN;
       
   442     WriteToConsole(msgLoading + s + ' ');
   420     WriteToConsole(msgLoading + s + ' ');
   443 
   421 
   444     Mus:= Mix_LoadMUS(Str2PChar(s));
   422     Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
   445     SDLTry(Mus <> nil, false);
   423     SDLTry(Mus <> nil, false);
   446     WriteLnToConsole(msgOK);
   424     WriteLnToConsole(msgOK);
   447 
   425 
   448     SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
   426     SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
   449 end;
   427 end;