Ticket #3355: t3355_move_game_speeds_v1.1.patch
File t3355_move_game_speeds_v1.1.patch, 18.9 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
131 131 return sizes; 132 132 } 133 133 134 134 // ==================================================================== 135 135 136 // Load game speed data137 function initGameSpeeds()138 {139 var gameSpeeds = {140 "names": [],141 "speeds": [],142 "default": 0143 };144 145 var data = Engine.ReadJSONFile("simulation/data/game_speeds.json");146 if (!data || !data.Speeds)147 {148 error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)");149 return gameSpeeds;150 }151 152 translateObjectKeys(data, ["Name"]);153 for (var i = 0; i < data.Speeds.length; ++i)154 {155 gameSpeeds.names.push(data.Speeds[i].Name);156 gameSpeeds.speeds.push(data.Speeds[i].Speed);157 158 if (data.Speeds[i].Default)159 gameSpeeds["default"] = i;160 }161 162 return gameSpeeds;163 }164 165 166 // ====================================================================167 168 136 // Convert integer color values to string (for use in GUI objects) 169 137 function rgbToGuiColor(color, alpha) 170 138 { 171 139 var ret; 172 140 if (color && ("r" in color) && ("g" in color) && ("b" in color)) -
binaries/data/mods/public/gui/common/settings.js
29 29 */ 30 30 function loadSettingsValues() 31 31 { 32 32 var settings = { 33 33 "Ceasefire": loadCeasefire(), 34 "GameSpeeds": loadSettingValuesFile("game_speeds.json"), 34 35 "PopulationCapacities": loadPopulationCapacities(), 35 36 "StartingResources": loadSettingValuesFile("starting_resources.json") 36 37 }; 37 38 38 39 if (Object.keys(settings).some(key => settings[key] === undefined)) … … 129 130 for (let property in settingValues[index]) 130 131 { 131 132 if (property == "Default") 132 133 continue; 133 134 134 if ( index == 0)135 if (!settings[property]) 135 136 settings[property] = []; 136 137 137 138 // Switch property and index 138 139 settings[property][index] = settingValues[index][property]; 139 140 } -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
4 4 const DEFAULT_OFFLINE_MAP = "Acropolis 01"; 5 5 6 6 const VICTORY_DEFAULTIDX = 1; 7 7 8 8 const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined); 9 const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined); 9 10 const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined); 10 11 const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined); 11 12 12 13 //////////////////////////////////////////////////////////////////////////////////////////////// 13 14 … … 43 44 var g_DefaultPlayerData = []; 44 45 var g_GameAttributes = { 45 46 settings: {} 46 47 }; 47 48 48 var g_GameSpeeds = {};49 49 var g_MapSizes = {}; 50 50 51 51 var g_AIs = []; 52 52 53 53 var g_ChatMessages = []; … … 123 123 g_DefaultPlayerData = initPlayerDefaults(); 124 124 g_DefaultPlayerData.shift(); 125 125 for (var i = 0; i < g_DefaultPlayerData.length; ++i) 126 126 g_DefaultPlayerData[i].Civ = "random"; 127 127 128 g_GameSpeeds = initGameSpeeds();129 128 g_MapSizes = initMapSizes(); 130 129 131 130 // Init civs 132 131 initCivNameList(); 133 132 … … 181 180 numPlayersSelection.selected = g_MaxPlayers - 1; 182 181 183 182 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 184 183 gameSpeed.hidden = false; 185 184 Engine.GetGUIObjectByName("gameSpeedText").hidden = true; 186 gameSpeed.list = g_GameSpeeds. names;187 gameSpeed.list_data = g_GameSpeeds. speeds;185 gameSpeed.list = g_GameSpeeds.Title; 186 gameSpeed.list_data = g_GameSpeeds.Speed; 188 187 gameSpeed.onSelectionChange = function() { 189 188 if (this.selected != -1) 190 g_GameAttributes.gameSpeed = g_GameSpeeds. speeds[this.selected];189 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected]; 191 190 192 191 updateGameAttributes(); 193 192 } 194 gameSpeed.selected = g_GameSpeeds ["default"];193 gameSpeed.selected = g_GameSpeeds.Default; 195 194 196 195 var populationCaps = Engine.GetGUIObjectByName("populationCap"); 197 196 populationCaps.list = g_PopulationCapacities.Title; 198 197 populationCaps.list_data = g_PopulationCapacities.Population; 199 198 populationCaps.selected = g_PopulationCapacities.Default; … … 772 771 } 773 772 774 773 if (attrs.gameSpeed) 775 774 { 776 775 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 777 gameSpeedBox.selected = g_GameSpeeds. speeds.indexOf(attrs.gameSpeed);776 gameSpeedBox.selected = g_GameSpeeds.Speed.indexOf(attrs.gameSpeed); 778 777 } 779 778 780 779 if (!Engine.HasXmppClient()) 781 780 { 782 781 g_GameAttributes.settings.RatingEnabled = false; … … 1222 1221 var gameSpeedText = Engine.GetGUIObjectByName("gameSpeedText"); 1223 1222 var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); 1224 1223 1225 1224 // We have to check for undefined on these properties as not all maps define them. 1226 1225 var sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]); 1227 var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"];1228 1226 var victories = getVictoryConditions(); 1229 1227 var victoryIdx = (mapSettings.GameType !== undefined && victories.data.indexOf(mapSettings.GameType) != -1 ? victories.data.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX); 1230 1228 enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true); 1231 1229 enableCheatsText.caption = (enableCheats.checked ? translate("Yes") : translate("No")); 1232 1230 if (mapSettings.RatingEnabled !== undefined) … … 1241 1239 enableRatingText.caption = "Unknown"; 1242 1240 1243 1241 observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin; 1244 1242 observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No"); 1245 1243 1246 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 1244 var speedIdx = g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) != -1 ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1245 gameSpeedText.caption = g_GameSpeeds.Title[speedIdx]; 1247 1246 gameSpeedBox.selected = speedIdx; 1247 1248 1248 populationCap.selected = mapSettings.PopulationCap !== undefined && g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; 1249 1249 populationCapText.caption = g_PopulationCapacities.Title[populationCap.selected]; 1250 1250 startingResources.selected = mapSettings.StartingResources !== undefined && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; 1251 1251 startingResourcesText.caption = g_StartingResources.Title[startingResources.selected]; 1252 1252 ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; -
binaries/data/mods/public/gui/session/session.js
1 const g_IsReplay = Engine.IsVisualReplay(); 2 const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly || g_IsReplay) : undefined); 3 1 4 // Network Mode 2 5 var g_IsNetworked = false; 3 6 4 7 // Is this user in control of game settings (i.e. is a network server, or offline player) 5 8 var g_IsController; … … 11 14 // Cache the basic player data (name, civ, color) 12 15 var g_Players = []; 13 16 // Cache the useful civ data 14 17 var g_CivData = {}; 15 18 16 var g_GameSpeeds = {};17 var g_CurrentSpeed;18 19 19 var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } }; 20 20 21 21 // Cache dev-mode settings that are frequently or widely used 22 22 var g_DevSettings = { 23 23 controlAll: false … … 142 142 } 143 143 144 144 return g_TechnologyData[technologyName]; 145 145 } 146 146 147 // Init148 147 function init(initData, hotloadData) 149 148 { 149 if (!g_Settings) 150 { 151 Engine.EndGame(); 152 Engine.SwitchGuiPage("page_pregame.xml"); 153 return; 154 } 155 150 156 if (initData) 151 157 { 152 158 g_IsNetworked = initData.isNetworked; // Set network mode 153 159 g_IsController = initData.isController; // Set controller mode 154 160 g_PlayerAssignments = initData.playerAssignments; … … 175 181 if (Engine.GetPlayerID() <= 0) 176 182 g_IsObserver = true; 177 183 178 184 updateTopPanel(); 179 185 180 g_GameSpeeds = initGameSpeeds();181 g_CurrentSpeed = Engine.GetSimRate();182 186 var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 183 gameSpeed.list = g_GameSpeeds. names;184 gameSpeed.list_data = g_GameSpeeds. speeds;185 var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed);186 gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"];187 gameSpeed.list = g_GameSpeeds.Title; 188 gameSpeed.list_data = g_GameSpeeds.Speed; 189 var gameSpeedIdx = g_GameSpeeds.Speed.indexOf(Engine.GetSimRate()); 190 gameSpeed.selected = gameSpeedIdx != -1 ? gameSpeedIdx : g_GameSpeeds.Default; 187 191 gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); } 188 192 initMenuPosition(); // set initial position 189 193 190 194 // Populate player selection dropdown 191 195 var playerNames = []; … … 398 402 /** 399 403 * Called every frame. 400 404 */ 401 405 function onTick() 402 406 { 407 if (!g_Settings) 408 return; 409 403 410 var now = new Date; 404 411 var tickLength = new Date - lastTickTime; 405 412 lastTickTime = now; 406 413 407 414 checkPlayerState(); … … 507 514 508 515 function changeGameSpeed(speed) 509 516 { 510 517 // For non-networked games only 511 518 if (!g_IsNetworked) 512 {513 519 Engine.SetSimRate(speed); 514 g_CurrentSpeed = speed;515 }516 520 } 517 521 518 522 /** 519 523 * Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation 520 524 * update (see session.xml), or from onTick when the selection has changed. -
binaries/data/mods/public/gui/session/session.xml
6 6 <script file="gui/common/functions_civinfo.js"/> 7 7 <script file="gui/common/functions_global_object.js"/> 8 8 <script file="gui/common/functions_utility.js"/> 9 9 <script file="gui/common/l10n.js"/> 10 10 <script file="gui/common/music.js"/> 11 <script file="gui/common/settings.js"/> 11 12 <script file="gui/common/timer.js"/> 12 13 <script file="gui/common/tooltips.js"/> 13 14 <!-- load all scripts in this directory --> 14 15 <script directory="gui/session/"/> 15 16 -
binaries/data/mods/public/l10n/messages.json
451 451 } 452 452 }, 453 453 { 454 454 "extractor": "json", 455 455 "filemasks": [ 456 "simulation/data/game_speeds.json",457 456 "simulation/data/player_defaults.json" 458 457 ], 459 458 "options": { 460 459 "keywords": [ 461 460 "Name" … … 463 462 } 464 463 }, 465 464 { 466 465 "extractor": "json", 467 466 "filemasks": [ 467 "simulation/data/settings/game_speeds.json" 468 ], 469 "options": { 470 "keywords": ["Title"] 471 } 472 }, 473 { 474 "extractor": "json", 475 "filemasks": [ 468 476 "simulation/data/settings/starting_resources.json" 469 477 ], 470 478 "options": { 471 479 "keywords": ["Title"], 472 480 "context": "startingResources" -
binaries/data/mods/public/simulation/data/game_speeds.json
1 {2 "Speeds":3 [4 {5 "Name": "Turtle (0.1x)",6 "Speed": 0.107 },8 {9 "Name": "Slow (0.25x)",10 "Speed": 0.2511 },12 {13 "Name": "Leisurely (0.5x)",14 "Speed": 0.5015 },16 {17 "Name": "Relaxed (0.75x)",18 "Speed": 0.7519 },20 {21 "Name": "Normal (1x)",22 "Speed": 1.0,23 "Default": true24 },25 {26 "Name": "Fast (1.25x)",27 "Speed": 1.2528 },29 {30 "Name": "Very Fast (1.5x)",31 "Speed": 1.532 },33 {34 "Name": "Insane (2x)",35 "Speed": 2.036 }37 ]38 } -
binaries/data/mods/public/simulation/data/settings/game_speeds.json
1 { 2 "TranslatedKeys": ["Title"], 3 "Data": 4 [ 5 { 6 "Speed": 0.10, 7 "Title": "Turtle (0.1x)" 8 }, 9 { 10 "Speed": 0.25, 11 "Title": "Slow (0.25x)" 12 }, 13 { 14 "Speed": 0.50, 15 "Title": "Leisurely (0.5x)" 16 }, 17 { 18 "Speed": 0.75, 19 "Title": "Relaxed (0.75x)" 20 }, 21 { 22 "Speed": 1.0, 23 "Title": "Normal (1x)", 24 "Default": true 25 }, 26 { 27 "Speed": 1.25, 28 "Title": "Fast (1.25x)" 29 }, 30 { 31 "Speed": 1.5, 32 "Title": "Very Fast (1.5x)" 33 }, 34 { 35 "Speed": 2.0, 36 "Title": "Insane (2x)" 37 }, 38 { 39 "Speed": 5.0, 40 "Title": "Fast Forward (5x)", 41 "ReplayOnly": true 42 }, 43 { 44 "Speed": 10.0, 45 "Title": "Faster Forward (10x)", 46 "ReplayOnly": true 47 }, 48 { 49 "Speed": 20.0, 50 "Title": "Very Fast Forward (20x)", 51 "ReplayOnly": true 52 } 53 ] 54 } -
source/gui/scripting/ScriptFunctions.cpp
179 179 std::wstring old = g_CursorName; 180 180 g_CursorName = name; 181 181 return old; 182 182 } 183 183 184 bool IsVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) 185 { 186 return g_Game ? g_Game->IsVisualReplay() : false; 187 } 188 184 189 int GetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) 185 190 { 186 191 if (g_Game) 187 192 return g_Game->GetPlayerID(); 188 193 return -1; … … 976 981 scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave"); 977 982 scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad"); 978 983 979 984 // Misc functions 980 985 scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor"); 986 scriptInterface.RegisterFunction<bool, &IsVisualReplay>("IsVisualReplay"); 981 987 scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID"); 982 988 scriptInterface.RegisterFunction<void, int, &SetPlayerID>("SetPlayerID"); 983 989 scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL"); 984 990 scriptInterface.RegisterFunction<std::wstring, &GetMatchID>("GetMatchID"); 985 991 scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas"); -
source/ps/Game.cpp
70 70 m_GameStarted(false), 71 71 m_Paused(false), 72 72 m_SimRate(1.0f), 73 73 m_PlayerID(-1), 74 74 m_IsSavedGame(false), 75 m_Is Replay(false),75 m_IsVisualReplay(false), 76 76 m_ReplayStream(NULL) 77 77 { 78 78 // TODO: should use CDummyReplayLogger unless activated by cmd-line arg, perhaps? 79 79 if (replayLog) 80 80 m_ReplayLogger = new CReplayLogger(m_Simulation2->GetScriptInterface()); … … 120 120 m_TurnManager->SetPlayerID(m_PlayerID); 121 121 } 122 122 123 123 int CGame::LoadReplayData() 124 124 { 125 ENSURE(m_Is Replay);125 ENSURE(m_IsVisualReplay); 126 126 ENSURE(!m_ReplayPath.empty()); 127 127 ENSURE(m_ReplayStream); 128 128 129 129 CNetReplayTurnManager* replayTurnMgr = static_cast<CNetReplayTurnManager*>(GetTurnManager()); 130 130 … … 165 165 m_FinalReplayTurn = currentTurn; 166 166 replayTurnMgr->StoreFinalReplayTurn(currentTurn); 167 167 return 0; 168 168 } 169 169 170 bool CGame::Start Replay(const std::string& replayPath)170 bool CGame::StartVisualReplay(const std::string& replayPath) 171 171 { 172 m_Is Replay = true;172 m_IsVisualReplay = true; 173 173 ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); 174 174 175 175 SetTurnManager(new CNetReplayTurnManager(*m_Simulation2, GetReplayLogger())); 176 176 177 177 m_ReplayPath = replayPath; … … 248 248 RegMemFun(g_Renderer.GetSingletonPtr()->GetWaterManager(), &WaterManager::LoadWaterTextures, L"LoadWaterTextures", 80); 249 249 250 250 if (m_IsSavedGame) 251 251 RegMemFun(this, &CGame::LoadInitialState, L"Loading game", 1000); 252 252 253 if (m_Is Replay)253 if (m_IsVisualReplay) 254 254 RegMemFun(this, &CGame::LoadReplayData, L"Loading replay data", 1000); 255 255 256 256 LDR_EndRegistering(); 257 257 } 258 258 -
source/ps/Game.h
75 75 bool m_Paused; 76 76 77 77 void StartGame(JS::MutableHandleValue attribs, const std::string& savedState); 78 78 PSRETURN ReallyStartGame(); 79 79 80 bool Start Replay(const std::string& replayPath);80 bool StartVisualReplay(const std::string& replayPath); 81 81 82 82 /** 83 83 * Periodic heartbeat that controls the process. performs all per-frame updates. 84 84 * Simulation update is called and game status update is called. 85 85 * … … 114 114 { 115 115 return m_GameStarted; 116 116 } 117 117 118 118 /** 119 * Get m_IsVisualReplay. 120 * 121 * @return bool the value of m_IsVisualReplay. 122 **/ 123 inline bool IsVisualReplay() 124 { return m_IsVisualReplay; } 125 126 /** 119 127 * Get the pointer to the game world object. 120 128 * 121 129 * @return CWorld * the value of m_World. 122 130 **/ 123 131 inline CWorld *GetWorld() … … 175 183 std::string m_InitialSavedState; // valid between RegisterInit and LoadInitialState 176 184 bool m_IsSavedGame; // true if loading a saved game; false for a new game 177 185 178 186 int LoadReplayData(); 179 187 std::string m_ReplayPath; 180 bool m_Is Replay;188 bool m_IsVisualReplay; 181 189 std::istream* m_ReplayStream; 182 190 u32 m_FinalReplayTurn; 183 191 }; 184 192 185 193 extern CGame *g_Game; -
source/ps/GameSetup/GameSetup.cpp
1476 1476 if (!FileExists(OsPath(replayFile))) 1477 1477 return false; 1478 1478 1479 1479 g_Game = new CGame(false, false); 1480 1480 g_Game->SetPlayerID(-1); 1481 g_Game->Start Replay(replayFile);1481 g_Game->StartVisualReplay(replayFile); 1482 1482 1483 1483 // TODO: Non progressive load can fail - need a decent way to handle this 1484 1484 LDR_NonprogressiveLoad(); 1485 1485 1486 1486 PSRETURN ret = g_Game->ReallyStartGame();