Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2011, 8:53:28 PM (14 years ago)
Author:
dafrick
Message:

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

Location:
code/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r8327 r8706  
    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
     42#include "controllers/HumanController.h"
    3543#include "interfaces/GametypeMessageListener.h"
     44#include "interfaces/NotificationListener.h"
     45
     46#include "PlayerInfo.h"
    3647
    3748namespace orxonox
     
    4556    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4657
     58    registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn);
     59    registerMemberNetworkFunction(GametypeInfo, changedSpawned);
     60
     61    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
     62
     63    /**
     64    @brief
     65        Registers and initializes the object.
     66    */
    4767    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
    4868    {
    4969        RegisterObject(GametypeInfo);
    50 
     70       
    5171        this->bStarted_ = false;
    5272        this->bEnded_ = false;
    53         this->startCountdown_ = 0;
     73        this->startCountdown_ = 0.0f;
    5474        this->bStartCountdownRunning_ = false;
     75        this->counter_ = 0;
     76        this->spawned_ = false;
     77        this->readyToSpawn_ = false;
    5578
    5679        this->registerVariables();
     
    6386    void GametypeInfo::registerVariables()
    6487    {
    65         registerVariable(this->bStarted_,               VariableDirection::ToClient);
    66         registerVariable(this->bEnded_,                 VariableDirection::ToClient);
     88        registerVariable(this->bStarted_,               VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted));
     89        registerVariable(this->bEnded_,                 VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded));
     90        registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning));
    6791        registerVariable(this->startCountdown_,         VariableDirection::ToClient);
    68         registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient);
     92        registerVariable(this->counter_,                VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter));
    6993        registerVariable(this->hudtemplate_,            VariableDirection::ToClient);
    7094    }
     95
     96    /**
     97    @brief
     98        Is called when the game has changed to started.
     99    */
     100    void GametypeInfo::changedStarted(void)
     101    {
     102        NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     103    }
     104
     105    /**
     106    @brief
     107        Is called when the game has changed to ended.
     108    */
     109    void GametypeInfo::changedEnded(void)
     110    {
     111        // If the game has ended, a "Game has ended" notification is displayed.
     112        if(this->hasEnded())
     113            NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER);
     114    }
     115
     116    /**
     117    @brief
     118        Is called when the start countdown has been either started or stopped.
     119    */
     120    void GametypeInfo::changedStartCountdownRunning(void)
     121    {
     122        // Send first countdown notification if the countdown has started.
     123        if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     124            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     125    }
     126
     127    /**
     128    @brief
     129        Is called when the start countdown counter has changed.
     130    */
     131    void GametypeInfo::changedCountdownCounter(void)
     132    {
     133        // Send countdown notification if the counter has gone down.
     134        if(this->isReadyToSpawn() &&  !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     135            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     136    }
     137
     138    /**
     139    @brief
     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);
     157    }
     158
     159    /**
     160    @brief
     161        Inform the GametypeInfo that the game has started.
     162    */
     163    void GametypeInfo::start(void)
     164    {
     165        if(this->bStarted_)
     166            return;
     167       
     168        this->bStarted_ = true;
     169        this->changedStarted();
     170    }
     171
     172    /**
     173    @brief
     174        Inform the GametypeInfo that the game has ended.
     175    */
     176    void GametypeInfo::end(void)
     177    {
     178        if(this->bEnded_)
     179            return;
     180
     181        this->bEnded_ = true;
     182        this->changedEnded();
     183    }
     184
     185    /**
     186    @brief
     187        Set the start countdown to the input value.
     188    @param countdown
     189        The countdown to be set.
     190    */
     191    void GametypeInfo::setStartCountdown(float countdown)
     192    {
     193        if(this->startCountdown_ == countdown || countdown < 0.0f)
     194            return;
     195       
     196        this->startCountdown_ = countdown;
     197        // Set the counter to the ceiling of the current countdown.
     198        this->counter_ = std::ceil(countdown);
     199        this->changedCountdownCounter();
     200    }
     201
     202    /**
     203    @brief
     204        Count down the start countdown by the specified value.
     205    @param countDown
     206        The amount by which we count down.
     207    */
     208    void GametypeInfo::countdownStartCountdown(float countDown)
     209    {
     210        float newCountdown = this->startCountdown_ - countDown;
     211        // If we have switched integers or arrived at zero, we also count down the start countdown counter.
     212        if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f)
     213            this->countDown();
     214        this->startCountdown_ = newCountdown;
     215    }
     216
     217    /**
     218    @brief
     219        Count down the start countdown counter.
     220    */
     221    void GametypeInfo::countDown()
     222    {
     223        if(this->counter_ == 0)
     224            return;
     225       
     226        this->counter_--;
     227        this->changedCountdownCounter();
     228    }
     229
     230    /**
     231    @brief
     232        Inform the GametypeInfo about the start of the start countdown.
     233    */
     234    void GametypeInfo::startStartCountdown(void)
     235    {
     236        if(GameMode::isMaster())
     237        {
     238            if(this->bStartCountdownRunning_)
     239                return;
     240
     241            this->bStartCountdownRunning_ = true;
     242            this->changedStartCountdownRunning();
     243        }
     244    }
     245
     246    /**
     247    @brief
     248        Inform the GametypeInfo about the stop of the start countdown.
     249    */
     250    void GametypeInfo::stopStartCountdown(void)
     251    {
     252        if(GameMode::isMaster())
     253        {
     254            if(!this->bStartCountdownRunning_)
     255                return;
     256
     257            this->bStartCountdownRunning_ = false;
     258            this->changedStartCountdownRunning();
     259        }
     260    }
     261
     262    /**
     263    @brief
     264        Inform the GametypeInfo about a player that is ready to spawn.
     265    @param player
     266        The player that is ready to spawn.
     267    */
     268    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
     269    {
     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        }
     279    }
     280
     281    /**
     282    @brief
     283        Inform the GametypeInfo about a player whose Pawn has been killed.
     284    @param player
     285        The player whose Pawn has been killed.
     286    */
     287    void GametypeInfo::pawnKilled(PlayerInfo* player)
     288    {
     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        }
     297    }
     298
     299    /**
     300    @brief
     301        Inform the GametypeInfo about a player that has spawned.
     302    @param player
     303        The player that has spawned.
     304    */
     305    void GametypeInfo::playerSpawned(PlayerInfo* player)
     306    {
     307        if(GameMode::isMaster())
     308        {
     309            if(this->hasStarted() && !this->hasEnded())
     310
     311                this->setSpawnedHelper(player, true);
     312        }
     313    }
     314
     315    /**
     316    @brief
     317        Inform the GametypeInfo that the local player has changed its spawned status.
     318    @param spawned
     319        Whether the local player has changed to spawned or to not spawned.
     320    */
     321    void GametypeInfo::changedSpawned(bool spawned)
     322    {
     323        if(this->spawned_ == spawned)
     324            return;
     325       
     326        this->spawned_ = spawned;
     327        // Clear the notifications if the Player has spawned.
     328        if(this->spawned_ && !this->hasEnded())
     329            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     330    }
     331
     332    /**
     333    @brief
     334        Inform the GametypeInfo about a player that has entered,
     335    @param player
     336        The player that has entered.
     337    */
     338    void GametypeInfo::playerEntered(PlayerInfo* player)
     339    {
     340        if(GameMode::isMaster())
     341        {
     342            if( player->isHumanPlayer() )
     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    /**
     355    @brief
     356        Helper method. Sends changedReadyToSpawn notifiers over the network.
     357    @param player
     358        The player that has changed its ready to spawn status.
     359    @param ready
     360        The new ready to spawn status.
     361    */
     362    void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready)
     363    {
     364        if(GameMode::isMaster())
     365        {
     366            if(player->getClientID() == CLIENTID_SERVER)
     367                this->changedReadyToSpawn(ready);
     368            else
     369                callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready);
     370        }
     371    }
     372
     373    /**
     374    @brief
     375        Helper method. Sends changedSpawned notifiers over the network.
     376    @param player
     377        The player that has changed its spawned status.
     378    @param ready
     379        The new spawned status.
     380    */
     381    void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned)
     382    {
     383        if(GameMode::isMaster())
     384        {
     385            if(player->getClientID() == CLIENTID_SERVER)
     386                    this->changedSpawned(spawned);
     387            else
     388                callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned);
     389        }
     390    }
     391
     392    // Announce messages.
     393    // TODO: Replace with notifications.
    71394
    72395    void GametypeInfo::sendAnnounceMessage(const std::string& message)
  • code/trunk/src/orxonox/infos/GametypeInfo.h

    r7163 r8706  
    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            /**
     64            @brief Get whether the game has started yet.
     65            @return Returns true if the game has started, false if not.
     66            */
    4767            inline bool hasStarted() const
    4868                { return this->bStarted_; }
     69            void changedStarted(void); // Is called when the game has changed to started.
     70           
     71            /**
     72            @brief Get whether the game has ended yet.
     73            @return Returns true if the game has ended, false if not.
     74            */
    4975            inline bool hasEnded() const
    5076                { return this->bEnded_; }
     77            void changedEnded(void); // Is called when the game has changed to ended.
    5178
     79            /**
     80            @brief Get whether the start countdown is currently running.
     81            @return Returns true if the countdown is running, false if not.
     82            */
    5283            inline bool isStartCountdownRunning() const
    5384                { return this->bStartCountdownRunning_; }
     85            void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
     86
     87            /**
     88            @brief Get the current value of the start countdown.
     89            @return Returns the current value of the start countdown.
     90            */
    5491            inline float getStartCountdown() const
    5592                { return this->startCountdown_; }
     93
     94            /**
     95            @brief Get the current start countdown counter.
     96                   The start countdown counter only has integer values that correspond to the actually displayed countdown.
     97            @return Returns the current integer countdown counter.
     98            */
     99            inline unsigned int getStartCountdownCounter() const
     100                { return this->counter_; }
     101            void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
     102
     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.
    56118
    57119            inline const std::string& getHUDTemplate() const
     
    70132            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
    71133            void dispatchFadingMessage(const std::string& message);
     134           
     135        protected:
     136            void start(void); // Inform the GametypeInfo that the game has started.
     137            void end(void); // Inform the GametypeInfo that the game has ended.
     138            void setStartCountdown(float countdown); // Set the start countdown to the input value.
     139            void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value.
     140            void countDown(); // Count down the start countdown counter.
     141            void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown.
     142            void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown.
     143            void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
     144            void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
     145            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,
     147
     148            inline void setHUDTemplate(const std::string& templateName)
     149                { this->hudtemplate_ = templateName; };
    72150
    73151        private:
    74152            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.
    75155
    76             bool bStarted_;
    77             bool bEnded_;
    78             bool bStartCountdownRunning_;
    79             float startCountdown_;
     156            static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
     157
     158            bool bStarted_; //!< Whether the game has started,
     159            bool bEnded_; //!< Whether the game has ended.
     160            bool bStartCountdownRunning_; //!< Whether the start countdown is running.
     161            float startCountdown_; //!< The current value of the start countdown.
     162            unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
    80163            std::string hudtemplate_;
     164           
     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.
    81168    };
    82169}
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r8327 r8706  
    5151        this->controllableEntity_ = 0;
    5252        this->controllableEntityID_ = OBJECTID_UNKNOWN;
    53         this->oldControllableEntity_ = 0;
    5453
    5554        this->gtinfo_ = 0;
     
    151150            return;
    152151
    153         if (this->oldControllableEntity_)
     152        while (this->previousControllableEntity_.size() > 0)
    154153            this->stopTemporaryControl();
     154       
    155155        if (this->controllableEntity_)
    156156            this->stopControl();
     
    177177            return;
    178178
    179         assert( this->oldControllableEntity_==0 );
    180 
    181         this->oldControllableEntity_ = this->controllableEntity_;
     179        this->controllableEntity_->destroyHud(); // HACK-ish
     180        this->previousControllableEntity_.push_back(WeakPtr<ControllableEntity>(this->controllableEntity_));
    182181        this->controllableEntity_ = entity;
    183182        this->controllableEntityID_ = entity->getObjectID();
     
    194193    void PlayerInfo::stopControl()
    195194    {
    196         if ( this->oldControllableEntity_ )
     195        while ( this->previousControllableEntity_.size() > 0)
    197196            this->stopTemporaryControl();
    198197
     
    215214    }
    216215
     216    void PlayerInfo::pauseControl()
     217    {
     218        ControllableEntity* entity = this->controllableEntity_;
     219
     220        if (!entity)
     221            return;
     222
     223        this->controllableEntity_->getController()->setActive(false);
     224        //this->controllableEntity_->getController()->setControllableEntity(NULL);
     225        this->controllableEntity_->setController(0);
     226    }
     227
    217228    void PlayerInfo::stopTemporaryControl()
    218229    {
    219230        ControllableEntity* entity = this->controllableEntity_;
    220231
    221         assert( this->controllableEntity_ && this->oldControllableEntity_ );
    222         if( !entity || !this->oldControllableEntity_ )
     232        assert(this->controllableEntity_ != NULL);
     233        if( !entity || this->previousControllableEntity_.size() == 0 )
    223234            return;
    224235
    225236        this->controllableEntity_->setController(0);
     237        this->controllableEntity_->destroyHud(); // HACK-ish
    226238       
    227         this->controllableEntity_ = this->oldControllableEntity_;
     239//        this->controllableEntity_ = this->previousControllableEntity_.back();
     240        do {
     241            this->controllableEntity_ = this->previousControllableEntity_.back();
     242        } while(this->controllableEntity_ == NULL && this->previousControllableEntity_.size() > 0);
    228243        this->controllableEntityID_ = this->controllableEntity_->getObjectID();
    229         this->oldControllableEntity_ = 0;
    230 
    231         if ( this->controllableEntity_ && this->controller_)
     244        this->previousControllableEntity_.pop_back();
     245
     246        if ( this->controllableEntity_ != NULL && this->controller_ != NULL)
    232247            this->controller_->setControllableEntity(this->controllableEntity_);
     248
     249         // HACK-ish
     250        if(this->controllableEntity_ != NULL)
     251            this->controllableEntity_->createHud();
    233252
    234253        if ( GameMode::isMaster() )
  • code/trunk/src/orxonox/infos/PlayerInfo.h

    r7163 r8706  
    6868            void startControl(ControllableEntity* entity);
    6969            void stopControl();
     70            void pauseControl();
    7071            void startTemporaryControl(ControllableEntity* entity);
    7172            void stopTemporaryControl();
     
    9899            Controller* controller_;
    99100            ControllableEntity* controllableEntity_;
    100             ControllableEntity* oldControllableEntity_;
     101            std::vector< WeakPtr<ControllableEntity> > previousControllableEntity_; //!< List of the previous ControllableEntities if repeatedly startTemporary control was called. The ControllableEntity at the back is the most recent.
    101102            unsigned int controllableEntityID_;
    102103
Note: See TracChangeset for help on using the changeset viewer.