1
0
forked from 0ad/0ad

Cache gameAttributes in the session. Patch by Imarok, refs #3143, #3263.

This was SVN commit r18452.
This commit is contained in:
elexis 2016-06-29 01:45:20 +00:00
parent 46cabf0fde
commit a23884d79a
3 changed files with 11 additions and 27 deletions

View File

@ -619,7 +619,7 @@ function openGameSummary()
let extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
Engine.PushGuiPage("page_summary.xml", {
"sim": {
"mapSettings": Engine.GetMapSettings(),
"mapSettings": g_GameAttributes.settings,
"playerStates": extendedSimState.players,
"timeElapsed" : extendedSimState.timeElapsed
},

View File

@ -12,6 +12,11 @@ const g_PopulationAlertColor = "orange";
*/
const g_Ambient = [ "audio/ambient/dayscape/day_temperate_gen_03.ogg" ];
/**
* Map, player and match settings set in gamesetup.
*/
var g_GameAttributes;
/**
* Is this user in control of game settings (i.e. is a network server, or offline player).
*/
@ -63,11 +68,6 @@ var g_ViewedPlayer = Engine.GetPlayerID();
*/
var g_FollowPlayer = false;
/**
* Unique ID for lobby reports.
*/
var g_MatchID;
/**
* Cache the basic player data (name, civ, color).
*/
@ -230,7 +230,7 @@ function init(initData, hotloadData)
g_IsNetworked = initData.isNetworked;
g_IsController = initData.isController;
g_PlayerAssignments = initData.playerAssignments;
g_MatchID = initData.attribs.matchID;
g_GameAttributes = initData.attribs;
g_ReplaySelectionData = initData.replaySelectionData;
g_HasRejoined = initData.isRejoining;
@ -485,7 +485,7 @@ function updateTopPanel()
function reportPerformance(time)
{
let settings = Engine.GetMapSettings();
let settings = g_GameAttributes.settings;
Engine.SubmitUserReport("profile", 3, JSON.stringify({
"time": time,
"map": settings.Name,
@ -526,7 +526,7 @@ function leaveGame(willRejoin)
let simData = {
"timeElapsed" : extendedSimState.timeElapsed,
"playerStates": extendedSimState.players,
"mapSettings": Engine.GetMapSettings()
"mapSettings": g_GameAttributes.settings
};
if (!g_IsReplay)
@ -1225,7 +1225,7 @@ function reportGame()
playerStatistics.feminisation = "";
playerStatistics.percentMapExplored = "";
let mapName = Engine.GetMapSettings().Name;
let mapName = g_GameAttributes.settings.Name;
let playerStates = "";
let playerCivs = "";
let teams = "";
@ -1275,7 +1275,7 @@ function reportGame()
reportObject.timeElapsed = extendedSimState.timeElapsed;
reportObject.playerStates = playerStates;
reportObject.playerID = Engine.GetPlayerID();
reportObject.matchID = g_MatchID;
reportObject.matchID = g_GameAttributes.matchID;
reportObject.civs = playerCivs;
reportObject.teams = teams;
reportObject.teamsLocked = String(teamsLocked);

View File

@ -510,21 +510,6 @@ JS::Value LoadMapSettings(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath&
return settings;
}
JS::Value GetMapSettings(ScriptInterface::CxPrivate* pCxPrivate)
{
if (!g_Game)
return JS::UndefinedValue();
JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
JS::RootedValue mapSettings(cx);
g_Game->GetSimulation2()->GetMapSettings(&mapSettings);
return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(
g_Game->GetSimulation2()->GetScriptInterface(),
mapSettings);
}
/**
* Get the current X coordinate of the camera.
*/
@ -1070,7 +1055,6 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
scriptInterface.RegisterFunction<JS::Value, VfsPath, &LoadMapSettings>("LoadMapSettings");
scriptInterface.RegisterFunction<JS::Value, &GetMapSettings>("GetMapSettings");
scriptInterface.RegisterFunction<float, &CameraGetX>("CameraGetX");
scriptInterface.RegisterFunction<float, &CameraGetZ>("CameraGetZ");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");