Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/Settings.cc @ 1645

Last change on this file since 1645 was 1638, checked in by rgrieder, 16 years ago

merged input branch into gui test branch (was about time)
svn save (it's still a mess and CMLs haven't been updated)
I'll have to create a special project to create the tolua_bind files for tolua itself anyway..

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32    Implementation of the Settings class.
33*/
34
35#include "OrxonoxStableHeaders.h"
36#include "Settings.h"
37
38#include "util/String.h"
39#include "core/CoreIncludes.h"
40#include "core/ConfigValueIncludes.h"
41
42namespace orxonox
43{
44
45// Using a macro makes the above list much more readable.
46// Settings::addGameMode adds the mode in a map, so we can access game modes by string.
47#define CreateGameMode(name, showsGraphics, isMaster, hasServer)                                        \
48    const GameMode GameMode::GM_##name = { GameMode::name, showsGraphics, isMaster, hasServer, #name }; \
49    bool temporaryVariable##name = Settings::addGameMode(&GameMode::GM_##name)
50
51    //                          showsGraphics  isMaster  hasServer
52    CreateGameMode(None,        false,         false,    false);
53    CreateGameMode(Unspecified, true,          false,    false);
54    CreateGameMode(Server,      true,          true,     true );
55    CreateGameMode(Client,      true,          false,    false);
56    CreateGameMode(Standalone,  true,          true,     false);
57    CreateGameMode(Dedicated,   false,         true,     true );
58
59    /**
60    @brief
61        Constructor: Registers the object and sets the config-values.
62    */
63    Settings::Settings()
64    {
65        RegisterRootObject(Settings);
66        gameMode_ = GameMode::GM_Unspecified;
67        setConfigValues();
68    }
69
70    /**
71    @brief
72        Returns a unique instance of Core.
73    @return
74        The instance
75    */
76    Settings& Settings::getInstance()
77    {
78        static Settings instance;
79        return instance;
80    }
81
82    /**
83    @brief
84        Function to collect the SetConfigValue-macro calls.
85    */
86    void Settings::setConfigValues()
87    {
88        SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.");
89        if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/')
90        {
91            ModifyConfigValue(dataPath_, set, dataPath_ + "/");
92        }
93
94        if (dataPath_ == "")
95        {
96            ModifyConfigValue(dataPath_, set, "/");
97            COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl;
98        }
99    }
100
101    /**
102    @brief
103        Temporary sets the data path
104    @param path
105        The new data path
106    */
107    void Settings::_tsetDataPath(const std::string& path)
108    {
109        ModifyConfigValue(dataPath_, tset, path);
110    }
111
112    /**
113    @brief
114        Sets the game mode.
115    */
116    /*static*/ void Settings::setGameMode(const std::string& mode)
117    {
118        std::string modeL = getLowercase(mode);
119        std::map<std::string, const GameMode*>::const_iterator it = getInstance().gameModes_.find(modeL);
120        if (it != getInstance().gameModes_.end())
121            getInstance().gameMode_ = *(*it).second;
122        else
123        {
124            COUT(2) << "Warning: mode \"" << mode << "\" doesn't exist. "
125                    << "Defaulting to 'Standalone'" << std::endl;
126            getInstance().gameMode_ = GameMode::GM_Standalone;
127        }
128    }
129
130    /*static*/ bool Settings::addGameMode(const GameMode* mode)
131    {
132        getInstance().gameModes_[getLowercase(mode->name)] = mode;
133        return true;
134    }
135
136
137    /**
138    @brief
139        Gets an argument from the command line by name.
140    @return
141        Is 0 if name was not found.
142    */
143    /*static*/ const Settings::CommandLineArgument* Settings::getCommandLineArgument(const std::string &name)
144    {
145        std::map<std::string, CommandLineArgument>::const_iterator it = getInstance().commandArguments_.find(name);
146        if (it != getInstance().commandArguments_.end())
147        {
148            return &((*it).second);
149        }
150        else
151            return 0;
152    }
153
154}
Note: See TracBrowser for help on using the repository browser.