0ad/binaries/data/mods/public/gui/common
Vantha 0a3bd16cb5
Optimise GetEntityState
GetEntityState is a performance-critical function in the GUI when a
large number of units are selected. The goal of this patch is to
increase the efficiency of it without modifying the returned states
visible to rest of the GUI in any way (it renames a few properties of
entities states or moves them around, but the information they contain
and the way to access it remain the complete same)

As explained the comments, certain parts (the template data) of an
entity state are "predictable" and can be reused between entities with
the same template.
What one has to account for, however, is that values of the template
data can be modified. This happens on two different levels:
Firstly, player-wide modifications, which apply to all entities owned
by that player. This includes stuff like bonuses from researched techs,
civs bonuses, team bonuses. And secondly, entity-local modifications,
which apply to individual entities. This includes buffs or debuffs from
status effects or auras (of other entities).

So we can construct a whole entity state by first just computing the
dynamic state (stuff like current hitpoints, which differs from entity
to entity) and then adding the (potentially already cached) template
data to it, which can be reused between entities with the same template
and owning player. And then overwrite the values affected by
entity-local modifications, which are usually just a few and even they
can be cached and reused for entities with the same owning player,
template, and entity-local modifications (identified by the
"modifications ID").

This saves the effort of retrieving/computing a ton of data each turn
and also saves the time it takes the engine to clone the data from the
simulation to the GUI (as the return value of the GUI interface call),
which previously took just as long as retrieving the entity states
themselves.

Since only the dynamic state is read from the components, a number of
small getter methods have become unused; they are kept (for now at
least) since they might be useful again in the future or for mods.
2026-08-14 12:47:04 +02:00
..
campaigns Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
resources Add Han Chinese Techs, Auras 2022-02-19 16:56:31 +00:00
AlignmentHelper.js Refactor GUI object resizing JS code passages 2025-06-17 12:57:37 -05:00
color.js Fix eslint rule 'prefer-const' 2025-05-28 19:34:46 +02:00
colorFades.js Fix eslint rule 'prefer-const' in gui/common 2025-05-09 19:32:43 +02:00
functions_global_object.js Remove Engine.SwitchGuiPage from loading 2026-04-26 12:44:40 +02:00
functions_utility.js Add hotkeys for opening GUI pages across the game 2026-05-16 20:53:54 +02:00
gamedescription.js Use a slider for population cap 2026-02-20 20:02:37 +01:00
global.xml Add a tutorial panel for explaining the GUI 2026-07-22 23:51:49 +02:00
hotkeys.js Fix eslint rule 'prefer-const' in gui/common 2025-05-09 19:32:43 +02:00
music.js Fix eslint rule 'prefer-const' in gui/common 2025-05-09 19:32:43 +02:00
network.js Fix request timeout error dialog 2026-02-20 21:26:52 +01:00
Observable.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
OverlayCounter.js Implement keyDown event 2020-05-26 21:47:03 +00:00
OverlayCounterFPS.js Rewrite FPS/Realtime/Gametime/Ceasefire counters to use object semantics using class notation, refs #5387. 2019-10-27 12:39:28 +00:00
OverlayCounterManager.js Fix eslint rule 'prefer-const' in gui/common 2025-05-09 19:32:43 +02:00
OverlayCounterRealtime.js Rewrite FPS/Realtime/Gametime/Ceasefire counters to use object semantics using class notation, refs #5387. 2019-10-27 12:39:28 +00:00
Profilable.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
settings.js Use a slider for population cap 2026-02-20 20:02:37 +01:00
setup.xml Revert "Fix element positions after new font rendering" 2025-06-11 08:10:57 -05:00
sprites.xml Add a new button style: 'BrownButton' 2025-09-28 22:59:27 +02:00
styles.xml Move "TutorialPanel" style to session styles 2026-07-22 23:51:49 +02:00
tab_buttons.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
tab_buttons.xml Absorb duplicated summary tab code to the tab_buttons gui 2020-06-23 20:15:36 +00:00
timer.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
tooltips.js Optimise GetEntityState 2026-08-14 12:47:04 +02:00