Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7324


Ignore:
Timestamp:
Sep 2, 2010, 10:06:51 AM (14 years ago)
Author:
dafrick
Message:

Hiding MultiTrigger behind PlayerTrigger for consistency of use.
Trying some things out with notifications.

Location:
code/branches/notifications/src/modules
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/src/modules/notifications/CMakeLists.txt

    r7193 r7324  
    1616    NotificationsPrecompiledHeaders.h
    1717  LINK_LIBRARIES
     18    objects
    1819    orxonox
    1920    overlays
  • code/branches/notifications/src/modules/notifications/Notification.cc

    r7193 r7324  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "network/NetworkFunction.h"
    3738#include "NotificationManager.h"
    3839
     
    4243    CreateUnloadableFactory(Notification);
    4344
     45    registerMemberNetworkFunction(Notification, send);
     46
    4447    /**
    4548    @brief
    4649        Default constructor. Initializes the object.
    4750    */
    48     Notification::Notification(BaseObject* creator) : BaseObject(creator)
     51    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    4952    {
    5053        RegisterObject(Notification);
    5154        this->initialize();
     55        this->registerVariables();
    5256    }
    5357
     
    5862        The message of the Notification.
    5963    */
    60     Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
     64    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
    6165    {
    6266        RegisterObject(Notification);
    6367        this->initialize();
    6468        this->message_ = message;
     69        this->registerVariables();
    6570    }
    6671
     
    8590    }
    8691
    87     /**
    88     @brief
    89         Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
    90     @return
    91         Returns true if successful.
    92     */
    93     bool Notification::send(void)
     92    void Notification::registerVariables(void)
    9493    {
    95         return this->send(NotificationManager::NONE);
     94        registerVariable(this->message_);
     95        registerVariable(this->sender_);
     96        registerVariable(this->sent_);
    9697    }
    9798
     
    104105        Returns true if successful.
    105106    */
    106     bool Notification::send(const std::string & sender)
     107    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
    107108    {
    108         if(this->isSent()) //TODO: Needed?
    109             return false;
    110        
    111         this->sender_ = sender;
    112         bool successful = NotificationManager::getInstance().registerNotification(this);
    113         if(!successful)
    114             return false;
    115         this->sent_ = true;
     109        if(GameMode::isMaster())
     110        {
     111            if(this->isSent()) //TODO: Needed?
     112                return false;
    116113
    117         COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
     114            this->sender_ = sender;
     115            bool successful = NotificationManager::getInstance().registerNotification(this);
     116            if(!successful)
     117                return false;
     118            this->sent_ = true;
     119
     120            COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
     121        }
     122        else
     123        {
     124            callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
     125        }
    118126
    119127        return true;
  • code/branches/notifications/src/modules/notifications/Notification.h

    r7164 r7324  
    3939#include <string>
    4040#include "core/BaseObject.h"
     41#include "network/synchronisable/Synchronisable.h"
    4142
    4243namespace orxonox
     
    4950        Damian 'Mozork' Frick
    5051    */
    51     class _NotificationsExport Notification : public BaseObject
     52    class _NotificationsExport Notification : public BaseObject, public Synchronisable
    5253    {
    5354        public:
     
    5657            virtual ~Notification();
    5758
    58             bool send(void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;
    59             bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
     59            bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
    6060
    6161            /**
     
    8383
    8484            void initialize(void);
     85            void registerVariables(void);
    8586
    8687    };
  • code/branches/notifications/src/modules/notifications/NotificationDispatcher.cc

    r7285 r7324  
    3939#include "Notification.h"
    4040#include "NotificationManager.h"
     41#include "interfaces/PlayerTrigger.h"
     42#include "infos/PlayerInfo.h"
     43#include "worldentities/pawns/Pawn.h"
    4144
    4245namespace orxonox
     
    8689    @brief
    8790        Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
     91    @param clientId
     92        The id of the client the notification should be dispatched to.
    8893    */
    89     void NotificationDispatcher::dispatch(void)
     94    void NotificationDispatcher::dispatch(unsigned int clientId)
    9095    {
    9196        const std::string message = this->createNotificationMessage();
    9297        Notification* notification = new Notification(this, message);
    9398
    94         notification->send(this->getSender());
     99        notification->send(clientId, this->getSender());
    95100    }
    96101
     
    103108        Returns true if the NotificationDispatcher was successfully triggered.
    104109    */
    105     bool NotificationDispatcher::trigger(bool triggered)
     110    bool NotificationDispatcher::trigger(bool triggered, BaseObject* trigger)
    106111    {
    107112        if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed.
     
    110115        COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
    111116
    112         this->dispatch();
     117        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
     118        Pawn* pawn = NULL;
     119
     120        // If the trigger is a PlayerTrigger.
     121        if(pTrigger != NULL)
     122        {
     123            if(!pTrigger->isForPlayer())  //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
     124                return false;
     125            else
     126                pawn = pTrigger->getTriggeringPlayer();
     127        }
     128        else
     129            return false;
     130
     131        if(pawn == NULL)
     132        {
     133            COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
     134            return false;
     135        }
     136
     137        //! Extract the PlayerInfo from the Pawn.
     138        PlayerInfo* player = pawn->getPlayer();
     139
     140        if(player == NULL)
     141        {
     142            COUT(3) << "The PlayerInfo* is NULL." << std::endl;
     143            return false;
     144        }
     145
     146        this->dispatch(player->getClientID());
    113147
    114148        return true;
  • code/branches/notifications/src/modules/notifications/NotificationDispatcher.h

    r7285 r7324  
    6565                { return this->sender_; }
    6666
    67             void dispatch(void); //!< Dispatches a specific Notification.
    68             bool trigger(bool triggered); //!< Is called when the NotificationDispatcher is triggered.
     67            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
     68            bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
    6969
    7070        protected:
  • code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.cc

    r7301 r7324  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "worldentities/pawns/Pawn.h"
    3738
    3839namespace orxonox
     
    6566    {
    6667        RegisterObject(MultiTriggerContainer);
     68
     69        Pawn* pawn = orxonox_cast<Pawn*>(data);
     70        if(pawn != NULL)
     71        {
     72            this->setForPlayer(true);
     73            this->setTriggeringPlayer(pawn);
     74        }
    6775    }
    6876
  • code/branches/notifications/src/modules/objects/triggers/MultiTriggerContainer.h

    r7301 r7324  
    3838
    3939#include "core/BaseObject.h"
     40#include "interfaces/PlayerTrigger.h"
    4041
    4142namespace orxonox
     
    4849        Damian 'Mozork' Frick
    4950    */
    50     class _ObjectsExport MultiTriggerContainer : public BaseObject
     51    class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger
    5152    {
    5253
     
    7273            MultiTrigger* originator_; //!< The originator.
    7374            BaseObject* data_; //!< The data.
     75
    7476    };
    7577
  • code/branches/notifications/src/modules/objects/triggers/Trigger.cc

    r7319 r7324  
    160160  void Trigger::triggered(bool bIsTriggered)
    161161  {
    162       COUT(1) << "Trigger triggered." << std::endl; //TODO: Remove debug.
    163162    this->fireEvent(bIsTriggered);
    164163  }
  • code/branches/notifications/src/modules/questsystem/QuestNotification.cc

    r7163 r7324  
    7373    bool QuestNotification::send(void)
    7474    {
    75         return this->Notification::send(QuestNotification::SENDER);
     75        return true;//this->Notification::send(QuestNotification::SENDER); //TODO: Adjust.
    7676    }
    7777
Note: See TracChangeset for help on using the changeset viewer.