2015-09-13 12:15:07 -07:00
|
|
|
const g_IsReplay = Engine.IsVisualReplay();
|
2016-09-03 02:11:02 -07:00
|
|
|
|
2017-08-26 11:53:37 -07:00
|
|
|
const g_CivData = loadCivData(false, true);
|
|
|
|
|
|
2016-09-03 02:11:02 -07:00
|
|
|
const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes);
|
|
|
|
|
const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
|
|
|
|
|
const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
|
|
|
|
|
const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
|
2018-03-09 13:51:18 -08:00
|
|
|
const g_VictoryConditions = g_Settings && g_Settings.VictoryConditions;
|
|
|
|
|
|
2019-10-30 07:39:44 -07:00
|
|
|
var g_Ambient;
|
Allow picking a default formation for walk (and walk-like) orders.
This allows choosing a "default formation", which is activated
automatically for units given walk orders (and attack-walk etc.).
Conversely, units in formation that are given a gather/build/... order
are taken out of formation and given the order individually.
The default formation can be selected by right-clicking on any formation
icon.
This leverages formations for walking, where they are quite efficient
(in fact, perhaps too efficient), while circumventing issues with
various orders.
Choosing the "null formation" as the default formation de-activates the
behaviour entirely, and plays out exactly like SVN.
This makes it possible to queue a formation-order then a
noformation-order (i.e. walk then repair), though the behaviour isn't
very flexible.
For modders, it should be relatively easy to change the setup for each
order, and/or to force deactivating/activating formations in general.
Tested by: Freagarach, Angen
Refs #3479, #1791.
Makes #3478 mostly invalid.
Differential Revision: https://code.wildfiregames.com/D2764
This was SVN commit r24480.
2020-12-31 02:04:58 -08:00
|
|
|
var g_AutoFormation;
|
2019-10-06 07:42:12 -07:00
|
|
|
var g_Chat;
|
2019-10-30 07:06:27 -07:00
|
|
|
var g_Cheats;
|
2026-01-04 06:22:19 -08:00
|
|
|
var g_CinemaOverlay;
|
2019-10-18 17:26:34 -07:00
|
|
|
var g_DeveloperOverlay;
|
2019-10-11 05:28:12 -07:00
|
|
|
var g_DiplomacyColors;
|
|
|
|
|
var g_DiplomacyDialog;
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
var g_GameSpeedControl;
|
2025-04-22 03:41:46 -07:00
|
|
|
var g_MatchSettingsDialog;
|
2019-10-18 07:11:43 -07:00
|
|
|
var g_Menu;
|
2019-10-11 05:28:12 -07:00
|
|
|
var g_MiniMapPanel;
|
2019-10-30 06:48:27 -07:00
|
|
|
var g_NetworkStatusOverlay;
|
2021-03-29 00:53:06 -07:00
|
|
|
var g_NetworkDelayOverlay;
|
2019-10-30 04:14:55 -07:00
|
|
|
var g_OutOfSyncNetwork;
|
|
|
|
|
var g_OutOfSyncReplay;
|
2019-10-22 10:53:22 -07:00
|
|
|
var g_PanelEntityManager;
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
var g_PauseControl;
|
|
|
|
|
var g_PauseOverlay;
|
|
|
|
|
var g_PlayerViewControl;
|
2019-10-30 04:14:55 -07:00
|
|
|
var g_QuitConfirmationDefeat;
|
|
|
|
|
var g_QuitConfirmationReplay;
|
2019-10-25 04:56:20 -07:00
|
|
|
var g_RangeOverlayManager;
|
2019-10-21 16:05:04 -07:00
|
|
|
var g_ResearchProgress;
|
2019-10-30 07:39:44 -07:00
|
|
|
var g_TimeNotificationOverlay;
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
var g_TopPanel;
|
2019-10-30 07:39:44 -07:00
|
|
|
var g_TradeDialog;
|
2026-02-25 05:37:05 -08:00
|
|
|
var g_TutorialManager;
|
2015-12-14 08:47:45 -08:00
|
|
|
|
2016-06-28 18:45:20 -07:00
|
|
|
/**
|
2020-12-17 03:47:04 -08:00
|
|
|
* Map, player and match settings set in game setup.
|
2016-06-28 18:45:20 -07:00
|
|
|
*/
|
2021-03-19 03:02:10 -07:00
|
|
|
const g_InitAttributes = deepfreeze(Engine.GuiInterfaceCall("GetInitAttributes"));
|
2016-06-28 18:45:20 -07:00
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
2018-04-04 05:43:25 -07:00
|
|
|
* True if this is a multiplayer game.
|
2016-01-19 10:09:34 -08:00
|
|
|
*/
|
2018-04-04 05:43:25 -07:00
|
|
|
const g_IsNetworked = Engine.HasNetClient();
|
2015-12-13 21:37:34 -08:00
|
|
|
|
|
|
|
|
/**
|
2018-04-04 05:43:25 -07:00
|
|
|
* Is this user in control of game settings (i.e. is a network server, or offline player).
|
2015-12-13 21:37:34 -08:00
|
|
|
*/
|
2021-02-27 09:44:59 -08:00
|
|
|
var g_IsController = !g_IsNetworked || Engine.IsNetController();
|
2016-01-19 10:09:34 -08:00
|
|
|
|
2016-10-23 07:49:32 -07:00
|
|
|
/**
|
|
|
|
|
* Whether we have finished the synchronization and
|
|
|
|
|
* can start showing simulation related message boxes.
|
|
|
|
|
*/
|
|
|
|
|
var g_IsNetworkedActive = false;
|
|
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
|
|
|
|
* True if the connection to the server has been lost.
|
|
|
|
|
*/
|
|
|
|
|
var g_Disconnected = false;
|
2015-12-13 21:37:34 -08:00
|
|
|
|
2016-01-19 09:23:16 -08:00
|
|
|
/**
|
|
|
|
|
* True if the current user has observer capabilities.
|
|
|
|
|
*/
|
2014-03-16 16:29:27 -07:00
|
|
|
var g_IsObserver = false;
|
2013-11-07 12:07:24 -08:00
|
|
|
|
2016-04-28 02:10:16 -07:00
|
|
|
/**
|
|
|
|
|
* True if the current user has rejoined (or joined the game after it started).
|
|
|
|
|
*/
|
|
|
|
|
var g_HasRejoined = false;
|
|
|
|
|
|
2016-01-19 09:23:16 -08:00
|
|
|
/**
|
|
|
|
|
* The playerID selected in the change perspective tool.
|
|
|
|
|
*/
|
|
|
|
|
var g_ViewedPlayer = Engine.GetPlayerID();
|
|
|
|
|
|
2016-03-14 21:02:15 -07:00
|
|
|
/**
|
|
|
|
|
* True if the camera should focus on attacks and player commands
|
|
|
|
|
* and select the affected units.
|
|
|
|
|
*/
|
|
|
|
|
var g_FollowPlayer = false;
|
|
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
|
|
|
|
* Cache the basic player data (name, civ, color).
|
|
|
|
|
*/
|
2010-08-11 15:16:16 -07:00
|
|
|
var g_Players = [];
|
2015-12-04 07:35:34 -08:00
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
|
|
|
|
* Last time when onTick was called().
|
|
|
|
|
* Used for animating the main menu.
|
|
|
|
|
*/
|
2017-06-18 12:11:24 -07:00
|
|
|
var g_LastTickTime = Date.now();
|
2015-12-13 21:37:34 -08:00
|
|
|
|
2017-05-25 18:47:48 -07:00
|
|
|
/**
|
|
|
|
|
* Recalculate which units have their status bars shown with this frequency in milliseconds.
|
|
|
|
|
*/
|
2017-08-26 13:10:39 -07:00
|
|
|
var g_StatusBarUpdate = 200;
|
2017-05-25 18:47:48 -07:00
|
|
|
|
2016-04-22 15:25:50 -07:00
|
|
|
/**
|
|
|
|
|
* For restoring selection, order and filters when returning to the replay menu
|
|
|
|
|
*/
|
|
|
|
|
var g_ReplaySelectionData;
|
|
|
|
|
|
2018-04-04 11:46:36 -07:00
|
|
|
/**
|
|
|
|
|
* Remembers which clients are assigned to which player slots.
|
2019-11-23 00:10:36 -08:00
|
|
|
* The keys are GUIDs or "local" in single-player.
|
2018-04-04 11:46:36 -07:00
|
|
|
*/
|
|
|
|
|
var g_PlayerAssignments;
|
2010-08-12 12:31:17 -07:00
|
|
|
|
2017-06-17 07:17:30 -07:00
|
|
|
/**
|
|
|
|
|
* Whether the entire UI should be hidden (useful for promotional screenshots).
|
|
|
|
|
* Can be toggled with a hotkey.
|
|
|
|
|
*/
|
|
|
|
|
var g_ShowGUI = true;
|
|
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
|
|
|
|
* Whether status bars should be shown for all of the player's units.
|
|
|
|
|
*/
|
2012-07-23 21:14:09 -07:00
|
|
|
var g_ShowAllStatusBars = false;
|
|
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
2017-08-26 14:48:57 -07:00
|
|
|
* Cache of simulation state and template data (apart from TechnologyData, updated on every simulation update).
|
2016-01-19 10:09:34 -08:00
|
|
|
*/
|
2013-04-10 14:05:46 -07:00
|
|
|
var g_SimState;
|
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-02-12 06:52:21 -08:00
|
|
|
var g_EntityStates = new Map();
|
|
|
|
|
var g_TemplateData = new Map();
|
2016-01-19 10:09:34 -08:00
|
|
|
var g_TechnologyData = {};
|
2017-08-26 14:48:57 -07:00
|
|
|
|
2016-11-19 06:29:45 -08:00
|
|
|
var g_ResourceData = new Resources();
|
2013-04-10 14:05:46 -07:00
|
|
|
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
/**
|
|
|
|
|
* These handlers are called each time a new turn was simulated.
|
|
|
|
|
* Use this as sparely as possible.
|
|
|
|
|
*/
|
2019-10-18 17:26:34 -07:00
|
|
|
var g_SimulationUpdateHandlers = new Set();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These handlers are called after the player states have been initialized.
|
|
|
|
|
*/
|
2019-10-18 17:26:34 -07:00
|
|
|
var g_PlayersInitHandlers = new Set();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These handlers are called when a player has been defeated or won the game.
|
|
|
|
|
*/
|
2019-10-18 17:26:34 -07:00
|
|
|
var g_PlayerFinishedHandlers = new Set();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These events are fired whenever the player added or removed entities from the selection.
|
|
|
|
|
*/
|
2019-10-18 17:26:34 -07:00
|
|
|
var g_EntitySelectionChangeHandlers = new Set();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* These events are fired when the user has performed a hotkey assignment change.
|
|
|
|
|
* Currently only fired on init, but to be fired from any hotkey editor dialog.
|
|
|
|
|
*/
|
2019-10-21 08:00:59 -07:00
|
|
|
var g_HotkeyChangeHandlers = new Set();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
2016-01-19 10:09:34 -08:00
|
|
|
/**
|
|
|
|
|
* List of additional entities to highlight.
|
|
|
|
|
*/
|
2013-11-30 09:30:08 -08:00
|
|
|
var g_ShowGuarding = false;
|
|
|
|
|
var g_ShowGuarded = false;
|
|
|
|
|
var g_AdditionalHighlight = [];
|
|
|
|
|
|
2017-04-09 16:10:50 -07:00
|
|
|
/**
|
|
|
|
|
* Order in which the panel entities are shown.
|
|
|
|
|
*/
|
|
|
|
|
var g_PanelEntityOrder = ["Hero", "Relic"];
|
2014-01-06 05:32:48 -08:00
|
|
|
|
2016-01-19 08:04:59 -08:00
|
|
|
/**
|
|
|
|
|
* Unit classes to be checked for the idle-worker-hotkey.
|
|
|
|
|
*/
|
2025-06-10 11:00:31 -07:00
|
|
|
var g_WorkerTypes = ["Civilian", "Trader", "FishingBoat", "Citizen"];
|
2017-03-23 10:54:36 -07:00
|
|
|
|
2016-08-27 03:34:21 -07:00
|
|
|
/**
|
|
|
|
|
* Unit classes to be checked for the military-only-selection modifier and for the idle-warrior-hotkey.
|
|
|
|
|
*/
|
|
|
|
|
var g_MilitaryTypes = ["Melee", "Ranged"];
|
2016-01-19 08:04:59 -08:00
|
|
|
|
2013-04-10 14:05:46 -07:00
|
|
|
function GetSimState()
|
|
|
|
|
{
|
|
|
|
|
if (!g_SimState)
|
2017-09-03 09:37:09 -07:00
|
|
|
g_SimState = deepfreeze(Engine.GuiInterfaceCall("GetSimulationState"));
|
2013-04-10 14:05:46 -07:00
|
|
|
|
|
|
|
|
return g_SimState;
|
|
|
|
|
}
|
|
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
/**
|
|
|
|
|
* Piece together the entire entity state, either from g_TemplateData or the data provided (one of which
|
|
|
|
|
* should always be possible) and then cache it in g_EntityStates.
|
|
|
|
|
* Intended for internal use only.
|
|
|
|
|
*/
|
|
|
|
|
function _processNewEntityState(data, entId)
|
2010-08-28 14:12:52 -07:00
|
|
|
{
|
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-02-12 06:52:21 -08:00
|
|
|
if (!data?.dynamicState)
|
|
|
|
|
{
|
|
|
|
|
g_EntityStates.set(entId, null);
|
2018-01-15 13:27:30 -08:00
|
|
|
return null;
|
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-02-12 06:52:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Certain parts (the template data) of an entity state are "predictable" and can therefore 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-global modifications, which apply to all entities owned by that player. This includes stuff
|
|
|
|
|
// like bonuses from researched techs, civs bonuses, team bonuses.
|
|
|
|
|
// - Secondly, entity-local modifications, which apply to individual entities. This includes buffs or debuffs
|
|
|
|
|
// from status effects or auras (of other entities).
|
|
|
|
|
//
|
|
|
|
|
// To take advantage of this, the whole entity state consists of three parts that we need to combine here:
|
|
|
|
|
// 1. The template data of the entity's template, which only has the player-global modifications applied. It is
|
|
|
|
|
// the same for all entities with the same template and owner, so it cached and reused when possible.
|
|
|
|
|
// 2. The modified template data of the entity, which can contain a subset of the template data's values,
|
|
|
|
|
// overwriting them. It has both the player-global and entity-local modifications applied, but only contains the
|
|
|
|
|
// values that actually differ from its template data. It is therefore the same for all entities with the same
|
|
|
|
|
// owner, template, and modifications ID, so it cached and reused when possible.
|
|
|
|
|
// 3. the dynamic state, which differs from entity to entity and therefore isn't cached.
|
|
|
|
|
|
|
|
|
|
const state = data.dynamicState;
|
|
|
|
|
|
|
|
|
|
// This is the only two-level-deep value of the dynamic state supposed to overwrite the corresponding value in the
|
|
|
|
|
// (modified) template data, so we have to treat it explicitly here, which is quite ugly.
|
|
|
|
|
const elevationAdaptedRange = state.attack?.Ranged?.elevationAdaptedRange;
|
|
|
|
|
|
|
|
|
|
const playerCache = g_TemplateData.get(state.player);
|
|
|
|
|
let templateData = data.templateData;
|
|
|
|
|
if (templateData)
|
|
|
|
|
{
|
|
|
|
|
translateObjectKeys(templateData, ["specific", "generic", "tooltip"]);
|
|
|
|
|
playerCache.set(state.templateName, deepfreeze(templateData));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
templateData = playerCache.get(state.templateName);
|
|
|
|
|
|
|
|
|
|
let modifiedTemplateData;
|
|
|
|
|
if (data.modificationsID)
|
|
|
|
|
{
|
|
|
|
|
const cacheKey = `${state.templateName}: ${data.modificationsID}`;
|
|
|
|
|
modifiedTemplateData = data.modifiedTemplateData;
|
|
|
|
|
if (modifiedTemplateData)
|
|
|
|
|
playerCache.set(cacheKey, deepfreeze(modifiedTemplateData));
|
|
|
|
|
else
|
|
|
|
|
modifiedTemplateData = playerCache.get(cacheKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const key in templateData)
|
|
|
|
|
{
|
|
|
|
|
const templateVal = modifiedTemplateData?.[key] || templateData[key];
|
|
|
|
|
const stateVal = state[key];
|
|
|
|
|
// Individual entries of dynamic state don't overlap with the ones in the (modified) template data, but they are
|
|
|
|
|
// organised into child objects. So we are only combining the two here, not actually overwriting anything.
|
|
|
|
|
// (elevationAdaptedRange is the only exception)
|
|
|
|
|
if (typeof stateVal == "object")
|
|
|
|
|
Object.assign(stateVal, templateVal);
|
|
|
|
|
else
|
|
|
|
|
state[key] = templateVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (elevationAdaptedRange)
|
|
|
|
|
state.attack.Ranged.elevationAdaptedRange = elevationAdaptedRange;
|
|
|
|
|
|
|
|
|
|
g_EntityStates.set(entId, deepfreeze(state));
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pull states of multiple entities from the simulation and cache them.
|
|
|
|
|
* This is faster than doing it for each individually.
|
|
|
|
|
*/
|
|
|
|
|
function PreloadMultipleEntityStates(ents)
|
|
|
|
|
{
|
|
|
|
|
const newEnts = ents.filter(ent => !g_EntityStates.has(ent));
|
|
|
|
|
if (!newEnts.length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const items = Engine.GuiInterfaceCall("GetMultipleEntityStates", newEnts);
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
|
_processNewEntityState(items[i], newEnts[i]);
|
2010-08-28 14:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-31 08:32:34 -08:00
|
|
|
/**
|
|
|
|
|
* Get the current state of a given entity. The data is pulled from the simulation.
|
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-02-12 06:52:21 -08:00
|
|
|
*
|
|
|
|
|
* An entity state is like a subtype of template data (returned by GetTemplateData), it contains
|
|
|
|
|
* all of the values present in the latter, plus some more. Substitutability is given, it can be
|
|
|
|
|
* used everywhere where a template is expected.
|
|
|
|
|
* However, even the values also in present template data could be modified entity-locally, by
|
|
|
|
|
* stuff like auras and status effects. For example, two spearman of the same player can have
|
|
|
|
|
* different attack damage with both different from the value in the spearman template data.
|
|
|
|
|
* To obtain the values that are consistent player-wide (which a new entity with that template of
|
|
|
|
|
* that player would have) call GetTemplateData(GetEntityState(entId).templateName)
|
|
|
|
|
*
|
2025-12-31 08:32:34 -08:00
|
|
|
* The state is null, if the ID is undefined, invalid or no entity with the ID exists (anymore).
|
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-02-12 06:52:21 -08:00
|
|
|
*
|
|
|
|
|
* Note about performance: Calling this the first time for an entity in a simulation turn is rather
|
|
|
|
|
* expensive, but every time after that extremely cheap, since the states are cached.
|
2025-12-31 08:32:34 -08:00
|
|
|
*/
|
2018-01-15 13:27:30 -08:00
|
|
|
function GetEntityState(entId)
|
2013-12-08 02:02:19 -08:00
|
|
|
{
|
2025-12-31 08:32:34 -08:00
|
|
|
if (!entId || entId == INVALID_ENTITY)
|
|
|
|
|
return null;
|
|
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
let state = g_EntityStates.get(entId);
|
|
|
|
|
// The cached state can very well be null, we only need to retrieve it from the simulation if it's undefined
|
|
|
|
|
// (i.e not yet present in the cache at all)
|
|
|
|
|
if (state === undefined)
|
|
|
|
|
state = _processNewEntityState(Engine.GuiInterfaceCall("GetEntityState", entId), entId);
|
2017-09-03 09:37:09 -07:00
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
return state;
|
2013-12-08 02:02:19 -08:00
|
|
|
}
|
|
|
|
|
|
2019-12-14 12:10:32 -08:00
|
|
|
/**
|
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-02-12 06:52:21 -08:00
|
|
|
* Returns template data of a given template accounting for player-wide modifications such
|
|
|
|
|
* as researched techs or team bonuses.
|
|
|
|
|
* @param {string} templateName - Name of the template.
|
|
|
|
|
* @param {number} [player] - The player whose modifications to apply to the data.
|
|
|
|
|
* If undefined, the currently viewed player is be used.
|
2019-12-14 12:10:32 -08:00
|
|
|
*/
|
2020-01-30 13:36:01 -08:00
|
|
|
function GetTemplateData(templateName, player)
|
2010-08-28 14:12:52 -07:00
|
|
|
{
|
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-02-12 06:52:21 -08:00
|
|
|
const targetPlayer = player || (g_ViewedPlayer >= 0 ? g_ViewedPlayer : 0);
|
|
|
|
|
const playerCache = g_TemplateData.get(targetPlayer);
|
2026-02-12 08:39:27 -08:00
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
let templateData = playerCache.get(templateName);
|
2026-02-12 08:39:27 -08:00
|
|
|
if (!templateData)
|
|
|
|
|
{
|
|
|
|
|
templateData = Engine.GuiInterfaceCall("GetTemplateData", { "templateName": templateName, "player": targetPlayer });
|
|
|
|
|
translateObjectKeys(templateData, ["specific", "generic", "tooltip"]);
|
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-02-12 06:52:21 -08:00
|
|
|
playerCache.set(templateName, deepfreeze(templateData));
|
2026-02-12 08:39:27 -08:00
|
|
|
}
|
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-02-12 06:52:21 -08:00
|
|
|
|
2026-02-12 08:39:27 -08:00
|
|
|
return templateData;
|
2010-08-28 14:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-08 06:00:20 -08:00
|
|
|
function GetTechnologyData(technologyName, civ)
|
2012-04-20 10:21:04 -07:00
|
|
|
{
|
2017-01-08 06:00:20 -08:00
|
|
|
if (!g_TechnologyData[civ])
|
|
|
|
|
g_TechnologyData[civ] = {};
|
|
|
|
|
|
|
|
|
|
if (!(technologyName in g_TechnologyData[civ]))
|
2012-04-20 10:21:04 -07:00
|
|
|
{
|
2022-02-05 04:12:58 -08:00
|
|
|
const tech = TechnologyTemplates.Get(technologyName);
|
|
|
|
|
if (!tech)
|
2025-05-19 08:47:28 -07:00
|
|
|
return undefined;
|
2025-05-10 07:42:27 -07:00
|
|
|
const template = GetTechnologyDataHelper(tech, civ, g_ResourceData);
|
2014-04-20 13:51:48 -07:00
|
|
|
translateObjectKeys(template, ["specific", "generic", "description", "tooltip", "requirementsTooltip"]);
|
2017-09-03 09:37:09 -07:00
|
|
|
g_TechnologyData[civ][technologyName] = deepfreeze(template);
|
2012-04-20 10:21:04 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-08 06:00:20 -08:00
|
|
|
return g_TechnologyData[civ][technologyName];
|
2012-04-20 10:21:04 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 07:14:41 -07:00
|
|
|
async function init(initData, hotloadData)
|
2010-06-30 14:34:44 -07:00
|
|
|
{
|
2015-09-13 12:15:07 -07:00
|
|
|
if (!g_Settings)
|
|
|
|
|
{
|
|
|
|
|
Engine.EndGame();
|
2025-08-09 07:14:41 -07:00
|
|
|
return { [Engine.openRequest]: { "page": "page_pregame.xml" } };
|
2015-09-13 12:15:07 -07:00
|
|
|
}
|
|
|
|
|
|
2018-04-04 11:46:36 -07:00
|
|
|
// Fallback used by atlas
|
|
|
|
|
g_PlayerAssignments = initData ? initData.playerAssignments : { "local": { "player": 1 } };
|
|
|
|
|
|
|
|
|
|
// Fallback used by atlas and autostart games
|
|
|
|
|
if (g_PlayerAssignments.local && !g_PlayerAssignments.local.name)
|
|
|
|
|
g_PlayerAssignments.local.name = singleplayerName();
|
|
|
|
|
|
2010-08-11 15:16:16 -07:00
|
|
|
if (initData)
|
|
|
|
|
{
|
2016-04-22 15:25:50 -07:00
|
|
|
g_ReplaySelectionData = initData.replaySelectionData;
|
2016-04-28 02:10:16 -07:00
|
|
|
g_HasRejoined = initData.isRejoining;
|
2010-11-02 17:21:52 -07:00
|
|
|
|
2012-05-06 21:18:54 -07:00
|
|
|
if (initData.savedGUIData)
|
|
|
|
|
restoreSavedGameData(initData.savedGUIData);
|
2010-08-11 15:16:16 -07:00
|
|
|
}
|
2011-08-30 19:41:21 -07:00
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
// Necessary when hotloading in order to repopulate g_TemplateData
|
|
|
|
|
Engine.GuiInterfaceCall("ResetEntityStateRetriever");
|
|
|
|
|
|
2026-03-23 15:39:42 -07:00
|
|
|
if (g_InitAttributes.campaignData)
|
|
|
|
|
g_CampaignSession = new CampaignSession(g_InitAttributes.campaignData);
|
2021-03-02 07:43:44 -08:00
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
const mapCache = new MapCache();
|
2019-10-30 07:06:27 -07:00
|
|
|
g_Cheats = new Cheats();
|
2019-10-11 05:28:12 -07:00
|
|
|
g_DiplomacyColors = new DiplomacyColors();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_PlayerViewControl = new PlayerViewControl();
|
|
|
|
|
g_PlayerViewControl.registerViewedPlayerChangeHandler(g_DiplomacyColors.updateDisplayedPlayerColors.bind(g_DiplomacyColors));
|
|
|
|
|
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(g_PlayerViewControl.rebuild.bind(g_PlayerViewControl));
|
2019-10-30 04:14:55 -07:00
|
|
|
g_PauseControl = new PauseControl();
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_PlayerViewControl.registerPreViewedPlayerChangeHandler(removeStatusBarDisplay);
|
2019-10-30 07:39:44 -07:00
|
|
|
g_Ambient = new Ambient();
|
Allow picking a default formation for walk (and walk-like) orders.
This allows choosing a "default formation", which is activated
automatically for units given walk orders (and attack-walk etc.).
Conversely, units in formation that are given a gather/build/... order
are taken out of formation and given the order individually.
The default formation can be selected by right-clicking on any formation
icon.
This leverages formations for walking, where they are quite efficient
(in fact, perhaps too efficient), while circumventing issues with
various orders.
Choosing the "null formation" as the default formation de-activates the
behaviour entirely, and plays out exactly like SVN.
This makes it possible to queue a formation-order then a
noformation-order (i.e. walk then repair), though the behaviour isn't
very flexible.
For modders, it should be relatively easy to change the setup for each
order, and/or to force deactivating/activating formations in general.
Tested by: Freagarach, Angen
Refs #3479, #1791.
Makes #3478 mostly invalid.
Differential Revision: https://code.wildfiregames.com/D2764
This was SVN commit r24480.
2020-12-31 02:04:58 -08:00
|
|
|
g_AutoFormation = new AutoFormation();
|
2019-10-30 07:06:27 -07:00
|
|
|
g_Chat = new Chat(g_PlayerViewControl, g_Cheats);
|
2026-01-04 06:22:19 -08:00
|
|
|
g_CinemaOverlay = new CinemaOverlay();
|
2019-10-18 17:26:34 -07:00
|
|
|
g_DeveloperOverlay = new DeveloperOverlay(g_PlayerViewControl, g_Selection);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_DiplomacyDialog = new DiplomacyDialog(g_PlayerViewControl, g_DiplomacyColors);
|
|
|
|
|
g_GameSpeedControl = new GameSpeedControl(g_PlayerViewControl);
|
2025-04-22 03:41:46 -07:00
|
|
|
g_MatchSettingsDialog = new MatchSettingsDialog(g_PlayerViewControl, mapCache);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_MiniMapPanel = new MiniMapPanel(g_PlayerViewControl, g_DiplomacyColors, g_WorkerTypes);
|
2021-03-29 00:53:06 -07:00
|
|
|
g_NetworkDelayOverlay = new NetworkDelayOverlay();
|
2019-10-30 04:14:55 -07:00
|
|
|
g_OutOfSyncNetwork = new OutOfSyncNetwork();
|
|
|
|
|
g_OutOfSyncReplay = new OutOfSyncReplay();
|
2019-10-22 10:53:22 -07:00
|
|
|
g_PanelEntityManager = new PanelEntityManager(g_PlayerViewControl, g_Selection, g_PanelEntityOrder);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_PauseOverlay = new PauseOverlay(g_PauseControl);
|
2019-10-25 04:56:20 -07:00
|
|
|
g_RangeOverlayManager = new RangeOverlayManager(g_Selection);
|
2019-10-22 10:53:22 -07:00
|
|
|
g_ResearchProgress = new ResearchProgress(g_PlayerViewControl, g_Selection);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_TradeDialog = new TradeDialog(g_PlayerViewControl);
|
2025-04-22 03:41:46 -07:00
|
|
|
g_TopPanel = new TopPanel(g_PlayerViewControl, g_DiplomacyDialog, g_TradeDialog, g_MatchSettingsDialog, g_GameSpeedControl);
|
2019-10-30 07:39:44 -07:00
|
|
|
g_TimeNotificationOverlay = new TimeNotificationOverlay(g_PlayerViewControl);
|
2019-10-06 07:42:12 -07:00
|
|
|
|
2025-10-13 19:23:30 -07:00
|
|
|
initUnitsAndBuildingsHotkeys();
|
2019-10-25 04:56:20 -07:00
|
|
|
initBatchTrain();
|
2021-03-24 23:58:47 -07:00
|
|
|
initDisplayedNames();
|
2019-10-12 20:43:42 -07:00
|
|
|
initSelectionPanels();
|
2018-01-02 13:50:41 -08:00
|
|
|
LoadModificationTemplates();
|
2017-02-23 15:34:35 -08:00
|
|
|
updatePlayerData();
|
2016-02-15 04:53:06 -08:00
|
|
|
initializeMusic(); // before changing the perspective
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
Engine.SetBoundingBoxDebugOverlay(false);
|
2026-03-19 13:46:55 -07:00
|
|
|
Engine.SetGlobalHotkey("catafalque", "Press", async() =>
|
|
|
|
|
{
|
|
|
|
|
closeOpenDialogs();
|
|
|
|
|
g_PauseControl.implicitPause();
|
|
|
|
|
await Engine.OpenChildPage("page_catafalque.xml");
|
|
|
|
|
resumeGame();
|
|
|
|
|
});
|
|
|
|
|
Engine.SetGlobalHotkey("tips", "Press", async() =>
|
|
|
|
|
{
|
|
|
|
|
closeOpenDialogs();
|
|
|
|
|
g_PauseControl.implicitPause();
|
|
|
|
|
await Engine.OpenChildPage("page_tips.xml");
|
|
|
|
|
resumeGame();
|
|
|
|
|
});
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
|
2026-06-02 13:14:51 -07:00
|
|
|
g_DiplomacyColors.updateDisplayedPlayerColors();
|
|
|
|
|
|
2026-04-29 12:44:55 -07:00
|
|
|
const promise = Promise.race([new Promise((_, reject) =>
|
|
|
|
|
{
|
|
|
|
|
if (g_IsNetworked)
|
|
|
|
|
handleNetMessages().catch(reject);
|
2026-06-11 12:06:33 -07:00
|
|
|
}), new Promise(closeSession =>
|
2026-04-29 12:44:55 -07:00
|
|
|
{
|
2026-06-11 12:06:33 -07:00
|
|
|
g_Menu = new Menu(g_PauseControl, g_PlayerViewControl, g_Chat, closeSession);
|
|
|
|
|
g_NetworkStatusOverlay = new NetworkStatusOverlay(closeSession);
|
|
|
|
|
g_QuitConfirmationDefeat = new QuitConfirmationDefeat(closeSession);
|
|
|
|
|
g_QuitConfirmationReplay = new QuitConfirmationReplay(closeSession);
|
|
|
|
|
g_TutorialManager = new TutorialManager(closeSession, hotloadData?.tutorial);
|
2026-04-29 12:44:55 -07:00
|
|
|
})]);
|
2025-08-09 07:14:41 -07:00
|
|
|
|
2026-02-24 07:07:05 -08:00
|
|
|
// TODO: use event instead
|
|
|
|
|
onSimulationUpdate();
|
|
|
|
|
Engine.GetGUIObjectByName("session").onSimulationUpdate = onSimulationUpdate;
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const handler of g_PlayersInitHandlers)
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
handler();
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const handler of g_HotkeyChangeHandlers)
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
handler();
|
2012-04-19 18:41:54 -07:00
|
|
|
|
2026-03-20 09:06:22 -07:00
|
|
|
registerPlayersFinishedHandler(updatePlayerData);
|
|
|
|
|
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(updatePlayerData);
|
|
|
|
|
registerCeasefireEndedHandler(updatePlayerData);
|
|
|
|
|
|
2011-05-04 12:31:01 -07:00
|
|
|
if (hotloadData)
|
2019-10-06 07:42:12 -07:00
|
|
|
{
|
2011-05-04 12:31:01 -07:00
|
|
|
g_Selection.selected = hotloadData.selection;
|
2019-10-06 07:42:12 -07:00
|
|
|
g_PlayerAssignments = hotloadData.playerAssignments;
|
|
|
|
|
g_Players = hotloadData.player;
|
|
|
|
|
}
|
2015-04-20 07:51:06 -07:00
|
|
|
|
2016-02-04 09:14:46 -08:00
|
|
|
setTimeout(displayGamestateNotifications, 1000);
|
2024-09-21 11:24:36 -07:00
|
|
|
|
2026-06-11 12:06:33 -07:00
|
|
|
const showSummary = await promise;
|
|
|
|
|
|
|
|
|
|
// Depends on the simulation, so it has to be called before EndGame.
|
|
|
|
|
const openRequest = getNextPageOpenRequest(showSummary);
|
|
|
|
|
|
|
|
|
|
Engine.EndGame();
|
|
|
|
|
// After the replay file was closed in EndGame
|
|
|
|
|
if (!g_IsReplay)
|
|
|
|
|
Engine.AddReplayToCache(Engine.GetCurrentReplayDirectory());
|
|
|
|
|
if (g_IsController && Engine.HasXmppClient())
|
|
|
|
|
Engine.SendUnregisterGame();
|
|
|
|
|
|
|
|
|
|
return { [Engine.openRequest]: openRequest };
|
2011-02-18 19:14:37 -08:00
|
|
|
}
|
|
|
|
|
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
function registerPlayersInitHandler(handler)
|
2018-04-04 09:53:31 -07:00
|
|
|
{
|
2019-10-18 17:26:34 -07:00
|
|
|
g_PlayersInitHandlers.add(handler);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function registerPlayersFinishedHandler(handler)
|
|
|
|
|
{
|
2019-10-18 17:26:34 -07:00
|
|
|
g_PlayerFinishedHandlers.add(handler);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function registerSimulationUpdateHandler(handler)
|
|
|
|
|
{
|
2019-10-18 17:26:34 -07:00
|
|
|
g_SimulationUpdateHandlers.add(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unregisterSimulationUpdateHandler(handler)
|
|
|
|
|
{
|
|
|
|
|
g_SimulationUpdateHandlers.delete(handler);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function registerEntitySelectionChangeHandler(handler)
|
|
|
|
|
{
|
2019-10-18 17:26:34 -07:00
|
|
|
g_EntitySelectionChangeHandlers.add(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unregisterEntitySelectionChangeHandler(handler)
|
|
|
|
|
{
|
|
|
|
|
g_EntitySelectionChangeHandlers.delete(handler);
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function registerHotkeyChangeHandler(handler)
|
|
|
|
|
{
|
2019-10-21 08:00:59 -07:00
|
|
|
g_HotkeyChangeHandlers.add(handler);
|
2018-04-04 09:53:31 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-23 15:34:35 -08:00
|
|
|
function updatePlayerData()
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const simState = GetSimState();
|
2017-02-23 15:34:35 -08:00
|
|
|
if (!simState)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
const playerData = [];
|
2017-02-23 15:34:35 -08:00
|
|
|
|
|
|
|
|
for (let i = 0; i < simState.players.length; ++i)
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const playerState = simState.players[i];
|
2017-02-23 15:34:35 -08:00
|
|
|
|
|
|
|
|
playerData.push({
|
|
|
|
|
"name": playerState.name,
|
2026-02-21 08:35:27 -08:00
|
|
|
"id": i,
|
2017-02-23 15:34:35 -08:00
|
|
|
"civ": playerState.civ,
|
|
|
|
|
"color": {
|
|
|
|
|
"r": playerState.color.r * 255,
|
|
|
|
|
"g": playerState.color.g * 255,
|
|
|
|
|
"b": playerState.color.b * 255,
|
|
|
|
|
"a": playerState.color.a * 255
|
|
|
|
|
},
|
|
|
|
|
"team": playerState.team,
|
2023-06-18 23:33:33 -07:00
|
|
|
"teamLocked": playerState.teamLocked,
|
2017-02-23 15:34:35 -08:00
|
|
|
"state": playerState.state,
|
|
|
|
|
"isAlly": playerState.isAlly,
|
|
|
|
|
"isMutualAlly": playerState.isMutualAlly,
|
|
|
|
|
"isNeutral": playerState.isNeutral,
|
|
|
|
|
"isEnemy": playerState.isEnemy,
|
|
|
|
|
"guid": undefined, // network guid for players controlled by hosts
|
|
|
|
|
"offline": g_Players[i] && !!g_Players[i].offline
|
|
|
|
|
});
|
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-02-12 06:52:21 -08:00
|
|
|
|
|
|
|
|
// This is done here in order to theoretically support the number of players changing.
|
|
|
|
|
if (i >= g_TemplateData.size)
|
|
|
|
|
g_TemplateData.set(i, new Map());
|
2017-02-23 15:34:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const guid in g_PlayerAssignments)
|
2017-02-23 15:34:35 -08:00
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const playerID = g_PlayerAssignments[guid].player;
|
2017-02-23 15:34:35 -08:00
|
|
|
|
|
|
|
|
if (!playerData[playerID])
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
playerData[playerID].guid = guid;
|
|
|
|
|
playerData[playerID].name = g_PlayerAssignments[guid].name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_Players = playerData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-01 23:34:52 -08:00
|
|
|
* @param {number} ent - The entity to get its ID for.
|
|
|
|
|
* @return {number} - The entity ID of the entity or of its garrisonHolder.
|
2017-02-23 15:34:35 -08:00
|
|
|
*/
|
|
|
|
|
function getEntityOrHolder(ent)
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const entState = GetEntityState(ent);
|
2021-01-01 23:34:52 -08:00
|
|
|
if (entState && !entState.position && entState.garrisonable && entState.garrisonable.holder != INVALID_ENTITY)
|
|
|
|
|
return getEntityOrHolder(entState.garrisonable.holder);
|
2017-02-23 15:34:35 -08:00
|
|
|
|
|
|
|
|
return ent;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 04:53:06 -08:00
|
|
|
function initializeMusic()
|
|
|
|
|
{
|
|
|
|
|
initMusic();
|
2017-05-01 03:03:15 -07:00
|
|
|
if (g_ViewedPlayer != -1 && g_CivData[g_Players[g_ViewedPlayer].civ].Music)
|
2016-02-15 04:53:06 -08:00
|
|
|
global.music.storeTracks(g_CivData[g_Players[g_ViewedPlayer].civ].Music);
|
|
|
|
|
global.music.setState(global.music.states.PEACE);
|
2026-03-20 09:06:22 -07:00
|
|
|
|
|
|
|
|
registerPlayersFinishedHandler((players, won) =>
|
|
|
|
|
{
|
|
|
|
|
if (players.includes(Engine.GetPlayerID()) && !Engine.IsAtlasRunning())
|
|
|
|
|
global.music.setState(won ? global.music.states.VICTORY : global.music.states.DEFEAT);
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-15 04:53:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the player with that ID is in observermode.
|
|
|
|
|
*/
|
|
|
|
|
function isPlayerObserver(playerID)
|
2016-01-19 09:23:16 -08:00
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const playerStates = GetSimState().players;
|
2016-02-15 04:53:06 -08:00
|
|
|
return !playerStates[playerID] || playerStates[playerID].state != "active";
|
2015-05-08 08:21:09 -07:00
|
|
|
}
|
|
|
|
|
|
2016-01-09 14:01:08 -08:00
|
|
|
/**
|
|
|
|
|
* Returns true if the current user can issue commands for that player.
|
|
|
|
|
*/
|
|
|
|
|
function controlsPlayer(playerID)
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const playerStates = GetSimState().players;
|
2016-06-09 07:47:25 -07:00
|
|
|
|
2019-07-23 14:46:32 -07:00
|
|
|
return !!playerStates[Engine.GetPlayerID()] &&
|
2016-07-04 17:51:15 -07:00
|
|
|
playerStates[Engine.GetPlayerID()].controlsAll ||
|
|
|
|
|
Engine.GetPlayerID() == playerID &&
|
2019-07-23 14:46:32 -07:00
|
|
|
!!playerStates[playerID] &&
|
2016-07-04 17:51:15 -07:00
|
|
|
playerStates[playerID].state != "defeated";
|
2016-01-09 14:01:08 -08:00
|
|
|
}
|
|
|
|
|
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
function resumeGame()
|
2015-05-08 08:21:09 -07:00
|
|
|
{
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
g_PauseControl.implicitResume();
|
2013-07-28 17:53:44 -07:00
|
|
|
}
|
2011-09-10 20:30:41 -07:00
|
|
|
|
2019-10-18 07:11:43 -07:00
|
|
|
function closeOpenDialogs()
|
2012-08-05 11:07:56 -07:00
|
|
|
{
|
2019-10-18 07:11:43 -07:00
|
|
|
g_Menu.close();
|
|
|
|
|
g_Chat.closePage();
|
|
|
|
|
g_DiplomacyDialog.close();
|
2025-04-22 03:41:46 -07:00
|
|
|
g_MatchSettingsDialog.close();
|
2019-10-18 07:11:43 -07:00
|
|
|
g_TradeDialog.close();
|
2012-08-05 11:07:56 -07:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 12:06:33 -07:00
|
|
|
/**
|
|
|
|
|
* Put together an open request for the next GUI page to show after closing the session.
|
|
|
|
|
* This could be, depending on the situation, the the summary screen, the main menu, the lobby, etc.
|
|
|
|
|
*/
|
|
|
|
|
function getNextPageOpenRequest(showSummary)
|
2010-06-30 14:34:44 -07:00
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const summaryData = {
|
2026-06-11 12:06:33 -07:00
|
|
|
"sim": Engine.GuiInterfaceCall("GetReplayMetadata"),
|
2016-06-25 20:36:55 -07:00
|
|
|
"gui": {
|
2018-01-06 17:12:27 -08:00
|
|
|
"dialog": false,
|
2026-06-11 12:06:33 -07:00
|
|
|
"assignedPlayer": Engine.GetPlayerID(),
|
2016-06-25 20:36:55 -07:00
|
|
|
"disconnected": g_Disconnected,
|
|
|
|
|
"isReplay": g_IsReplay,
|
2026-06-11 12:06:33 -07:00
|
|
|
"replayDirectory": !g_HasRejoined && Engine.GetCurrentReplayDirectory(),
|
2016-06-25 20:36:55 -07:00
|
|
|
"replaySelectionData": g_ReplaySelectionData
|
|
|
|
|
}
|
2021-03-02 07:43:44 -08:00
|
|
|
};
|
|
|
|
|
|
2021-03-19 03:02:10 -07:00
|
|
|
if (g_InitAttributes.campaignData)
|
2021-03-02 07:43:44 -08:00
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const menu = g_CampaignSession.getMenu();
|
2021-03-19 03:02:10 -07:00
|
|
|
if (g_InitAttributes.campaignData.skipSummary)
|
2025-08-09 07:14:41 -07:00
|
|
|
return { "page": menu };
|
2026-06-11 12:06:33 -07:00
|
|
|
|
2021-03-19 03:02:10 -07:00
|
|
|
summaryData.campaignData = { "filename": g_InitAttributes.campaignData.run };
|
2021-03-02 07:43:44 -08:00
|
|
|
summaryData.nextPage = menu;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 23:31:16 -07:00
|
|
|
if (showSummary)
|
2025-08-09 07:14:41 -07:00
|
|
|
return { "page": "page_summary.xml", "argument": summaryData };
|
|
|
|
|
if (g_InitAttributes.campaignData)
|
|
|
|
|
return { "page": summaryData.nextPage, "argument": summaryData.campaignData };
|
|
|
|
|
if (Engine.HasXmppClient())
|
|
|
|
|
return { "page": "page_lobby.xml", "argument": { "dialog": false } };
|
|
|
|
|
if (g_IsReplay)
|
|
|
|
|
return { "page": "page_replaymenu.xml" };
|
|
|
|
|
|
|
|
|
|
return { "page": "page_pregame.xml" };
|
2010-06-30 14:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return some data that we'll use when hotloading this file after changes
|
|
|
|
|
function getHotloadData()
|
|
|
|
|
{
|
2019-10-06 07:42:12 -07:00
|
|
|
return {
|
|
|
|
|
"selection": g_Selection.selected,
|
|
|
|
|
"playerAssignments": g_PlayerAssignments,
|
|
|
|
|
"player": g_Players,
|
2026-03-11 08:32:30 -07:00
|
|
|
"tutorial": g_TutorialManager.getHotloadData()
|
2019-10-06 07:42:12 -07:00
|
|
|
};
|
2010-06-30 14:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
2011-10-29 17:07:28 -07:00
|
|
|
function getSavedGameData()
|
|
|
|
|
{
|
2015-12-13 21:37:34 -08:00
|
|
|
return {
|
|
|
|
|
"groups": g_Groups.groups
|
|
|
|
|
};
|
2011-10-29 17:07:28 -07:00
|
|
|
}
|
2011-09-11 15:42:40 -07:00
|
|
|
|
2012-05-06 21:18:54 -07:00
|
|
|
function restoreSavedGameData(data)
|
|
|
|
|
{
|
2014-04-06 09:27:57 -07:00
|
|
|
// Restore camera if any
|
|
|
|
|
if (data.camera)
|
|
|
|
|
Engine.SetCameraData(data.camera.PosX, data.camera.PosY, data.camera.PosZ,
|
|
|
|
|
data.camera.RotX, data.camera.RotY, data.camera.Zoom);
|
|
|
|
|
|
2013-10-10 16:58:29 -07:00
|
|
|
// Clear selection when loading a game
|
|
|
|
|
g_Selection.reset();
|
|
|
|
|
|
2012-05-06 21:18:54 -07:00
|
|
|
// Restore control groups
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const groupNumber in data.groups)
|
2012-05-06 21:18:54 -07:00
|
|
|
{
|
|
|
|
|
g_Groups.groups[groupNumber].groups = data.groups[groupNumber].groups;
|
|
|
|
|
g_Groups.groups[groupNumber].ents = data.groups[groupNumber].ents;
|
|
|
|
|
}
|
|
|
|
|
updateGroups();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 12:22:22 -07:00
|
|
|
/**
|
|
|
|
|
* Called every frame.
|
|
|
|
|
*/
|
2010-06-30 14:34:44 -07:00
|
|
|
function onTick()
|
|
|
|
|
{
|
2015-09-13 12:15:07 -07:00
|
|
|
if (!g_Settings)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
const now = Date.now();
|
|
|
|
|
const tickLength = now - g_LastTickTime;
|
2017-06-18 12:11:24 -07:00
|
|
|
g_LastTickTime = now;
|
2011-10-29 17:07:28 -07:00
|
|
|
|
2012-03-08 12:42:28 -08:00
|
|
|
updateCursorAndTooltip();
|
2026-01-04 06:22:19 -08:00
|
|
|
updateTimers();
|
|
|
|
|
|
|
|
|
|
if (g_CinemaOverlay.isInCutsceneMode())
|
|
|
|
|
return;
|
2010-06-30 14:34:44 -07:00
|
|
|
|
|
|
|
|
if (g_Selection.dirty)
|
2010-08-05 03:20:47 -07:00
|
|
|
{
|
2013-12-05 10:50:29 -08:00
|
|
|
g_Selection.dirty = false;
|
2018-01-15 13:27:30 -08:00
|
|
|
// When selection changed, get the entityStates of new entities
|
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-02-12 06:52:21 -08:00
|
|
|
PreloadMultipleEntityStates(g_Selection.toList());
|
2013-12-05 10:50:29 -08:00
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const handler of g_EntitySelectionChangeHandlers)
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
handler();
|
|
|
|
|
|
2016-02-08 06:01:21 -08:00
|
|
|
updateGUIObjects();
|
2010-08-05 03:20:47 -07:00
|
|
|
|
2020-01-11 02:58:43 -08:00
|
|
|
// Display rally points for selected structures.
|
2016-01-19 09:23:16 -08:00
|
|
|
if (Engine.GetPlayerID() != -1)
|
2014-03-16 16:29:27 -07:00
|
|
|
Engine.GuiInterfaceCall("DisplayRallyPoint", { "entities": g_Selection.toList() });
|
2010-08-05 03:20:47 -07:00
|
|
|
}
|
2017-05-25 18:47:48 -07:00
|
|
|
else if (g_ShowAllStatusBars && now % g_StatusBarUpdate <= tickLength)
|
|
|
|
|
recalculateStatusBarDisplay();
|
2010-08-11 14:04:09 -07:00
|
|
|
|
2011-10-23 14:00:59 -07:00
|
|
|
Engine.GuiInterfaceCall("ClearRenamedEntities");
|
2010-06-30 14:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 07:07:05 -08:00
|
|
|
function onSimulationUpdate()
|
2010-06-30 14:34:44 -07:00
|
|
|
{
|
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-02-12 06:52:21 -08:00
|
|
|
g_EntityStates.clear();
|
2017-09-03 09:37:09 -07:00
|
|
|
g_SimState = undefined;
|
2011-08-30 19:41:21 -07:00
|
|
|
|
2026-08-12 02:14:05 -07:00
|
|
|
Engine.ProfileStart("sdf");
|
|
|
|
|
const info = Engine.GuiInterfaceCall("GetAndClearTemplateChanges");
|
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-02-12 06:52:21 -08:00
|
|
|
if (info.playersWithChangedModifications)
|
|
|
|
|
for (const player of info.playersWithChangedModifications)
|
|
|
|
|
// Player-global modifications changed (e.g. by a technology), so the template data cache needs to be cleared.
|
2026-08-12 02:14:05 -07:00
|
|
|
g_TemplateData[player] = {};
|
|
|
|
|
|
|
|
|
|
// Some changes require reloading some cached values even if the selection itself didn't change.
|
|
|
|
|
if (info.selectionDirty)
|
2020-07-17 01:23:45 -07:00
|
|
|
g_Selection.onChange();
|
2026-08-12 02:14:05 -07:00
|
|
|
|
|
|
|
|
Engine.ProfileStop("sdf");
|
2020-07-17 01:23:45 -07:00
|
|
|
|
2017-09-03 09:37:09 -07:00
|
|
|
if (!GetSimState())
|
2010-06-30 14:34:44 -07:00
|
|
|
return;
|
|
|
|
|
|
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-02-12 06:52:21 -08:00
|
|
|
PreloadMultipleEntityStates(g_Selection.toList());
|
2018-01-15 13:27:30 -08:00
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const handler of g_SimulationUpdateHandlers)
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
handler();
|
|
|
|
|
|
|
|
|
|
// TODO: Move to handlers
|
2026-02-24 07:07:05 -08:00
|
|
|
handleNotifications();
|
2016-02-08 06:01:21 -08:00
|
|
|
updateGUIObjects();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 02:33:03 -07:00
|
|
|
function toggleGUI()
|
|
|
|
|
{
|
|
|
|
|
g_ShowGUI = !g_ShowGUI;
|
2026-01-04 06:22:19 -08:00
|
|
|
Engine.GetGUIObjectByName("primaryOverlays").hidden = !g_ShowGUI;
|
|
|
|
|
Engine.GetGUIObjectByName("supplementaryOverlays").hidden = !g_ShowGUI;
|
2021-04-18 09:23:10 -07:00
|
|
|
}
|
|
|
|
|
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
// TODO: Use event subscription onSimulationUpdate, onEntitySelectionChange, onPlayerViewChange, ... instead
|
2016-02-08 06:01:21 -08:00
|
|
|
function updateGUIObjects()
|
|
|
|
|
{
|
2015-11-28 03:16:13 -08:00
|
|
|
g_Selection.update();
|
|
|
|
|
|
2012-07-23 21:14:09 -07:00
|
|
|
if (g_ShowAllStatusBars)
|
|
|
|
|
recalculateStatusBarDisplay();
|
|
|
|
|
|
2013-11-30 09:30:08 -08:00
|
|
|
if (g_ShowGuarding || g_ShowGuarded)
|
|
|
|
|
updateAdditionalHighlight();
|
|
|
|
|
|
2011-04-26 11:19:16 -07:00
|
|
|
updateGroups();
|
2010-08-11 15:16:16 -07:00
|
|
|
updateSelectionDetails();
|
2011-02-11 03:17:32 -08:00
|
|
|
updateBuildingPlacementPreview();
|
2015-12-13 21:37:34 -08:00
|
|
|
|
2016-06-25 21:40:50 -07:00
|
|
|
if (!g_IsObserver)
|
2014-03-16 16:29:27 -07:00
|
|
|
{
|
|
|
|
|
// Update music state on basis of battle state.
|
2025-05-10 07:42:27 -07:00
|
|
|
const battleState = Engine.GuiInterfaceCall("GetBattleState", g_ViewedPlayer);
|
2014-03-16 16:29:27 -07:00
|
|
|
if (battleState)
|
|
|
|
|
global.music.setState(global.music.states[battleState]);
|
|
|
|
|
}
|
2019-08-05 07:12:55 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-26 11:19:16 -07:00
|
|
|
function updateGroups()
|
|
|
|
|
{
|
2011-06-17 15:13:39 -07:00
|
|
|
g_Groups.update();
|
2016-07-20 09:21:42 -07:00
|
|
|
|
2016-09-16 03:47:00 -07:00
|
|
|
// Determine the sum of the costs of a given template
|
2025-12-30 00:57:37 -08:00
|
|
|
const getCostSum = (ent) =>
|
|
|
|
|
{
|
2026-02-21 09:03:34 -08:00
|
|
|
const cost = GetEntityState(ent).cost;
|
2016-10-07 10:57:03 -07:00
|
|
|
return cost ? Object.keys(cost).map(key => cost[key]).reduce((sum, cur) => sum + cur) : 0;
|
2016-09-16 03:47:00 -07:00
|
|
|
};
|
|
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const i in Engine.GetGUIObjectByName("unitGroupPanel").children)
|
2011-04-26 11:19:16 -07:00
|
|
|
{
|
2022-04-28 10:03:58 -07:00
|
|
|
Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = +i + 1;
|
2016-07-20 09:21:42 -07:00
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
const button = Engine.GetGUIObjectByName("unitGroupButton[" + i + "]");
|
2015-12-13 21:37:34 -08:00
|
|
|
button.hidden = g_Groups.groups[i].getTotalCount() == 0;
|
2025-05-14 08:38:33 -07:00
|
|
|
button.onPress = (function(groupId) { return function() { performGroup((Engine.HotkeyIsPressed("selection.add") ? "add" : "select"), groupId); }; })(i);
|
|
|
|
|
button.onDoublePress = (function(groupId) { return function() { performGroup("snap", groupId); }; })(i);
|
|
|
|
|
button.onPressRight = (function(groupId) { return function() { performGroup("breakUp", groupId); }; })(i);
|
2016-09-16 03:47:00 -07:00
|
|
|
|
2018-12-29 10:15:09 -08:00
|
|
|
// Choose the icon of the most common template (or the most costly if it's not unique)
|
2016-09-16 03:47:00 -07:00
|
|
|
if (g_Groups.groups[i].getTotalCount() > 0)
|
|
|
|
|
{
|
2026-02-21 09:03:34 -08:00
|
|
|
const icon = GetEntityState(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) =>
|
2025-12-30 00:57:37 -08:00
|
|
|
{
|
2016-09-16 03:47:00 -07:00
|
|
|
if (pre.ents.length == cur.ents.length)
|
2017-02-06 14:17:21 -08:00
|
|
|
return getCostSum(pre.ents[0]) > getCostSum(cur.ents[0]) ? pre : cur;
|
2016-09-16 03:47:00 -07:00
|
|
|
return pre.ents.length > cur.ents.length ? pre : cur;
|
2026-02-21 09:03:34 -08:00
|
|
|
}).ents[0]).icon;
|
2016-09-16 03:47:00 -07:00
|
|
|
|
|
|
|
|
Engine.GetGUIObjectByName("unitGroupIcon[" + i + "]").sprite =
|
|
|
|
|
icon ? ("stretched:session/portraits/" + icon) : "groupsIcon";
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-15 05:08:58 -07:00
|
|
|
setPanelObjectPosition(button, i, 1);
|
2011-04-26 11:19:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 04:53:06 -08:00
|
|
|
/**
|
|
|
|
|
* Toggles the display of status bars for all of the player's entities.
|
2016-06-01 17:20:02 -07:00
|
|
|
*
|
2020-08-24 04:50:31 -07:00
|
|
|
* @param {boolean} remove - Whether to hide all previously shown status bars.
|
2016-02-15 04:53:06 -08:00
|
|
|
*/
|
2016-06-01 17:20:02 -07:00
|
|
|
function recalculateStatusBarDisplay(remove = false)
|
2012-07-23 21:14:09 -07:00
|
|
|
{
|
2015-12-13 21:37:34 -08:00
|
|
|
let entities;
|
2016-06-01 17:20:02 -07:00
|
|
|
if (g_ShowAllStatusBars && !remove)
|
2016-05-23 08:26:47 -07:00
|
|
|
entities = g_ViewedPlayer == -1 ?
|
|
|
|
|
Engine.PickNonGaiaEntitiesOnScreen() :
|
|
|
|
|
Engine.PickPlayerEntitiesOnScreen(g_ViewedPlayer);
|
2012-07-23 21:14:09 -07:00
|
|
|
else
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const selected = g_Selection.toList();
|
2021-05-18 08:56:47 -07:00
|
|
|
for (const ent of g_Selection.highlighted)
|
|
|
|
|
selected.push(ent);
|
2012-07-23 21:14:09 -07:00
|
|
|
|
2016-05-23 08:26:47 -07:00
|
|
|
// Remove selected entities from the 'all entities' array,
|
|
|
|
|
// to avoid disabling their status bars.
|
|
|
|
|
entities = Engine.GuiInterfaceCall(
|
|
|
|
|
g_ViewedPlayer == -1 ? "GetNonGaiaEntities" : "GetPlayerEntities", {
|
|
|
|
|
"viewedPlayer": g_ViewedPlayer
|
|
|
|
|
}).filter(idx => selected.indexOf(idx) == -1);
|
2012-07-23 21:14:09 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 08:26:47 -07:00
|
|
|
Engine.GuiInterfaceCall("SetStatusBars", {
|
|
|
|
|
"entities": entities,
|
2018-01-30 07:10:20 -08:00
|
|
|
"enabled": g_ShowAllStatusBars && !remove,
|
2019-04-25 08:58:54 -07:00
|
|
|
"showRank": Engine.ConfigDB_GetValue("user", "gui.session.rankabovestatusbar") == "true",
|
|
|
|
|
"showExperience": Engine.ConfigDB_GetValue("user", "gui.session.experiencestatusbar") == "true"
|
2016-05-23 08:26:47 -07:00
|
|
|
});
|
2012-07-23 21:14:09 -07:00
|
|
|
}
|
|
|
|
|
|
Implement session event subscription system and rewrite TopPanel, PlayerViewControl, GameSpeed, Pausing, ObjectivesDialog to use object orientation, refs #5387.
New controller classes: PlayerViewControl, PauseControl,
GameSpeedControl
New viewer classes: ObjectivesDialog, PauseOverlay, FollowPlayer,
TopPanel (BuildLabel, CivIcon, CounterManager, CounterPopulation,
CounterResource refs 7e14a33411/D1113, GameSpeedButton,
ObjectivesDialogButton)
New events: SimulationUpdate, EntitySelectionChange, ViewedPlayerChange,
PreViewedPlayerChangeHandler, PlayerIDChange, PlayersInit,
PlayersFinished, Pause, DiplomacyColorsChange, HotkeyChange, refs #2604
Improves GUI onSimuationUpdate performance without selected entities by
allegedly 30%.
Delete misleading dead code resign command from leaveGame and rename to
endGame. The command is not sent via network (see fa85527baf) nor
processed in simulation, because the Game instance is deleted
immediately thereafter, introduced in fcedcae052, refs a3e1c68b9a,
39ffb0a6bd, 9f796068f8.
Remove explicitResume 0 value from e57c99c6f6 and 8ae67ed15f which
should have been a false if defined, and is equivalent to the default.
Restore fast forwarding option from cd571035bb/D595 for developers
changing the perspective to observer or player following 56308ec1ad.
Add pausing for the delete dialog missing following 7a7ebaa983.
Differential Revision: https://code.wildfiregames.com/D2378
This was SVN commit r23076.
2019-10-17 08:08:56 -07:00
|
|
|
function removeStatusBarDisplay()
|
|
|
|
|
{
|
|
|
|
|
if (g_ShowAllStatusBars)
|
|
|
|
|
recalculateStatusBarDisplay(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 23:58:47 -07:00
|
|
|
/**
|
|
|
|
|
* Updates the primary/secondary names in the simulation and GUI.
|
|
|
|
|
*/
|
|
|
|
|
function updateDisplayedNames()
|
|
|
|
|
{
|
|
|
|
|
g_SpecificNamesPrimary = Engine.ConfigDB_GetValue("user", "gui.session.howtoshownames") == 0 || Engine.ConfigDB_GetValue("user", "gui.session.howtoshownames") == 2;
|
|
|
|
|
g_ShowSecondaryNames = Engine.ConfigDB_GetValue("user", "gui.session.howtoshownames") == 0 || Engine.ConfigDB_GetValue("user", "gui.session.howtoshownames") == 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-17 07:17:30 -07:00
|
|
|
/**
|
|
|
|
|
* Inverts the given configuration boolean and returns the current state.
|
|
|
|
|
* For example "silhouettes".
|
|
|
|
|
*/
|
|
|
|
|
function toggleConfigBool(configName)
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const enabled = Engine.ConfigDB_GetValue("user", configName) != "true";
|
2022-11-02 00:21:25 -07:00
|
|
|
Engine.ConfigDB_CreateAndSaveValue("user", configName, String(enabled));
|
2017-06-17 07:17:30 -07:00
|
|
|
return enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-30 09:30:08 -08:00
|
|
|
// Update the additional list of entities to be highlighted.
|
|
|
|
|
function updateAdditionalHighlight()
|
|
|
|
|
{
|
2025-05-10 07:42:27 -07:00
|
|
|
const entsAdd = []; // list of entities units to be highlighted
|
|
|
|
|
const entsRemove = [];
|
|
|
|
|
const highlighted = g_Selection.toList();
|
2021-05-18 08:56:47 -07:00
|
|
|
for (const ent of g_Selection.highlighted)
|
|
|
|
|
highlighted.push(ent);
|
2013-11-30 09:30:08 -08:00
|
|
|
|
|
|
|
|
if (g_ShowGuarding)
|
|
|
|
|
// flag the guarding entities to add in this additional highlight
|
2021-05-18 08:56:47 -07:00
|
|
|
for (const sel of g_Selection.toList())
|
2013-11-30 09:30:08 -08:00
|
|
|
{
|
2021-05-18 08:56:47 -07:00
|
|
|
const state = GetEntityState(sel);
|
2013-11-30 09:30:08 -08:00
|
|
|
if (!state.guard || !state.guard.entities.length)
|
|
|
|
|
continue;
|
2015-12-13 21:37:34 -08:00
|
|
|
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const ent of state.guard.entities)
|
2013-11-30 09:30:08 -08:00
|
|
|
if (highlighted.indexOf(ent) == -1 && entsAdd.indexOf(ent) == -1)
|
|
|
|
|
entsAdd.push(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_ShowGuarded)
|
|
|
|
|
// flag the guarded entities to add in this additional highlight
|
2021-05-18 08:56:47 -07:00
|
|
|
for (const sel of g_Selection.toList())
|
2013-11-30 09:30:08 -08:00
|
|
|
{
|
2021-05-18 08:56:47 -07:00
|
|
|
const state = GetEntityState(sel);
|
2013-11-30 09:30:08 -08:00
|
|
|
if (!state.unitAI || !state.unitAI.isGuarding)
|
|
|
|
|
continue;
|
2025-05-10 07:42:27 -07:00
|
|
|
const ent = state.unitAI.isGuarding;
|
2013-11-30 09:30:08 -08:00
|
|
|
if (highlighted.indexOf(ent) == -1 && entsAdd.indexOf(ent) == -1)
|
|
|
|
|
entsAdd.push(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// flag the entities to remove (from the previously added) from this additional highlight
|
2025-05-10 07:42:27 -07:00
|
|
|
for (const ent of g_AdditionalHighlight)
|
2015-12-20 13:20:05 -08:00
|
|
|
if (highlighted.indexOf(ent) == -1 && entsAdd.indexOf(ent) == -1 && entsRemove.indexOf(ent) == -1)
|
2013-11-30 09:30:08 -08:00
|
|
|
entsRemove.push(ent);
|
|
|
|
|
|
2015-12-13 21:37:34 -08:00
|
|
|
_setHighlight(entsAdd, g_HighlightedAlpha, true);
|
|
|
|
|
_setHighlight(entsRemove, 0, false);
|
2013-11-30 09:30:08 -08:00
|
|
|
g_AdditionalHighlight = entsAdd;
|
|
|
|
|
}
|