This patch decouples the panel entity GUI code from the global session code and uses the class syntax to achieve that, refs #5387.
The code logic is changed a bit (while the behavior visible to the player is the same) in order to perform less useless work.
- Buttons are created at one point in time and only updated with simstate relevant code.
- The buttons are only repositioned if a button was inserted or deleted.
- Each buttonhandler will use the same button throughout its lifetime rather than mapping dynamically.
- sprite, onPress and onDoublePress are ressigned upon addition / removal of the button and perform the lookup on the entityID directly rather than iterating / lookup to find the correct entity
- updateGUIStatusBar was reduced to 3 lines (changing one property of the size property) due to lack of other use cases and GUI resizing being simple enough to make the helper an unneeded indirection and odditiy instead of a timesaver
- Engine.GetGUIObjectByName only upon construction of a button / manager to avoid repeated useless work
- Health bar resizing only if health changed
These changes may help to make it easier to animate the button position instead of instant changes, as the TODO from rP18361 suggests.
The performance analsis shows that this is only slightly faster, < 5%, because there are two heavy performance blockers here.
One is the GetEntityState and the other is the tooltip functions (which also call GetEntityState).
Those two consume 300 microseconds per button on my machine whereas the rest of the new update function consumes something like 30 microseconds.
So the result is that we get yet another hint that GetEntityState interface needs to become smarter.
The tooltip functions equally. Perhaps one can make it so that the tooltip work is not performed anymore unless the tooltip is shown.
It would be a C++ patch, so thats only a prospect.
Everything besides those two evil calls should have been reduced to noisefloor, at least it's all 1, 5, or otherwise < 30 microseconds,
see the code comments in the first version of the patch uploaded.
Attached a measurement showing something like 13 relics in observerview selected, and the same replay from player 1 perspective who gained and lost relics and a hero.
(Notice the first graphics has a horizontal offset)
replay used to measure:
replay used to verify behavior:
Notice that it now uses 15 microseconds where it had 80 microseconds before in case there are no panel entities, yay.