Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 2:51:02 PM (16 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.