aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-11-02 12:16:50 +0000
committerjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-11-02 12:16:50 +0000
commitae057627ff135d55891e9f04f399608fbc47e9ee (patch)
tree7561eaee2663ea1308dcada578549e013f9110c4 /Game/Code
parent35b7a40253bd38d1e1df8469d4151e99f9978850 (diff)
downloadusdx-ae057627ff135d55891e9f04f399608fbc47e9ee.tar.gz
usdx-ae057627ff135d55891e9f04f399608fbc47e9ee.tar.xz
usdx-ae057627ff135d55891e9f04f399608fbc47e9ee.zip
Runtime Song Addition
jira:USDX-157 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@553 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UAudio_FFMpeg.pas1
-rw-r--r--Game/Code/Classes/UCatCovers.pas2
-rw-r--r--Game/Code/Classes/UMain.pas1
-rw-r--r--Game/Code/Classes/USongs.pas66
-rw-r--r--Game/Code/Screens/UScreenSong.pas95
-rw-r--r--Game/Code/UltraStar.dpr2
6 files changed, 145 insertions, 22 deletions
diff --git a/Game/Code/Classes/UAudio_FFMpeg.pas b/Game/Code/Classes/UAudio_FFMpeg.pas
index afbb23c1..b89fa00f 100644
--- a/Game/Code/Classes/UAudio_FFMpeg.pas
+++ b/Game/Code/Classes/UAudio_FFMpeg.pas
@@ -380,7 +380,6 @@ end;
procedure TAudio_ffMpeg.PlayStart;
begin
-
// LoadSoundFromFile(BassStart, SoundPath + 'foo fighters - best of you.mp3');
// TODO : jb_linux replace with something other than bass
diff --git a/Game/Code/Classes/UCatCovers.pas b/Game/Code/Classes/UCatCovers.pas
index b1c91e48..516544be 100644
--- a/Game/Code/Classes/UCatCovers.pas
+++ b/Game/Code/Classes/UCatCovers.pas
@@ -49,7 +49,7 @@ var
Name, Filename, Temp: string;
begin
try
- Ini := TMemIniFile.Create(CoversPath + 'covers.ini');
+ Ini := TMemIniFile.Create(CoversPath + 'covers.ini');
List := TStringlist.Create;
//Add every Cover in Covers Ini for Every Sorting option
diff --git a/Game/Code/Classes/UMain.pas b/Game/Code/Classes/UMain.pas
index d7ae51f4..fa4c45b5 100644
--- a/Game/Code/Classes/UMain.pas
+++ b/Game/Code/Classes/UMain.pas
@@ -303,6 +303,7 @@ begin
Log.LogStatus('Creating 2nd Song Array', 'Initialization');
CatSongs := TCatSongs.Create;
+
Log.BenchmarkEnd(1);
Log.LogBenchmark('Loading Songs', 1);
diff --git a/Game/Code/Classes/USongs.pas b/Game/Code/Classes/USongs.pas
index 6a58a8dd..2eeeec87 100644
--- a/Game/Code/Classes/USongs.pas
+++ b/Game/Code/Classes/USongs.pas
@@ -8,17 +8,21 @@ interface
{$I switches.inc}
-uses SysUtils,
+uses
{$ifndef MSWINDOWS}
- {$IFDEF DARWIN}
- baseunix,
- {$ELSE}
- oldlinux,
- {$ENDIF}
+ {$IFDEF DARWIN}
+ baseunix,
+ {$ELSE}
+ oldlinux,
+ {$ENDIF}
baseunix,
UnixType,
syscall,
+ {$else}
+ windows,
+ DirWatch,
{$endif}
+ SysUtils,
Classes,
ULog,
UTexture,
@@ -87,7 +91,11 @@ type
fWatch : longint;
fParseSongDirectory : boolean;
fProcessing : boolean;
+ {$ifdef win32}
+ fDirWatch : TDirectoryWatch;
+ {$endif}
procedure int_LoadSongList;
+ procedure DoDirChanged(Sender: TObject);
protected
procedure Execute; override;
public
@@ -143,6 +151,8 @@ const
implementation
uses StrUtils,
+ UGraphic,
+ UCovers,
UFiles,
UMain,
UIni;
@@ -159,6 +169,14 @@ begin
inherited create( false );
self.freeonterminate := true;
+ {$IFDEF Win32}
+ fDirWatch := TDirectoryWatch.create(nil);
+ fDirWatch.OnChange := DoDirChanged;
+ fDirWatch.Directory := SongPath;
+ fDirWatch.WatchSubDirs := true;
+ fDirWatch.active := true;
+ {$ENDIF}
+
{$IFDEF linux}
(*
Thankyou to : http://www.linuxjournal.com/article/8478
@@ -186,23 +204,21 @@ begin
Setlength(Song, 0);
end;
+procedure TSongs.DoDirChanged(Sender: TObject);
+begin
+ LoadSongList();
+end;
+
procedure TSongs.Execute();
-(*
var
- lrfds : fdSet;
- time : Ttimeval;
- res : integer;
- buf : pchar;
- len, bufflen : longint;
- str : String;
-*)
+ fChangeNotify : THandle;
begin
fParseSongDirectory := true;
while not self.terminated do
begin
-// if fParseSongDirectory then
+ if fParseSongDirectory then
begin
writeln( 'int_LoadSongList' );
int_LoadSongList();
@@ -217,7 +233,8 @@ procedure TSongs.int_LoadSongList;
begin
try
fProcessing := true;
-
+ Setlength(Song, 0);
+
Log.LogError('SongList', 'Searching For Songs');
Setlength(Song, 50);
@@ -228,6 +245,23 @@ begin
//Set Correct SongArray Length
SetLength(Song, BrowsePos);
+
+ if assigned( CatSongs ) then
+ CatSongs.Refresh;
+
+ if assigned( CatCovers ) then
+ CatCovers.Load;
+
+ if assigned( Covers ) then
+ Covers.Load;
+
+ if assigned(ScreenSong) then
+ begin
+ ScreenSong.GenerateThumbnails();
+ ScreenSong.OnShow; // refresh ScreenSong
+ end;
+
+
finally
Log.LogError('SongList', 'Search Complete');
diff --git a/Game/Code/Screens/UScreenSong.pas b/Game/Code/Screens/UScreenSong.pas
index 85c38c26..bd9e5e67 100644
--- a/Game/Code/Screens/UScreenSong.pas
+++ b/Game/Code/Screens/UScreenSong.pas
@@ -92,6 +92,7 @@ type
procedure SetScroll6;
function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
function Draw: boolean; override;
+ procedure GenerateThumbnails();
procedure onShow; override;
procedure onHide; override;
procedure SelectNext;
@@ -696,9 +697,9 @@ end;
constructor TScreenSong.Create;
var
- Pet: integer;
+// Pet: integer;
I: integer;
-Label CreateSongButtons;
+//Label CreateSongButtons;
begin
inherited Create;
@@ -755,6 +756,8 @@ begin
// Songs.LoadSongList; // moved to the UltraStar unit
CatSongs.Refresh;
+ GenerateThumbnails();
+(*
if (length(CatSongs.Song) > 0) then
begin
//Set Length of Button Array one Time Instead of one time for every Song
@@ -830,6 +833,7 @@ begin
GoTo CreateSongButtons;
end;
+*)
// Randomize Patch
Randomize;
@@ -843,6 +847,89 @@ begin
Interaction := 0;
end;
+procedure TScreenSong.GenerateThumbnails();
+var
+ I : Integer;
+ Pet: integer;
+Label CreateSongButtons;
+begin
+ if (length(CatSongs.Song) > 0) then
+ begin
+ //Set Length of Button Array one Time Instead of one time for every Song
+ SetButtonLength(Length(CatSongs.Song));
+
+ I := 0;
+ CreateSongButtons:
+
+ try
+ for Pet := I to High(CatSongs.Song) do begin // creating all buttons
+ // new
+ Texture.Limit := 512;// 256 0.4.2 value, 512 in 0.5.0
+
+ if not FileExists(CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover) then
+ CatSongs.Song[Pet].Cover := ''; // 0.5.0: if cover not found then show 'no cover'
+
+ if CatSongs.Song[Pet].Cover = '' then
+ AddButton(300 + Pet*250, 140, 200, 200, Skin.GetTextureFileName('SongCover'), 'JPG', 'Plain', Theme.Song.Cover.Reflections)
+ else begin
+ // cache texture if there is a need to this
+ if not Covers.CoverExists(CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover) then
+ begin
+ Texture.CreateCacheMipmap := true;
+ Texture.GetTexture(CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover, 'Plain', true); // preloads textures and creates cache mipmap
+ Texture.CreateCacheMipmap := false;
+
+ // puts this texture to the cache file
+ Covers.AddCover(CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover);
+
+ // unload full size texture
+ Texture.UnloadTexture(CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover, false);
+
+ // we should also add mipmap texture by calling createtexture and use mipmap cache as data source
+ end;
+
+ // and now load it from cache file (small place for the optimization by eliminating reading it from file, but not here)
+ AddButton(300 + Pet*250, 140, 200, 200, CatSongs.Song[Pet].Path + CatSongs.Song[Pet].Cover, 'JPG', 'Plain', Theme.Song.Cover.Reflections);
+ end;
+ Texture.Limit := 1024*1024;
+ I := -1;
+ end;
+ except
+ //When Error is reported the First time for this Song
+ if (I <> Pet) then
+ begin
+ //Some Error reporting:
+ Log.LogError('Could not load Cover: ' + CatSongs.Song[Pet].Cover);
+
+ //Change Cover to NoCover and Continue Loading
+ CatSongs.Song[Pet].Cover := '';
+ I := Pet;
+ end
+ else //when Error occurs Multiple Times(NoSong Cover is damaged), then start loading next Song
+ begin
+ Log.LogError('NoCover Cover is damaged!');
+ try
+ AddButton(300 + Pet*250, 140, 200, 200, '', 'JPG', 'Plain', Theme.Song.Cover.Reflections);
+ except
+ {$IFDEF MSWINDOWS}
+ Messagebox(0, PChar('No Cover Image is damage. Could not Workaround Song Loading, Ultrastar will exit now.'), PChar(Language.Translate('US_VERSION')), MB_ICONERROR or MB_OK);
+ {$ELSE}
+ // TODO : JB_linux - better handle this message and display to user..
+ writeln( 'No Cover Image is damage. Could not Workaround Song Loading, Ultrastar will exit now.');
+ Log.LogError( 'No Cover Image is damage. Could not Workaround Song Loading, Ultrastar will exit now.' );
+ {$ENDIF}
+ Halt;
+ end;
+ I := Pet + 1;
+ end;
+ end;
+
+ if (I <> -1) then
+ GoTo CreateSongButtons;
+
+ end;
+end;
+
procedure TScreenSong.SetScroll;
var
VS, B: Integer;
@@ -1418,7 +1505,7 @@ begin
AudioPlayback.Stop;
if Ini.Players <= 3 then PlayersPlay := Ini.Players + 1;
- if Ini.Players = 4 then PlayersPlay := 6;
+ if Ini.Players = 4 then PlayersPlay := 6;
//Cat Mod etc
if (Ini.Tabs_at_startup = 1) AND (CatSongs.CatNumShow = -1) then
@@ -1701,7 +1788,7 @@ begin
UnLoadDetailedCover;
Interaction := High(CatSongs.Song);
- SongTarget := 0;
+ SongTarget := 0;
for I := 1 to Target+1 do
SelectNext;
diff --git a/Game/Code/UltraStar.dpr b/Game/Code/UltraStar.dpr
index 80312bd1..2e04df9f 100644
--- a/Game/Code/UltraStar.dpr
+++ b/Game/Code/UltraStar.dpr
@@ -36,6 +36,8 @@ uses
opt in 'lib\ffmpeg\opt.pas',
avio in 'lib\ffmpeg\avio.pas',
+ DirWatch in 'lib\other\DirWatch.pas',
+
SQLiteTable3 in 'lib\SQLite\SQLiteTable3.pas',
SQLite3 in 'lib\SQLite\SQLite3.pas',