Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2009, 11:41:25 AM (16 years ago)
Author:
dafrick
Message:

Made QuestManager and NotificationManager to Singletons. Fixed/Changed som other stuff I don't remember…

Location:
code/branches/questsystem5/src/orxonox/objects/quest
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc

    r2779 r2785  
    9797        try
    9898        {
    99             Quest* quest = QuestManager::findQuest(this->getQuestId());
     99            Quest* quest = QuestManager::getInstance().findQuest(this->getQuestId());
    100100            if(quest == NULL || !quest->start(player))
    101101            {
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc

    r2779 r2785  
    117117        try
    118118        {
    119             QuestHint* hint = QuestManager::findHint(this->hintId_);
     119            QuestHint* hint = QuestManager::getInstance().findHint(this->hintId_);
    120120            if(hint == NULL || !hint->setActive(player))
    121121            {
  • code/branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc

    r2779 r2785  
    9696        try
    9797        {
    98             quest = QuestManager::findQuest(this->getQuestId());
     98            quest = QuestManager::getInstance().findQuest(this->getQuestId());
    9999            if(quest == NULL || !quest->complete(player))
    100100            {
  • code/branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc

    r2779 r2785  
    9595        try
    9696        {
    97             quest = QuestManager::findQuest(this->getQuestId());
     97            quest = QuestManager::getInstance().findQuest(this->getQuestId());
    9898            if(quest == NULL || !quest->fail(player))
    9999            {
  • code/branches/questsystem5/src/orxonox/objects/quest/Quest.cc

    r2779 r2785  
    7979        XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode);
    8080
    81         QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager.
     81        QuestManager::getInstance().registerQuest(this); //!<Registers the Quest with the QuestManager.
    8282    }
    8383
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc

    r2779 r2785  
    7373        SUPER(QuestHint, XMLPort, xmlelement, mode);
    7474
    75         QuestManager::registerHint(this); //!< Registers the QuestHint with the QuestManager.
     75        QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
    7676       
    7777        COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc

    r2779 r2785  
    112112    bool QuestListener::setQuestId(const std::string & id)
    113113    {
    114         this->quest_ = QuestManager::findQuest(id); //!< Find the Quest corresponding to the given questId.
     114        this->quest_ = QuestManager::getInstance().findQuest(id); //!< Find the Quest corresponding to the given questId.
    115115       
    116116        if(this->quest_ == NULL) //!< If there is no such Quest.
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc

    r2779 r2785  
    4343namespace orxonox
    4444{
    45     //! All Quests registered by their id's.
    46     std::map<std::string, Quest*> QuestManager::questMap_s;
    47     //! All QuestHints registered by their id's.
    48     std::map<std::string, QuestHint*> QuestManager::hintMap_s;
     45    //! Pointer to the current (and single) instance of this class.
     46    QuestManager* QuestManager::singletonRef_s = NULL;
    4947
    5048    /**
    5149    @brief
    5250        Constructor. Registers the object.
    53     */
    54     QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator)
    55     {
    56         RegisterObject(QuestManager);
     51    @todo
     52        Is inheriting from BaseObject proper?
     53    */
     54    QuestManager::QuestManager() : BaseObject(this)
     55    {
     56        RegisterRootObject(QuestManager);
     57
    5758    }
    5859
     
    6465    {
    6566
     67    }
     68
     69    /**
     70    @brief
     71        Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
     72    @return
     73        Returns a reference to the single instance of the Quest Manager.
     74    */
     75    /*static*/ QuestManager & QuestManager::getInstance()
     76    {
     77        if(singletonRef_s == NULL)
     78        {
     79            singletonRef_s = new QuestManager();
     80        }
     81        return *singletonRef_s;
    6682    }
    6783
     
    7591        Returns true if successful, false if not.
    7692    */
    77     /*static*/ bool QuestManager::registerQuest(Quest* quest)
     93    bool QuestManager::registerQuest(Quest* quest)
    7894    {
    7995        if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
     
    84100
    85101        std::pair<std::map<std::string, Quest*>::iterator,bool> result;
    86         result = questMap_s.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
     102        result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
    87103
    88104        if(result.second) //!< If inserting was a success.
     
    107123        Returns true if successful, false if not.
    108124    */
    109     /*static*/ bool QuestManager::registerHint(QuestHint* hint)
     125    bool QuestManager::registerHint(QuestHint* hint)
    110126    {
    111127        if(hint == NULL) //!< Still not liking NULL-pointers.
     
    116132
    117133        std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
    118         result = hintMap_s.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
     134        result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
    119135
    120136        if(result.second) //!< If inserting was a success.
     
    141157        Throws an exception if the given questId is invalid.
    142158    */
    143     /*static*/ Quest* QuestManager::findQuest(const std::string & questId)
     159    Quest* QuestManager::findQuest(const std::string & questId)
    144160    {
    145161        if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
     
    149165
    150166        Quest* quest;
    151         std::map<std::string, Quest*>::iterator it = questMap_s.find(questId);
    152         if (it != questMap_s.end()) //!< If the Quest is registered.
     167        std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
     168        if (it != this->questMap_.end()) //!< If the Quest is registered.
    153169        {
    154170            quest = it->second;
     
    175191        Throws an exception if the given hintId is invalid.
    176192    */
    177     /*static*/ QuestHint* QuestManager::findHint(const std::string & hintId)
     193    QuestHint* QuestManager::findHint(const std::string & hintId)
    178194    {
    179195        if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
     
    183199
    184200        QuestHint* hint;
    185         std::map<std::string, QuestHint*>::iterator it = hintMap_s.find(hintId);
    186         if (it != hintMap_s.end()) //!< If the QuestHint is registered.
     201        std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
     202        if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
    187203        {
    188204            hint = it->second;
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.h

    r2779 r2785  
    4646    /**
    4747    @brief
    48         Is a static class and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
     48        Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
    4949        Quests (and QuestHints) are registered in the QuestManager with their id, and can be accessed in the same way.
    5050    @author
     
    5454    {
    5555
     56        protected:
     57            QuestManager();
     58
    5659        public:
    57             QuestManager(BaseObject* creator);
    5860            virtual ~QuestManager();
    5961
    60             static bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
    61             static bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
     62            static QuestManager& getInstance(); //!< Returns a reference to the single instance of the Quest Manager.
    6263
    63             static Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
    64             static QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
     64            bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
     65            bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
     66
     67            Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
     68            QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
    6569
    6670        private:
    67             static std::map<std::string, Quest*> questMap_s; //!< All Quests registered by their id's.
    68             static std::map<std::string, QuestHint*> hintMap_s; //!< All QuestHints registered by their id's.
     71            static QuestManager* singletonRef_s;
     72
     73            std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
     74            std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
    6975
    7076    };
Note: See TracChangeset for help on using the changeset viewer.