Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 12, 2011, 12:31:23 AM (13 years ago)
Author:
dafrick
Message:

Merging tutoriallevel2 branch into tutoriallevel3 branch.

Location:
code/branches/tutoriallevel3
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3

  • code/branches/tutoriallevel3/src/orxonox/LevelManager.cc

    r8079 r8453  
    222222                this->nextLevel_ = this->availableLevels_.begin();
    223223            }
     224
    224225            while(this->nextIndex_ != index)
    225226            {
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc

    r8327 r8453  
    5959        this->defaultControllableEntity_ = Class(Spectator);
    6060
     61        this->bFirstTick_ = true;
     62       
    6163        this->bAutoStart_ = false;
    6264        this->bForceSpawn_ = false;
     
    112114        SUPER(Gametype, tick, dt);
    113115
     116        // Activate the GametypeInfo.
     117        if(this->bFirstTick_)
     118        {
     119            this->gtinfo_->setActive(true);
     120            this->bFirstTick_ = false;
     121        }
     122
    114123        //count timer
    115124        if (timerIsActive_)
     
    121130        }
    122131
    123         if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
    124             this->gtinfo_->startCountdown_ -= dt;
    125 
    126         if (!this->gtinfo_->bStarted_)
     132        if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
     133            this->gtinfo_->countdownStartCountdown(dt);
     134
     135        if (!this->gtinfo_->hasStarted())
    127136            this->checkStart();
    128         else if (!this->gtinfo_->bEnded_)
     137        else if (!this->gtinfo_->hasEnded())
    129138            this->spawnDeadPlayersIfRequested();
    130139
     
    136145        this->addBots(this->numberOfBots_);
    137146
    138         this->gtinfo_->bStarted_ = true;
     147        this->gtinfo_->start();
    139148
    140149        this->spawnPlayersIfRequested();
     
    143152    void Gametype::end()
    144153    {
    145         this->gtinfo_->bEnded_ = true;
     154        this->gtinfo_->end();
    146155
    147156        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     
    270279                }
    271280
     281                if(victim->getPlayer()->isHumanPlayer())
     282                    this->gtinfo_->pawnKilled(victim->getPlayer());
     283
    272284                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
    273285                if (victim->getCamera())
     
    346358                it->second.state_ = PlayerState::Dead;
    347359
    348                 if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
     360                if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
    349361                {
    350362                    this->spawnPlayerAsDefaultPawn(it->first);
     
    357369    void Gametype::checkStart()
    358370    {
    359         if (!this->gtinfo_->bStarted_)
    360         {
    361             if (this->gtinfo_->bStartCountdownRunning_)
    362             {
    363                 if (this->gtinfo_->startCountdown_ <= 0)
    364                 {
    365                     this->gtinfo_->bStartCountdownRunning_ = false;
    366                     this->gtinfo_->startCountdown_ = 0;
     371        if (!this->gtinfo_->hasStarted())
     372        {
     373            if (this->gtinfo_->isStartCountdownRunning())
     374            {
     375                if (this->gtinfo_->getStartCountdown() <= 0.0f)
     376                {
     377                    this->gtinfo_->stopStartCountdown();
     378                    this->gtinfo_->setStartCountdown(0.0f);;
    367379                    this->start();
    368380                }
     
    384396                        if (it->first->isHumanPlayer())
    385397                            hashumanplayers = true;
     398
     399                        // Inform the GametypeInfo that the player is ready to spawn.
     400                        // TODO: Can it happen, that that changes?
     401                        if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
     402                            this->gtinfo_->playerReadyToSpawn(it->first);
    386403                    }
    387404                    if (allplayersready && hashumanplayers)
     
    389406                        // If in developer's mode, there is no start countdown.
    390407                        if(Core::getInstance().inDevMode())
    391                             this->gtinfo_->startCountdown_ = 0;
     408                            this->start();
    392409                        else
    393                             this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
    394                         this->gtinfo_->bStartCountdownRunning_ = true;
     410                            this->gtinfo_->setStartCountdown(this->initialStartCountdown_);
     411                        this->gtinfo_->startStartCountdown();
    395412                    }
    396413                }
     
    402419    {
    403420        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     421        {
    404422            if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    405423                this->spawnPlayer(it->first);
     424        }
    406425    }
    407426
     
    422441            player->startControl(spawnpoint->spawn());
    423442            this->players_[player].state_ = PlayerState::Alive;
     443
     444            if(player->isHumanPlayer())
     445                this->gtinfo_->playerSpawned(player);
     446           
    424447            this->playerPostSpawn(player);
    425448        }
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h

    r8178 r8453  
    7878
    7979            inline bool hasStarted() const
    80                 { return this->gtinfo_->bStarted_; }
     80                { return this->gtinfo_->hasStarted(); }
    8181            inline bool hasEnded() const
    82                 { return this->gtinfo_->bEnded_; }
     82                { return this->gtinfo_->hasEnded(); }
    8383
    8484            virtual void start();
     
    114114
    115115            inline bool isStartCountdownRunning() const
    116                 { return this->gtinfo_->bStartCountdownRunning_; }
     116                { return this->gtinfo_->isStartCountdownRunning(); }
    117117            inline float getStartCountdown() const
    118                 { return this->gtinfo_->startCountdown_; }
     118                { return this->gtinfo_->getStartCountdown(); }
    119119
    120120            inline void setHUDTemplate(const std::string& name)
    121                 { this->gtinfo_->hudtemplate_ = name; }
     121                { this->gtinfo_->setHUDTemplate(name); }
    122122            inline const std::string& getHUDTemplate() const
    123                 { return this->gtinfo_->hudtemplate_; }
     123                { return this->gtinfo_->getHUDTemplate(); }
    124124
    125125            void addBots(unsigned int amount);
     
    168168            SmartPtr<GametypeInfo> gtinfo_;
    169169
     170            bool bFirstTick_; //!< Whether this is the first tick or not.
     171           
    170172            bool bAutoStart_;
    171173            bool bForceSpawn_;
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc

    r8327 r8453  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.cc
     31    @brief Implementation of the GametypeInfo class
     32*/
    2833
    2934#include "GametypeInfo.h"
     
    3136#include "core/CoreIncludes.h"
    3237#include "core/GameMode.h"
     38#include "network/Host.h"
    3339#include "network/NetworkFunction.h"
    34 #include "network/Host.h"
     40#include "util/Convert.h"
     41
    3542#include "interfaces/GametypeMessageListener.h"
     43#include "interfaces/NotificationListener.h"
     44
     45#include "PlayerInfo.h"
    3646
    3747namespace orxonox
     
    4555    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4656
     57    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
     58
     59    /**
     60    @brief
     61        Registers and initializes the object.
     62    */
    4763    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
    4864    {
    4965        RegisterObject(GametypeInfo);
    5066
     67        this->bActive_ = false; // At first the GametypeInfo is inactive.
     68       
    5169        this->bStarted_ = false;
    5270        this->bEnded_ = false;
    53         this->startCountdown_ = 0;
     71        this->startCountdown_ = 0.0f;
    5472        this->bStartCountdownRunning_ = false;
     73        this->counter_ = 0;
    5574
    5675        this->registerVariables();
     
    6382    void GametypeInfo::registerVariables()
    6483    {
    65         registerVariable(this->bStarted_,               VariableDirection::ToClient);
    66         registerVariable(this->bEnded_,                 VariableDirection::ToClient);
     84        registerVariable(this->bStarted_,               VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted));
     85        registerVariable(this->bEnded_,                 VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded));
     86        registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning));
    6787        registerVariable(this->startCountdown_,         VariableDirection::ToClient);
    68         registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient);
     88        registerVariable(this->counter_,                VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter));
    6989        registerVariable(this->hudtemplate_,            VariableDirection::ToClient);
     90    }
     91
     92    /**
     93    @brief
     94        Is called when the activity has changed.
     95    */
     96    void GametypeInfo::changedActivity(void)
     97    {
     98        SUPER(GametypeInfo, changedActivity);
     99
     100        // If the GametypeInfo has become active the "Press [Fire] to start the match" notification is sent.
     101        if(this->isActive())
     102            NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER);
     103    }
     104
     105    /**
     106    @brief
     107        Is called when the game has changed to started.
     108    */
     109    void GametypeInfo::changedStarted(void)
     110    {
     111       
     112    }
     113
     114    /**
     115    @brief
     116        Is called when the game has changed to ended.
     117    */
     118    void GametypeInfo::changedEnded(void)
     119    {
     120        // If the game has ended, a "Game has ended" notification is displayed.
     121        if(this->hasEnded())
     122            NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER);
     123    }
     124
     125    /**
     126    @brief
     127        Is called when the start countdown has been either started or stopped.
     128    */
     129    void GametypeInfo::changedStartCountdownRunning(void)
     130    {
     131        // Clear the notifications if the countdown has stopped running.
     132        if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     133            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     134        // Send first countdown notification if the countdown has started.
     135        if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     136            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     137    }
     138
     139    /**
     140    @brief
     141        Is called when the start countdown counter has changed.
     142    */
     143    void GametypeInfo::changedCountdownCounter(void)
     144    {
     145        // Send countdown notification if the counter has gone down.
     146        if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     147            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     148    }
     149
     150    /**
     151    @brief
     152        Is called when a player has become ready to spawn.
     153    @param player
     154        The player that has become ready to spawn.
     155    */
     156    void GametypeInfo::changedReadyToSpawn(PlayerInfo* player)
     157    {
     158        // Send "Waiting for other players" over the network to the right player if a player has become ready to spawn.
     159        if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     160            NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     161        // Clear the notifications if the player has respawned.
     162        if(this->hasStarted() && !this->hasEnded())
     163            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
     164    }
     165
     166    /**
     167    @brief
     168        Inform the GametypeInfo that the game has started.
     169    */
     170    void GametypeInfo::start(void)
     171    {
     172        if(this->bStarted_)
     173            return;
     174       
     175        this->bStarted_ = true;
     176        this->changedStarted();
     177    }
     178
     179    /**
     180    @brief
     181        Inform the GametypeInfo that the game has ended.
     182    */
     183    void GametypeInfo::end(void)
     184    {
     185        if(this->bEnded_)
     186            return;
     187
     188        this->bEnded_ = true;
     189        this->changedEnded();
     190    }
     191
     192    /**
     193    @brief
     194        Set the start countdown to the input value.
     195    @param countdown
     196        The countdown to be set.
     197    */
     198    void GametypeInfo::setStartCountdown(float countdown)
     199    {
     200        if(this->startCountdown_ == countdown || countdown < 0.0f)
     201            return;
     202       
     203        this->startCountdown_ = countdown;
     204        // Set the counter to the ceiling of the current countdown.
     205        this->counter_ = ceil(countdown);
     206        this->changedCountdownCounter();
     207    }
     208
     209    /**
     210    @brief
     211        Count down the start countdown by the specified value.
     212    @param countDown
     213        The amount by which we count down.
     214    */
     215    void GametypeInfo::countdownStartCountdown(float countDown)
     216    {
     217        float newCountdown = this->startCountdown_ - countDown;
     218        // If we have switched integers or arrived at zero, we also count down the start countdown counter.
     219        if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f)
     220            this->countDown();
     221        this->startCountdown_ = newCountdown;
     222    }
     223
     224    /**
     225    @brief
     226        Count down the start countdown counter.
     227    */
     228    void GametypeInfo::countDown()
     229    {
     230        if(this->counter_ == 0)
     231            return;
     232       
     233        this->counter_--;
     234        this->changedCountdownCounter();
     235    }
     236
     237    /**
     238    @brief
     239        Inform the GametypeInfo about the start of the start countdown.
     240    */
     241    void GametypeInfo::startStartCountdown(void)
     242    {
     243        if(this->bStartCountdownRunning_)
     244            return;
     245       
     246        this->bStartCountdownRunning_ = true;
     247        this->changedStartCountdownRunning();
     248    }
     249
     250    /**
     251    @brief
     252        Inform the GametypeInfo about the stop of the start countdown.
     253    */
     254    void GametypeInfo::stopStartCountdown(void)
     255    {
     256        if(!this->bStartCountdownRunning_)
     257            return;
     258       
     259        this->bStartCountdownRunning_ = false;
     260        this->changedStartCountdownRunning();
     261    }
     262
     263    /**
     264    @brief
     265        Inform the GametypeInfo about a player that is ready to spawn.
     266    @param player
     267        The player that is ready to spawn.
     268    */
     269    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
     270    {
     271        // If the player has spawned already.
     272        if(this->spawned_.find(player) != this->spawned_.end())
     273            return;
     274
     275        this->spawned_.insert(player);
     276        this->changedReadyToSpawn(player);
     277    }
     278
     279    /**
     280    @brief
     281        Inform the GametypeInfo about a player whose Pawn has been killed.
     282    @param player
     283        The player whose Pawn has been killed.
     284    */
     285    void GametypeInfo::pawnKilled(PlayerInfo* player)
     286    {
     287        NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     288        // Remove the player from the list of players that have spawned, since it currently is not.
     289        this->spawned_.erase(player);
     290    }
     291
     292    /**
     293    @brief
     294        Inform the GametypeInfo about a player that has spawned.
     295    @param player
     296        The player that has spawned.
     297    */
     298    void GametypeInfo::playerSpawned(PlayerInfo* player)
     299    {
     300        if(this->hasStarted() && !this->hasEnded())
     301            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
    70302    }
    71303
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h

    r7163 r8453  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.h
     31    @brief Definition of the GametypeInfo class
     32*/
    2833
    2934#ifndef _GametypeInfo_H__
     
    3338
    3439#include <string>
     40
    3541#include "Info.h"
    3642
    3743namespace orxonox
    3844{
     45
     46    /**
     47    @brief
     48        The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it.
     49
     50    @author
     51        Fabian 'x3n' Landau
     52    @author
     53        Damian 'Mozork' Frick
     54    */
    3955    class _OrxonoxExport GametypeInfo : public Info
    4056    {
     
    4561            virtual ~GametypeInfo();
    4662
     63            virtual void changedActivity(void); // Is called when the activity has changed.
     64
     65            /**
     66            @brief Get whether the game has started yet.
     67            @return Returns true if the game has started, false if not.
     68            */
    4769            inline bool hasStarted() const
    4870                { return this->bStarted_; }
     71            void changedStarted(void); // Is called when the game has changed to started.
     72           
     73            /**
     74            @brief Get whether the game has ended yet.
     75            @return Returns true if the game has ended, false if not.
     76            */
    4977            inline bool hasEnded() const
    5078                { return this->bEnded_; }
     79            void changedEnded(void); // Is called when the game has changed to ended.
    5180
     81            /**
     82            @brief Get whether the start countdown is currently running.
     83            @return Returns true if the countdown is running, false if not.
     84            */
    5285            inline bool isStartCountdownRunning() const
    5386                { return this->bStartCountdownRunning_; }
     87            void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
     88
     89            /**
     90            @brief Get the current value of the start countdown.
     91            @return Returns the current value of the start countdown.
     92            */
    5493            inline float getStartCountdown() const
    5594                { return this->startCountdown_; }
     95
     96            /**
     97            @brief Get the current start countdown counter.
     98                   The start countdown counter only has integer values that correspond to the actually displayed countdown.
     99            @return Returns the current integer countdown counter.
     100            */
     101            inline unsigned int getStartCountdownCounter() const
     102                { return this->counter_; }
     103            void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
    56104
    57105            inline const std::string& getHUDTemplate() const
     
    70118            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
    71119            void dispatchFadingMessage(const std::string& message);
     120           
     121        protected:
     122            void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.
     123           
     124            void start(void); // Inform the GametypeInfo that the game has started.
     125            void end(void); // Inform the GametypeInfo that the game has ended.
     126            void setStartCountdown(float countdown); // Set the start countdown to the input value.
     127            void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value.
     128            void countDown(); // Count down the start countdown counter.
     129            void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown.
     130            void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown.
     131            void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
     132            void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
     133            void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
     134
     135            inline void setHUDTemplate(const std::string& templateName)
     136                { this->hudtemplate_ = templateName; };
    72137
    73138        private:
    74139            void registerVariables();
    75140
    76             bool bStarted_;
    77             bool bEnded_;
    78             bool bStartCountdownRunning_;
    79             float startCountdown_;
     141            static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
     142
     143            bool bStarted_; //!< Whether the game has started,
     144            bool bEnded_; //!< Whether the game has ended.
     145            bool bStartCountdownRunning_; //!< Whether the start countdown is running.
     146            float startCountdown_; //!< The current value of the start countdown.
     147            unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
    80148            std::string hudtemplate_;
     149           
     150            std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned.
    81151    };
    82152}
  • code/branches/tutoriallevel3/src/orxonox/interfaces/CMakeLists.txt

    r7504 r8453  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  InterfaceCompilation.cc
     3  NotificationListener.cc
    34  Pickupable.cc
    45  PickupCarrier.cc
  • code/branches/tutoriallevel3/src/orxonox/interfaces/InterfaceCompilation.cc

    r7606 r8453  
    8686        RegisterRootObject(Rewardable);
    8787    }
    88 
    89     //----------------------------
    90     // NotificationListener
    91     //----------------------------
    92     NotificationListener::NotificationListener()
    93     {
    94         RegisterRootObject(NotificationListener);
    95     }
    9688}
  • code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.h

    r7552 r8453  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Damian 'Mozork' Frick
    2424 *   Co-authors:
    2525 *      ...
     
    4848namespace orxonox
    4949{
    50     class Notification;
     50    // TODO: Document.
     51    namespace notificationMessageType
     52    {
     53        enum Value {
     54            info,
     55            important
     56        };
     57    }
     58   
     59    namespace notificationSendMode
     60    {
     61        enum Value {
     62            local,
     63            network,
     64            broadcast
     65        };
     66    }
     67   
     68    namespace notificationCommand
     69    {
     70        enum Value {
     71            none,
     72            clear
     73        };
     74    }
    5175
     76    // TODO: Update doc.
    5277    /**
    5378    @brief
    5479        NotificationListener interface.
    5580
    56         The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed)
    57         When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager".
     81        The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
     82        The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton.
     83
     84        When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
    5885
    5986    @author
    60         Fabian 'x3n' Landau
    61 
     87        Damian 'Mozork' Frick
     88       
    6289    @ingroup Notifications
     90    @todo Consistent terminology between message, notification and command.
    6391    */
    6492    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
     
    6997
    7098            /**
    71             @brief Get the senders that are targets of this NotificationListener.
    72             @return Returns the set of senders that are targets of this NotificationListener.
     99            @brief Sends a Notification with the specified message to the specified client from the specified sender.
     100            @param message The message that should be sent.
     101            @param sender The sender that sent the notification. Default is 'none'.
     102            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
     103            @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.
     104            @param clientId The id of the client the notification should be sent to. Default is 0.
    73105            */
    74             virtual const std::set<std::string> & getTargetsSet(void) = 0;
     106            static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     107                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
     108            /**
     109            @brief Sends a specified command to the specified client from the specified sender.
     110            @param command The command that should be sent (and later executed).
     111            @param sender The sender that sent the notification. Default is 'none'.
     112            @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
     113            @param clientId The id of the client the command should be sent to. Default is 0.
     114            */
     115            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     116                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
    75117
     118            static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
     119
     120            //TODO: Make protected?
     121           
    76122            /**
    77             @brief Updates the whole NotificationListener.
    78                    This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations.
     123            @brief Registers a notification with the NotificationListener.
     124                   This needs to be overloaded by each class inheriting from NotificationListener.
     125            @param message The notification's message.
     126            @param sender The sender of the notification.
     127            @param type The type of the notification.
     128            @return Returns true if the notification was successfully registered, false if not.
    79129            */
    80             virtual void update(void) = 0;
     130            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     131                { return false; }
    81132            /**
    82             @brief Updates the NotificationListener, when a new Notification has come in at the specified time.
    83             @param notification A pointer to the @ref orxonox::Notification "Notification".
    84             @param time The time the @ref orxonox::Notification "Notification" has come in.
     133            @brief Executes a command with the NotificationListener
     134                   This needs to be overloaded by each class inheriting from NotificationListener.
     135            @param command The command to be executed.
     136            @param sender The sender of the command.
     137            @return Returns true if the command was successfully executed, false if not.
    85138            */
    86             virtual void update(Notification* notification, const std::time_t & time) = 0;
     139            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
     140
     141        public:
     142           
     143            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
     144            static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
     145           
     146            //! Commands
     147            static const std::string COMMAND_CLEAR;
     148            static const std::string COMMAND_NONE;
     149           
     150        protected:
     151            static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
     152
     153            static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
     154            static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
    87155    };
    88156}
Note: See TracChangeset for help on using the changeset viewer.