Ticket #785: gamespeed-minimal-03182013.patch
File gamespeed-minimal-03182013.patch, 18.6 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/common/functions_utility.js
134 134 135 135 // ==================================================================== 136 136 137 // Load default player data, for when it's not otherwise specified 138 function initPlayerDefaults() 137 // Parse and return JSON data from file in simulation/data/* 138 // returns valid object or undefined on error 139 function parseJSONFromDataFile(filename) 139 140 { 140 var filename = "simulation/data/player_defaults.json"; 141 var defaults = []; 142 var rawData = readFile(filename); 141 var path = "simulation/data/"+filename; 142 var rawData = readFile(path); 143 143 if (!rawData) 144 error("Failed to read player defaults file: "+filename);145 144 error("Failed to read file: "+path); 145 146 146 try 147 { // Catch nasty errors from JSON parsing 147 { 148 // Catch nasty errors from JSON parsing 148 149 // TODO: Need more info from the parser on why it failed: line number, position, etc! 149 150 var data = JSON.parse(rawData); 150 if (!data || !data.PlayerData) 151 error("Failed to parse player defaults in: "+filename+" (check for valid JSON data)"); 152 153 defaults = data.PlayerData; 151 return data; 154 152 } 155 153 catch(err) 156 154 { 157 error(err.toString()+": parsing player defaults in "+filename);155 error(err.toString()+": parsing JSON data in "+path); 158 156 } 159 157 158 return undefined; 159 } 160 161 // ==================================================================== 162 163 // Load default player data, for when it's not otherwise specified 164 function initPlayerDefaults() 165 { 166 var defaults = []; 167 168 var data = parseJSONFromDataFile("player_defaults.json"); 169 if (!data || !data.PlayerData) 170 error("Failed to parse player defaults in player_defaults.json (check for valid JSON data)"); 171 else 172 defaults = data.PlayerData; 173 160 174 return defaults; 161 175 } 162 176 … … 165 179 // Load map size data 166 180 function initMapSizes() 167 181 { 168 var filename = "simulation/data/map_sizes.json";169 182 var sizes = { 170 names:[],171 tiles: [],172 default: 0183 "names":[], 184 "tiles": [], 185 "default": 0 173 186 }; 174 var rawData = readFile(filename); 175 if (!rawData) 176 error("Failed to read map sizes file: "+filename); 177 178 try 179 { // Catch nasty errors from JSON parsing 180 // TODO: Need more info from the parser on why it failed: line number, position, etc! 181 var data = JSON.parse(rawData); 182 if (!data || !data.Sizes) 183 error("Failed to parse map sizes in: "+filename+" (check for valid JSON data)"); 184 187 188 var data = parseJSONFromDataFile("map_sizes.json"); 189 if (!data || !data.Sizes) 190 error("Failed to parse map sizes in map_sizes.json (check for valid JSON data)"); 191 else 192 { 185 193 for (var i = 0; i < data.Sizes.length; ++i) 186 194 { 187 195 sizes.names.push(data.Sizes[i].LongName); 188 196 sizes.tiles.push(data.Sizes[i].Tiles); 189 197 190 198 if (data.Sizes[i].Default) 191 sizes .default= i;199 sizes["default"] = i; 192 200 } 193 201 } 194 catch(err) 202 203 return sizes; 204 } 205 206 // ==================================================================== 207 208 // Load game speed data 209 function initGameSpeeds() 210 { 211 var gameSpeeds = { 212 "names": [], 213 "speeds": [], 214 "default": 0 215 }; 216 217 var data = parseJSONFromDataFile("game_speeds.json"); 218 if (!data || !data.Speeds) 219 error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)"); 220 else 195 221 { 196 error(err.toString()+": parsing map sizes in "+filename); 222 for (var i = 0; i < data.Speeds.length; ++i) 223 { 224 gameSpeeds.names.push(data.Speeds[i].Name); 225 gameSpeeds.speeds.push(data.Speeds[i].Speed); 226 227 if (data.Speeds[i].Default) 228 gameSpeeds["default"] = i; 229 } 197 230 } 198 199 return sizes;231 232 return gameSpeeds; 200 233 } 201 234 235 202 236 // ==================================================================== 203 237 204 238 // Convert integer color values to string (for use in GUI objects) -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
36 36 settings: {} 37 37 }; 38 38 39 var g_GameSpeeds = {}; 39 40 var g_MapSizes = {}; 40 41 41 42 var g_AIs = []; … … 97 98 g_DefaultPlayerData.shift(); 98 99 for (var i = 0; i < g_DefaultPlayerData.length; i++) 99 100 g_DefaultPlayerData[i].Civ = "random"; 100 101 102 g_GameSpeeds = initGameSpeeds(); 101 103 g_MapSizes = initMapSizes(); 102 104 103 105 // Init civs … … 135 137 numPlayersSelection.list = players; 136 138 numPlayersSelection.list_data = players; 137 139 numPlayersSelection.selected = MAX_PLAYERS - 1; 140 141 var gameSpeed = getGUIObjectByName("gameSpeed"); 142 gameSpeed.hidden = false; 143 getGUIObjectByName("gameSpeedText").hidden = true; 144 gameSpeed.list = g_GameSpeeds.names; 145 gameSpeed.list_data = g_GameSpeeds.speeds; 146 gameSpeed.onSelectionChange = function() 147 { 148 // Update attributes so other players can see change 149 if (this.selected != -1) 150 g_GameAttributes.gameSpeed = g_GameSpeeds.speeds[this.selected]; 138 151 152 if (!g_IsInGuiUpdate) 153 updateGameAttributes(); 154 } 155 gameSpeed.selected = g_GameSpeeds["default"]; 156 139 157 var populationCaps = getGUIObjectByName("populationCap"); 140 158 populationCaps.list = POPULATION_CAP; 141 159 populationCaps.list_data = POPULATION_CAP_DATA; … … 245 263 getGUIObjectByName("mapSelection").hidden = true; 246 264 getGUIObjectByName("victoryConditionText").hidden = false; 247 265 getGUIObjectByName("victoryCondition").hidden = true; 248 266 getGUIObjectByName("gameSpeedText").hidden = false; 267 getGUIObjectByName("gameSpeed").hidden = true; 268 249 269 // Disable player and game options controls 250 270 // TODO: Shouldn't players be able to choose their own assignment? 251 271 for (var i = 0; i < MAX_PLAYERS; ++i) … … 955 975 var enableCheatsText = getGUIObjectByName("enableCheatsText"); 956 976 var populationCapText = getGUIObjectByName("populationCapText"); 957 977 var startingResourcesText = getGUIObjectByName("startingResourcesText"); 958 959 var sizeIdx = (g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes.default); 978 var gameSpeedText = getGUIObjectByName("gameSpeedText"); 979 980 var sizeIdx = (g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]); 981 var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.names.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.names.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"]; 960 982 var victoryIdx = (VICTORY_DATA.indexOf(mapSettings.GameType) != -1 ? VICTORY_DATA.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX); 961 983 enableCheats.checked = (g_GameAttributes.settings.CheatsEnabled === undefined || !g_GameAttributes.settings.CheatsEnabled ? false : true) 962 984 enableCheatsText.caption = (enableCheats.checked ? "Yes" : "No"); 985 gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; 963 986 populationCap.selected = (POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) != -1 ? POPULATION_CAP_DATA.indexOf(mapSettings.PopulationCap) : POPULATION_CAP_DEFAULTIDX); 964 987 populationCapText.caption = POPULATION_CAP[populationCap.selected]; 965 988 startingResources.selected = (STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) != -1 ? STARTING_RESOURCES_DATA.indexOf(mapSettings.StartingResources) : STARTING_RESOURCES_DEFAULTIDX); 966 989 startingResourcesText.caption = STARTING_RESOURCES[startingResources.selected]; 990 967 991 // Handle map type specific logic 968 992 switch (g_GameAttributes.mapType) 969 993 { -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
178 178 </object> 179 179 180 180 <!-- More Options --> 181 <object name="moreOptions" type="image" sprite="StoneWindow" size="50%-200 50%-1 20 50%+200 50%+155" z="70" hidden="true">181 <object name="moreOptions" type="image" sprite="StoneWindow" size="50%-200 50%-150 50%+200 50%+155" z="70" hidden="true"> 182 182 <object style="TitleText" type="text" size="50%-128 11 50%+128 27"> 183 183 More Options 184 184 </object> 185 185 186 186 <object size="14 38 94% 66"> 187 187 <object size="0 0 40% 28"> 188 <object size="0 0 100% 100%" type="text" style="RightLabelText"> Victory condition:</object>188 <object size="0 0 100% 100%" type="text" style="RightLabelText">Game Speed:</object> 189 189 </object> 190 <object name="gameSpeedText" size="40% 0 100% 100%" type="text" style="LeftLabelText"/> 191 <object name="gameSpeed" size="40% 0 100% 28" type="dropdown" style="StoneDropDown" hidden="true" tooltip_style="onscreenToolTip" tooltip="Select game speed."/> 192 </object> 193 194 <object size="14 68 94% 96"> 195 <object size="0 0 40% 28"> 196 <object size="0 0 100% 100%" type="text" style="RightLabelText">Victory Condition:</object> 197 </object> 190 198 <object name="victoryConditionText" size="40% 0 100% 100%" type="text" style="LeftLabelText"/> 191 199 <object name="victoryCondition" size="40% 0 100% 28" type="dropdown" style="StoneDropDown" hidden="true" tooltip_style="onscreenToolTip" tooltip="Select victory condition."/> 192 200 </object> 193 201 194 <object size="14 68 94% 96">202 <object size="14 98 94% 126"> 195 203 <object size="0 0 40% 28"> 196 204 <object size="0 0 100% 100%" type="text" style="RightLabelText">Population Cap:</object> 197 205 </object> … … 199 207 <object name="populationCap" size="40% 0 100% 28" type="dropdown" style="StoneDropDown" hidden="true" tooltip_style="onscreenToolTip" tooltip="Select population cap."/> 200 208 </object> 201 209 202 <object size="14 98 94% 126">210 <object size="14 128 94% 156"> 203 211 <object size="0 0 40% 28"> 204 212 <object size="0 0 100% 100%" type="text" style="RightLabelText">Starting Resources:</object> 205 213 </object> … … 207 215 <object name="startingResources" size="40% 0 100% 28" type="dropdown" style="StoneDropDown" hidden="true" tooltip_style="onscreenToolTip" tooltip="Select the game's starting resources."/> 208 216 </object> 209 217 210 <object size="14 1 28 94% 216">218 <object size="14 158 94% 246"> 211 219 <object size="0 0 40% 28"> 212 <object size="0 0 100% 100%" type="text" style="RightLabelText">Reveal map:</object>220 <object size="0 0 100% 100%" type="text" style="RightLabelText">Reveal Map:</object> 213 221 </object> 214 222 <object size="0 30 40% 58"> 215 <object size="0 0 100% 100%" type="text" style="RightLabelText">Teams locked:</object>223 <object size="0 0 100% 100%" type="text" style="RightLabelText">Teams Locked:</object> 216 224 </object> 217 225 <object size="0 60 40% 88" name="enableCheatsDesc" hidden="true"> 218 226 <object size="0 0 100% 100%" type="text" style="RightLabelText">Cheats:</object> … … 237 245 name="hideMoreOptions" 238 246 type="button" 239 247 style="StoneButton" 240 size="50%-70 2 18 50%+70 246"248 size="50%-70 248 50%+70 274" 241 249 tooltip_style="onscreenToolTip" 242 250 tooltip="Close more game options window" 243 251 > -
binaries/data/mods/public/gui/session/menu.js
361 361 openDiplomacy(); 362 362 }; 363 363 364 function toggleGameSpeed() 365 { 366 var gameSpeed = getGUIObjectByName("gameSpeed"); 367 gameSpeed.hidden = !gameSpeed.hidden; 368 } 369 364 370 function pauseGame() 365 371 { 366 372 getGUIObjectByName("pauseButtonText").caption = RESUME; -
binaries/data/mods/public/gui/session/session.js
6 6 // Cache the useful civ data 7 7 var g_CivData = {}; 8 8 9 var g_GameSpeeds = {}; 10 var g_CurrentSpeed; 11 9 12 var g_PlayerAssignments = { "local": { "name": "You", "player": 1 } }; 10 13 11 14 // Cache dev-mode settings that are frequently or widely used … … 83 86 g_Players = getPlayerData(g_PlayerAssignments); 84 87 85 88 if (initData.savedGUIData) 86 {87 89 restoreSavedGameData(initData.savedGUIData); 88 } 90 91 getGUIObjectByName("gameSpeedButton").hidden = g_IsNetworked; 89 92 } 90 93 else // Needed for autostart loading option 91 94 { … … 96 99 g_CivData = loadCivData(); 97 100 g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" }; 98 101 102 g_GameSpeeds = initGameSpeeds(); 103 g_CurrentSpeed = Engine.GetSimRate(); 104 var gameSpeed = getGUIObjectByName("gameSpeed"); 105 gameSpeed.list = g_GameSpeeds.names; 106 gameSpeed.list_data = g_GameSpeeds.speeds; 107 var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed); 108 gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"]; 109 gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); } 110 99 111 getGUIObjectByName("civIcon").sprite = "stretched:" + g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem; 100 112 getGUIObjectByName("civIcon").tooltip = g_CivData[g_Players[Engine.GetPlayerID()].civ].Name; 101 113 initMenuPosition(); // set initial position … … 347 359 } 348 360 } 349 361 362 function changeGameSpeed(speed) 363 { 364 // For non-networked games only 365 if (!g_IsNetworked) 366 { 367 Engine.SetSimRate(speed); 368 g_CurrentSpeed = speed; 369 } 370 } 371 350 372 /** 351 373 * Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation 352 374 * update (see session.xml), or from onTick when the selection has changed. … … 520 542 521 543 function updateTimeElapsedCounter(simState) 522 544 { 545 var speed = g_CurrentSpeed != 1.0 ? " (" + g_CurrentSpeed + "x)" : ""; 523 546 var timeElapsedCounter = getGUIObjectByName("timeElapsedCounter"); 524 timeElapsedCounter.caption = timeToString(simState.timeElapsed) ;547 timeElapsedCounter.caption = timeToString(simState.timeElapsed) + speed; 525 548 } 526 549 527 550 // Toggles the display of status bars for all of the player's entities. -
binaries/data/mods/public/gui/session/session.xml
220 220 <!-- ================================ ================================ --> 221 221 <!-- Time elapsed counter --> 222 222 <!-- ================================ ================================ --> 223 <object size="100%-100 50 100%-10 70" type="text" name="timeElapsedCounter" style="SettingsText" hotkey="timeelapsedcounter.toggle" hidden="true"> 223 224 <object size="100%-120 45 100%-10 65" type="text" name="timeElapsedCounter" style="SettingsText" hotkey="timeelapsedcounter.toggle" hidden="true"> 224 225 <action on="Press">this.hidden = !this.hidden;</action> 225 226 </object> 226 227 … … 513 514 <!-- ================================ ================================ --> 514 515 515 516 <!-- Displays Alpha name and number --> 516 <object size=" 70%-128 0 70%+128100%" name="alphaLabel" type="text" style="CenteredLabelText" text_valign="top" ghost="true">517 <object size="50%+48 0 100%-226 100%" name="alphaLabel" type="text" style="CenteredLabelText" text_valign="top" ghost="true"> 517 518 ALPHA XIII : Magadha<!-- IMPORTANT: remember to update pregame/mainmenu.xml in sync with this --> 518 519 519 520 <!-- Displays build date and revision number--> … … 522 523 </object> 523 524 </object> 524 525 526 <!-- ================================ ================================ --> 527 <!-- Game Speed Button --> 525 528 <!-- ================================ ================================ --> 529 <object type="button" 530 name="gameSpeedButton" 531 size="100%-226 4 100%-198 32" 532 style="iconButton" 533 tooltip_style="sessionToolTip" 534 tooltip="Game speed" 535 > 536 <object size="5 5 100%-5 100%-5" type="image" sprite="stretched:session/icons/resources/time_small.png" ghost="true"/> 537 <action on="Press"> 538 toggleGameSpeed(); 539 </action> 540 </object> 541 542 <object size="100%-230 45 100%-140 70" name="gameSpeed" type="dropdown" buffer_zone="5" style="StoneDropDown" hidden="true" tooltip="Choose game speed" tooltip_style="sessionToolTip"/> 543 544 <!-- ================================ ================================ --> 526 545 <!-- Diplomacy Button --> 527 546 <!-- ================================ ================================ --> 528 547 <object type="button" 529 548 name="diplomacyButton1" 530 size="100%-19 6 0 100%-16432"549 size="100%-194 4 100%-166 32" 531 550 style="iconButton" 532 551 tooltip_style="sessionToolTip" 533 552 tooltip="Diplomacy" -
source/gui/scripting/ScriptFunctions.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 526 526 g_Game->SetSimRate(rate); 527 527 } 528 528 529 float GetSimRate(void* UNUSED(cbdata)) 530 { 531 return g_Game->GetSimRate(); 532 } 533 529 534 void SetTurnLength(void* UNUSED(cbdata), int length) 530 535 { 531 536 if (g_NetServer) … … 680 685 681 686 // Development/debugging functions 682 687 scriptInterface.RegisterFunction<void, float, &SetSimRate>("SetSimRate"); 688 scriptInterface.RegisterFunction<float, &GetSimRate>("GetSimRate"); 683 689 scriptInterface.RegisterFunction<void, int, &SetTurnLength>("SetTurnLength"); 684 690 scriptInterface.RegisterFunction<void, float, float, float, &SetCameraTarget>("SetCameraTarget"); 685 691 scriptInterface.RegisterFunction<int, &Crash>("Crash"); -
source/ps/Game.cpp
126 126 std::string mapType; 127 127 m_Simulation2->GetScriptInterface().GetProperty(attribs.get(), "mapType", mapType); 128 128 129 float speed; 130 if (m_Simulation2->GetScriptInterface().HasProperty(attribs.get(), "gameSpeed") && m_Simulation2->GetScriptInterface().GetProperty(attribs.get(), "gameSpeed", speed)) 131 SetSimRate(speed); 132 129 133 LDR_BeginRegistering(); 130 134 131 135 RegMemFun(m_Simulation2, &CSimulation2::ProgressiveLoad, L"Simulation init", 1000); -
source/ps/Game.h
145 145 * clamped to 0.0f. 146 146 **/ 147 147 inline void SetSimRate(float simRate) 148 { m_SimRate = std::max(simRate, 0.0f); }148 { if (isfinite(simRate)) m_SimRate = std::max(simRate, 0.0f); } 149 149 150 inline float GetSimRate() 151 { return m_SimRate; } 152 150 153 /** 151 154 * Replace the current turn manager. 152 155 * This class will take ownership of the pointer.