aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-04-20 15:29:48 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-04-20 15:29:48 +0000
commit34988301a511ca8552a954c231fafde007cb94a1 (patch)
treec3c4f520a33301ca081999e4d80016704e1226fc /Game/Code
parent6a7518ffc93647ec4da4ed151186b858a271626b (diff)
downloadusdx-34988301a511ca8552a954c231fafde007cb94a1.tar.gz
usdx-34988301a511ca8552a954c231fafde007cb94a1.tar.xz
usdx-34988301a511ca8552a954c231fafde007cb94a1.zip
Some Memory tweaking (13 MB Less Ram using at 800 Songs)
Some Loading Time tweaking (From 8 Secs to 6 Secs on my Computer) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@123 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/USongs.pas26
-rw-r--r--Game/Code/Menu/UMenu.pas35
-rw-r--r--Game/Code/Screens/UScreenOptionsRecord.pas2
-rw-r--r--Game/Code/Screens/UScreenSong.pas3
4 files changed, 61 insertions, 5 deletions
diff --git a/Game/Code/Classes/USongs.pas b/Game/Code/Classes/USongs.pas
index cc3c8b95..4240d135 100644
--- a/Game/Code/Classes/USongs.pas
+++ b/Game/Code/Classes/USongs.pas
@@ -58,6 +58,9 @@ type
end;
TSongs = class
+ private
+ BrowsePos: Cardinal; //Actual Pos in Song Array
+ public
Song: array of TSong; // array of songs
Selected: integer; // selected song index
procedure LoadSongList; // load all songs
@@ -100,10 +103,14 @@ begin
Log.LogStatus('Initializing', 'LoadSongList');
// clear
- Setlength(Song, 0);
+ Setlength(Song, 50);
+ BrowsePos := 0;
// browse directories
BrowseDir(SongPath);
+
+ //Set Correct SongArray Length
+ SetLength(Song, BrowsePos + 1);
// if Ini.Debug = 1 then BrowseDir('D:\Extract\Songs\');
end;
@@ -125,14 +132,19 @@ begin
if FindFirst(Dir + '*.txt', 0, SR) = 0 then begin
// Log.LogStatus('Parsing file: ' + Dir + SR.Name + '\' + SRD.Name, 'LoadSongList');
repeat
+ //New Mod for better Memory Management
+
+ SLen := BrowsePos;
+ {//Old
SLen := Length(Song);
- SetLength(Song, SLen + 1);
+ SetLength(Song, SLen + 1);//}
+
Song[SLen].Path := Dir;
Song[SLen].Folder := Copy(Dir, Length(SongPath)+1, 10000);
Song[SLen].Folder := Copy(Song[SLen].Folder, 1, Pos('\', Song[SLen].Folder)-1);
Song[SLen].FileName := SR.Name;
- if (AnalyseFile(Song[SLen]) = false) then SetLength(Song, SLen)
+ if (AnalyseFile(Song[SLen]) = false) then Dec(BrowsePos)
else begin
// scanning complete, file is good
// if there is no cover then try to find it
@@ -146,6 +158,14 @@ begin
// Song[SLen].Cover := Song[SLen].Path + Song[SLen].Cover;
end;
+ //Change Length Only every 50 Entrys
+ Inc(BrowsePos);
+
+ if (BrowsePos mod 50 = 0) AND (BrowsePos <> 0) then
+ begin
+ SetLength(Song, Length(Song) + 50);
+ end;
+
until FindNext(SR) <> 0;
end; // if FindFirst
FindClose(SR);
diff --git a/Game/Code/Menu/UMenu.pas b/Game/Code/Menu/UMenu.pas
index 7908d980..1c4418c1 100644
--- a/Game/Code/Menu/UMenu.pas
+++ b/Game/Code/Menu/UMenu.pas
@@ -11,6 +11,8 @@ type
PMenu = ^TMenu;
TMenu = class
protected
+ ButtonPos: Integer;
+
Interactions: array of TInteract;
SelInteraction: integer;
Button: array of TButton;
@@ -59,6 +61,7 @@ type
function AddText(X, Y, W: real; Style: integer; Size, ColR, ColG, ColB: real; Align: integer; Tekst: string): integer; overload;
// button
+ Procedure SetButtonLength(Length: Cardinal); //Function that Set Length of Button Array in one Step instead of register new Memory for every Button
function AddButton(ThemeButton: TThemeButton): integer; overload;
function AddButton(X, Y, W, H: real; Name: String): integer; overload;
function AddButton(X, Y, W, H: real; Name, Format, Typ: String; Reflection: Boolean): integer; overload;
@@ -150,6 +153,9 @@ begin
SetLength(Button, 0);
BackImg.TexNum := -1;
+
+ //Set ButtonPos to Autoset Length
+ ButtonPos := -1;
end;
constructor TMenu.Create(Back: String);
@@ -165,6 +171,9 @@ begin
BackH := 1;
end else
BackImg.TexNum := -1;
+
+ //Set ButtonPos to Autoset Length
+ ButtonPos := -1;
end;
constructor TMenu.Create(Back: string; W, H: integer);
@@ -356,6 +365,19 @@ begin
Result := TextNum;
end;
+//Function that Set Length of Button Array in one Step instead of register new Memory for every Button
+Procedure TMenu.SetButtonLength(Length: Cardinal);
+begin
+ if (ButtonPos = -1) AND (Length > 0) then
+ begin
+ //Set Length of Button
+ SetLength(Button, Length);
+
+ //Set ButtonPos to start with 0
+ ButtonPos := 0;
+ end;
+end;
+
// Method to add a button in our TMenu. It returns the assigned ButtonNumber
function TMenu.AddButton(ThemeButton: TThemeButton): integer;
@@ -399,8 +421,17 @@ end;
function TMenu.AddButton(X, Y, W, H, ColR, ColG, ColB, Int, DColR, DColG, DColB, DInt: real; Name, Format, Typ: String; Reflection: Boolean; ReflectionSpacing: Real): integer;
begin
// adds button
- Result := Length(Button);
- SetLength(Button, Result + 1);
+ //SetLength is used to reduce Memory usement
+ if (ButtonPos <> -1) then
+ begin
+ Result := ButtonPos;
+ Inc(ButtonPos)
+ end
+ else //Old Method -> Reserve new Memory for every Button
+ begin
+ Result := Length(Button);
+ SetLength(Button, Result + 1);
+ end;
// Button[Result] := TButton.Create(Texture.GetTexture(Name, Typ));
// check here for cache
diff --git a/Game/Code/Screens/UScreenOptionsRecord.pas b/Game/Code/Screens/UScreenOptionsRecord.pas
index e6989d43..1d09d0b8 100644
--- a/Game/Code/Screens/UScreenOptionsRecord.pas
+++ b/Game/Code/Screens/UScreenOptionsRecord.pas
@@ -72,6 +72,8 @@ var
SC: integer;
SCI: integer;
begin
+ inherited Create;
+
AddBackground(Theme.OptionsRecord.Background.Tex);
for I := 0 to High(Theme.OptionsRecord.Static) do
AddStatic(Theme.OptionsRecord.Static[I]);
diff --git a/Game/Code/Screens/UScreenSong.pas b/Game/Code/Screens/UScreenSong.pas
index 7c8447ee..79a5abb1 100644
--- a/Game/Code/Screens/UScreenSong.pas
+++ b/Game/Code/Screens/UScreenSong.pas
@@ -634,6 +634,9 @@ begin
// Song List
// Songs.LoadSongList; // moved to the UltraStar unit
CatSongs.Refresh;
+
+ //Set Length of Button Array one Time Instead of one time for every Song
+ SetButtonLength(Length(CatSongs.Song));
for Pet := 0 to High(CatSongs.Song) do begin // creating all buttons
// new
Texture.Limit := 512;// 256 0.4.2 value, 512 in 0.5.0