Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

added Ogre::Vector2 as configurable type

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.