--- a/hedgewars/hwengine.dpr Fri Jul 20 19:04:24 2007 +0000
+++ b/hedgewars/hwengine.dpr Sat Jul 21 12:29:09 2007 +0000
@@ -69,7 +69,7 @@
inc(RealTicks, Lag);
inc(MusicTimerTicks, Lag);
-if MusicTimerTicks > 3000 then
+if (MusicTimerTicks > 3000) and (GameState > gsStart) then
begin
PlayMusic;
MusicTimerTicks:= 0
@@ -81,6 +81,7 @@
GameState:= gsStart;
end;
gsStart: begin
+ InitPlaylistChunk(GetRandom(High(LongWord)));
AssignHHCoords;
AddMiscGears;
AdjustColor(cColorNearBlack);
@@ -90,7 +91,6 @@
AdjustColor(cConsoleSplitterColor);
ResetKbd;
SoundLoad;
- InitPlaylistChunk(GetRandom(High(LongWord)));
if GameType = gmtSave then
begin
isSEBackup:= isSoundEnabled;
--- a/hedgewars/uSound.pas Fri Jul 20 19:04:24 2007 +0000
+++ b/hedgewars/uSound.pas Sat Jul 21 12:29:09 2007 +0000
@@ -102,15 +102,19 @@
{$IFDEF HAVE_MUSIC}
if not isSoundEnabled then exit;
if Mix_PlayingMusic() <> 0 then exit;
+
Mix_FreeMusic(Mus);
+
+CurrMusic:= playlistchain[CurrMusic];
+
s:= PathPrefix + '/Music/' + playlist[CurrMusic];
-CurrMusic:= playlistchain[CurrMusic];
WriteToConsole(msgLoading + s + ' ');
+
Mus:= Mix_LoadMUS(Str2PChar(s));
TryDo(Mus <> nil, msgFailed, false);
WriteLnToConsole(msgOK);
-Mix_PlayMusic(Mus, 0)
+Mix_PlayMusic(Mus, 1)
{$ENDIF}
end;
@@ -128,18 +132,21 @@
end;
procedure InitPlaylistChunk(seed: LongWord);
-var i, t, tmp: Longword;
+var i, t, nt: Longword;
begin
{$IFDEF HAVE_MUSIC}
for i:= 0 to Pred(cPlayListLength) do
- playlistchain[i]:= i;
+ playlistchain[i]:= 0;
-for i:= 0 to Pred(cPlayListLength) do
+t:= 0;
+for i:= 0 to cPlayListLength - 2 do
begin
- t:= (i + 1) mod cPlayListLength;
- tmp:= playlistchain[t];
- playlistchain[t]:= playlistchain[i];
- playlistchain[i]:= tmp;
+ repeat
+ seed:= seed * 1664525 + 1013904223;
+ nt:= seed mod cPlayListLength;
+ until (t <> nt) and (playlistchain[nt] = 0);
+ playlistchain[t]:= nt;
+ t:= nt;
end
{$ENDIF}
end;