Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2008, 7:49:26 PM (16 years ago)
Author:
rgrieder
Message:

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..

Location:
code/branches/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui

  • code/branches/gui/src/orxonox/Settings.cc

    r1535 r1638  
    2828
    2929/**
    30     @file
    31     @brief Implementation of the Settings class.
     30@file
     31@brief
     32    Implementation of the Settings class.
    3233*/
    3334
     
    3536#include "Settings.h"
    3637
     38#include "util/String.h"
    3739#include "core/CoreIncludes.h"
    3840#include "core/ConfigValueIncludes.h"
     
    4042namespace orxonox
    4143{
    42   /**
    43     @brief Constructor: Registers the object and sets the config-values.
    44   */
    45   Settings::Settings()
    46   {
    47     RegisterRootObject(Settings);
    48     setConfigValues();
    49   }
    5044
    51   Settings::~Settings()
    52   {
    53   }
     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)
    5450
    55   /**
    56     @brief Returns a unique instance of Core.
    57     @return The instance
    58   */
    59   Settings& Settings::getSingleton()
    60   {
    61     static Settings instance;
    62     return instance;
    63   }
     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 );
    6458
    65   /**
    66     @brief Function to collect the SetConfigValue-macro calls.
    67   */
    68   void Settings::setConfigValues()
    69   {
    70     SetConfigValue(dataPath_, "../../Media/").description("Relative path to the game data.");
    71     if (dataPath_ != "" && dataPath_[dataPath_.size() - 1] != '/')
     59    /**
     60    @brief
     61        Constructor: Registers the object and sets the config-values.
     62    */
     63    Settings::Settings()
    7264    {
    73       ModifyConfigValue(dataPath_, set, dataPath_ + "/");
     65        RegisterRootObject(Settings);
     66        gameMode_ = GameMode::GM_Unspecified;
     67        setConfigValues();
    7468    }
    7569
    76     if (dataPath_ == "")
     70    /**
     71    @brief
     72        Returns a unique instance of Core.
     73    @return
     74        The instance
     75    */
     76    Settings& Settings::getInstance()
    7777    {
    78       ModifyConfigValue(dataPath_, set, "/");
    79       COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl;
     78        static Settings instance;
     79        return instance;
    8080    }
    81   }
    8281
    83   /**
    84     @brief Temporary sets the data path
    85     @param path The new data path
    86   */
    87   void Settings::_tsetDataPath(const std::string& path)
    88   {
    89     ModifyConfigValue(dataPath_, tset, path);
    90   }
     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        }
    9193
    92   /*static*/ void Settings::tsetDataPath(const std::string& path)
    93   {
    94     getSingleton()._tsetDataPath(path);
    95   }
     94        if (dataPath_ == "")
     95        {
     96            ModifyConfigValue(dataPath_, set, "/");
     97            COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl;
     98        }
     99    }
    96100
    97   /**
    98     @brief Returns the relative path to the game data.
    99     @return The path to the game data
    100   */
    101   /*static*/ const std::string& Settings::getDataPath()
    102   {
    103     return getSingleton().dataPath_;
    104   }
     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
    105154}
Note: See TracChangeset for help on using the changeset viewer.