Compare commits

..

6 commits

Author SHA1 Message Date
Vantha
9239b5952b
Remove some unused getters from components
Since __________, a bunch of getter on various components are now
unused. This patch removes three of them:
- `Identity.prototype.GetRankTechName`, because it is kinda redundant since
  there's also `Identity.prototype.GetRank`.
- `Auras.prototype.GetDescriptions` and `Upgrade.prototype.GetUpgrades`
  because they are long and perform additional logic (only duplicating
  some lines from globalscripts/Templates.js).

All of the other getters are simple and kept for now because they are
useful to have in general and might be handy in the future or for mods.
2026-08-12 11:55:15 +02:00
Vantha
c793678d4b
Deduplicate GetEntityState(clickedEntity) calls 2026-08-12 11:55:15 +02:00
Vantha
874d35888a
Simplify GetTemplateData calls
Previously it was made so that "template data" was a sort of super type
of "entity state" and that the former could always be replaced by the
latter. Using this we can simplify some code passages by removing
GetTemplateData calls and using the entity's state directly instead.
2026-08-12 11:55:14 +02:00
Vantha
35bf79fdf3
Rename the formation field to formationController
This patch renames the `unitAI.formation` field in entity states to
`unitAI.formationController` for clarity (there's `unitAI.formations`
as well, which was confusing)
2026-08-12 11:55:14 +02:00
Vantha
a954b7742e
Remove selectableStance from entity states
The array was wastefully created and passed to the GUI every single
turn for every single selected unit.
Since the GUI defines the (selectable) stances' names and tooltips, it
already knew them anyway, so they don't even need to be passed from the
simulation to it in the first place.
2026-08-12 11:55:14 +02:00
Vantha
6d3012139d
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-12 11:55:01 +02:00

View file

@ -150,7 +150,7 @@ ModifiersManager.prototype.GetModifiersInfo = function(entity)
components.add(component);
// Sort the modifiers to ignore insertion order.
const modifiers = modifications[value].toSorted((a, b) =>
const modifiers = modifications[value].sort((a, b) =>
a._ID > b._ID ? 1 : -1 // the IDs can't be the same
);
for (const modifier of modifiers)