Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1387 for code/trunk


Ignore:
Timestamp:
May 22, 2008, 5:22:33 PM (17 years ago)
Author:
FelixSchulthess
Message:

made HUD singleton

Location:
code/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/bin/keybindings.ini

    r1376 r1387  
    1515KeyEQUALS=activateConsole
    1616KeyBACK=
    17 KeyTAB=cycleFocus
     17KeyTAB=cycleRadarFocus
    1818KeyQ=
    1919KeyW=
  • code/trunk/src/orxonox/Orxonox.cc

    r1374 r1387  
    180180  {
    181181    // keep in mind: the order of deletion is very important!
    182     if (this->orxonoxHUD_)
    183       delete this->orxonoxHUD_;
     182//    if (this->orxonoxHUD_)
     183//      delete this->orxonoxHUD_;
    184184    Loader::close();
    185185    InputManager::destroy();
     
    348348    // Load the HUD
    349349    COUT(3) << "Orxonox: Loading HUD..." << std::endl;
    350     orxonoxHUD_ = new HUD(1);
     350    orxonoxHUD_ = &HUD::getSingleton();
    351351
    352352    COUT(3) << "Orxonox: Loading Console..." << std::endl;
     
    487487//      orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());
    488488      if (eventTimes[3].back() - eventTimes[3].front() != 0)
    489         orxonoxHUD_->setFPS(50000.0f/(eventTimes[3].back() - eventTimes[3].front()));
     489        HUD::setFPS(50000.0f/(eventTimes[3].back() - eventTimes[3].front()));
    490490
    491491      // Iterate through all Tickables and call their tick(dt) function
  • code/trunk/src/orxonox/hud/HUD.cc

    r1375 r1387  
    4343namespace orxonox
    4444{
     45    ConsoleCommandShortcut(HUD, cycleRadarFocus, AccessLevel::User);
     46
    4547    using namespace Ogre;
    4648
    47     HUD::HUD(int zoom){
     49    HUD::HUD(){
    4850        om = &Ogre::OverlayManager::getSingleton();
    4951
     
    103105        radar->addObject(Vector3(0.0, 4000.0, 0.0));
    104106        radar->addObject(Vector3(0.0, 0.0, 6800.0));
    105         RadarOverlayElement::cycleFocus();
     107    }
     108
     109    HUD::~HUD(){
     110        //todo: clean up objects
    106111    }
    107112
     
    123128    }
    124129
    125     void HUD::setFPS(float fps){
    126         fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
     130    /*static*/HUD& HUD::getSingleton(){
     131        static HUD theInstance;
     132        return theInstance;
    127133    }
    128134
    129     HUD::~HUD(void){
     135    /*static*/void HUD::setFPS(float fps){
     136        HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
     137    }
     138
     139    /*static*/void HUD::cycleRadarFocus(){
     140        HUD::getSingleton().radar->cycleFocus();
    130141    }
    131142}
  • code/trunk/src/orxonox/hud/HUD.h

    r1374 r1387  
    4646    {
    4747        private:
     48            HUD();
     49            HUD(HUD& instance);
     50            ~HUD();
    4851            Ogre::OverlayManager* om;
    4952            Ogre::Overlay* orxonoxHUD;
     
    5659
    5760        public:
    58             HUD(int zoom);
    59             ~HUD();
    60             void setFPS(float fps);
    6161            virtual void tick(float);
    6262
     63            static HUD* instance_s;
     64            static HUD& getSingleton();
     65            static void setFPS(float fps);
     66            static void cycleRadarFocus();
    6367    };
    6468}
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1362 r1387  
    3030namespace orxonox
    3131{
    32     ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);
    3332
    3433    using namespace Ogre;
    3534
    36     RadarOverlayElement* RadarOverlayElement::instance_s = NULL;
    37 
    3835    RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
    39         RadarOverlayElement::instance_s = this;
    4036    }
    4137
     
    205201        }
    206202
    207         /*static*/void RadarOverlayElement::cycleFocus(){
    208             if(RadarOverlayElement::instance_s == NULL) return;
    209 
    210             if(RadarOverlayElement::instance_s->focus_ == NULL){
    211             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;
     203        void RadarOverlayElement::cycleFocus(){
     204            if(focus_ == NULL){
     205            focus_ = firstRadarObject_;
    212206            }
    213207        else{
    214             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");
    215             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;
    216         }
    217 
    218         if(RadarOverlayElement::instance_s->focus_ == NULL){
    219             RadarOverlayElement::instance_s->navMarker_->hide();
    220         }
    221         else{
    222             RadarOverlayElement::instance_s->navMarker_->show();
    223             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");
     208            focus_->panel_->setMaterialName("Orxonox/RedDot");
     209            focus_ = focus_->next;
     210        }
     211
     212        if(focus_ == NULL){
     213            navMarker_->hide();
     214        }
     215        else{
     216            navMarker_->show();
     217            focus_->panel_->setMaterialName("Orxonox/WhiteDot");
    224218        }
    225219        }
  • code/trunk/src/orxonox/hud/RadarOverlayElement.h

    r1362 r1387  
    7272            void addObject(Vector3 pos);
    7373            void listObjects();
     74            void cycleFocus();
    7475            float getDist2Focus();
    7576            float calcRadius(RadarObject* obj);
     
    8182                        RadarObject* lastRadarObject_;          // end of linked list
    8283                        RadarObject* focus_;                    // object that is focussed
    83 
    84             static RadarOverlayElement* instance_s;
    85             static void cycleFocus();
    8684        };
    8785}
Note: See TracChangeset for help on using the changeset viewer.