Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 27, 2007, 3:44:20 AM (17 years ago)
Author:
landauf
Message:

yet another version of the DebugLevel hack.
DebugLevel is an OrxonoxClass again, to make the softDebugLevel-variable changeable during the game. now there are 2 static bools to avoid an infinite recursion. i hope this works.
(btw: the ClassIdentifier seems to work now, finally)

Location:
code/branches/FICN/src/orxonox/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/DebugLevel.cc

    r689 r695  
    3131*/
    3232
    33 #include "ConfigValueContainer.h"
     33#include "CoreIncludes.h"
    3434#include "Debug.h"
    3535#include "DebugLevel.h"
     
    3939    /**
    4040        @brief Constructor: Registers the object and sets the debug level.
     41        @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
    4142    */
    42     DebugLevel::DebugLevel()
     43    DebugLevel::DebugLevel(bool& bReturnSoftDebugLevel)
    4344    {
    44         this->softDebugLevelContainer_ = new ConfigValueContainer(std::string("DebugLevel"), std::string("softDebugLevel_"), this->softDebugLevel_ = 2);
    45         this->softDebugLevel_ = this->softDebugLevelContainer_->getValue(this->softDebugLevel_);
     45        RegisterRootObject(DebugLevel);
     46        this->setConfigValues();
     47        bReturnSoftDebugLevel = true;
     48    }
     49
     50    /**
     51        @brief Function to collect the SetConfigValue-macro calls.
     52    */
     53    void DebugLevel::setConfigValues()
     54    {
     55        SetConfigValue(softDebugLevel_, 2);
    4656    }
    4757
     
    5161    int DebugLevel::getSoftDebugLevel()
    5262    {
    53         static DebugLevel theOneAndOnlyInstance = DebugLevel();
    54         return theOneAndOnlyInstance.softDebugLevel_;
     63        static bool bCreatingSoftDebugLevelObject = true;   // Static variable - used to enhance the performance
     64        static bool bReturnSoftDebugLevel = false;          // Static variable - used to avoid an infinite recursion
     65        static DebugLevel* theOnlyDebugLevelObject = 0;     // Static variable - will contain a pointer to the only instance of the DebugLevel class
     66
     67        // If bReturnSoftDebugLevel is true, the instance of DebugLevel was created (it's set to true at the end of the constructor, call by reference)
     68        if (bReturnSoftDebugLevel)
     69            return theOnlyDebugLevelObject->softDebugLevel_;
     70
     71        // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
     72        if (bCreatingSoftDebugLevelObject)
     73        {
     74            bCreatingSoftDebugLevelObject = false;
     75            theOnlyDebugLevelObject = new DebugLevel(bReturnSoftDebugLevel);
     76            return theOnlyDebugLevelObject->softDebugLevel_;
     77        }
     78
     79        // Return a constant value while we're creating the object
     80        return 4;
    5581    }
    56 
    5782}
    5883
  • code/branches/FICN/src/orxonox/core/DebugLevel.h

    r689 r695  
    3838
    3939#include "CorePrereqs.h"
     40#include "OrxonoxClass.h"
    4041
    4142namespace orxonox
    4243{
    4344    //! The DebugLevel class is a singleton, only used to configure the amount of debug output.
    44     class _CoreExport DebugLevel
     45    class _CoreExport DebugLevel : public OrxonoxClass
    4546    {
    4647        public:
    4748            static int getSoftDebugLevel();
     49            void setConfigValues();
     50
    4851        private:
    49             DebugLevel();                       // don't create
     52            explicit DebugLevel(bool& bReturnSoftDebugLevel);
    5053            DebugLevel(const DebugLevel& dl) {} // don't copy
    5154            ~DebugLevel() {}                    // don't delete
  • code/branches/FICN/src/orxonox/core/OrxonoxClass.cc

    r670 r695  
    4343        this->bActive_ = true;
    4444        this->bVisible_ = true;
     45
     46        this->setConfigValues();
    4547    }
    4648
  • code/branches/FICN/src/orxonox/core/OrxonoxClass.h

    r682 r695  
    5757            virtual ~OrxonoxClass();
    5858
     59            /** @brief Function to collect the SetConfigValue-macro calls. */
    5960            void setConfigValues() {};
    6061
Note: See TracChangeset for help on using the changeset viewer.