Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/doc/ConfigValueContainer


Ignore:
Timestamp:
Feb 27, 2008, 7:17:38 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/ConfigValueContainer

    v1 v1  
     1= !ConfigValueContainer =
     2
     3== Description ==
     4
     5The [wiki:ConfigValueContainer] is a class that manages config-values. A config-value is a member-variable of a class that can be changed through the config-file. The config-file is usually ''orxonox.ini''. A new config-value can be defined by using the !SetConfigValue(varname, defvalue) macro (you have to include [wiki:CoreIncludes CoreIncludes.h] to use it), where ''varname'' is a member variable of a class. The macro-call must take place in the setConfigValues() function of this class. This allows the user to change the value of the variable ingame by using console-commands or the menu.
     6
     7Every config-value has it's own [wiki:ConfigValueContainer]. The container is stored in a map inside the [wiki:Identifier] of the corresponding class. That way it's possible to iterate through all [wiki:ConfigValueContainers] of a class.
     8
     9Calling setConfigValues() of an object causes all [wiki:ConfigValueContainers] of it's class to assign the stored values to the variables of the object. The values are initially read from the config-file but can be changed during the game by using console-commands or the menu. It's possible to change variables only temporary without saving the new value in the config-file, but usually changes are saved.
     10
     11== Functions ==
     12
     13 * '''!ConfigValueContainer('''''classname''''', '''''varname''''', '''''defvalue''''')''': The constructor creates a new config-value with given name and default value of a class with the given name.
     14 * '''getValue('''''pointer''''')''': Assigns the stored value to the ''pointer''. ''pointer'' must point to a variable of the same type as stored in the container. This functions is used to assign the values to all instances of a class.
     15 * '''description('''''string''''')''': Adds a description to the config-value. The description gets exported to the [wiki:Language]-file and can be localised.
     16 * '''resetConfigValue()''': Sets the config-value and the entry in the config-file back to the default value.
     17
     18== Macros ==
     19
     20 * '''!SetConfigValue('''''varname''''', '''''defvalue''''')''': Defines a new config-value with a default value. ''varname'' must be a member-variable of a class and the macro should only be used in the setConfigValues() function of this class to allow ingame-changes of the values. A description can be set by adding '''.description('''''string''''')''' at the end of the macro.
     21 * '''!ResetConfigValue('''''varname''''')''': Sets the given config-value back to the default value.
     22
     23== Example ==
     24
     25Definition of a class in the header-file:
     26{{{
     27#!cpp
     28class MyClass : public BaseObject
     29{
     30  public:
     31    MyClass();              // Constructor
     32    void setConfigValues(); // Inherited function
     33
     34    const std::string& getName()
     35      { return this->name_; }
     36
     37    float getVersion()
     38      { return this->version_; }
     39
     40  private:
     41    std::string name_;
     42    float version_;   
     43};
     44}}}
     45
     46Implementation of the class source-file:
     47{{{
     48#!cpp
     49MyClass::MyClass()
     50{
     51  // Macro call to create an Identifier
     52  RegisterObject(MyClass);
     53
     54  // Function call to assign the config-values to the new object
     55  this->setConfigValues();
     56}
     57
     58void MyClass::setConfigValues()
     59{
     60  SetConfigValue(name_, "Orxonox").description("The name of the game");
     61  SetConfigValue(version_, "1.0").description("The version-number");
     62}
     63}}}
     64
     65Extract of orxonox.ini:
     66{{{
     67[MyClass]
     68name_="Orxonox"
     69version_=1.1 // We have changed this value from 1.0 to 1.1
     70}}}
     71
     72Some other code:
     73{{{
     74#!cpp
     75MyObject orxonoxobject;
     76std::cout << "Name:    " << orxonoxobject.getName() << std::endl;
     77std::cout << "Version: " << orxonoxobject.getVersion() << std::endl;
     78}}}
     79
     80Output:
     81{{{
     82Name:    Orxonox
     83Version: 1.1
     84}}}
     85
     86== The config-file ==
     87
     88