⚡ Cache tile list thumbnails in memory

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.
This commit is contained in:
2026-11-15 22:08:32 +01:00
parent 75220f3dc4
commit 818590ded0
+35 -9
View File
@@ -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