[Orxonox-commit 2224] r6940 - code/branches/presentation3/src/modules/questsystem
dafrick at orxonox.net
dafrick at orxonox.net
Thu May 20 19:38:53 CEST 2010
Author: dafrick
Date: 2010-05-20 19:38:53 +0200 (Thu, 20 May 2010)
New Revision: 6940
Modified:
code/branches/presentation3/src/modules/questsystem/AddQuestHint.cc
code/branches/presentation3/src/modules/questsystem/ChangeQuestStatus.cc
code/branches/presentation3/src/modules/questsystem/Quest.cc
code/branches/presentation3/src/modules/questsystem/Quest.h
code/branches/presentation3/src/modules/questsystem/QuestHint.cc
code/branches/presentation3/src/modules/questsystem/QuestItem.cc
code/branches/presentation3/src/modules/questsystem/QuestItem.h
code/branches/presentation3/src/modules/questsystem/QuestListener.cc
code/branches/presentation3/src/modules/questsystem/QuestManager.cc
code/branches/presentation3/src/modules/questsystem/QuestManager.h
Log:
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.
Modified: code/branches/presentation3/src/modules/questsystem/AddQuestHint.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/AddQuestHint.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/AddQuestHint.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -84,7 +84,7 @@
*/
bool AddQuestHint::setHintId(const std::string & id)
{
- if(!QuestItem::isId(id))
+ if(id.compare(BLANKSTRING) == 0)
{
COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
return false;
Modified: code/branches/presentation3/src/modules/questsystem/ChangeQuestStatus.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/ChangeQuestStatus.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/ChangeQuestStatus.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -77,7 +77,7 @@
*/
bool ChangeQuestStatus::setQuestId(const std::string & id)
{
- if(!QuestItem::isId(id))
+ if(id.compare(BLANKSTRING) == 0)
{
COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
return false;
Modified: code/branches/presentation3/src/modules/questsystem/Quest.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/Quest.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/Quest.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -60,7 +60,8 @@
*/
Quest::~Quest()
{
-
+ if(this->isRegistered())
+ QuestManager::getInstance().unregisterQuest(this);
}
/**
Modified: code/branches/presentation3/src/modules/questsystem/Quest.h
===================================================================
--- code/branches/presentation3/src/modules/questsystem/Quest.h 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/Quest.h 2010-05-20 17:38:53 UTC (rev 6940)
@@ -103,7 +103,7 @@
bool start(PlayerInfo* player); //!< Sets a Quest to active.
virtual bool fail(PlayerInfo* player); //!< Fails the Quest.
virtual bool complete(PlayerInfo* player); //!< Completes the Quest.
-
+
bool addListener(QuestListener* listener); //!< Adds a QuestListener to the list of QuestListeners listening to this Quest.
protected:
Modified: code/branches/presentation3/src/modules/questsystem/QuestHint.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestHint.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestHint.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -58,7 +58,8 @@
*/
QuestHint::~QuestHint()
{
-
+ if(this->isRegistered())
+ QuestManager::getInstance().unregisterHint(this);
}
/**
Modified: code/branches/presentation3/src/modules/questsystem/QuestItem.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestItem.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestItem.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -45,6 +45,8 @@
*/
QuestItem::QuestItem(BaseObject* creator) : BaseObject(creator)
{
+ this->registered_ = false;
+
RegisterObject(QuestItem);
}
@@ -78,7 +80,7 @@
*/
void QuestItem::setId(const std::string & id)
{
- if(!isId(id)) //!< Checks whether the id is a valid id.
+ if(id.compare(BLANKSTRING) == 0) //!< Checks whether the id is a valid id.
{
COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl;
return;
@@ -87,17 +89,4 @@
this->id_ = id;
}
- /**
- @brief
- Checks whether an input id is of the required form.
- @param id
- The id to be checked.
- @return
- Returns true if the string is likely to be of the required form.
- */
- /*static*/ bool QuestItem::isId(const std::string & id)
- {
- return id.size() >= 32;
- }
-
}
Modified: code/branches/presentation3/src/modules/questsystem/QuestItem.h
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestItem.h 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestItem.h 2010-05-20 17:38:53 UTC (rev 6940)
@@ -40,6 +40,7 @@
#include <string>
#include "core/BaseObject.h"
+#include "QuestManager.h"
namespace orxonox
{
@@ -73,7 +74,17 @@
inline const QuestDescription* getDescription(void) const
{ return this->description_; }
- static bool isId(const std::string & id); //!< Checks whether a given id is valid.
+ /**
+ @brief Check whether the QuestItem is registered with the QuestManager.
+ @return Returns true if the QuestItem is registered with the QuestManager.
+ */
+ inline bool isRegistered(void)
+ { return this->registered_; }
+ /**
+ @brief Set the QuestItem as being registered with the QuestManager.
+ */
+ inline void setRegistered(void)
+ { this->registered_ = true; }
protected:
void setId(const std::string & id); //!< Sets the id of the QuestItem.
@@ -89,6 +100,8 @@
std::string id_; //!< Identifier. Should be of GUID form: http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Basic_structure
QuestDescription* description_; //!< The QuestDescription of the QuestItem.
+ bool registered_;
+
};
}
Modified: code/branches/presentation3/src/modules/questsystem/QuestListener.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestListener.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestListener.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -73,7 +73,8 @@
XMLPortParam(QuestListener, "questId", setQuestId, getQuestId, xmlelement, mode);
XMLPortParam(QuestListener, "mode", setMode, getMode, xmlelement, mode);
- this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
+ if(this->quest_ != NULL)
+ this->quest_->addListener(this); //!< Adds the QuestListener to the Quests list of listeners.
COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} with mode '" << this->getMode() << "'." << std::endl;
}
Modified: code/branches/presentation3/src/modules/questsystem/QuestManager.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestManager.cc 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestManager.cc 2010-05-20 17:38:53 UTC (rev 6940)
@@ -113,6 +113,7 @@
if(result.second) //!< If inserting was a success.
{
+ quest->setRegistered();
COUT(3) << "Quest with questId {" << quest->getId() << "} successfully inserted." << std::endl;
return true;
}
@@ -125,6 +126,15 @@
/**
@brief
+ Unregisters a Quest in the QuestManager.
+ */
+ bool QuestManager::unregisterQuest(Quest* quest)
+ {
+ return this->questMap_.erase(quest->getId()) == 1;
+ }
+
+ /**
+ @brief
Registers a QuestHint with the QuestManager to make it globally accessable.
Uses it's id to make sure to be able to be identify and retrieve it later.
@param hint
@@ -145,6 +155,7 @@
if(result.second) //!< If inserting was a success.
{
+ hint->setRegistered();
COUT(3) << "QuestHint with hintId {" << hint->getId() << "} successfully inserted." << std::endl;
return true;
}
@@ -157,6 +168,15 @@
/**
@brief
+ Unregisters a QuestHint in the QuestManager.
+ */
+ bool QuestManager::unregisterHint(QuestHint* hint)
+ {
+ return this->hintMap_.erase(hint->getId()) == 1;
+ }
+
+ /**
+ @brief
Finds a Quest with the given id.
@param questId
The id of the Quest sought for.
@@ -168,7 +188,7 @@
*/
Quest* QuestManager::findQuest(const std::string & questId)
{
- if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
+ if(questId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
{
ThrowException(Argument, "Invalid questId.");
}
@@ -202,7 +222,7 @@
*/
QuestHint* QuestManager::findHint(const std::string & hintId)
{
- if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
+ if(hintId.compare(BLANKSTRING) == 1) //!< Check vor validity of the given id.
{
ThrowException(Argument, "Invalid hintId.");
}
Modified: code/branches/presentation3/src/modules/questsystem/QuestManager.h
===================================================================
--- code/branches/presentation3/src/modules/questsystem/QuestManager.h 2010-05-20 14:39:03 UTC (rev 6939)
+++ code/branches/presentation3/src/modules/questsystem/QuestManager.h 2010-05-20 17:38:53 UTC (rev 6940)
@@ -75,7 +75,9 @@
CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export
bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
- bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
+ bool unregisterQuest(Quest* quest); //!< Unregisters a Quest in the QuestManager.
+ bool registerHint(QuestHint* hint); //!< Registers a QuestHint in the QuestManager.
+ bool unregisterHint(QuestHint* hint); //!< Unregisters a QuestHint in the QuestManager.
Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
More information about the Orxonox-commit
mailing list