Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 27, 2007, 3:44:20 AM (16 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)

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