LCOV - code coverage report
Current view: top level - source/ps/GameSetup - Config.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 50 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 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/CStr.h"
      23             : #include "ps/ConfigDB.h"
      24             : #include "ps/GameSetup/CmdLineArgs.h"
      25             : #include "ps/Profiler2.h"
      26             : 
      27             : #include <cstddef>
      28             : #include <vector>
      29             : 
      30             : // (these variables are documented in the header.)
      31             : bool g_PauseOnFocusLoss = false;
      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 :     g_PauseOnFocusLoss = g_ConfigDB.Get("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(':') != std::string::npos)
      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           0 :         }
      62           0 :     }
      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             :     {
      93           0 :         const CStr str{args.Get("serializationtest")};
      94           0 :         g_ConfigDB.SetValueString(CFG_COMMAND, "serializationtest", str.empty() ? "0" : str);
      95           0 :     }
      96             : 
      97           0 :     if (args.Has("rejointest"))
      98           0 :         g_ConfigDB.SetValueString(CFG_COMMAND, "rejointest", args.Get("rejointest"));
      99           0 : }
     100             : 
     101             : 
     102           0 : void CONFIG_Init(const CmdLineArgs& args)
     103             : {
     104           0 :     PROFILE2("CONFIG_Init");
     105             : 
     106           0 :     CConfigDB::Initialise();
     107             : 
     108             :     // Load the global, default config file
     109           0 :     g_ConfigDB.SetConfigFile(CFG_DEFAULT, L"config/default.cfg");
     110           0 :     g_ConfigDB.Reload(CFG_DEFAULT); // 216ms
     111             :     // Try loading the local system config file (which doesn't exist by
     112             :     // default) - this is designed as a way of letting developers edit the
     113             :     // system config without accidentally committing their changes back to SVN.
     114           0 :     g_ConfigDB.SetConfigFile(CFG_SYSTEM, L"config/local.cfg");
     115           0 :     g_ConfigDB.Reload(CFG_SYSTEM);
     116             : 
     117           0 :     g_ConfigDB.SetConfigFile(CFG_USER, L"config/user.cfg");
     118           0 :     g_ConfigDB.Reload(CFG_USER);
     119             : 
     120           0 :     g_ConfigDB.SetConfigFile(CFG_MOD, L"config/mod.cfg");
     121             :     // No point in reloading mod.cfg here - we haven't mounted mods yet
     122             : 
     123           0 :     ProcessCommandLineArgs(args);
     124             : 
     125             :     // Collect information from system.cfg, the profile file,
     126             :     // and any command-line overrides to fill in the globals.
     127           0 :     LoadGlobals();  // 64ms
     128           0 : }

Generated by: LCOV version 1.16