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.
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.
If no player is provided then the function falls back to the viewed
player, which is sometimes not the right one (like for observers), which
resulted in inconsistent/incorrect data being returned. This patch fixes
that.
This patch merges the four GuiInterface calls in OnSimulationUpdate in
the GUI into a single one. This makes both sides shorter, is better
in terms of performance and decouples the simulation more from the GUI.
Previously, all templates were stored in the same cache. This was
problematic because the data returned by the GuiInterface depends on
the player passed (since it applies player modifications). The reason
this didn't cause a lot of issues is because most of the time
GetTemplateData is called without the player parameter, in which case
the viewed player is always fallen back to. In a few other cases the
viewed player is even passed directly to it, which has the same effect.
Creating one cache for each player is the best way to ensure the
stored template data is consistent and what one would expect.
Also, this allows us to stop having to reset the cache when the viewed
player is changed.
Some statements could be inlined and only passing relevant aura
templates to the TemplateHelper isn't required, so we can simply always pass
all of them and save the work.
This patch is primarily meant as preparation in order to be able to
reuse this logic for GetEntityState calls in the future.
Key changes:
- Clearer API by providing different functions for different purposes.
- Slight performance optimisation by storing parameters in a context
object and pulling the info from there instead of redeclaring a lambda
each time, which it seems Spidermonkey struggled to optimise well.
- Allow computing only partial template data, specified by passing a
list of desired components. (to be used more in the future)
- Make it so the naming and structure of template data and matches 1:1
with the data in entity states. This makes accessing values from them
more consistent and would also allow e.g. adopting data between the two
in the future.
We don't need to use pointers because we know lifetimes of all
renderers. And its list statically defined. A new renderer should follow
DOD and use a separate submission list with a separate inplace renderer.
Separates submitted models and moder renderer and makes relations
explicit. Now it's clear that we don't need separate ModelRenderer and
ModelVertexRenderer.
We use only shaders to render models so we don't need a separate class.
BatchModelRenderer was renamed in 6bc33fe8bd.
m_Renderer became unused in 0346ba1b18.
In case the build fails this will allow other Jenkins jobs to restore
the old working state themselves.
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
CSimulation2 used , CSimulation2Impl mixed /, and
CTurnManager used for the same turn-count concept, forcing a
static_cast<int64_t> at the one place these types already met
(rejoin-test comparison).
Add (alias for std::int32_t) in SimulationCommand.h and use
it consistently for every turn counter in CSimulation2/Impl,
CTurnManager and its subclasses (CLocalTurnManager,
CReplayTurnManager), CNetServerTurnManager/CNetClientTurnManager, and
the network wire format (m_Turn in CEndCommandBatchMessage,
CSimulationMessage, CSyncCheckMessage, CSyncErrorMessage, and
m_CurrentTurn in CLoadedGameMessage).
Turn *duration* fields (m_TurnLength, m_CommandDelay,
DEFAULT_TURN_LENGTH, COMMAND_DELAY_SP/MP, SetTurnLength,
GetSavedTurnLength return type) are left as u32 — they're milliseconds,
not a counter, and out of scope here.
Remaining turn_id_t vs size_t comparisons use std::cmp_equal or
explicit casts, matching the existing pattern in Simulation2.cpp.
Fixes#8718
Doesn't make sense to have the Paths StaticBox inside the Common
settings StaticBox so make it a top-level item as well.
While at it dissolve nested constructors to make the creation of the
widgets more readable.
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
To follow coding convention rename the vector Node to m_Nodes,
MaxDistance to m_MaxDistance and NodeCount to m_NodeCount.
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>