Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2361


Ignore:
Timestamp:
Dec 9, 2008, 2:07:24 AM (15 years ago)
Author:
landauf
Message:
  • Fixed a problem with SUPER in combination with a pure-virtual base-function when called from a direct child of the base-class.
  • Added random number generator initialization to Core (configurable)
  • Fixed a bug in Convert.h
Location:
code/branches/objecthierarchy2/src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/core/Core.cc

    r2344 r2361  
    5656        RegisterRootObject(Core);
    5757
    58         assert(singletonRef_s == 0);
    59         singletonRef_s = this;
     58        assert(this->singletonRef_s == 0);
     59        this->singletonRef_s = this;
     60        this->bInitializeRandomNumberGenerator_ = false;
    6061
    6162        this->setConfigValues();
     
    8081        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
    8182        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
     83        SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
    8284    }
    8385
     
    174176        ResetConfigValue(language_);
    175177    }
     178
     179    void Core::initializeRandomNumberGenerator()
     180    {
     181        static bool bInitialized = false;
     182        if (!bInitialized && this->bInitializeRandomNumberGenerator_)
     183        {
     184            srand(time(0));
     185            rand();
     186            bInitialized = true;
     187        }
     188    }
    176189}
  • code/branches/objecthierarchy2/src/core/Core.h

    r2344 r2361  
    7878            Core(const Core&);
    7979            void resetLanguageIntern();
     80            void initializeRandomNumberGenerator();
    8081
    8182            int softDebugLevel_;                            //!< The debug level
     
    8485            int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    8586            std::string language_;                          //!< The language
     87            bool bInitializeRandomNumberGenerator_;          //!< If true, srand(time(0)) is called
    8688
    8789            static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
  • code/branches/objecthierarchy2/src/core/Super.h

    r2257 r2361  
    9999            \
    100100            static void apply(void* temp) {} \
     101            \
    101102            static void apply(baseclass* temp) \
    102103            { \
     
    104105                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \
    105106                { \
     107                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     108                    { \
     109                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \
     110                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \
     111                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \
     112                    } \
     113                    \
    106114                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
    107115                    { \
     
    163171                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
    164172                {
     173                    // Check if the caller is a fallback-caller
     174                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     175                    {
     176                        // Delete the fallback caller an prepare to get a real caller
     177                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_;
     178                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0;
     179                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false;
     180                    }
     181
    165182                    // Check if there's not already a caller
    166183                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     
    183200        struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
    184201        { \
    185             // The check function just behaves like the fallback - it advances to the check for the next super-function (functionnumber + 1)
     202            // The check function acts like the fallback - it advances to the check for the next super-function (functionnumber + 1)
    186203            static void check() \
    187204            { \
     
    301318            }; \
    302319            \
     320            class _CoreExport SuperFunctionCaller_##functionname \
     321            { \
     322                public: \
     323                    virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
     324                    virtual ~SuperFunctionCaller_##functionname () {} \
     325            }; \
     326            \
     327            template <class T> \
     328            class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \
     329            { \
     330                public: \
     331                    inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \
     332                    { \
     333                    } \
     334            }; \
     335            \
    303336            template <class T> \
    304337            struct SuperFunctionInitialization<functionnumber, T> \
     
    306339                static void initialize(ClassIdentifier<T>* identifier) \
    307340                { \
    308                     identifier->superFunctionCaller_##functionname##_ = 0; \
     341                    identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \
     342                    identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \
    309343                    SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \
    310344                } \
     
    322356            }; \
    323357            \
    324             class _CoreExport SuperFunctionCaller_##functionname \
    325             { \
    326                 public: \
    327                     virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
    328                     virtual ~SuperFunctionCaller_##functionname () {} \
    329             }; \
    330             \
    331358            template <class T> \
    332359            class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \
     
    375402        };
    376403
    377         // Initializes the SuperFunctionCaller-pointer with zero.
     404        // Baseclass of the super-function caller. The real call will be done by a
     405        // templatized subclass through the virtual () operator.
     406        class _CoreExport SuperFunctionCaller_##functionname
     407        {
     408            public:
     409                virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
     410                virtual ~SuperFunctionCaller_##functionname () {}
     411        };
     412
     413        // Fallback if the base is pure virtual
     414        template <class T>
     415        class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname
     416        {
     417            public:
     418                // Fallback does nothing
     419                inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) )
     420                {
     421                }
     422        };
     423
     424        // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual
    378425        template <class T>
    379426        struct SuperFunctionInitialization<functionnumber, T>
     
    381428            static void initialize(ClassIdentifier<T>* identifier)
    382429            {
    383                 identifier->superFunctionCaller_##functionname##_ = 0;
     430                identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>;
     431                identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true;
    384432
    385433                // Calls the initialization of the next super-function (functionnumber + 1)
     
    400448                SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier);
    401449            }
    402         };
    403 
    404         // Baseclass of the super-function caller. The real call will be done by a
    405         // templatized subclass through the virtual () operator.
    406         class _CoreExport SuperFunctionCaller_##functionname
    407         {
    408             public:
    409                 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
    410                 virtual ~SuperFunctionCaller_##functionname () {}
    411450        };
    412451
     
    497536        #ifndef SUPER_INTRUSIVE_DECLARATION
    498537          #define SUPER_INTRUSIVE_DECLARATION(functionname) \
    499             SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_
     538            SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \
     539            bool bSuperFunctionCaller_##functionname##_isFallback_
    500540        #endif
    501541
  • code/branches/objecthierarchy2/src/orxonox/objects/Radar.cc

    r2256 r2361  
    9999    void Radar::tick(float dt)
    100100    {
     101        SUPER(Radar, tick, dt);
     102
    101103        if (this->focus_ != *(this->itFocus_))
    102104        {
  • code/branches/objecthierarchy2/src/orxonox/objects/Scene.cc

    r2171 r2361  
    167167    void Scene::tick(float dt)
    168168    {
     169        SUPER(Scene, tick, dt);
     170
    169171        if (!Core::showsGraphics())
    170172        {
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc

    r2171 r2361  
    6262    void Gametype::tick(float dt)
    6363    {
     64        SUPER(Gametype, tick, dt);
     65
    6466        if (this->bStartCountdownRunning_ && !this->bStarted_)
    6567            this->startCountdown_ -= dt;
     
    150152        if (this->spawnpoints_.size() > 0)
    151153        {
    152             srand(time(0));
    153             rnd();
    154 
    155154            unsigned int randomspawn = (unsigned int)rnd(this->spawnpoints_.size());
    156155            unsigned int index = 0;
  • code/branches/objecthierarchy2/src/orxonox/objects/items/Engine.cc

    r2350 r2361  
    144144            return;
    145145
     146        SUPER(Engine, tick, dt);
     147
    146148        const Vector3& direction = this->getDirection();
    147149        Vector3 velocity = this->ship_->getVelocity();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2171 r2361  
    7575    void BlinkingBillboard::tick(float dt)
    7676    {
     77        SUPER(BlinkingBillboard, tick, dt);
     78
    7779        if (Core::isMaster() && this->isActive())
    7880        {
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Camera.cc

    r2350 r2361  
    9494    void Camera::tick(float dt)
    9595    {
     96        SUPER(Camera, tick, dt);
    9697/*
    9798        // this stuff here may need some adjustments
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2256 r2361  
    232232        if (this->isActive())
    233233        {
     234            SUPER(ControllableEntity, tick, dt);
     235
    234236            this->velocity_ += (dt * this->acceleration_);
    235237            this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/FadingBillboard.cc

    r2254 r2361  
    140140    void FadingBillboard::tick(float dt)
    141141    {
     142        SUPER(FadingBillboard, tick, dt);
     143
    142144        if (this->changedirection_ > 0 && (this->fadedColour_.a < this->getColour().a))
    143145        {
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/MovableEntity.cc

    r2171 r2361  
    7474        if (this->isActive())
    7575        {
     76            SUPER(MovableEntity, tick, dt);
     77
    7678            this->velocity_ += (dt * this->acceleration_);
    7779            this->node_->translate(dt * this->velocity_);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2171 r2361  
    106106    if (!this->BaseObject::isActive())
    107107        return;
     108
     109    SUPER(Trigger, tick, dt);
    108110
    109111    bool newTriggered = this->isTriggered() ^ this->bInvertMode_;
  • code/branches/objecthierarchy2/src/orxonox/overlays/debug/DebugFPSText.cc

    r2087 r2361  
    4949    void DebugFPSText::tick(float dt)
    5050    {
     51        SUPER(DebugFPSText, tick, dt);
     52
    5153        float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond();
    5254        this->setCaption(convertToString(fps));
  • code/branches/objecthierarchy2/src/orxonox/overlays/debug/DebugRTRText.cc

    r2087 r2361  
    4949    void DebugRTRText::tick(float dt)
    5050    {
     51        SUPER(DebugRTRText, tick, dt);
     52
    5153        float rtr = GraphicsEngine::getInstance().getAverageTickTime();
    5254        this->setCaption(convertToString(rtr));
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDNavigation.cc

    r2087 r2361  
    129129    void HUDNavigation::tick(float dt)
    130130    {
     131        SUPER(HUDNavigation, tick, dt);
     132
    131133        if (!Radar::getInstance().getFocus())
    132134        {
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDSpeedBar.cc

    r2256 r2361  
    5252    void HUDSpeedBar::tick(float dt)
    5353    {
     54        SUPER(HUDSpeedBar, tick, dt);
     55
    5456        if (this->owner_ && this->owner_->getEngine())
    5557        {
  • code/branches/objecthierarchy2/src/orxonox/tools/Shader.cc

    r2358 r2361  
    101101    void Shader::tick(float dt)
    102102    {
     103        SUPER(Shader, tick, dt);
     104
    103105        if (this->bLoadCompositor_ && !this->bViewportInitialized_ && this->scenemanager_ && this->scenemanager_->getCurrentViewport())
    104106        {
  • code/branches/objecthierarchy2/src/util/Convert.h

    r2171 r2361  
    460460            else
    461461              *output = "false";
    462             return false;
     462            return true;
    463463        }
    464464    };
Note: See TracChangeset for help on using the changeset viewer.