[Orxonox-commit 2619] r7324 - in code/branches/notifications/src/modules: notifications objects/triggers questsystem
dafrick at orxonox.net
dafrick at orxonox.net
Thu Sep 2 10:06:51 CEST 2010
Author: dafrick
Date: 2010-09-02 10:06:51 +0200 (Thu, 02 Sep 2010)
New Revision: 7324
Modified:
code/branches/notifications/src/modules/notifications/CMakeLists.txt
code/branches/notifications/src/modules/notifications/Notification.cc
code/branches/notifications/src/modules/notifications/Notification.h
code/branches/notifications/src/modules/notifications/NotificationDispatcher.cc
code/branches/notifications/src/modules/notifications/NotificationDispatcher.h
code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.cc
code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.h
code/branches/notifications/src/modules/objects/triggers/Trigger.cc
code/branches/notifications/src/modules/questsystem/QuestNotification.cc
Log:
Hiding MultiTrigger behind PlayerTrigger for consistency of use.
Trying some things out with notifications.
Modified: code/branches/notifications/src/modules/notifications/CMakeLists.txt
===================================================================
--- code/branches/notifications/src/modules/notifications/CMakeLists.txt 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/notifications/CMakeLists.txt 2010-09-02 08:06:51 UTC (rev 7324)
@@ -15,6 +15,7 @@
PCH_FILE
NotificationsPrecompiledHeaders.h
LINK_LIBRARIES
+ objects
orxonox
overlays
SOURCE_FILES ${NOTIFICATIONS_SRC_FILES}
Modified: code/branches/notifications/src/modules/notifications/Notification.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/Notification.cc 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/notifications/Notification.cc 2010-09-02 08:06:51 UTC (rev 7324)
@@ -34,6 +34,7 @@
#include "Notification.h"
#include "core/CoreIncludes.h"
+#include "network/NetworkFunction.h"
#include "NotificationManager.h"
namespace orxonox
@@ -41,14 +42,17 @@
CreateUnloadableFactory(Notification);
+ registerMemberNetworkFunction(Notification, send);
+
/**
@brief
Default constructor. Initializes the object.
*/
- Notification::Notification(BaseObject* creator) : BaseObject(creator)
+ Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
{
RegisterObject(Notification);
this->initialize();
+ this->registerVariables();
}
/**
@@ -57,11 +61,12 @@
@param message
The message of the Notification.
*/
- Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
+ Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
{
RegisterObject(Notification);
this->initialize();
this->message_ = message;
+ this->registerVariables();
}
/**
@@ -84,15 +89,11 @@
this->sent_ = false;
}
- /**
- @brief
- Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
- @return
- Returns true if successful.
- */
- bool Notification::send(void)
+ void Notification::registerVariables(void)
{
- return this->send(NotificationManager::NONE);
+ registerVariable(this->message_);
+ registerVariable(this->sender_);
+ registerVariable(this->sent_);
}
/**
@@ -103,19 +104,26 @@
@return
Returns true if successful.
*/
- bool Notification::send(const std::string & sender)
+ bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
{
- if(this->isSent()) //TODO: Needed?
- return false;
-
- this->sender_ = sender;
- bool successful = NotificationManager::getInstance().registerNotification(this);
- if(!successful)
- return false;
- this->sent_ = true;
+ if(GameMode::isMaster())
+ {
+ if(this->isSent()) //TODO: Needed?
+ return false;
- COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
+ this->sender_ = sender;
+ bool successful = NotificationManager::getInstance().registerNotification(this);
+ if(!successful)
+ return false;
+ this->sent_ = true;
+ COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
+ }
+ else
+ {
+ callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
+ }
+
return true;
}
Modified: code/branches/notifications/src/modules/notifications/Notification.h
===================================================================
--- code/branches/notifications/src/modules/notifications/Notification.h 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/notifications/Notification.h 2010-09-02 08:06:51 UTC (rev 7324)
@@ -38,6 +38,7 @@
#include <string>
#include "core/BaseObject.h"
+#include "network/synchronisable/Synchronisable.h"
namespace orxonox
{
@@ -48,15 +49,14 @@
@author
Damian 'Mozork' Frick
*/
- class _NotificationsExport Notification : public BaseObject
+ class _NotificationsExport Notification : public BaseObject, public Synchronisable
{
public:
Notification(BaseObject* creator);
Notification(BaseObject* creator, const std::string & message);
virtual ~Notification();
- bool send(void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;
- bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
+ bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
/**
@brief Checks whether the Notification was sent.
@@ -82,6 +82,7 @@
bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
void initialize(void);
+ void registerVariables(void);
};
Modified: code/branches/notifications/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationDispatcher.cc 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/notifications/NotificationDispatcher.cc 2010-09-02 08:06:51 UTC (rev 7324)
@@ -38,6 +38,9 @@
#include "core/EventIncludes.h"
#include "Notification.h"
#include "NotificationManager.h"
+#include "interfaces/PlayerTrigger.h"
+#include "infos/PlayerInfo.h"
+#include "worldentities/pawns/Pawn.h"
namespace orxonox
{
@@ -85,13 +88,15 @@
/**
@brief
Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
+ @param clientId
+ The id of the client the notification should be dispatched to.
*/
- void NotificationDispatcher::dispatch(void)
+ void NotificationDispatcher::dispatch(unsigned int clientId)
{
const std::string message = this->createNotificationMessage();
Notification* notification = new Notification(this, message);
- notification->send(this->getSender());
+ notification->send(clientId, this->getSender());
}
/**
@@ -102,15 +107,44 @@
@return
Returns true if the NotificationDispatcher was successfully triggered.
*/
- bool NotificationDispatcher::trigger(bool triggered)
+ bool NotificationDispatcher::trigger(bool triggered, BaseObject* trigger)
{
if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed.
return false;
COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
- this->dispatch();
+ PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
+ Pawn* pawn = NULL;
+ // If the trigger is a PlayerTrigger.
+ if(pTrigger != NULL)
+ {
+ if(!pTrigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
+ return false;
+ else
+ pawn = pTrigger->getTriggeringPlayer();
+ }
+ else
+ return false;
+
+ if(pawn == NULL)
+ {
+ COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
+ return false;
+ }
+
+ //! Extract the PlayerInfo from the Pawn.
+ PlayerInfo* player = pawn->getPlayer();
+
+ if(player == NULL)
+ {
+ COUT(3) << "The PlayerInfo* is NULL." << std::endl;
+ return false;
+ }
+
+ this->dispatch(player->getClientID());
+
return true;
}
Modified: code/branches/notifications/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationDispatcher.h 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/notifications/NotificationDispatcher.h 2010-09-02 08:06:51 UTC (rev 7324)
@@ -64,8 +64,8 @@
const std::string& getSender(void)
{ return this->sender_; }
- void dispatch(void); //!< Dispatches a specific Notification.
- bool trigger(bool triggered); //!< Is called when the NotificationDispatcher is triggered.
+ void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
+ bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
protected:
std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
Modified: code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.cc
===================================================================
--- code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.cc 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.cc 2010-09-02 08:06:51 UTC (rev 7324)
@@ -34,6 +34,7 @@
#include "MultiTriggerContainer.h"
#include "core/CoreIncludes.h"
+#include "worldentities/pawns/Pawn.h"
namespace orxonox
{
@@ -64,6 +65,13 @@
MultiTriggerContainer::MultiTriggerContainer(BaseObject* creator, MultiTrigger* originator, BaseObject* data) : BaseObject(creator), originator_(originator), data_(data)
{
RegisterObject(MultiTriggerContainer);
+
+ Pawn* pawn = orxonox_cast<Pawn*>(data);
+ if(pawn != NULL)
+ {
+ this->setForPlayer(true);
+ this->setTriggeringPlayer(pawn);
+ }
}
/**
Modified: code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.h
===================================================================
--- code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.h 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.h 2010-09-02 08:06:51 UTC (rev 7324)
@@ -37,6 +37,7 @@
#include "objects/ObjectsPrereqs.h"
#include "core/BaseObject.h"
+#include "interfaces/PlayerTrigger.h"
namespace orxonox
{
@@ -47,7 +48,7 @@
@author
Damian 'Mozork' Frick
*/
- class _ObjectsExport MultiTriggerContainer : public BaseObject
+ class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger
{
public:
@@ -71,6 +72,7 @@
private:
MultiTrigger* originator_; //!< The originator.
BaseObject* data_; //!< The data.
+
};
}
Modified: code/branches/notifications/src/modules/objects/triggers/Trigger.cc
===================================================================
--- code/branches/notifications/src/modules/objects/triggers/Trigger.cc 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/objects/triggers/Trigger.cc 2010-09-02 08:06:51 UTC (rev 7324)
@@ -159,7 +159,6 @@
void Trigger::triggered(bool bIsTriggered)
{
- COUT(1) << "Trigger triggered." << std::endl; //TODO: Remove debug.
this->fireEvent(bIsTriggered);
}
Modified: code/branches/notifications/src/modules/questsystem/QuestNotification.cc
===================================================================
--- code/branches/notifications/src/modules/questsystem/QuestNotification.cc 2010-09-02 01:16:08 UTC (rev 7323)
+++ code/branches/notifications/src/modules/questsystem/QuestNotification.cc 2010-09-02 08:06:51 UTC (rev 7324)
@@ -72,7 +72,7 @@
*/
bool QuestNotification::send(void)
{
- return this->Notification::send(QuestNotification::SENDER);
+ return true;//this->Notification::send(QuestNotification::SENDER); //TODO: Adjust.
}
More information about the Orxonox-commit
mailing list