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).
This commit is contained in:
@@ -101,8 +101,18 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
public ProductionQueue CurrentQueue
|
public ProductionQueue CurrentQueue
|
||||||
{
|
{
|
||||||
get { return currentQueue; }
|
get
|
||||||
set { currentQueue = value; RefreshIcons(); }
|
{
|
||||||
|
return currentQueue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
currentQueue = value;
|
||||||
|
if (currentQueue != null)
|
||||||
|
UpdateCachedProductionIconOverlays();
|
||||||
|
|
||||||
|
RefreshIcons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Rectangle EventBounds { get { return eventBounds; } }
|
public override Rectangle EventBounds { get { return eventBounds; } }
|
||||||
@@ -115,6 +125,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
SpriteFont overlayFont, symbolFont;
|
SpriteFont overlayFont, symbolFont;
|
||||||
float2 iconOffset, holdOffset, readyOffset, timeOffset, queuedOffset, infiniteOffset;
|
float2 iconOffset, holdOffset, readyOffset, timeOffset, queuedOffset, infiniteOffset;
|
||||||
|
|
||||||
|
Player cachedQueueOwner;
|
||||||
|
IProductionIconOverlay[] pios;
|
||||||
|
|
||||||
[CustomLintableHotkeyNames]
|
[CustomLintableHotkeyNames]
|
||||||
public static IEnumerable<string> LinterHotkeyNames(MiniYamlNode widgetNode, Action<string> emitError, Action<string> emitWarning)
|
public static IEnumerable<string> LinterHotkeyNames(MiniYamlNode widgetNode, Action<string> emitError, Action<string> emitWarning)
|
||||||
{
|
{
|
||||||
@@ -225,7 +238,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
CurrentQueue = null;
|
CurrentQueue = null;
|
||||||
|
|
||||||
if (CurrentQueue != null)
|
if (CurrentQueue != null)
|
||||||
|
{
|
||||||
|
if (CurrentQueue.Actor.Owner != cachedQueueOwner)
|
||||||
|
UpdateCachedProductionIconOverlays();
|
||||||
|
|
||||||
RefreshIcons();
|
RefreshIcons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
@@ -413,6 +431,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateCachedProductionIconOverlays()
|
||||||
|
{
|
||||||
|
cachedQueueOwner = CurrentQueue.Actor.Owner;
|
||||||
|
pios = cachedQueueOwner.PlayerActor.TraitsImplementing<IProductionIconOverlay>().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
public void RefreshIcons()
|
public void RefreshIcons()
|
||||||
{
|
{
|
||||||
icons = new Dictionary<Rectangle, ProductionIcon>();
|
icons = new Dictionary<Rectangle, ProductionIcon>();
|
||||||
@@ -480,8 +504,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
var buildableItems = CurrentQueue.BuildableItems();
|
var buildableItems = CurrentQueue.BuildableItems();
|
||||||
|
|
||||||
var pios = currentQueue.Actor.Owner.PlayerActor.TraitsImplementing<IProductionIconOverlay>();
|
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
Game.Renderer.EnableAntialiasingFilter();
|
Game.Renderer.EnableAntialiasingFilter();
|
||||||
foreach (var icon in icons.Values)
|
foreach (var icon in icons.Values)
|
||||||
|
|||||||
Reference in New Issue
Block a user