--- a/hedgewars/uSound.pas Fri Jul 20 13:46:27 2007 +0000
+++ b/hedgewars/uSound.pas Fri Jul 20 19:04:24 2007 +0000
@@ -28,11 +28,16 @@
procedure PlayMusic;
procedure StopSound(snd: TSound);
function ChangeVolume(voldelta: LongInt): LongInt;
+procedure InitPlaylistChunk(seed: LongWord);
implementation
uses uMisc, uConsole;
+
+{$INCLUDE playlist.inc}
+
const chanTPU = 12;
-var Mus: PMixMusic;
+var Mus: PMixMusic = nil;
+ CurrMusic: Longword = 0;
Volume: LongInt;
procedure InitSound;
@@ -74,12 +79,6 @@
TryDo(Soundz[i].id <> nil, msgFailed, true);
WriteLnToConsole(msgOK);
end;
-
-s:= PathPrefix + '/Music/kahvi140a_alexander_chereshnev-illusion.ogg';
-WriteToConsole(msgLoading + s + ' ');
-Mus:= Mix_LoadMUS(Str2PChar(s));
-TryDo(Mus <> nil, msgFailed, false);
-WriteLnToConsole(msgOK)
end;
procedure PlaySound(snd: TSound; infinite: boolean);
@@ -98,10 +97,21 @@
end;
procedure PlayMusic;
+var s: string;
begin
+{$IFDEF HAVE_MUSIC}
if not isSoundEnabled then exit;
-if Mix_PlayingMusic = 0 then
- Mix_PlayMusic(Mus, -1)
+if Mix_PlayingMusic() <> 0 then exit;
+Mix_FreeMusic(Mus);
+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)
+{$ENDIF}
end;
function ChangeVolume(voldelta: LongInt): LongInt;
@@ -117,4 +127,21 @@
ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
end;
+procedure InitPlaylistChunk(seed: LongWord);
+var i, t, tmp: Longword;
+begin
+{$IFDEF HAVE_MUSIC}
+for i:= 0 to Pred(cPlayListLength) do
+ playlistchain[i]:= i;
+
+for i:= 0 to Pred(cPlayListLength) do
+ begin
+ t:= (i + 1) mod cPlayListLength;
+ tmp:= playlistchain[t];
+ playlistchain[t]:= playlistchain[i];
+ playlistchain[i]:= tmp;
+ end
+{$ENDIF}
+end;
+
end.
--- a/hedgewars/uWorld.pas Fri Jul 20 13:46:27 2007 +0000
+++ b/hedgewars/uWorld.pas Fri Jul 20 19:04:24 2007 +0000
@@ -39,8 +39,7 @@
implementation
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound;
-const hwFloatTicks: Longword = 0;
- FPS: Longword = 0;
+const FPS: Longword = 0;
CountTicks: Longword = 0;
SoundTimerTicks: Longword = 0;
prevPoint: TPoint = (X: 0; Y: 0);
@@ -145,7 +144,7 @@
end;
bSelected:= false;
-if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (hwFloatTicks shr 6) mod 8, Surface)
+if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
end;
procedure MoveCamera; forward;
@@ -173,7 +172,6 @@
if not isPaused then MoveCamera;
// Sky
-inc(hwFloatTicks, Lag);
if WorldDy > 0 then
begin
if WorldDy > cScreenHeight then r.h:= cScreenHeight
@@ -189,8 +187,8 @@
// Waves
{$WARNINGS OFF}
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (hwFloatTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface);
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (hwFloatTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface);
+for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface);
+for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface);
{$WARNINGS ON}
DrawLand(WorldDx, WorldDy, Surface);
@@ -209,9 +207,9 @@
// Waves
{$WARNINGS OFF}
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (hwFloatTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface);
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (hwFloatTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface);
-for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (hwFloatTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface);
+for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface);
+for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface);
+for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface);
{$WARNINGS ON}
// Turn time
@@ -263,7 +261,7 @@
begin
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface);
inc(i, Surf^.h + 2);
- if EndTime <= hwFloatTicks then
+ if EndTime <= RealTicks then
begin
SDL_FreeSurface(Surf);
Surf:= nil;
@@ -293,7 +291,7 @@
end;
// Lag alert
-if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (hwFloatTicks shr 7) mod 12, Surface);
+if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface);
// Wind bar
DrawGear(sWindBar, cScreenWidth - 180, cScreenHeight - 30, Surface);
@@ -302,7 +300,7 @@
with StuffPoz[sWindR] do
begin
{$WARNINGS OFF}
- r.x:= x + 8 - (hwFloatTicks shr 6) mod 8;
+ r.x:= x + 8 - (RealTicks shr 6) mod 8;
{$WARNINGS ON}
r.y:= y;
r.w:= WindBarWidth;
@@ -315,7 +313,7 @@
with StuffPoz[sWindL] do
begin
{$WARNINGS OFF}
- r.x:= x + (WindBarWidth + hwFloatTicks shr 6) mod 8;
+ r.x:= x + (WindBarWidth + RealTicks shr 6) mod 8;
{$WARNINGS ON}
r.y:= y;
r.w:= - WindBarWidth;
@@ -341,7 +339,7 @@
CursorPoint.Y - SpritesData[PosSprite].Height div 2,
i, Surface);
end;
- DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (hwFloatTicks shr 6) mod 8, Surface)
+ DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
end;
{$IFDEF COUNTTICKS}
@@ -386,7 +384,7 @@
if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf);
Captions[Group].Surf:= RenderString(s, Color, fntBig);
-Captions[Group].EndTime:= hwFloatTicks + 1500
+Captions[Group].EndTime:= RealTicks + 1500
end;
procedure MoveCamera;