Skip to content

Commit 235fb19

Browse files
reaperrrabcdefg30
authored andcommitted
Cache overlay traits in ProductionPaletteWidget
Instead of looking this up every Draw tick, cache and update it only when a non-null new CurrentQueue is set (as the overlays can only change at that time).
1 parent c0f54fa commit 235fb19

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,18 @@ public enum ReadyTextStyleOptions { Solid, AlternatingColor, Blinking }
101101

102102
public ProductionQueue CurrentQueue
103103
{
104-
get { return currentQueue; }
105-
set { currentQueue = value; RefreshIcons(); }
104+
get
105+
{
106+
return currentQueue;
107+
}
108+
set
109+
{
110+
currentQueue = value;
111+
if (currentQueue != null)
112+
UpdateCachedProductionIconOverlays();
113+
114+
RefreshIcons();
115+
}
106116
}
107117

108118
public override Rectangle EventBounds { get { return eventBounds; } }
@@ -115,6 +125,9 @@ public ProductionQueue CurrentQueue
115125
SpriteFont overlayFont, symbolFont;
116126
float2 iconOffset, holdOffset, readyOffset, timeOffset, queuedOffset, infiniteOffset;
117127

128+
Player cachedQueueOwner;
129+
IProductionIconOverlay[] pios;
130+
118131
[CustomLintableHotkeyNames]
119132
public static IEnumerable<string> LinterHotkeyNames(MiniYamlNode widgetNode, Action<string> emitError, Action<string> emitWarning)
120133
{
@@ -225,7 +238,12 @@ public override void Tick()
225238
CurrentQueue = null;
226239

227240
if (CurrentQueue != null)
241+
{
242+
if (CurrentQueue.Actor.Owner != cachedQueueOwner)
243+
UpdateCachedProductionIconOverlays();
244+
228245
RefreshIcons();
246+
}
229247
}
230248

231249
public override void MouseEntered()
@@ -413,6 +431,12 @@ bool SelectProductionBuilding()
413431
return true;
414432
}
415433

434+
void UpdateCachedProductionIconOverlays()
435+
{
436+
cachedQueueOwner = CurrentQueue.Actor.Owner;
437+
pios = cachedQueueOwner.PlayerActor.TraitsImplementing<IProductionIconOverlay>().ToArray();
438+
}
439+
416440
public void RefreshIcons()
417441
{
418442
icons = new Dictionary<Rectangle, ProductionIcon>();
@@ -480,8 +504,6 @@ public override void Draw()
480504

481505
var buildableItems = CurrentQueue.BuildableItems();
482506

483-
var pios = currentQueue.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>();
484-
485507
// Icons
486508
Game.Renderer.EnableAntialiasingFilter();
487509
foreach (var icon in icons.Values)

0 commit comments

Comments
 (0)