Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2084


Ignore:
Timestamp:
Nov 1, 2008, 2:51:02 PM (15 years ago)
Author:
rgrieder
Message:
  • Added debug overlay that is constantly shown in graphics mode. F2 toggles its visibility, but only in level mode for now.
  • Added ConstructionCallback to get informed about the construction of any object of a specific type. Use RegisterConstructionCallback(ThisClassName, TargetClassName, FunctionName); to register such a callback.
Location:
code/branches/objecthierarchy/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/core/CoreIncludes.h

    r2034 r2084  
    4646#include "Factory.h"
    4747#include "ClassFactory.h"
     48#include "Functor.h"
    4849#include "util/Debug.h"
    4950
     
    128129    orxonox::Factory::getIdentifier(networkID)
    129130
     131/**
     132    @brief Registers a member function as callback when an object of 'type' is created.
     133    @param
     134*/
     135#define RegisterConstructionCallback(ThisClassName, TargetClassName, FunctionName) \
     136    orxonox::ClassIdentifier<TargetClassName>::getIdentifier()->addConstructionCallback( \
     137        createFunctor(&ThisClassName::FunctionName)->setObject(this))
     138
    130139#endif /* _CoreIncludes_H__ */
  • code/branches/objecthierarchy/src/core/Functor.h

    r2019 r2084  
    167167            }
    168168
    169             void setObject(T* object)
     169            FunctorMember* setObject(T* object)
    170170            {
    171171                this->bConstObject_ = false;
    172172                this->object_ = object;
     173                return this;
    173174            }
    174175
    175             void setObject(const T* object)
     176            FunctorMember* setObject(const T* object)
    176177            {
    177178                this->bConstObject_ = true;
    178179                this->constObject_ = object;
     180                return this;
    179181            }
    180182
  • code/branches/objecthierarchy/src/core/Identifier.cc

    r2063 r2084  
    6363        this->bHasConfigValues_ = false;
    6464        this->bHasConsoleCommands_ = false;
     65        this->bHasConstructionCallback_ = false;
    6566
    6667        this->children_ = new std::set<const Identifier*>();
     
    508509
    509510    /**
     511        @brief Adds a construction callback functor that gets called every time an object is created.
     512        @param functor Functor pointer to any function with no argument.
     513    */
     514    void Identifier::addConstructionCallback(Functor* functor)
     515    {
     516        for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i)
     517        {
     518            if (this->constructionCallbacks_[i] == functor)
     519                return;
     520        }
     521        this->constructionCallbacks_.push_back(functor);
     522        this->bHasConstructionCallback_ = true;
     523    }
     524
     525    /**
     526        @brief Removes a construction callback functor that gets called every time an object is created.
     527        @param functor Functor pointer to any function with no argument.
     528    */
     529    void Identifier::removeConstructionCallback(Functor* functor)
     530    {
     531        for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i)
     532        {
     533            if (this->constructionCallbacks_[i] == functor)
     534            {
     535                this->constructionCallbacks_.erase(this->constructionCallbacks_.begin() + i);
     536            }
     537        }
     538        if (constructionCallbacks_.empty())
     539            this->bHasConstructionCallback_ = false;
     540    }
     541
     542    /**
    510543        @brief Lists the names of all Identifiers in a std::set<const Identifier*>.
    511544        @param out The outstream
  • code/branches/objecthierarchy/src/core/Identifier.h

    r2063 r2084  
    5757#include <set>
    5858#include <map>
     59#include <vector>
    5960#include <string>
    6061#include <utility>
     
    221222            /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
    222223            inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
     224            /** @brief Returns true if this class has at least one construction callback Functor registered. */
     225            inline bool hasConstructionCallback() const { return this->bHasConstructionCallback_; }
    223226
    224227            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     
    247250            ConsoleCommand* getConsoleCommand(const std::string& name) const;
    248251            ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
     252
     253            void addConstructionCallback(Functor* functor);
     254            void removeConstructionCallback(Functor* functor);
    249255
    250256            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     
    267273            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
    268274            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
     275
     276            bool bHasConstructionCallback_;                                //!< True if at least one Functor is registered to get informed when an object of type T is created.
     277            std::vector<Functor*> constructionCallbacks_;                  //!< All construction callback Functors of this class.
    269278
    270279            ObjectListBase* objects_;                                      //!< The list of all objects of this class
     
    441450        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    442451        object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
     452        if (this->bHasConstructionCallback_)
     453        {
     454            // Call all registered callbacks that a new object of type T has been created.
     455            // Do NOT deliver a T* pointer here because it's way too risky (object not yet fully created).
     456            for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i)
     457                (*constructionCallbacks_[i])();
     458        }
    443459    }
    444460
  • code/branches/objecthierarchy/src/network/packet/Packet.cc

    r2080 r2084  
    214214  delete it->second;
    215215  //packetMap_.erase(it);
     216  COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
    216217}
    217218
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSGraphics.cc

    r2023 r2084  
    5151#include "core/input/KeyBinder.h"
    5252#include "core/input/ExtendedInputState.h"
     53#include "core/Loader.h"
     54#include "core/XMLFile.h"
    5355#include "overlays/console/InGameConsole.h"
    5456#include "gui/GUIManager.h"
    5557#include "tools/WindowEventListener.h"
     58#include "objects/Tickable.h"
    5659#include "Settings.h"
    5760
     
    6568        , renderWindow_(0)
    6669        , viewport_(0)
     70        , bWindowEventListenerUpdateRequired_(false)
    6771        , inputManager_(0)
    6872        , console_(0)
     
    7781        , statisticsStartCount_(0)
    7882        , tickTime_(0)
     83        , debugOverlay_(0)
    7984    {
    8085        RegisterRootObject(GSGraphics);
     
    114119        this->initialiseResources();
    115120
    116 
    117         // HACK: temporary:
    118         //graphicsEngine_->renderWindow_  = this->renderWindow_;
    119         //graphicsEngine_->root_          = this->ogreRoot_;
    120         //graphicsEngine_->viewport_      = this->viewport_;
    121 
     121        // We want to get informed whenever an object of type WindowEventListener is created
     122        // in order to later update the window size.
     123        bWindowEventListenerUpdateRequired_ = false;
     124        RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate);
     125
     126        // load debug overlay
     127        COUT(3) << "Loading Debug Overlay..." << std::endl;
     128        this->debugOverlay_ = new XMLFile(Settings::getDataPath() + "overlay/debug.oxo");
     129        Loader::open(debugOverlay_);
    122130
    123131        // Calls the InputManager which sets up the input devices.
     
    166174        //delete this->masterKeyBinder_;
    167175        delete this->inputManager_;
     176
     177        Loader::unload(this->debugOverlay_);
     178        delete this->debugOverlay_;
    168179
    169180        // destroy render window
     
    222233        this->console_->tick(dt);
    223234        this->tickChild(time);
     235
     236        /*** HACK *** HACK ***/
     237        // Call the Tickable objects
     238        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     239            it->tick(time.getDeltaTime());
     240        /*** HACK *** HACK ***/
     241
     242        if (this->bWindowEventListenerUpdateRequired_)
     243        {
     244            // Update all WindowEventListeners for the case a new one was created.
     245            this->windowResized(this->renderWindow_);
     246            this->bWindowEventListenerUpdateRequired_ = false;
     247        }
    224248
    225249        unsigned long long timeAfterTick = time.getRealMicroseconds();
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSGraphics.h

    r1891 r2084  
    7777        void windowClosed      (Ogre::RenderWindow* rw);
    7878
     79        void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; }
     80
    7981    private: // variables
    8082        Ogre::RenderWindow*   renderWindow_;          //!< the current render window
    8183        Ogre::Viewport*       viewport_;              //!< default full size viewport
     84        bool bWindowEventListenerUpdateRequired_;     //!< True if a new WindowEventListener was created but not yet updated.
    8285
    8386        // managed singletons
     
    97100        unsigned long         statisticsStartCount_;
    98101        unsigned int          tickTime_;
     102        XMLFile*              debugOverlay_;
    99103
    100104        // config values
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSLevel.cc

    r2073 r2084  
    163163    void GSLevel::ticked(const Clock& time)
    164164    {
    165         // Call the scene objects
    166         for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    167             it->tick(time.getDeltaTime() * this->timeFactor_);
     165        // Commented by 1337: Temporarily moved to GSGraphics.
     166        //// Call the scene objects
     167        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     168        //    it->tick(time.getDeltaTime() * this->timeFactor_);
    168169    }
    169170
  • code/branches/objecthierarchy/src/orxonox/overlays/OrxonoxOverlay.cc

    r2075 r2084  
    7676        this->overlay_->add2D(this->background_);
    7777
    78         // We'll have to get the aspect ratio manually for the first time. Afterwards windowResized() gets
    79         // called automatically by GSGraphics.
    80         this->windowAspectRatio_ = Ogre::OverlayManager::getSingleton().getViewportAspectRatio();
     78        // We'll have to set the aspect ratio to a default value first.
     79        // GSGraphics gets informed about our construction here and can update us in the next tick.
     80        this->windowAspectRatio_ = 1.0;
    8181        this->sizeCorrectionChanged();
    8282
Note: See TracChangeset for help on using the changeset viewer.