Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 450 for code/branches


Ignore:
Timestamp:
Dec 10, 2007, 3:40:55 AM (17 years ago)
Author:
landauf
Message:

added Ogre::Vector2 as configurable type

Location:
code/branches/objecthierarchy/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.cc

    r449 r450  
    144144
    145145    /**
    146         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_.
     146        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector2_.
    147147        @param classname The name of the class the variable belongs to
    148148        @param varname The name of the variable
    149149        @param defvalue The default-value
    150150    */
    151     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue)
    152     {
    153         // Try to convert the default-value from Vector3 to string
     151    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue)
     152    {
     153        // Try to convert the default-value from Vector2 to string
    154154        std::ostringstream ostream;
    155         if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")")
     155        if (ostream << "(" << defvalue.x << "," << defvalue.y << ")")
    156156            this->defvalue_ = ostream.str();
    157157        else
    158             this->defvalue_ = "(0,0,0)";
     158            this->defvalue_ = "(0,0)";
    159159
    160160        // Set the default values, then get the value-string
     
    187187        }
    188188
    189         if (count != 2)
    190             bEntryIsCorrupt = true;
    191 
    192         // Try to convert the stripped value-string to Vector3
     189        if (count != 1)
     190            bEntryIsCorrupt = true;
     191
     192        // Try to convert the stripped value-string to Vector2
    193193        if (!bEntryIsCorrupt)
    194194        {
    195195            std::istringstream istream(valueString);
    196             if (!(istream >> this->value_vector3_.x))
    197             {
    198                 // The conversion failed - use the default value and restore the entry in the config-file
    199                 this->value_vector3_.x = defvalue.x;
    200                 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    201                 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    202             }
    203             if (!(istream >> this->value_vector3_.y))
    204             {
    205                 // The conversion failed - use the default value and restore the entry in the config-file
    206                 this->value_vector3_.y = defvalue.y;
    207                 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    208                 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
    209             }
    210             if (!(istream >> this->value_vector3_.z))
    211             {
    212                 // The conversion failed - use the default value and restore the entry in the config-file
    213                 this->value_vector3_.z = defvalue.z;
     196            if (!(istream >> this->value_vector2_.x))
     197            {
     198                // The conversion failed - use the default value and restore the entry in the config-file
     199                this->value_vector2_.x = defvalue.x;
     200                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     201                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     202            }
     203            if (!(istream >> this->value_vector2_.y))
     204            {
     205                // The conversion failed - use the default value and restore the entry in the config-file
     206                this->value_vector2_.y = defvalue.y;
    214207                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    215208                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    219212        {
    220213            // The conversion failed - use the default value and restore the entry in the config-file
    221             this->value_vector3_ = defvalue;
     214            this->value_vector2_ = defvalue;
    222215            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
    223216            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     
    226219
    227220    /**
    228         @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_.
     221        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_.
    229222        @param classname The name of the class the variable belongs to
    230223        @param varname The name of the variable
    231224        @param defvalue The default-value
    232225    */
    233     ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue)
    234     {
    235         // Try to convert the default-value from ColourValue to string
     226    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue)
     227    {
     228        // Try to convert the default-value from Vector3 to string
    236229        std::ostringstream ostream;
    237         if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")")
     230        if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")")
    238231            this->defvalue_ = ostream.str();
    239232        else
    240             this->defvalue_ = "(0,0,0,0)";
     233            this->defvalue_ = "(0,0,0)";
    241234
    242235        // Set the default values, then get the value-string
     
    269262        }
    270263
     264        if (count != 2)
     265            bEntryIsCorrupt = true;
     266
     267        // Try to convert the stripped value-string to Vector3
     268        if (!bEntryIsCorrupt)
     269        {
     270            std::istringstream istream(valueString);
     271            if (!(istream >> this->value_vector3_.x))
     272            {
     273                // The conversion failed - use the default value and restore the entry in the config-file
     274                this->value_vector3_.x = defvalue.x;
     275                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     276                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     277            }
     278            if (!(istream >> this->value_vector3_.y))
     279            {
     280                // The conversion failed - use the default value and restore the entry in the config-file
     281                this->value_vector3_.y = defvalue.y;
     282                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     283                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     284            }
     285            if (!(istream >> this->value_vector3_.z))
     286            {
     287                // The conversion failed - use the default value and restore the entry in the config-file
     288                this->value_vector3_.z = defvalue.z;
     289                (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     290                ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     291            }
     292        }
     293        else
     294        {
     295            // The conversion failed - use the default value and restore the entry in the config-file
     296            this->value_vector3_ = defvalue;
     297            (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_;
     298            ConfigValueContainer::writeConfigFile(CONFIGFILEPATH);
     299        }
     300    }
     301
     302    /**
     303        @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_.
     304        @param classname The name of the class the variable belongs to
     305        @param varname The name of the variable
     306        @param defvalue The default-value
     307    */
     308    ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue)
     309    {
     310        // Try to convert the default-value from ColourValue to string
     311        std::ostringstream ostream;
     312        if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")")
     313            this->defvalue_ = ostream.str();
     314        else
     315            this->defvalue_ = "(0,0,0,0)";
     316
     317        // Set the default values, then get the value-string
     318        this->setDefaultValues(classname, varname);
     319        std::string valueString = this->getValueString();
     320
     321        // Strip the value-string
     322        bool bEntryIsCorrupt = false;
     323        valueString = this->getStrippedLine(valueString);
     324        unsigned int pos1, pos2, pos3;
     325        pos1 = valueString.find("(");
     326        if (pos1 == 0)
     327            valueString.erase(pos1, 1);
     328        else
     329            bEntryIsCorrupt = true;
     330
     331        pos2 = valueString.find(")");
     332        if (pos2 == valueString.length() - 1)
     333            valueString.erase(pos2, 1);
     334        else
     335            bEntryIsCorrupt = true;
     336
     337        int count = 0;
     338        while ((pos3 = valueString.find(",")) < valueString.length())
     339        {
     340            count++;
     341            valueString.replace(pos3, 1, " ");
     342            if (pos3 < pos1)
     343                bEntryIsCorrupt = true;
     344        }
     345
    271346        if (count != 3)
    272347            bEntryIsCorrupt = true;
     
    333408        this->value_bool_ = false;
    334409        this->value_string_ = "";
     410        this->value_vector2_ = Ogre::Vector2(0, 0);
    335411        this->value_vector3_ = Ogre::Vector3(0, 0, 0);
    336412        this->value_colourvalue_ = Ogre::ColourValue(0, 0, 0, 0);
  • code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h

    r447 r450  
    1818#include <string>
    1919#include <list>
     20
     21#include "OgreVector2.h"
    2022#include "OgreVector3.h"
    2123#include "OgreColourValue.h"
     
    4648            ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue);
    4749            ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue);
     50            ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector2 defvalue);
    4851            ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue);
    4952            ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue);
     
    6770            /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */
    6871            inline std::string getValue(const std::string& value)               { return this->value_string_; }
     72            /** @returns the value of the type Vector2. @param value This is only needed to determine the right type. */
     73            inline Ogre::Vector2 getValue(const Ogre::Vector2& value)           { return this->value_vector2_; }
    6974            /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */
    7075            inline Ogre::Vector3 getValue(const Ogre::Vector3& value)           { return this->value_vector3_; }
     
    8186            bool                value_bool_;                    //!< The value, if the variable is of the type bool
    8287            std::string         value_string_;                  //!< The value, if the variable is of the type string
     88            Ogre::Vector2       value_vector2_;                 //!< The value, if the variable is of the type Vector2
    8389            Ogre::Vector3       value_vector3_;                 //!< The value, if the variable is of the type Vector3
    8490            Ogre::ColourValue   value_colourvalue_;             //!< The value, if the variable is of the type ColourValue
  • code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h

    r447 r450  
    1818#include "ConfigValueContainer.h"
    1919
     20#include "OgreVector2.h"
    2021#include "OgreVector3.h"
    2122#include "OgreColourValue.h"
     
    2526namespace orxonox
    2627{
     28    typedef Ogre::Vector2 Vector2;
    2729    typedef Ogre::Vector3 Vector3;
    2830    typedef Ogre::ColourValue ColourValue;
     
    109111        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
    110112    } \
    111     this->varname = container##varname->getValue(varname)
     113    varname = container##varname->getValue(varname)
  • code/branches/objecthierarchy/src/orxonox/objects/test3.cc

    r434 r450  
    2020        SetConfigValue(value_bool_, true);
    2121        SetConfigValue(value_string_, "Dies ist ein Test");
     22        SetConfigValue(value_vector2_, Vector2(101, 202));
    2223        SetConfigValue(value_vector3_, Vector3(13, 26, 39));
    2324        SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887));
     
    2829    }
    2930
     31        #include <fstream>
    3032    void Test3::configOutput()
    3133    {
     
    3436        std::cout << this->value_bool_ << std::endl;
    3537        std::cout << this->value_string_ << std::endl;
     38        std::cout << this->value_vector2_ << std::endl;
    3639        std::cout << this->value_vector3_ << std::endl;
    3740        std::cout << this->value_colourvalue_ << std::endl;
  • code/branches/objecthierarchy/src/orxonox/objects/test3.h

    r434 r450  
    2727            bool                value_bool_;
    2828            std::string         value_string_;
     29            Vector2             value_vector2_;
    2930            Vector3             value_vector3_;
    3031            ColourValue         value_colourvalue_;
Note: See TracChangeset for help on using the changeset viewer.