Only load command buttons that will be displayed

There are currently 19 entity commands in total, but only the first 6
possible (depends on the active selection, e.g. patrolling isn't
possible if no units are selected) ones are ever displayed as buttons
(defined by g_SelectionPanels.Command.getMaxNumberOfItems)  However,
when updating (once per turn or whenever the selection changes),
g_SelectionPanels.Command.getItems always called `getInfo` on all of
them, even though all data computed after the first 6 wasn't read or
used anywhere later. So, stopping immediately after the 6th and never
returning an array longer than 6 saves all of the dead time without
affecting the outcome in any way.

It's important to mention, that this issue isn't exclusive to the
'Command' selection panel: the getItems methods of the other panels can
also return an array longer than their getMaxNumbertOfItems value
(that's why they specify it in the first place). However, for the
command panel this happens for many common selections and seemingly to
by far the largest extent. For the other panels it happens much more
rarely, only for especially large and obscure selections, and even then
does not have nearly as big of an impact. So, modifying the other
getItems methods as well (to never return too many items) is probably
not worth it, and the more robust solution is to instead keep the
safeguard system of getMaxNumbertOfItems.
This commit is contained in:
Vantha 2025-10-21 21:21:18 +02:00
parent 6bdcab11b9
commit 83fc0dbca8

View file

@ -129,11 +129,12 @@ g_SelectionPanels.Command = {
for (const command in g_EntityCommands)
{
const info = getCommandInfo(command, unitEntStates);
if (info)
{
info.name = command;
commands.push(info);
}
if (!info)
continue;
info.name = command;
if (commands.push(info) >= this.getMaxNumberOfItems())
break;
}
return commands;
},