Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 29, 2009, 10:30:19 PM (15 years ago)
Author:
rgrieder
Message:

Changed the way config values associated with general settings (ConfigFileType::Settings) are handled:

  • ConfigFileManager only handles config files listed in the ConfigFileType enum (normal enum again)
  • ConfigFileManager only takes care of ConfigFiles and returns a pointer to the right one, just two functions left. —> use like: ConfigFileManager::getInstance().getConfigFile(myType)→doSomething();
  • Moved all code (except for the argument completion functions) relating to ConfigFileType::Settings to a new class: SettingsConfigFile, which is a Singleton (it doesn't make sense to have multiple instances unless you start coding a lot more)
  • SettingsConfigFile handles config value containers according to their section and entry in the ini file, not according to class and variables names. (In most cases it will be class and variable names though)
  • SettingsConfigFile supports:
    • clear() (removes any file entries not associated to a config value container)
    • updateConfigValues() (does exactly that through the identifier)
    • config, tconfig and getConfig
    • commands listed above are exported to tolua, and tconfig, config and getConfig were given shortcuts in Lua (e.g. orxonox.config)
  • If you need to organise ConfigFiles yourself, just do it without the ConfigFileManager, like the KeyBinder does.
  • All getValue() functions have been split into getOrCreateValue() and getValue(), which is const
  • Removed obsolete config value management code in the Identifier (it still stores and destroys them and provides access to them)

All of that leads to one HUGE advantage:
"config OutputHandler softDebugLevelInGameConsole"
works now :D (any further implications are up to the reader…)
(it didn't work before because the actual config value container is in the InGameConsole singleton)

Location:
code/branches/gamestate/src/libraries/core/input
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gamestate/src/libraries/core/input/Button.cc

    r6428 r6432  
    4242#include "core/CommandEvaluation.h"
    4343#include "core/CommandExecutor.h"
     44#include "core/ConfigFileManager.h"
    4445
    4546namespace orxonox
     
    8182    }
    8283
    83     void Button::readBinding(ConfigFileType type)
    84     {
    85         const std::string& binding = ConfigFileManager::getInstance().getValue(type, groupName_, name_, "", true);
     84    void Button::readBinding(ConfigFile* configFile)
     85    {
     86        const std::string& binding = configFile->getOrCreateValue(groupName_, name_, "", true);
    8687        this->parse(binding);
    8788    }
    8889
    89     void Button::setBinding(ConfigFileType type, const std::string& binding, bool bTemporary)
     90    void Button::setBinding(ConfigFile* configFile, const std::string& binding, bool bTemporary)
    9091    {
    9192        if (!bTemporary)
    92             ConfigFileManager::getInstance().setValue(type, groupName_, name_, binding, true);
     93            configFile->setValue(groupName_, name_, binding, true);
    9394        this->parse(binding);
    9495    }
  • code/branches/gamestate/src/libraries/core/input/Button.h

    r6428 r6432  
    4141#include <vector>
    4242#include "InputCommands.h"
    43 #include "core/ConfigFileManager.h"
    4443
    4544namespace orxonox
     
    5352        virtual bool addParamCommand(ParamCommand* command) { return false; }
    5453        void parse(const std::string& binding);
    55         void readBinding(ConfigFileType type);
    56         void setBinding(ConfigFileType type, const std::string& binding, bool bTemporary);
     54        void readBinding(ConfigFile* configFile);
     55        void setBinding(ConfigFile* configFile, const std::string& binding, bool bTemporary);
    5756        bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f);
    5857
  • code/branches/gamestate/src/libraries/core/input/JoyStick.cc

    r6417 r6432  
    106106    {
    107107        list.resize(size);
    108         unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName);
     108        unsigned int configValueVectorSize = ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)->getVectorSize(sectionName, valueName);
    109109        if (configValueVectorSize > size)
    110110            configValueVectorSize = size;
     
    112112        for (unsigned int i = 0; i < configValueVectorSize; ++i)
    113113        {
    114             list[i] = multi_cast<int>(ConfigFileManager::getInstance().getValue(
    115                 ConfigFileType::JoyStickCalibration, sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
     114            list[i] = multi_cast<int>(ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     115                ->getOrCreateValue(sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
    116116        }
    117117
     
    153153            if (configMinValues_[i] == INT_MAX)
    154154                configMinValues_[i] = -32768;
    155             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    156                 deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
     155            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     156                ->getOrCreateValue(deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
    157157
    158158            // Maximum values
    159159            if (configMaxValues_[i] == INT_MIN)
    160160                configMaxValues_[i] = 32767;
    161             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    162                 deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
     161            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     162                ->getOrCreateValue(deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
    163163
    164164            // Middle values
    165             ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
    166                 deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
     165            ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
     166                ->getOrCreateValue(deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
    167167        }
    168168
  • code/branches/gamestate/src/libraries/core/input/KeyBinder.cc

    r6428 r6432  
    4949        : deriveTime_(0.0f)
    5050        , filename_(filename)
     51        , configFile_(NULL)
    5152    {
    5253        mouseRelative_[0] = 0;
     
    9394            mouseAxes_[i].groupName_ = "MouseAxes";
    9495        }
    95 
    96         // We might not even load any bindings at all (KeyDetector for instance)
    97         this->configFile_ = ConfigFileType::NoType;
    9896
    9997        // initialise joy sticks separatly to allow for reloading
     
    163161
    164162        // load the bindings if required
    165         if (configFile_ != ConfigFileType::NoType)
     163        if (configFile_ != NULL)
    166164        {
    167165            for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
     
    249247        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    250248
    251         // Get a new ConfigFileType from the ConfigFileManager
    252         this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
    253 
    254         ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_);
     249        this->configFile_ = new ConfigFile(this->filename_);
     250        this->configFile_->load();
    255251
    256252        // Parse bindings and create the ConfigValueContainers if necessary
  • code/branches/gamestate/src/libraries/core/input/KeyBinder.h

    r6428 r6432  
    3838#include <boost/shared_ptr.hpp>
    3939
    40 #include "core/ConfigFileManager.h"
    4140#include "InputHandler.h"
    4241#include "Button.h"
     
    157156        //! Name of the file used in this KeyBinder (constant!)
    158157        const std::string filename_;
    159         //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded.
    160         ConfigFileType configFile_;
     158        //! Config file used. NULL in case of KeyDetector. Also indicates whether we've already loaded.
     159        ConfigFile* configFile_;
    161160
    162161    private:
Note: See TracChangeset for help on using the changeset viewer.