# HG changeset patch # User unc0rr # Date 1184958264 0 # Node ID 17fb45c670c150b3177f68539e23740fd7d80a1b # Parent 5131c641073f11e742389331cfb788c16795aec7 Finalize basic playlists implementation diff -r 5131c641073f -r 17fb45c670c1 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Fri Jul 20 13:46:27 2007 +0000 +++ b/hedgewars/CMakeLists.txt Fri Jul 20 19:04:24 2007 +0000 @@ -37,6 +37,7 @@ HHHandlers.inc SinTable.inc options.inc + playlist.inc proto.inc tunsetborder.inc ) diff -r 5131c641073f -r 17fb45c670c1 hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Fri Jul 20 13:46:27 2007 +0000 +++ b/hedgewars/hwengine.dpr Fri Jul 20 19:04:24 2007 +0000 @@ -63,8 +63,18 @@ //////////////////////////////// procedure DoTimer(Lag: LongInt); +const MusicTimerTicks: Longword = 0; var s: string; begin +inc(RealTicks, Lag); + +inc(MusicTimerTicks, Lag); +if MusicTimerTicks > 3000 then + begin + PlayMusic; + MusicTimerTicks:= 0 + end; + case GameState of gsLandGen: begin GenMap; @@ -80,7 +90,7 @@ AdjustColor(cConsoleSplitterColor); ResetKbd; SoundLoad; - PlayMusic; + InitPlaylistChunk(GetRandom(High(LongWord))); if GameType = gmtSave then begin isSEBackup:= isSoundEnabled; @@ -103,6 +113,7 @@ OnDestroy; end; end; + SDL_Flip(SDLPrimSurface); if flagMakeCapture then begin diff -r 5131c641073f -r 17fb45c670c1 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Fri Jul 20 13:46:27 2007 +0000 +++ b/hedgewars/uMisc.pas Fri Jul 20 19:04:24 2007 +0000 @@ -86,6 +86,8 @@ InitStepsFlags: Longword = 0; + RealTicks: Longword = 0; + AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP function hwSign(r: hwFloat): LongInt; diff -r 5131c641073f -r 17fb45c670c1 hedgewars/uSound.pas --- 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. diff -r 5131c641073f -r 17fb45c670c1 hedgewars/uWorld.pas --- 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; diff -r 5131c641073f -r 17fb45c670c1 share/hedgewars/Data/Music/CMakeLists.txt --- a/share/hedgewars/Data/Music/CMakeLists.txt Fri Jul 20 13:46:27 2007 +0000 +++ b/share/hedgewars/Data/Music/CMakeLists.txt Fri Jul 20 19:04:24 2007 +0000 @@ -5,25 +5,28 @@ set(PlayListINCFile ${hedgewars_SOURCE_DIR}/hedgewars/playlist.inc) file(WRITE ${PlayListINCFile} "const cPlayListLength = " ${PlayListLength} ";") -file(APPEND ${PlayListINCFile} "playlist = array[0..Pred(cPlayListLength)] of string = (") -set(i ${PlayListLength}) -foreach(musicfile ${BaseMusic}) - math(EXPR i "${i} - 1") - - get_filename_component(relfilename ${musicfile} NAME) - - file(APPEND ${PlayListINCFile} '${relfilename}') +if(PlayListLength GREATER 0) + file(APPEND ${PlayListINCFile} "{$DEFINE HAVE_MUSIC}") + file(APPEND ${PlayListINCFile} "playlist: array[0..Pred(cPlayListLength)] of string = (") - if(i GREATER 0) - file(APPEND ${PlayListINCFile} ",") - endif(i GREATER 0) -endforeach(musicfile) - -file(APPEND ${PlayListINCFile} ");") - -file(APPEND ${PlayListINCFile} "var playlistchain = array[0..Pred(cPlayListLength)] of LongWord;") - + set(i ${PlayListLength}) + foreach(musicfile ${BaseMusic}) + math(EXPR i "${i} - 1") + + get_filename_component(relfilename ${musicfile} NAME) + + file(APPEND ${PlayListINCFile} '${relfilename}') + + if(i GREATER 0) + file(APPEND ${PlayListINCFile} ",") + endif(i GREATER 0) + endforeach(musicfile) + + file(APPEND ${PlayListINCFile} ");") + + file(APPEND ${PlayListINCFile} "var playlistchain: array[0..Pred(cPlayListLength)] of LongWord;") +endif(PlayListLength GREATER 0) install(FILES ${BaseMusic}