aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UCovers.pas
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Code/Classes/UCovers.pas')
-rw-r--r--Game/Code/Classes/UCovers.pas141
1 files changed, 78 insertions, 63 deletions
diff --git a/Game/Code/Classes/UCovers.pas b/Game/Code/Classes/UCovers.pas
index c74bbaf4..2cb63a8d 100644
--- a/Game/Code/Classes/UCovers.pas
+++ b/Game/Code/Classes/UCovers.pas
@@ -14,6 +14,9 @@ type
end;
TCovers = class
+ private
+ SearchPos: integer;
+ public
Cover: array of TCover;
W: word;
H: word;
@@ -24,10 +27,10 @@ type
constructor Create;
procedure Load;
procedure Save;
- procedure AddCover(Name: string);
- function CoverExists(Name: string): boolean;
- function CoverNumber(Name: string): integer;
- procedure PrepareData(Name: string);
+ procedure AddCover(const Name: string);
+ function CoverExists(const Name: string): boolean;
+ function CoverNumber(const Name: string): integer;
+ procedure PrepareData(const Name: string);
end;
var
@@ -43,6 +46,7 @@ begin
Size := W*H*3;
Load;
WritetoFile := True;
+ SearchPos := 0;
end;
procedure TCovers.Load;
@@ -53,47 +57,39 @@ var
Bits: byte;
NLen: word;
Name: string;
-// Data: array of byte;
-begin
- if FileExists(GamePath + 'covers.cache') then begin
- AssignFile(F, GamePath + 'covers.cache');
- Reset(F, 1);
-
- WritetoFile := not FileIsReadOnly(GamePath + 'covers.cache');
-
- SetLength(Cover, 0);
- while not EOF(F) do begin
- SetLength(Cover, Length(Cover)+1);
+begin
+ if FileExists(GamePath + 'covers.cache') then
+ begin
+ AssignFile(F, GamePath + 'covers.cache');
+ Reset(F, 1);
- BlockRead(F, W, 2);
- Cover[High(Cover)].W := W;
+ WritetoFile := not FileIsReadOnly(GamePath + 'covers.cache');
- BlockRead(F, H, 2);
- Cover[High(Cover)].H := H;
+ SetLength(Cover, 0);
- BlockRead(F, Bits, 1);
+ while not EOF(F) do
+ begin
+ SetLength(Cover, Length(Cover)+1);
- Cover[High(Cover)].Size := W * H * (Bits div 8);
+ BlockRead(F, W, 2);
+ Cover[High(Cover)].W := W;
- // test
-// W := 128;
-// H := 128;
-// Bits := 24;
-// Seek(F, FilePos(F) + 3);
+ BlockRead(F, H, 2);
+ Cover[High(Cover)].H := H;
- BlockRead(F, NLen, 2);
- SetLength(Name, NLen);
+ BlockRead(F, Bits, 1);
- BlockRead(F, Name[1], NLen);
- Cover[High(Cover)].Name := Name;
+ Cover[High(Cover)].Size := W * H * (Bits div 8);
- Cover[High(Cover)].Position := FilePos(F);
- Seek(F, FilePos(F) + W*H*(Bits div 8));
+ BlockRead(F, NLen, 2);
+ SetLength(Name, NLen);
-// SetLength(Cover[High(Cover)].Data, W*H*(Bits div 8));
-// BlockRead(F, Cover[High(Cover)].Data[0], W*H*(Bits div 8));
+ BlockRead(F, Name[1], NLen);
+ Cover[High(Cover)].Name := Name;
+ Cover[High(Cover)].Position := FilePos(F);
+ Seek(F, FilePos(F) + W*H*(Bits div 8));
end;
CloseFile(F);
@@ -131,7 +127,7 @@ begin
CloseFile(F);}
end;
-procedure TCovers.AddCover(Name: string);
+procedure TCovers.AddCover(const Name: string);
var
//B: integer;
F: File;
@@ -139,7 +135,8 @@ var
NLen: word;
Bits: byte;
begin
- if not CoverExists(Name) then begin
+ if not CoverExists(Name) then
+ begin
SetLength(Cover, Length(Cover)+1);
Cover[High(Cover)].Name := Name;
@@ -147,70 +144,88 @@ begin
Cover[High(Cover)].H := H;
Cover[High(Cover)].Size := Size;
- // do not copy data. write them directly to file
-// SetLength(Cover[High(Cover)].Data, Size);
-// for B := 0 to Size-1 do
-// Cover[High(Cover)].Data[B] := CacheMipmap[B];
-
if WritetoFile then
begin
AssignFile(F, GamePath + 'covers.cache');
- if FileExists(GamePath + 'covers.cache') then begin
+
+ if FileExists(GamePath + 'covers.cache') then
+ begin
Reset(F, 1);
Seek(F, FileSize(F));
end else
Rewrite(F, 1);
- Bits := 24;
+ Bits := 24;
- BlockWrite(F, W, 2);
- BlockWrite(F, H, 2);
- BlockWrite(F, Bits, 1);
+ BlockWrite(F, W, 2);
+ BlockWrite(F, H, 2);
+ BlockWrite(F, Bits, 1);
- NLen := Length(Name);
- BlockWrite(F, NLen, 2);
- BlockWrite(F, Name[1], NLen);
+ NLen := Length(Name);
+ BlockWrite(F, NLen, 2);
+ BlockWrite(F, Name[1], NLen);
- Cover[High(Cover)].Position := FilePos(F);
- BlockWrite(F, CacheMipmap[0], W*H*(Bits div 8));
+ Cover[High(Cover)].Position := FilePos(F);
+ BlockWrite(F, CacheMipmap[0], W*H*(Bits div 8));
- CloseFile(F);
- end;
- end
- else
+ CloseFile(F);
+ end;
+ end else
Cover[High(Cover)].Position := 0;
end;
-function TCovers.CoverExists(Name: string): boolean;
+function TCovers.CoverExists(const Name: string): boolean;
var
C: integer; // cover
begin
Result := false;
+ C := SearchPos;
+ while (C <= High(Cover)) and not Result do
+ begin
+ if Cover[C].Name = Name then
+ begin
+ Result := true;
+ SearchPos := C;
+ end;
+ Inc(C);
+ end;
+
+ if Result then
+ Exit;
+
C := 0;
- while (C <= High(Cover)) and (Result = false) do begin
- if Cover[C].Name = Name then Result := true;
+ while (C <= High(Cover)) and not Result do
+ begin
+ if Cover[C].Name = Name then
+ begin
+ Result := true;
+ SearchPos := C;
+ end;
Inc(C);
end;
end;
-function TCovers.CoverNumber(Name: string): integer;
+function TCovers.CoverNumber(const Name: string): integer;
var
C: integer;
begin
Result := -1;
C := 0;
- while (C <= High(Cover)) and (Result = -1) do begin
- if Cover[C].Name = Name then Result := C;
+ while (C <= High(Cover)) and (Result = -1) do
+ begin
+ if Cover[C].Name = Name then
+ Result := C;
Inc(C);
end;
end;
-procedure TCovers.PrepareData(Name: string);
+procedure TCovers.PrepareData(const Name: string);
var
F: File;
C: integer;
begin
- if FileExists(GamePath + 'covers.cache') then begin
+ if FileExists(GamePath + 'covers.cache') then
+ begin
AssignFile(F, GamePath + 'covers.cache');
Reset(F, 1);