0ad/binaries/data/mods/public/globalscripts
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
..
tests Gendered Civilians 2025-09-02 10:23:44 +02:00
AttackEffects.js Fix eslint rule 'prefer-const' in globalscripts 2025-05-06 14:16:42 +02:00
DamageTypes.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
Formation.js Allow picking a default formation for walk (and walk-like) orders. 2020-12-31 10:04:58 +00:00
FSM.js Enable eslint rule 'no-redeclare' 2025-06-14 14:53:10 +02:00
interpolation.js Fix eslint rule 'space-before-function-paren' 2025-05-13 15:21:57 +02:00
Math.js Add Math.clamp utility function 2026-07-30 17:19:39 +02:00
ModificationTemplates.js Use @stylistic/brace-style for eslint 2026-01-12 21:33:52 +01:00
MultiKeyMap.js Fix eslint rule 'prefer-const' in globalscripts 2025-05-06 14:16:42 +02:00
random.js Add randomAngle helper function to abbreviate calls. 2018-01-15 14:20:57 +00:00
Resources.js Fix eslint rule 'prefer-const' in globalscripts 2025-05-06 14:16:42 +02:00
StatusEffects.js Fix eslint rule 'prefer-const' in globalscripts 2025-05-06 14:16:42 +02:00
Technologies.js Support setting multiply and add to 0 in techs 2026-02-20 21:26:19 +01:00
Templates.js Optimise GetEntityState 2026-08-14 12:47:04 +02:00
Trade.js Adapt trade gain normalization to map size (increased on small maps and decreased on large maps), and slow down the increase of the gain at very large distances. 2017-10-31 17:52:08 +00:00
utility.js Implement level class sorting for formations 2026-01-23 17:20:11 +01:00
vector.js Sort units spatially for freehand selection 2026-07-30 17:19:39 +02:00
WeightedList.js Fix eslint rule 'prefer-const' in globalscripts 2025-05-06 14:16:42 +02:00