Try this replacement OmegaImageList.pas
OmegaImageList.zip
It behaves exactly the same as the standard OmegaImageList, except it has some additional functionality.
OmegaImageList.ImageList.LoadFromFileData(Filename : String);
OmegaImageList.ImageList.LoadFromStreamData(Stream : TStream);
OmegaImageList.ImageList.SaveToFileData(Filename: String);
OmegaImageList.ImageList.SaveToStreamData(Stream: TStream);
To test it out, load your imagelist as normal, then after the call to OmegaImageList.Init, call OmegaImageList.ImageList.SaveToFileData() with a different filename. Run your application and it should write out a file.
Comment out the calls to LoadFromFile, Init and SaveToFileData. Add in their place a call to OmegaImageList.ImageList.LoadFromFileData(). No call to Init() is required! Run the game and see if there is any speed difference.
Here is my test code.
Code:
{.$DEFINE CREATEFILE}
{$DEFINE LOADFILE}
procedure TForm3.FormCreate(Sender: TObject);
{$IFDEF CREATEFILE}
var
Item: TImageListItem;
Index: Integer;
{$ENDIF CREATEFILE}
begin
OmegaScreen1.Init;
{$IFDEF CREATEFILE}
for Index := 1 to 7 do
begin
Item := OmegaImageList1.ImageList.Add;
Item.Filepath := 'D:\Files\Bitmaps\Tatiana\Tatiana' + IntToStr(Index) + '.jpg';
Item.TileWidth := -1;
Item.TileHeight := -1;
end;
OmegaImageList1.Init;
OmegaImageList1.ImageList.SaveToFileData('D:\Temp\tatiana.oil');
{$ENDIF CREATEFILE}
{$IFDEF LOADFILE}
OmegaImageList1.ImageList.LoadFromFileData('D:\Temp\tatiana.oil');
{$ENDIF LOADFILE}
end;
procedure TForm3.FormPaint(Sender: TObject);
var
Index: Integer;
begin
OmegaScreen1.BeginRender;
OmegaScreen1.ClearScreen(0, 0, 0);
for Index := 0 to OmegaImageList1.ImageList.Count - 1 do
OmegaImageList1.ImageList.Items[Index].Draw(Index * 32, Index * 32, Index);
OmegaScreen1.EndRender;
end;
The file is essentially a binary dump of the required properties of each image item, plus a PNG file written out by D3DXSaveTextureToFileInMemory(), all packed into one file. The file is loaded one image at a time, so memory usage has been cut dramatically.
Hope that helps. I scared myself because that code worked first time. Let me know how it goes.
It's time for me to go to bed seeing as it is now 1:50am and I have to get up at 7am.
Edit: I also added "uses Jpeg;" so that it could load JPGs.
Bookmarks