Line data Source code
1 : /* Copyright (C) 2021 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 "lib/timer.h"
23 : #include "ps/CConsole.h"
24 : #include "ps/CLogger.h"
25 : #include "ps/ConfigDB.h"
26 : #include "ps/GameSetup/CmdLineArgs.h"
27 :
28 : // (these variables are documented in the header.)
29 : bool g_PauseOnFocusLoss = false;
30 :
31 : int g_xres, g_yres;
32 :
33 : bool g_Quickstart = false;
34 : bool g_DisableAudio = false;
35 :
36 : //----------------------------------------------------------------------------
37 : // config
38 : //----------------------------------------------------------------------------
39 :
40 : // Fill in the globals from the config files.
41 0 : static void LoadGlobals()
42 : {
43 0 : CFG_GET_VAL("pauseonfocusloss", g_PauseOnFocusLoss);
44 0 : }
45 :
46 0 : static void ProcessCommandLineArgs(const CmdLineArgs& args)
47 : {
48 : // TODO: all these options (and the ones processed elsewhere) should
49 : // be documented somewhere for users.
50 :
51 : // Handle "-conf=key:value" (potentially multiple times)
52 0 : std::vector<CStr> conf = args.GetMultiple("conf");
53 0 : for (size_t i = 0; i < conf.size(); ++i)
54 : {
55 0 : CStr name_value = conf[i];
56 0 : if (name_value.Find(':') != -1)
57 : {
58 0 : CStr name = name_value.BeforeFirst(":");
59 0 : CStr value = name_value.AfterFirst(":");
60 0 : g_ConfigDB.SetValueString(CFG_COMMAND, name, value);
61 : }
62 : }
63 :
64 0 : if (args.Has("profile"))
65 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "profile", args.Get("profile"));
66 :
67 0 : if (args.Has("quickstart"))
68 : {
69 0 : g_Quickstart = true;
70 0 : g_DisableAudio = true; // do this for backward-compatibility with user expectations
71 : }
72 :
73 0 : if (args.Has("nosound"))
74 0 : g_DisableAudio = true;
75 :
76 0 : if (args.Has("shadows"))
77 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "shadows", "true");
78 :
79 0 : if (args.Has("xres"))
80 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "xres", args.Get("xres"));
81 :
82 0 : if (args.Has("yres"))
83 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "yres", args.Get("yres"));
84 :
85 0 : if (args.Has("vsync"))
86 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "vsync", "true");
87 :
88 0 : if (args.Has("ooslog"))
89 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "ooslog", "true");
90 :
91 0 : if (args.Has("serializationtest"))
92 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "serializationtest", "true");
93 :
94 0 : if (args.Has("rejointest"))
95 0 : g_ConfigDB.SetValueString(CFG_COMMAND, "rejointest", args.Get("rejointest"));
96 0 : }
97 :
98 :
99 0 : void CONFIG_Init(const CmdLineArgs& args)
100 : {
101 0 : TIMER(L"CONFIG_Init");
102 :
103 0 : CConfigDB::Initialise();
104 :
105 : // Load the global, default config file
106 0 : g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
107 0 : g_ConfigDB.Reload(CFG_DEFAULT); // 216ms
108 : // Try loading the local system config file (which doesn't exist by
109 : // default) - this is designed as a way of letting developers edit the
110 : // system config without accidentally committing their changes back to SVN.
111 0 : g_ConfigDB.SetConfigFile(CFG_SYSTEM, L"config/local.cfg");
112 0 : g_ConfigDB.Reload(CFG_SYSTEM);
113 :
114 0 : g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
115 0 : g_ConfigDB.Reload(CFG_USER);
116 :
117 0 : g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
118 : // No point in reloading mod.cfg here - we haven't mounted mods yet
119 :
120 0 : ProcessCommandLineArgs(args);
121 :
122 : // Collect information from system.cfg, the profile file,
123 : // and any command-line overrides to fill in the globals.
124 0 : LoadGlobals(); // 64ms
125 3 : }
|