-
Notifications
You must be signed in to change notification settings - Fork 0
Description
There is room for optimization in UIUpdate(). This function executes any time a new screen pops in the stack, is called by the tactical controller events (event ForceUIUpdate() and event PreRender(), and during the pre-render phase.
What UIUpdate() does is execute any delegates that were enlisted per tick, so UI elements such as arrows pointing on a units head, Flag manager, watching for Fullscreen changes, etc. all rely on continuous execution for its logic
At best, while the game is idle, UIUpdate() wouldn't be much of an issue, but worst case it can tank the FPS quite a bit while the delegates are processing:

Aggregate for 10 seconds of gameplay (no loading between GameReplicationInfo)

UIUpdate()/PreRender() can be pretty intense during normal gameplay for lower end processors.
The current code for reference:
for( i=0; i<m_arrUIUpdateCallbacks.length; i++ )
{
dCallback = m_arrUIUpdateCallbacks[i];
if (dCallback != none)
dCallback();
}
Most of this can be condensed down to using a foreach loop or a for loop without having to copy the delegate object.
foreach might be recommended because there's reason to believe that it can quickly process more iterations compared to for since we can forfeit the iterator:
So, using a foreach without an index would look like this:
local delegate< UpdateCallback > dCallback;
foreach m_arrUIUpdateCallbacks(dCallback)
{
dCallback();
}
However, it's pretty much just conjecture. There's no telling if this will improve performance or not without some profiling.