Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 28, 2011, 11:19:02 AM (14 years ago)
Author:
dafrick
Message:

Gametype status notifications now working.

Location:
code/branches/tutoriallevel3/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc

    r8453 r8634  
    5858
    5959        this->defaultControllableEntity_ = Class(Spectator);
    60 
    61         this->bFirstTick_ = true;
    6260       
    6361        this->bAutoStart_ = false;
     
    114112        SUPER(Gametype, tick, dt);
    115113
    116         // Activate the GametypeInfo.
    117         if(this->bFirstTick_)
    118         {
    119             this->gtinfo_->setActive(true);
    120             this->bFirstTick_ = false;
    121         }
    122 
    123114        //count timer
    124115        if (timerIsActive_)
     
    134125
    135126        if (!this->gtinfo_->hasStarted())
     127        {
     128            for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     129            {
     130                // Inform the GametypeInfo that the player is ready to spawn.
     131                if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
     132                    this->gtinfo_->playerReadyToSpawn(it->first);
     133            }
     134                   
    136135            this->checkStart();
     136        }
    137137        else if (!this->gtinfo_->hasEnded())
    138138            this->spawnDeadPlayersIfRequested();
     
    182182    {
    183183        this->players_[player].state_ = PlayerState::Joined;
     184        this->gtinfo_->playerEntered(player);
    184185    }
    185186
     
    396397                        if (it->first->isHumanPlayer())
    397398                            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);
    403399                    }
    404400                    if (allplayersready && hashumanplayers)
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h

    r8453 r8634  
    167167
    168168            SmartPtr<GametypeInfo> gtinfo_;
    169 
    170             bool bFirstTick_; //!< Whether this is the first tick or not.
    171169           
    172170            bool bAutoStart_;
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc

    r8453 r8634  
    4040#include "util/Convert.h"
    4141
     42#include "controllers/HumanController.h"
    4243#include "interfaces/GametypeMessageListener.h"
    4344#include "interfaces/NotificationListener.h"
     
    5556    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    5657
     58    registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn);
     59    registerMemberNetworkFunction(GametypeInfo, changedSpawned);
     60
    5761    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
    5862
     
    6468    {
    6569        RegisterObject(GametypeInfo);
    66 
    67         this->bActive_ = false; // At first the GametypeInfo is inactive.
    6870       
    6971        this->bStarted_ = false;
     
    7274        this->bStartCountdownRunning_ = false;
    7375        this->counter_ = 0;
     76        this->spawned_ = false;
     77        this->readyToSpawn_ = false;
    7478
    7579        this->registerVariables();
     
    9296    /**
    9397    @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
    10798        Is called when the game has changed to started.
    10899    */
     
    129120    void GametypeInfo::changedStartCountdownRunning(void)
    130121    {
    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);
    134122        // Send first countdown notification if the countdown has started.
    135         if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     123        if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
    136124            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
    137125    }
     
    144132    {
    145133        // Send countdown notification if the counter has gone down.
    146         if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     134        if(this->isReadyToSpawn() &&  !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
    147135            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
    148136    }
     
    150138    /**
    151139    @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());
     140        Inform the GametypeInfo that the local player has changed its ready to spawn status.
     141    @param ready
     142        Whether the player has become ready to spawn or not.
     143    */
     144    void GametypeInfo::changedReadyToSpawn(bool ready)
     145    {
     146        if(this->readyToSpawn_ == ready)
     147            return;
     148
     149        this->readyToSpawn_ = ready;
     150
     151        // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running.
     152        if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     153            NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER);
     154        // Send current countdown if the player is ready to spawn and the countdown has already started.
     155        else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     156            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
    164157    }
    165158
     
    241234    void GametypeInfo::startStartCountdown(void)
    242235    {
    243         if(this->bStartCountdownRunning_)
    244             return;
    245        
    246         this->bStartCountdownRunning_ = true;
    247         this->changedStartCountdownRunning();
     236        if(GameMode::isMaster())
     237        {
     238            if(this->bStartCountdownRunning_)
     239                return;
     240
     241            this->bStartCountdownRunning_ = true;
     242            this->changedStartCountdownRunning();
     243        }
    248244    }
    249245
     
    254250    void GametypeInfo::stopStartCountdown(void)
    255251    {
    256         if(!this->bStartCountdownRunning_)
    257             return;
    258        
    259         this->bStartCountdownRunning_ = false;
    260         this->changedStartCountdownRunning();
     252        if(GameMode::isMaster())
     253        {
     254            if(!this->bStartCountdownRunning_)
     255                return;
     256
     257            this->bStartCountdownRunning_ = false;
     258            this->changedStartCountdownRunning();
     259        }
    261260    }
    262261
     
    269268    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
    270269    {
    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);
     270        if(GameMode::isMaster())
     271        {
     272            // If the player has spawned already.
     273            if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end())
     274                return;
     275
     276            this->spawnedPlayers_.insert(player);
     277            this->setReadyToSpawnHelper(player, true);
     278        }
    277279    }
    278280
     
    285287    void GametypeInfo::pawnKilled(PlayerInfo* player)
    286288    {
    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);
     289        if(GameMode::isMaster())
     290        {
     291            NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     292            // Remove the player from the list of players that have spawned, since it currently is not.
     293            this->spawnedPlayers_.erase(player);
     294            this->setReadyToSpawnHelper(player, false);
     295            this->setSpawnedHelper(player, false);
     296        }
    290297    }
    291298
     
    298305    void GametypeInfo::playerSpawned(PlayerInfo* player)
    299306    {
    300         if(this->hasStarted() && !this->hasEnded())
    301             NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
    302     }
     307        if(GameMode::isMaster())
     308        {
     309            if(this->hasStarted() && !this->hasEnded())
     310            {
     311                //NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
     312                this->setSpawnedHelper(player, true);
     313            }
     314        }
     315    }
     316
     317    /**
     318    @brief
     319        Inform the GametypeInfo that the local player has changed its spawned status.
     320    @param spawned
     321        Whether the local player has changed to spawned or to not spawned.
     322    */
     323    void GametypeInfo::changedSpawned(bool spawned)
     324    {
     325        if(this->spawned_ == spawned)
     326            return;
     327       
     328        this->spawned_ = spawned;
     329        // Clear the notifications if the Player has spawned.
     330        if(this->spawned_ && !this->hasEnded())
     331            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     332    }
     333
     334    /**
     335    @brief
     336        Inform the GametypeInfo about a player that has entered,
     337    @param player
     338        The player that has entered.
     339    */
     340    void GametypeInfo::playerEntered(PlayerInfo* player)
     341    {
     342        if(GameMode::isMaster())
     343        {
     344            // Display "Press [Fire] to start the match" if the game has not yet ended.
     345            if(!this->hasEnded())
     346                NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     347            // Else display "Game has ended".
     348            else
     349                NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     350        }
     351    }
     352
     353    /**
     354    @brief
     355        Helper method. Sends changedReadyToSpawn notifiers over the network.
     356    @param player
     357        The player that has changed its ready to spawn status.
     358    @param ready
     359        The new ready to spawn status.
     360    */
     361    void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready)
     362    {
     363        if(GameMode::isMaster())
     364        {
     365            if(player->getClientID() == CLIENTID_SERVER)
     366                this->changedReadyToSpawn(ready);
     367            else
     368                callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready);
     369        }
     370    }
     371
     372    /**
     373    @brief
     374        Helper method. Sends changedSpawned notifiers over the network.
     375    @param player
     376        The player that has changed its spawned status.
     377    @param ready
     378        The new spawned status.
     379    */
     380    void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned)
     381    {
     382        if(GameMode::isMaster())
     383        {
     384            if(player->getClientID() == CLIENTID_SERVER)
     385                    this->changedSpawned(spawned);
     386            else
     387                callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned);
     388        }
     389    }
     390
     391    // Announce messages.
     392    // TODO: Replace with notifications.
    303393
    304394    void GametypeInfo::sendAnnounceMessage(const std::string& message)
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h

    r8453 r8634  
    6161            virtual ~GametypeInfo();
    6262
    63             virtual void changedActivity(void); // Is called when the activity has changed.
    64 
    6563            /**
    6664            @brief Get whether the game has started yet.
     
    103101            void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
    104102
     103            /**
     104            @brief Get whether the local player is ready to spawn.
     105            @return Returns true if the player is ready to spawn, false if not.
     106            */
     107            inline bool isReadyToSpawn() const
     108                { return this->readyToSpawn_; }
     109            void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status.
     110           
     111            /**
     112            @brief Get whether the local player is spawned.
     113            @return Returns true if the local player is currently spawned, false if not.
     114            */
     115            inline bool isSpawned() const
     116                { return this->spawned_; }
     117            void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status.
     118
    105119            inline const std::string& getHUDTemplate() const
    106120                { return this->hudtemplate_; }
     
    120134           
    121135        protected:
    122             void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.
    123            
    124136            void start(void); // Inform the GametypeInfo that the game has started.
    125137            void end(void); // Inform the GametypeInfo that the game has ended.
     
    132144            void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
    133145            void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
     146            void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered,
    134147
    135148            inline void setHUDTemplate(const std::string& templateName)
     
    138151        private:
    139152            void registerVariables();
     153            void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network.
     154            void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network.
    140155
    141156            static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
     
    148163            std::string hudtemplate_;
    149164           
    150             std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned.
     165            std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned.
     166            bool spawned_; //!< Whether the local Player is currently spawned.
     167            bool readyToSpawn_; //!< Whether the local Player is ready to spawn.
    151168    };
    152169}
  • code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.cc

    r8453 r8634  
    8282        else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)
    8383        {
    84             callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, (unsigned int)messageType);
     84            callStaticNetworkFunction(NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType);
    8585        }
    8686        else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)
    8787        {
    8888            // TODO: Works as intended?
    89             callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, (unsigned int)messageType);
     89            callStaticNetworkFunction(NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType);
    9090        }
    9191    }
Note: See TracChangeset for help on using the changeset viewer.