Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6940


Ignore:
Timestamp:
May 20, 2010, 7:38:53 PM (14 years ago)
Author:
dafrick
Message:

Resolved issue with the Questsystem causing a segfault when a level with Quests was loaded twice. The issue still persists, but not with the Questsystem anymore and it will be addressed with my next commit.
Also removed restrictions to the number of characters a quest/hint identifier must have.

Location:
code/branches/presentation3/src/modules/questsystem
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/modules/questsystem/AddQuestHint.cc

    r6417 r6940  
    8585    bool AddQuestHint::setHintId(const std::string & id)
    8686    {
    87         if(!QuestItem::isId(id))
     87        if(id.compare(BLANKSTRING) == 0)
    8888        {
    8989            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
  • code/branches/presentation3/src/modules/questsystem/ChangeQuestStatus.cc

    r6417 r6940  
    7878    bool ChangeQuestStatus::setQuestId(const std::string & id)
    7979    {
    80         if(!QuestItem::isId(id))
     80        if(id.compare(BLANKSTRING) == 0)
    8181        {
    8282            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
  • code/branches/presentation3/src/modules/questsystem/Quest.cc

    r6417 r6940  
    6161    Quest::~Quest()
    6262    {
    63 
     63        if(this->isRegistered())
     64            QuestManager::getInstance().unregisterQuest(this);
    6465    }
    6566
  • code/branches/presentation3/src/modules/questsystem/Quest.h

    r5781 r6940  
    104104            virtual bool fail(PlayerInfo* player); //!< Fails the Quest.
    105105            virtual bool complete(PlayerInfo* player); //!< Completes the Quest.
    106 
     106           
    107107            bool addListener(QuestListener* listener); //!< Adds a QuestListener to the list of QuestListeners listening to this Quest.
    108108
  • code/branches/presentation3/src/modules/questsystem/QuestHint.cc

    r6417 r6940  
    5959    QuestHint::~QuestHint()
    6060    {
    61 
     61        if(this->isRegistered())
     62            QuestManager::getInstance().unregisterHint(this);
    6263    }
    6364
  • code/branches/presentation3/src/modules/questsystem/QuestItem.cc

    r6417 r6940  
    4646    QuestItem::QuestItem(BaseObject* creator) : BaseObject(creator)
    4747    {
     48        this->registered_ = false;
     49       
    4850        RegisterObject(QuestItem);
    4951    }
     
    7981    void QuestItem::setId(const std::string & id)
    8082    {
    81         if(!isId(id)) //!< Checks whether the id is a valid id.
     83        if(id.compare(BLANKSTRING) == 0) //!< Checks whether the id is a valid id.
    8284        {
    8385            COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
     
    8890    }
    8991
    90     /**
    91     @brief
    92         Checks whether an input id is of the required form.
    93     @param id
    94         The id to be checked.
    95     @return
    96         Returns true if the string is likely to be of the required form.
    97     */
    98     /*static*/ bool QuestItem::isId(const std::string & id)
    99     {
    100         return id.size() >= 32;
    101     }
    102 
    10392}
  • code/branches/presentation3/src/modules/questsystem/QuestItem.h

    r5781 r6940  
    4141#include <string>
    4242#include "core/BaseObject.h"
     43#include "QuestManager.h"
    4344
    4445namespace orxonox
     
    7475                { return this->description_; }
    7576
    76             static bool isId(const std::string & id); //!< Checks whether a given id is valid.
     77            /**
     78            @brief Check whether the QuestItem is registered with the QuestManager.
     79            @return Returns true if the QuestItem is registered with the QuestManager.
     80            */
     81            inline bool isRegistered(void)
     82                { return this->registered_; }
     83            /**
     84            @brief Set the QuestItem as being registered with the QuestManager.
     85            */
     86            inline void setRegistered(void)
     87                { this->registered_ = true; }
    7788
    7889        protected:
     
    90101            QuestDescription* description_; //!< The QuestDescription of the QuestItem.
    91102
     103            bool registered_;
     104
    92105    };
    93106
  • code/branches/presentation3/src/modules/questsystem/QuestListener.cc

    r6417 r6940  
    7474        XMLPortParam(QuestListener, "mode", setMode, getMode, xmlelement, mode);
    7575
    76         this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
     76        if(this->quest_ != NULL)
     77            this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
    7778
    7879        COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} with mode '" << this->getMode() << "'." << std::endl;
  • code/branches/presentation3/src/modules/questsystem/QuestManager.cc

    r6536 r6940  
    114114        if(result.second) //!< If inserting was a success.
    115115        {
     116            quest->setRegistered();
    116117            COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
    117118            return true;
     
    122123           return false;
    123124        }
     125    }
     126
     127    /**
     128    @brief
     129        Unregisters a Quest in the QuestManager.
     130    */
     131    bool QuestManager::unregisterQuest(Quest* quest)
     132    {
     133        return this->questMap_.erase(quest->getId()) == 1;
    124134    }
    125135
     
    146156        if(result.second) //!< If inserting was a success.
    147157        {
     158            hint->setRegistered();
    148159            COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
    149160            return true;
     
    154165           return false;
    155166        }
     167    }
     168
     169    /**
     170    @brief
     171        Unregisters a QuestHint in the QuestManager.
     172    */
     173    bool QuestManager::unregisterHint(QuestHint* hint)
     174    {
     175        return this->hintMap_.erase(hint->getId()) == 1;
    156176    }
    157177
     
    169189    Quest* QuestManager::findQuest(const std::string & questId)
    170190    {
    171         if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
     191        if(questId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
    172192        {
    173193            ThrowException(Argument, "Invalid questId.");
     
    203223    QuestHint* QuestManager::findHint(const std::string & hintId)
    204224    {
    205         if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
     225        if(hintId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
    206226        {
    207227            ThrowException(Argument, "Invalid hintId.");
  • code/branches/presentation3/src/modules/questsystem/QuestManager.h

    r6536 r6940  
    7676
    7777            bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
    78             bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
     78            bool unregisterQuest(Quest* quest); //!< Unregisters a Quest in the QuestManager.
     79            bool registerHint(QuestHint* hint); //!< Registers a QuestHint in the QuestManager.
     80            bool unregisterHint(QuestHint* hint); //!< Unregisters a QuestHint in the QuestManager.
    7981
    8082            Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
Note: See TracChangeset for help on using the changeset viewer.