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.
This patch allows techs to optionally define a property "placeBelow"
specifying a combination of class requirements. The selection panel then
tries to place their research button below the training button whose
unit matches these classes -- if there is only and exactly one.
This is useful for techs only affecting a single type of unit: it e.g.
allows always placing the fishing nets research button below the fishing
boats training button.
To prevent duplicating information in "placeBelow" (e.g. from
"affects"), it can also be set to two magic values: "{AffectedUnit}" and
"{UnlockedUnit}". In practice, many techs use those, but class
combination remain useful for granular control in very specific cases.
Regarding tech pairs, as explained in a comment, their two research
buttons can now be placed in three different arrangements (with
descending preference):
1. Vertically below a single training button.
2. Horizontally below two adjacent training buttons.
3. Horizontally adjacent in the bottom row (below no training buttons).
Vertically in the third and fourth rows (below no training button) --
how it was previously -- is no longer done as it'd conflict with and
doesn't fit the new layout and the clear separation between "generic"
and "specific" techs.
Whenever a research button can't be placed in their preferred location
because it is already occupied, the code simply falls back to the default
position in the bottom row.
This patch also adds a new game option to hide the new small arrows above
the research buttons in order to give more experienced players who already
know the techs well the possibility to reduce visual clutter. By
default, the arrows are shown.
In the (common) case that the player controls all selected units or is
an observer, the 'Selection' and 'Command' panels were set up ahead and
then in the for loop again, which was wasteful.
GetGUIObjectByName was previously made stricter, logging an
error if it doesn't find the target object.
This commit deals with the resulting error-causing (invalid) calls,
by deleting them if they're unnecessary or converting them to the new
TryGetGUIObjectByName (which doesn't log any errors).
It is possible to modify sizes by setting the properties directly.
(Without having to create a copy of it)
This allows to shorten those passages quite a bit without any functional change.
The task of the production queue should first and foremost be that; a
queue for production items.
Hence, the specifics of training/researching are delegated to specific
components.
As a side effect, this improves the test coverage and fixes:
- Resource not refunding when hitting the entity limit. Introduced in
b8758c8941.
- Autoqueue changing when unable to spawn. Introduced in 956b3f96db.
Modders can change their templates using
https://code.wildfiregames.com/P256.
Differential revision: https://code.wildfiregames.com/D4333Fixes: #6363
Comments by: @Silier
Refs. #6364
This was SVN commit r26000.
By specifying the players which are allowed to use(/see) a command
button and adding an enabled/disabled property to the info.
Differential revision: D2343
Comments by: @Angen, @Stan
This was SVN commit r24501.
Where controllability is defined as the ability to receive _any_ order
from the player.
Fixes the concern not raised at a1dc9cadd8#42637.
Differential Revision: D1960
Reviewed By: @wraitii
Comments by: @bb, @Stan.
This was SVN commit r24148.
Move remains of common/sprite1.xml to common/common_sprites.xml.
Remove duplicates bkFillBlack and bkTranslucent.
Rename bkWhiteBorderBlack to BackgroundWhiteBorderBlack.
Move BackgroundSessionTooltip and BackgroundInformationTooltip to
session/.
Remove unused BackgroundErrorTooltip.
This was SVN commit r18636.
Use the cheat multiplier for upgrading and un/packing.
Remove if-statements that are always true.
Remove unused undefined "time" item from array in the selection panel.
Pass that object directly instead of copying each property explicitly.
Various indentation fixes in the selection panel code.
This was SVN commit r18472.
This new components allows giving the upgrade a cost, required
technologies, and a required time.
Implement gates using this generic component.
Fixes#2706
This was SVN commit r18467.
Introduce isPlayerObserver to easily cover that case.
Move some checks and updates into selectViewPlayer and eliminate
setObserverMode.
Initialize the music before changing the perspective.
This was SVN commit r17758.
This allows observers to see the training queue, researched techs, unit
stance, constructable buildings, garrisoned units, market prices etc.
for all players without changing the perspective.
All buttons are disabled if the user isn't allowed to control the
affected player.
Notice updateUnitCommands() fills out the panel differently in case of
selecting an allied building.
Extends the GUIInterface methods "GetNeededResources",
"CheckTechnologyRequirements" and "IsTechnologyResearched" to optionally
take a different player-argument.
This was SVN commit r17617.
"color" can make use of the sprite's alpha texture, and the "add_color"
effect will now take the original image's alpha into account.
Remove the no longer needed "unaffordableMask" images on a variety of
panels.
Somewhat based on a patch by BoeseRaupe. Fixes#2421 and #3688.
This was SVN commit r17456.