From 818590ded0d4ca5adb4cd1e22d9d76713228fe0c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 15 Nov 2026 14:34:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Cache=20tile=20list=20thumbnails=20?= =?UTF-8?q?in=20memory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tile browser decoded art from disk and rebuilt the image on every repaint of every visible cell; entries are now decoded once and reused. --- Client/UfrmMain.pas | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/Client/UfrmMain.pas b/Client/UfrmMain.pas index f67afa3..4872aae 100644 --- a/Client/UfrmMain.pas +++ b/Client/UfrmMain.pas @@ -37,7 +37,7 @@ uses LCLIntf, UOverlayUI, UStatics, UEnhancedMemoryStream, ActnList, XMLPropStorage, ImagingClasses, dateutils, UPlatformTypes, UMap, UPacket, UGLFont, DOM, XMLRead, XMLWrite, strutils, ULightManager, fgl, UTiledata, - UActions, UUoaDesigns; + UActions, UUoaDesigns, UArt; type TAccessChangedListener = procedure(AAccessLevel: TAccessLevel) of object; @@ -369,10 +369,14 @@ type FCurrentUoaDesign: TUoaDesign; FCurrentUoaDesignAnchor: TWorldItem; FCurrentUoaTiles: TStaticItemList; + FArtListCache: array[0..High(Word)] of TArt; + FArtListCached: array[0..High(Word)] of Boolean; + FArtListMissing: array[0..High(Word)] of Boolean; { Methods } procedure BuildTileList; function ConfirmAction: Boolean; procedure EnableActions(AEnabled: Boolean); + function GetCachedArt(AID: Word): TArt; function FindRandomPreset(AName: String): TDOMElement; procedure ForceUpdateCurrentTile; procedure GetDrawOffset(AX, AY: Integer; out DrawX, DrawY: Integer); inline; @@ -443,7 +447,7 @@ var implementation uses - UdmNetwork, UArt, UAdminHandling, UPackets, + UdmNetwork, UAdminHandling, UPackets, UfrmAccountControl, UGraphicHelper, ImagingComponents, UfrmDrawSettings, UfrmBoundaries, UfrmElevateSettings, UfrmConfirmation, UfrmMoveSettings, UfrmAbout, UPacketHandlers, UfrmHueSettings, UfrmRadar, UfrmLargeScaleCommand, @@ -1409,6 +1413,8 @@ begin end; procedure TfrmMain.FormDestroy(Sender: TObject); +var + i: Integer; begin CurrentTile := nil; SelectedTile := nil; @@ -1416,6 +1422,14 @@ begin SaveLocations; SaveRandomPresets; + for i := 0 to High(FArtListCache) do + if FArtListCached[i] and not FArtListMissing[i] then + FArtListCache[i].Free; + + for i := 0 to High(FArtListCache) do + if PtrUInt(FArtListCache[i]) > 1 then + FArtListCache[i].Free; + FreeAndNil(FTextureManager); FreeAndNil(FScreenBuffer); FreeAndNil(FOverlayUI); @@ -1728,6 +1742,23 @@ begin FTileHint.FlagsRect, DT_WORDBREAK); end; +function TfrmMain.GetCachedArt(AID: Word): TArt; +begin + if not FArtListCached[AID] then + begin + FArtListCached[AID] := True; + if ResMan.Art.Exists(AID) then + FArtListCache[AID] := ResMan.Art.GetArt(AID, + RGB2ARGB(vdtTiles.Canvas.Pixels[0, 0]), nil, False) + else + FArtListMissing[AID] := True; + end; + if FArtListMissing[AID] then + Result := nil + else + Result := FArtListCache[AID]; +end; + procedure TfrmMain.vdtTilesDrawNode(Sender: TBaseVirtualTree; const PaintInfo: TVTPaintInfo); var @@ -1753,14 +1784,9 @@ begin end; 1: begin - if ResMan.Art.Exists(tileInfo^.ID) then - begin - artEntry := ResMan.Art.GetArt(tileInfo^.ID, - RGB2ARGB(PaintInfo.Canvas.Pixels[PaintInfo.CellRect.Left, - PaintInfo.CellRect.Top]), nil, False); + artEntry := GetCachedArt(tileInfo^.ID); + if artEntry <> nil then DisplayImage(PaintInfo.Canvas, PaintInfo.CellRect, artEntry.Graphic); - artEntry.Free; - end; end; 2: begin