Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2428


Ignore:
Timestamp:
Dec 13, 2008, 10:54:26 PM (15 years ago)
Author:
landauf
Message:
  • Moved some variables from Gametype to GametypeInfo (Gametype exists only on the Server while GametypeInfo is synchronized)
  • Created a new HUD-element, GametypeStatus, based on GametypeInfo (the same effect was formerly achieved by using a hack in Spectator and a TextOverlay)
  • HumanController creates a HUD (additionally to the SpaceShips HUD) which includes GametypeStatus and ChatOverlay and even more in the future
Location:
code/branches/objecthierarchy2/src
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/core/BaseObject.h

    r2369 r2428  
    135135            inline Scene* getScene() const { return this->scene_; }
    136136
    137             inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
     137            inline void setGametype(Gametype* gametype)
     138            {
     139                if (gametype != this->gametype_)
     140                {
     141                    this->oldGametype_ = this->gametype_;
     142                    this->gametype_ = gametype;
     143                    this->changedGametype();
     144                }
     145            }
    138146            inline Gametype* getGametype() const { return this->gametype_; }
    139147            inline Gametype* getOldGametype() const { return this->oldGametype_; }
    140             virtual inline void changedGametype() {}
     148            virtual void changedGametype() {}
    141149
    142150            void fireEvent();
     
    197205    SUPER_FUNCTION(6, BaseObject, changedMainState, false);
    198206    SUPER_FUNCTION(9, BaseObject, changedName, false);
     207    SUPER_FUNCTION(10, BaseObject, changedGametype, false);
    199208}
    200209
  • code/branches/objecthierarchy2/src/core/Super.h

    r2369 r2428  
    265265    #define SUPER_changedName(classname, functionname, ...) \
    266266        SUPER_NOARGS(classname, functionname)
     267
     268    #define SUPER_changedGametype(classname, functionname, ...) \
     269        SUPER_NOARGS(classname, functionname)
    267270    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    268271
     
    513516
    514517        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false)
     518            ()
     519        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     520
     521        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false)
    515522            ()
    516523        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     
    568575    SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup);
    569576    SUPER_INTRUSIVE_DECLARATION(changedName);
     577    SUPER_INTRUSIVE_DECLARATION(changedGametype);
    570578    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    571579
  • code/branches/objecthierarchy2/src/network/Synchronisable.h

    r2171 r2428  
    111111    static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
    112112
    113     inline unsigned int getObjectID(){return objectID;}
    114     inline unsigned int getClassID(){return classID;}
     113    inline unsigned int getObjectID() const { return objectID; }
     114    inline unsigned int getClassID() const { return classID; }
    115115  protected:
    116116    Synchronisable(BaseObject* creator);
  • code/branches/objecthierarchy2/src/orxonox/OrxonoxPrereqs.h

    r2422 r2428  
    187187    class OverlayGroup;
    188188    class OverlayText;
     189    class GametypeStatus;
    189190
    190191    //gui
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/Controller.cc

    r2087 r2428  
    3131
    3232#include "core/CoreIncludes.h"
     33#include "overlays/OverlayGroup.h"
    3334
    3435namespace orxonox
     
    4243        this->player_ = 0;
    4344        this->controllableEntity_ = 0;
     45        this->hud_ = 0;
     46        this->bUpdateHUD_ = false;
    4447    }
    4548
    4649    Controller::~Controller()
    4750    {
     51        if (this->isInitialized() && this->hud_)
     52            delete this->hud_;
     53    }
     54
     55    void Controller::changedControllableEntity()
     56    {
     57        if (this->bUpdateHUD_)
     58        {
     59            this->updateHUD();
     60            this->bUpdateHUD_ = false;
     61        }
     62
     63        if (this->hud_)
     64            this->hud_->setOwner(this->getControllableEntity());
     65    }
     66
     67    void Controller::updateHUD()
     68    {
     69        if (this->hud_)
     70        {
     71            delete this->hud_;
     72            this->hud_ = 0;
     73        }
     74
     75        if (this->hudtemplate_ != "")
     76        {
     77            this->hud_ = new OverlayGroup(this);
     78            this->hud_->addTemplate(this->hudtemplate_);
     79            this->hud_->setOwner(this->getControllableEntity());
     80        }
    4881    }
    4982}
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/Controller.h

    r2362 r2428  
    5757            inline ControllableEntity* getControllableEntity() const
    5858                { return this->controllableEntity_; }
    59             virtual void changedControllableEntity() {}
     59            virtual void changedControllableEntity();
     60
     61            inline void setHUDTemplate(const std::string& name)
     62            {
     63                if (name != this->hudtemplate_)
     64                {
     65                    this->hudtemplate_ = name;
     66                    if (this->controllableEntity_)
     67                        this->updateHUD();
     68                    else
     69                        this->bUpdateHUD_ = true;
     70                }
     71            }
     72            inline const std::string& getHUDTemplate() const
     73                { return this->hudtemplate_; }
     74
     75            inline OverlayGroup* getHUD() const
     76                { return this->hud_; }
    6077
    6178        protected:
     79            void updateHUD();
     80
    6281            PlayerInfo* player_;
    6382            ControllableEntity* controllableEntity_;
     83            std::string hudtemplate_;
     84            OverlayGroup* hud_;
     85            bool bUpdateHUD_;
    6486    };
    6587}
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc

    r2369 r2428  
    3434
    3535#include "core/CoreIncludes.h"
     36#include "core/ConfigValueIncludes.h"
    3637#include "objects/infos/PlayerInfo.h"
    3738#include "objects/worldentities/pawns/Spectator.h"
     
    4445    CreateUnloadableFactory(Gametype);
    4546
    46     Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
     47    Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator)
    4748    {
    4849        RegisterObject(Gametype);
     
    5051        this->defaultControllableEntity_ = Class(Spectator);
    5152
    52         this->bStarted_ = false;
    53         this->bEnded_ = false;
    5453        this->bAutoStart_ = false;
    5554        this->bForceSpawn_ = false;
    5655
    5756        this->initialStartCountdown_ = 3;
    58         this->startCountdown_ = 0;
    59         this->bStartCountdownRunning_ = false;
     57
     58        this->setConfigValues();
     59    }
     60
     61    void Gametype::setConfigValues()
     62    {
     63        SetConfigValue(initialStartCountdown_, 3.0f);
    6064    }
    6165
     
    6468        SUPER(Gametype, tick, dt);
    6569
    66         if (this->bStartCountdownRunning_ && !this->bStarted_)
    67             this->startCountdown_ -= dt;
    68 
    69         if (!this->bStarted_)
     70        if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
     71            this->gtinfo_.startCountdown_ -= dt;
     72
     73        if (!this->gtinfo_.bStarted_)
    7074            this->checkStart();
    7175        else
     
    7882    {
    7983        COUT(0) << "game started" << std::endl;
    80         this->bStarted_ = true;
     84        this->gtinfo_.bStarted_ = true;
    8185
    8286        this->spawnPlayersIfRequested();
     
    8690    {
    8791        COUT(0) << "game ended" << std::endl;
    88         this->bEnded_ = true;
     92        this->gtinfo_.bEnded_ = true;
    8993    }
    9094
     
    173177                it->second = PlayerState::Dead;
    174178
    175                 if (!it->first->isReadyToSpawn() || !this->bStarted_)
     179                if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
    176180                {
    177181                    SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
     
    196200    void Gametype::checkStart()
    197201    {
    198         if (!this->bStarted_)
    199         {
    200             if (this->bStartCountdownRunning_)
    201             {
    202                 if (this->startCountdown_ <= 0)
    203                 {
    204                     this->bStartCountdownRunning_ = false;
    205                     this->startCountdown_ = 0;
     202        if (!this->gtinfo_.bStarted_)
     203        {
     204            if (this->gtinfo_.bStartCountdownRunning_)
     205            {
     206                if (this->gtinfo_.startCountdown_ <= 0)
     207                {
     208                    this->gtinfo_.bStartCountdownRunning_ = false;
     209                    this->gtinfo_.startCountdown_ = 0;
    206210                    this->start();
    207211                }
     
    226230                    if (allplayersready && hashumanplayers)
    227231                    {
    228                         this->startCountdown_ = this->initialStartCountdown_;
    229                         this->bStartCountdownRunning_ = true;
     232                        this->gtinfo_.startCountdown_ = this->initialStartCountdown_;
     233                        this->gtinfo_.bStartCountdownRunning_ = true;
    230234                    }
    231235                }
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.h

    r2171 r2428  
    3838#include "objects/worldentities/ControllableEntity.h"
    3939#include "objects/Tickable.h"
     40#include "objects/infos/GametypeInfo.h"
    4041
    4142namespace orxonox
     
    6061            virtual ~Gametype() {}
    6162
     63            void setConfigValues();
     64
    6265            virtual void tick(float dt);
    6366
     67            inline const GametypeInfo* getGametypeInfo() const
     68                { return &this->gtinfo_; }
     69
    6470            inline bool hasStarted() const
    65                 { return this->bStarted_; }
     71                { return this->gtinfo_.bStarted_; }
    6672            inline bool hasEnded() const
    67                 { return this->bEnded_; }
     73                { return this->gtinfo_.bEnded_; }
    6874
    6975            virtual void start();
     
    8894
    8995            inline bool isStartCountdownRunning() const
    90                 { return this->bStartCountdownRunning_; }
     96                { return this->gtinfo_.bStartCountdownRunning_; }
    9197            inline float getStartCountdown() const
    92                 { return this->startCountdown_; }
     98                { return this->gtinfo_.startCountdown_; }
    9399
    94100        private:
     
    104110            void spawnDeadPlayersIfRequested();
    105111
    106             bool bStarted_;
    107             bool bEnded_;
     112            GametypeInfo gtinfo_;
     113
    108114            bool bAutoStart_;
    109115            bool bForceSpawn_;
    110116
    111117            float initialStartCountdown_;
    112             float startCountdown_;
    113             bool bStartCountdownRunning_;
    114118
    115119            std::map<PlayerInfo*, PlayerState::Enum> players_;
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/CMakeLists.txt

    r2362 r2428  
    44  PlayerInfo.cc
    55  HumanPlayer.cc
     6  GametypeInfo.cc
    67)
    78
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/HumanPlayer.cc

    r2171 r2428  
    3737#include "objects/controllers/HumanController.h"
    3838#include "objects/gametypes/Gametype.h"
     39#include "overlays/OverlayGroup.h"
    3940
    4041namespace orxonox
     
    6364    {
    6465        SetConfigValue(nick_, "Player").callback(this, &HumanPlayer::configvaluecallback_changednick);
     66        SetConfigValue(hudtemplate_, "defaultHUD").callback(this, &HumanPlayer::configvaluecallback_changedHUDTemplate);
    6567    }
    6668
     
    6971        REGISTERSTRING(this->synchronize_nick_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));
    7072
    71         REGISTERDATA(this->clientID_,     direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
     73        REGISTERDATA(this->clientID_,           direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
    7274        REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));
    7375        REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));
     
    8385                this->setName(this->nick_);
    8486        }
     87    }
     88
     89    void HumanPlayer::configvaluecallback_changedHUDTemplate()
     90    {
     91        this->changedController();
    8592    }
    8693
     
    138145        this->networkcallback_clientIDchanged();
    139146    }
     147
     148    void HumanPlayer::changedController()
     149    {
     150        if (this->getController())
     151        {
     152            this->getController()->setHUDTemplate(this->hudtemplate_);
     153
     154            if (this->getController() && this->getController()->getHUD())
     155                this->getController()->getHUD()->setOwner(this->getControllableEntity());
     156        }
     157    }
    140158}
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/HumanPlayer.h

    r2362 r2428  
    5151            void setClientID(unsigned int clientID);
    5252
     53            virtual void changedController();
     54
    5355        protected:
    5456            void configvaluecallback_changednick();
     57            void configvaluecallback_changedHUDTemplate();
    5558            void networkcallback_changednick();
    5659            void networkcallback_clientIDchanged();
     
    6063            std::string nick_;
    6164            std::string synchronize_nick_;
     65            std::string hudtemplate_;
    6266            bool server_initialized_;
    6367            bool client_initialized_;
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.cc

    r2369 r2428  
    112112        if (this->controllableEntity_)
    113113            this->controller_->setControllableEntity(this->controllableEntity_);
     114        this->changedController();
    114115    }
    115116
    116117    void PlayerInfo::startControl(ControllableEntity* entity)
    117118    {
     119        if (entity == this->controllableEntity_)
     120            return;
     121
    118122        if (this->controllableEntity_)
    119123            this->stopControl(this->controllableEntity_);
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.h

    r2362 r2428  
    7171                { return this->controllableEntity_; }
    7272
     73            inline Controller* getController() const
     74                { return this->controller_; }
     75            virtual void changedController() {}
     76
    7377        protected:
    7478            void createController();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2361 r2428  
    3838#include "objects/worldentities/Camera.h"
    3939#include "objects/worldentities/CameraPosition.h"
     40#include "objects/gametypes/Gametype.h"
    4041#include "overlays/OverlayGroup.h"
    4142
     
    5960        this->bDestroyWhenPlayerLeft_ = false;
    6061
     62        this->gtinfo_ = 0;
     63        this->gtinfoID_ = OBJECTID_UNKNOWN;
     64        this->changedGametype();
     65
    6166        this->velocity_ = Vector3::ZERO;
    6267        this->acceleration_ = Vector3::ZERO;
     
    98103
    99104        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     105    }
     106
     107    void ControllableEntity::changedGametype()
     108    {
     109        SUPER(ControllableEntity, changedGametype);
     110
     111        this->gtinfo_ = 0;
     112        this->gtinfoID_ = OBJECTID_UNKNOWN;
     113
     114        if (this->getGametype() && this->getGametype()->getGametypeInfo())
     115        {
     116            this->gtinfo_ = this->getGametype()->getGametypeInfo();
     117            this->gtinfoID_ = this->gtinfo_->getObjectID();
     118        }
    100119    }
    101120
     
    199218    }
    200219
     220    void ControllableEntity::networkcallback_changedgtinfoID()
     221    {
     222        if (this->gtinfoID_ != OBJECTID_UNKNOWN)
     223        {
     224            this->gtinfo_ = dynamic_cast<GametypeInfo*>(Synchronisable::getSynchronisable(this->gtinfoID_));
     225
     226            if (!this->gtinfo_)
     227                this->gtinfoID_ = OBJECTID_UNKNOWN;
     228        }
     229    }
     230
    201231    void ControllableEntity::startLocalHumanControl()
    202232    {
     
    268298
    269299        REGISTERDATA(this->playerID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     300        REGISTERDATA(this->gtinfoID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedgtinfoID));
    270301    }
    271302
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h

    r2362 r2428  
    4646            virtual void tick(float dt);
    4747            void registerVariables();
     48
     49            virtual void changedGametype();
    4850
    4951            virtual void setPlayer(PlayerInfo* player);
     
    143145                { return this->bHasHumanController_; }
    144146
     147            inline const GametypeInfo* getGametypeInfo() const
     148                { return this->gtinfo_; }
     149
    145150        protected:
    146151            virtual void startLocalHumanControl();
     
    165170
    166171            void networkcallback_changedplayerID();
     172            void networkcallback_changedgtinfoID();
    167173
    168174            unsigned int server_overwrite_;
     
    190196            std::list<CameraPosition*> cameraPositions_;
    191197            std::string cameraPositionTemplate_;
     198
     199            const GametypeInfo* gtinfo_;
     200            unsigned int gtinfoID_;
    192201    };
    193202}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2422 r2428  
    5757        this->roll_ = 0;
    5858        this->setHudTemplate("spectatorhud");
    59         this->hudmode_ = 0;
    6059
    6160        this->setDestroyWhenPlayerLeft(true);
     
    9695        REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
    9796        REGISTERDATA(this->bGreeting_,             direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
    98         REGISTERDATA(this->hudmode_,               direction::toclient);
    9997    }
    10098
     
    112110    void Spectator::tick(float dt)
    113111    {
    114         this->updateHUD();
    115 
    116112        if (this->hasLocalController())
    117113        {
     
    193189        }
    194190    }
    195 
    196     void Spectator::updateHUD()
    197     {
    198         // <hack>
    199         if (Core::isMaster())
    200         {
    201             if (this->getPlayer() && this->getGametype())
    202             {
    203                 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())
    204                 {
    205                     if (!this->getPlayer()->isReadyToSpawn())
    206                         this->hudmode_ = 0;
    207                     else
    208                         this->hudmode_ = 1;
    209                 }
    210                 else if (!this->getGametype()->hasEnded())
    211                 {
    212                     if (this->getGametype()->isStartCountdownRunning())
    213                         this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());
    214                     else
    215                         this->hudmode_ = 3;
    216                 }
    217                 else
    218                     this->hudmode_ = 4;
    219             }
    220             else
    221                 return;
    222         }
    223 
    224         if (this->getHUD())
    225         {
    226             std::string text;
    227             int hudmode = this->hudmode_ % 10;
    228 
    229             switch (hudmode)
    230             {
    231                 case 0:
    232                     text = "Press [Fire] to start the match";
    233                     break;
    234                 case 1:
    235                     text = "Waiting for other players";
    236                     break;
    237                 case 2:
    238                     text = convertToString((this->hudmode_ - 2) / 10);
    239                     break;
    240                 case 3:
    241                     text = "Press [Fire] to respawn";
    242                     break;
    243                 case 4:
    244                     text = "Game has ended";
    245                     break;
    246                 default:;
    247             }
    248 
    249             std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();
    250             for (; it != this->getHUD()->getOverlays().end(); ++it)
    251             {
    252                 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")
    253                 {
    254                     OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);
    255                     if (overlay)
    256                         overlay->setCaption(text);
    257                     break;
    258                 }
    259             }
    260         }
    261         // </hack>
    262     }
    263191}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2362 r2428  
    6363            void changedGreeting();
    6464            void changedFlareVisibility();
    65             void updateHUD();
    6665
    6766            BillboardSet* greetingFlare_;
     
    7574            float pitch_;
    7675            float roll_;
    77 
    78             int hudmode_;
    7976    };
    8077}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/CMakeLists.txt

    r2369 r2428  
    66  HUDHealthBar.cc
    77  ChatOverlay.cc
     8  GametypeStatus.cc
    89)
    910
Note: See TracChangeset for help on using the changeset viewer.