Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Config.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "Config.h"
21 
22 #include "ps/ConfigDB.h"
23 #include "ps/CConsole.h"
24 #include "ps/CLogger.h"
26 #include "lib/timer.h"
28 
29 // (these variables are documented in the header.)
30 
31 CStrW g_CursorName = L"test";
32 
33 bool g_NoGLS3TC = false;
34 bool g_NoGLAutoMipmap = false;
35 bool g_NoGLVBO = false;
36 
37 bool g_PauseOnFocusLoss = false;
38 
39 bool g_Shadows = false;
40 bool g_ShadowPCF = false;
41 
42 bool g_WaterNormal = false;
43 bool g_WaterRealDepth = false;
44 bool g_WaterFoam = false;
45 bool g_WaterCoastalWaves = false;
46 bool g_WaterRefraction = false;
47 bool g_WaterReflection = false;
48 bool g_WaterShadows = false;
49 
50 bool g_Particles = false;
51 bool g_Silhouettes = false;
52 bool g_ShowSky = false;
53 
54 float g_Gamma = 1.0f;
55 
56 CStr g_RenderPath = "default";
57 
59 bool g_VSync = false;
60 
61 bool g_Quickstart = false;
62 bool g_DisableAudio = false;
63 
64 bool g_JSDebuggerEnabled = false;
66 
67 // flag to switch on drawing terrain overlays
69 
70 // flag to switch on triangulation pathfinding
71 bool g_TriPathfind = false;
72 
73 
74 // If non-empty, specified map will be automatically loaded
75 CStr g_AutostartMap = "";
76 
77 
78 //----------------------------------------------------------------------------
79 // config
80 //----------------------------------------------------------------------------
81 
82 // Fill in the globals from the config files.
83 static void LoadGlobals()
84 {
85  CFG_GET_VAL("vsync", Bool, g_VSync);
86 
87  CFG_GET_VAL("nos3tc", Bool, g_NoGLS3TC);
88  CFG_GET_VAL("noautomipmap", Bool, g_NoGLAutoMipmap);
89  CFG_GET_VAL("novbo", Bool, g_NoGLVBO);
90  CFG_GET_VAL("pauseonfocusloss", Bool, g_PauseOnFocusLoss);
91  CFG_GET_VAL("shadows", Bool, g_Shadows);
92  CFG_GET_VAL("shadowpcf", Bool, g_ShadowPCF);
93 
94  CFG_GET_VAL("waternormals",Bool, g_WaterNormal);
95  CFG_GET_VAL("waterrealdepth",Bool, g_WaterRealDepth);
96  CFG_GET_VAL("waterfoam",Bool, g_WaterFoam);
97  CFG_GET_VAL("watercoastalwaves",Bool, g_WaterCoastalWaves);
99  g_WaterCoastalWaves = false;
100  CFG_GET_VAL("waterrefraction",Bool, g_WaterRefraction);
101  CFG_GET_VAL("waterreflection",Bool, g_WaterReflection);
102  CFG_GET_VAL("watershadows",Bool, g_WaterShadows);
103 
104  CFG_GET_VAL("renderpath", String, g_RenderPath);
105  CFG_GET_VAL("particles", Bool, g_Particles);
106  CFG_GET_VAL("silhouettes", Bool, g_Silhouettes);
107  CFG_GET_VAL("showsky", Bool, g_ShowSky);
108 
109  if (g_SoundManager)
110  {
111  float gain = 0.5f;
112  float musicGain = 0.5f;
113  float ambientGain = 0.5f;
114  float actionGain = 0.5f;
115  float uiGain = 0.5f;
116 
117  CFG_GET_VAL("sound.mastergain", Float, gain);
118  CFG_GET_VAL("sound.musicgain", Float, musicGain);
119  CFG_GET_VAL("sound.ambientgain", Float, ambientGain);
120  CFG_GET_VAL("sound.actiongain", Float, actionGain);
121  CFG_GET_VAL("sound.uigain", Float, uiGain);
122 
123  g_SoundManager->SetMasterGain( gain );
124  g_SoundManager->SetMusicGain( musicGain );
125  g_SoundManager->SetAmbientGain( ambientGain );
126  g_SoundManager->SetActionGain( actionGain );
127  g_SoundManager->SetUIGain( uiGain );
128  }
129 
130 
131  CFG_GET_VAL("jsdebugger.enable", Bool, g_JSDebuggerEnabled);
132  CFG_GET_VAL("profiler2.script.enable", Bool, g_ScriptProfilingEnabled);
133 
134  // Script Debugging and profiling does not make sense together because of the hooks
135  // that reduce performance a lot - and it wasn't tested if it even works together.
137  LOGERROR(L"Enabling both script profiling and script debugging is not supported!");
138 }
139 
140 
141 static void ProcessCommandLineArgs(const CmdLineArgs& args)
142 {
143  // TODO: all these options (and the ones processed elsewhere) should
144  // be documented somewhere for users.
145 
146  if (args.Has("buildarchive"))
147  {
148  // note: VFS init is sure to have been completed by now
149  // (since CONFIG_Init reads from file); therefore,
150  // it is safe to call this from here directly.
151 // vfs_opt_rebuild_main_archive("mods/official/official1.zip", "../logs/trace.txt");
152  }
153 
154  // Handle "-conf=key:value" (potentially multiple times)
155  std::vector<CStr> conf = args.GetMultiple("conf");
156  for (size_t i = 0; i < conf.size(); ++i)
157  {
158  CStr name_value = conf[i];
159  if (name_value.Find(':') != -1)
160  {
161  CStr name = name_value.BeforeFirst(":");
162  CStr value = name_value.AfterFirst(":");
163  g_ConfigDB.CreateValue(CFG_COMMAND, name)->m_String = value;
164  }
165  }
166 
167  if (args.Has("g"))
168  {
169  g_Gamma = args.Get("g").ToFloat();
170  if (g_Gamma == 0.0f)
171  g_Gamma = 1.0f;
172  }
173 
174 // if (args.Has("listfiles"))
175 // trace_enable(true);
176 
177  if (args.Has("profile"))
178  g_ConfigDB.CreateValue(CFG_COMMAND, "profile")->m_String = args.Get("profile");
179 
180  if (args.Has("quickstart"))
181  {
182  g_Quickstart = true;
183  g_DisableAudio = true; // do this for backward-compatibility with user expectations
184  }
185 
186  if (args.Has("nosound"))
187  g_DisableAudio = true;
188 
189  if (args.Has("shadows"))
190  g_ConfigDB.CreateValue(CFG_COMMAND, "shadows")->m_String = "true";
191 
192  if (args.Has("xres"))
193  g_ConfigDB.CreateValue(CFG_COMMAND, "xres")->m_String = args.Get("xres");
194 
195  if (args.Has("yres"))
196  g_ConfigDB.CreateValue(CFG_COMMAND, "yres")->m_String = args.Get("yres");
197 
198  if (args.Has("vsync"))
199  g_ConfigDB.CreateValue(CFG_COMMAND, "vsync")->m_String = "true";
200 
201  if (args.Has("ooslog"))
202  g_ConfigDB.CreateValue(CFG_COMMAND, "ooslog")->m_String = "true";
203 
204  if (args.Has("serializationtest"))
205  g_ConfigDB.CreateValue(CFG_COMMAND, "serializationtest")->m_String = "true";
206 }
207 
208 
209 void CONFIG_Init(const CmdLineArgs& args)
210 {
211  TIMER(L"CONFIG_Init");
212 
213  new CConfigDB;
214 
215  // Load the global, default config file
216  g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
217  g_ConfigDB.Reload(CFG_DEFAULT); // 216ms
218  // Try loading the local system config file (which doesn't exist by
219  // default) - this is designed as a way of letting developers edit the
220  // system config without accidentally committing their changes back to SVN.
221  g_ConfigDB.SetConfigFile(CFG_SYSTEM, L"config/local.cfg");
222  g_ConfigDB.Reload(CFG_SYSTEM);
223 
224  g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
225  g_ConfigDB.Reload(CFG_USER);
226 
227  g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
228  // No point in reloading mod.cfg here - we haven't mounted mods yet
229 
231 
232  // Initialise console history file
233  int max_history_lines = 200;
234  CFG_GET_VAL("console.history.size", Int, max_history_lines);
235  g_Console->UseHistoryFile(L"config/console.txt", max_history_lines);
236 
237  // Collect information from system.cfg, the profile file,
238  // and any command-line overrides to fill in the globals.
239  LoadGlobals(); // 64ms
240 }
CStr Get(const char *name) const
Get the value of the named parameter.
Definition: CmdLineArgs.cpp:71
bool g_Silhouettes
Definition: Config.cpp:51
bool g_TriPathfind
Definition: Config.cpp:71
#define LOGERROR
Definition: CLogger.h:35
CStrW g_CursorName
Definition: Config.cpp:31
ISoundManager * g_SoundManager
int g_xres
Definition: Config.cpp:58
std::vector< CStr > GetMultiple(const char *name) const
Get all the values given to the named parameter.
Definition: CmdLineArgs.cpp:80
#define CFG_GET_VAL(name, type, destination)
Definition: ConfigDB.h:147
bool g_JSDebuggerEnabled
Definition: Config.cpp:64
bool g_WaterRefraction
Definition: Config.cpp:46
bool g_WaterShadows
Definition: Config.cpp:48
bool g_ScriptProfilingEnabled
Definition: Config.cpp:65
static void ProcessCommandLineArgs(const CmdLineArgs &args)
Definition: Config.cpp:141
virtual void SetActionGain(float gain)=0
bool g_Particles
Definition: Config.cpp:50
virtual void SetMasterGain(float gain)=0
void CONFIG_Init(const CmdLineArgs &args)
Definition: Config.cpp:209
CStr g_RenderPath
Definition: Config.cpp:56
CConsole * g_Console
Definition: CConsole.cpp:46
virtual void SetAmbientGain(float gain)=0
bool Has(const char *name) const
Test whether the given name was specified, as either -name or -name=value
Definition: CmdLineArgs.cpp:66
void UseHistoryFile(const VfsPath &filename, int historysize)
Definition: CConsole.cpp:586
bool g_WaterRealDepth
Definition: Config.cpp:43
virtual void SetMusicGain(float gain)=0
int g_yres
Definition: Config.cpp:58
bool g_Quickstart
Definition: Config.cpp:61
bool g_WaterFoam
Definition: Config.cpp:44
bool g_VSync
Definition: Config.cpp:59
bool g_ShowSky
Definition: Config.cpp:52
bool g_WaterReflection
Definition: Config.cpp:47
virtual void SetUIGain(float gain)=0
#define g_ConfigDB
Definition: ConfigDB.h:52
bool g_PauseOnFocusLoss
Definition: Config.cpp:37
#define TIMER(description)
Measures the time taken to execute code up until end of the current scope; displays it via debug_prin...
Definition: timer.h:108
bool g_WaterNormal
Definition: Config.cpp:42
bool g_NoGLVBO
Definition: Config.cpp:35
CStr g_AutostartMap
Definition: Config.cpp:75
bool g_ShadowPCF
Definition: Config.cpp:40
bool g_Shadows
Definition: Config.cpp:39
bool g_NoGLS3TC
Definition: Config.cpp:33
bool g_DisableAudio
Definition: Config.cpp:62
bool g_NoGLAutoMipmap
Definition: Config.cpp:34
static void LoadGlobals()
Definition: Config.cpp:83
bool g_ShowPathfindingOverlay
Definition: Config.cpp:68
bool g_WaterCoastalWaves
Definition: Config.cpp:45
float g_Gamma
Definition: Config.cpp:54