Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2369


Ignore:
Timestamp:
Dec 10, 2008, 3:37:48 AM (15 years ago)
Author:
landauf
Message:
  • Added a health bar
  • Some changes in CameraManager to handle the case when no camera exists after removing the last one, but this is still somehow buggy (freezes and later crashes reproducible but inexplicable after a few respawns)
  • Added PawnManager to handle destruction of Pawns without using delete within tick()
Location:
code/branches/objecthierarchy2/src
Files:
4 added
22 edited

Legend:

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

    r2254 r2369  
    196196    SUPER_FUNCTION(4, BaseObject, processEvent, false);
    197197    SUPER_FUNCTION(6, BaseObject, changedMainState, false);
     198    SUPER_FUNCTION(9, BaseObject, changedName, false);
    198199}
    199200
  • code/branches/objecthierarchy2/src/core/Super.h

    r2361 r2369  
    259259    #define SUPER_changedOwner(classname, functionname, ...) \
    260260        SUPER_NOARGS(classname, functionname)
     261
     262    #define SUPER_changedOverlayGroup(classname, functionname, ...) \
     263        SUPER_NOARGS(classname, functionname)
     264
     265    #define SUPER_changedName(classname, functionname, ...) \
     266        SUPER_NOARGS(classname, functionname)
    261267    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    262268
     
    501507            ()
    502508        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     509
     510        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false)
     511            ()
     512        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     513
     514        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false)
     515            ()
     516        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    503517        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    504518
     
    552566    SUPER_INTRUSIVE_DECLARATION(changedMainState);
    553567    SUPER_INTRUSIVE_DECLARATION(changedOwner);
     568    SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup);
     569    SUPER_INTRUSIVE_DECLARATION(changedName);
    554570    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    555571
  • code/branches/objecthierarchy2/src/core/Template.cc

    r2173 r2369  
    7272    void Template::changedName()
    7373    {
     74        SUPER(Template, changedName);
     75
    7476        if (this->getName() != "")
    7577        {
  • code/branches/objecthierarchy2/src/orxonox/CMakeLists.txt

    r2171 r2369  
    44  LevelManager.cc
    55  Main.cc
     6  PawnManager.cc
    67  PlayerManager.cc
    78  Settings.cc
  • code/branches/objecthierarchy2/src/orxonox/CameraManager.cc

    r2171 r2369  
    3030
    3131#include <OgreViewport.h>
     32#include <OgreSceneManager.h>
     33#include <OgreCamera.h>
    3234
    3335#include "core/Core.h"
    3436#include "objects/worldentities/Camera.h"
    35 
     37#include "objects/Scene.h"
     38#include "util/String.h"
    3639
    3740namespace orxonox
     
    4447        assert(singletonRef_s == 0);
    4548        singletonRef_s = this;
     49
     50        this->fallbackCamera_ = 0;
    4651    }
    4752
     
    5055        assert(singletonRef_s != 0);
    5156        singletonRef_s = 0;
     57
     58        if (this->fallbackCamera_)
     59        {
     60            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
     61COUT(0) << "remove camera-manager" << std::endl;
     62        }
    5263    }
    5364
     
    6879        if (this->cameraList_.size() > 0)
    6980            this->cameraList_.front()->removeFocus();
     81        else if (this->fallbackCamera_)
     82        {
     83            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
     84            this->fallbackCamera_ = 0;
     85COUT(0) << "remove fallback camera" << std::endl;
     86        }
    7087
    7188        camera->setFocus(this->viewport_);
    7289
     90        // make sure we don't add it twice
     91        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
     92            if ((*it) == camera)
     93                return;
     94
    7395        // add to list
    74         std::list<Camera*>::iterator it;
    75         for (it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
    76         {
    77             if ((*it) == camera)
    78                 return; // make sure we don't add it twice
    79         }
    8096        this->cameraList_.push_front(camera);
    8197    }
     
    92108            this->cameraList_.pop_front();
    93109
    94             // set new focus if necessary
    95             if (cameraList_.size() > 0)
    96                 cameraList_.front()->setFocus(this->viewport_);
     110            // set new focus if possible
     111            if (this->cameraList_.size() > 0)
     112                this->cameraList_.front()->setFocus(this->viewport_);
     113            else
     114            {
     115                // there are no more cameras, create a fallback
     116                if (!this->fallbackCamera_)
     117                {
     118COUT(0) << "create fallback camera" << std::endl;
     119                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
     120                }
     121                this->viewport_->setCamera(this->fallbackCamera_);
     122COUT(0) << "use fallback camera" << std::endl;
     123            }
    97124        }
    98125        else
  • code/branches/objecthierarchy2/src/orxonox/CameraManager.h

    r2171 r2369  
    6262            std::list<Camera*> cameraList_;
    6363            Ogre::Viewport* viewport_;
     64            Ogre::Camera* fallbackCamera_;
    6465
    6566            static CameraManager* singletonRef_s;
  • code/branches/objecthierarchy2/src/orxonox/OrxonoxPrereqs.h

    r2362 r2369  
    8282    class CameraManager;
    8383    class LevelManager;
     84    class PawnManager;
    8485    class PlayerManager;
    8586
     
    179180    class HUDRadar;
    180181    class HUDSpeedBar;
     182    class HUDHealthBar;
    181183    class InGameConsole;
    182184    class OrxonoxOverlay;
  • code/branches/objecthierarchy2/src/orxonox/objects/EventTarget.cc

    r2087 r2369  
    4848    void EventTarget::changedName()
    4949    {
     50        SUPER(EventTarget, changedName);
     51
    5052        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    5153            if (it->getName() == this->getName())
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc

    r2361 r2369  
    169169        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    170170        {
    171             if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_))
    172             {
    173                 SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
    174                 if (spawn)
    175                 {
    176                     // force spawn at spawnpoint with default pawn
    177                     ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
    178                     spawn->spawn(entity);
    179                     it->first->startControl(entity);
    180                     it->second = PlayerState::Dead;
    181                 }
    182                 else
    183                 {
    184                     COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
    185                     abort();
     171            if (!it->first->getControllableEntity())
     172            {
     173                it->second = PlayerState::Dead;
     174
     175                if (!it->first->isReadyToSpawn() || !this->bStarted_)
     176                {
     177                    SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
     178                    if (spawn)
     179                    {
     180                        // force spawn at spawnpoint with default pawn
     181                        ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
     182                        spawn->spawn(entity);
     183                        it->first->startControl(entity);
     184                        it->second = PlayerState::Dead;
     185                    }
     186                    else
     187                    {
     188                        COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
     189                        abort();
     190                    }
    186191                }
    187192            }
     
    211216                {
    212217                    bool allplayersready = true;
     218                    bool hashumanplayers = false;
    213219                    for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    214220                    {
    215221                        if (!it->first->isReadyToSpawn())
    216222                            allplayersready = false;
    217                     }
    218                     if (allplayersready)
     223                        if (it->first->isHumanPlayer())
     224                            hashumanplayers = true;
     225                    }
     226                    if (allplayersready && hashumanplayers)
    219227                    {
    220228                        this->startCountdown_ = this->initialStartCountdown_;
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.cc

    r2362 r2369  
    7777    void PlayerInfo::changedName()
    7878    {
     79        SUPER(PlayerInfo, changedName);
     80
    7981        if (this->isInitialized() && this->getGametype())
    8082            this->getGametype()->playerChangedName(this);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Camera.cc

    r2361 r2369  
    5454    {
    5555        RegisterObject(Camera);
    56 
     56COUT(0) << this << ": created camera" << std::endl;
    5757        if (!this->getScene() || !this->getScene()->getSceneManager())
    5858            ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");
     
    7070        this->configvaluecallback_changedNearClipDistance();
    7171
    72         this->requestFocus(); // ! HACK ! REMOVE THIS !
     72//        this->requestFocus(); // ! HACK ! REMOVE THIS !
    7373    }
    7474
     
    8080            this->getScene()->getSceneManager()->destroyCamera(this->camera_);
    8181        }
     82COUT(0) << this << ": destroyed camera" << std::endl;
    8283    }
    8384
     
    122123    void Camera::removeFocus()
    123124    {
     125COUT(0) << this << ": remove focus" << std::endl;
    124126        this->bHasFocus_ = false;
    125127    }
     
    142144        this->bHasFocus_ = true;
    143145        viewport->setCamera(this->camera_);
     146COUT(0) << this << ": set focus" << std::endl;
    144147
    145148        // reactivate all visible compositors
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2256 r2369  
    3333#include "core/XMLPort.h"
    3434#include "util/Math.h"
     35#include "PawnManager.h"
    3536#include "objects/infos/PlayerInfo.h"
    3637#include "objects/gametypes/Gametype.h"
     
    4546        RegisterObject(Pawn);
    4647
    47         this->bAlive_ = false;
     48        PawnManager::touch();
     49
     50        this->bAlive_ = true;
    4851
    4952        this->health_ = 0;
     
    7073    Pawn::~Pawn()
    7174    {
     75        if (this->isInitialized())
     76        {
     77            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
     78                it->destroyedPawn(this);
     79        }
    7280    }
    7381
     
    7684        SUPER(Pawn, XMLPort, xmlelement, mode);
    7785
    78         XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
     86        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
    7987        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    8088        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     
    8593        REGISTERDATA(this->bAlive_, direction::toclient);
    8694        REGISTERDATA(this->health_, direction::toclient);
     95        REGISTERDATA(this->initialHealth_, direction::toclient);
    8796    }
    8897
     
    9099    {
    91100        SUPER(Pawn, tick, dt);
     101
     102        this->health_ -= 15 * dt * rnd();
    92103
    93104        if (this->health_ <= 0)
     
    129140    void Pawn::death()
    130141    {
     142        // Set bAlive_ to false and wait for PawnManager to do the destruction
    131143        this->bAlive_ = false;
     144
    132145        if (this->getGametype())
    133146            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
     147
     148        this->setDestroyWhenPlayerLeft(false);
     149
    134150        if (this->getPlayer())
    135151            this->getPlayer()->stopControl(this);
    136 
    137         delete this;
    138152
    139153        // play death effect
     
    151165        this->spawn();
    152166    }
     167
     168    ///////////////////
     169    // Pawn Listener //
     170    ///////////////////
     171    PawnListener::PawnListener()
     172    {
     173        RegisterRootObject(PawnListener);
     174    }
    153175}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2256 r2369  
    5555            inline void removeHealth(float health)
    5656                { this->setHealth(this->health_ - health); }
    57             inline float getHealht() const
     57            inline float getHealth() const
    5858                { return this->health_; }
    5959
     
    9696            WeaponSystem* weaponSystem_;
    9797    };
     98
     99    class _OrxonoxExport PawnListener : public OrxonoxClass
     100    {
     101        friend class Pawn;
     102
     103        public:
     104            PawnListener();
     105            virtual ~PawnListener() {}
     106
     107        protected:
     108            virtual void destroyedPawn(Pawn* pawn) = 0;
     109    };
    98110}
    99111
  • code/branches/objecthierarchy2/src/orxonox/overlays/OrxonoxOverlay.cc

    r2256 r2369  
    6262
    6363        this->owner_ = 0;
     64        this->group_ = 0;
    6465
    6566        if (!Core::showsGraphics())
    6667            ThrowException(NoGraphics, "Can't create OrxonoxOverlay, graphics engine not initialized");
    67 
    68         // add this overlay to the static map of OrxonoxOverlays
    69         if (overlays_s.find(this->getName()) != overlays_s.end())
    70         {
    71             COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl;
    72         }
    73         overlays_s[this->getName()] = this;
    7468
    7569        // create the Ogre::Overlay
     
    132126
    133127        XMLPortParam(OrxonoxOverlay, "size",      setSize,      getSize,      xmlElement, mode);
    134         XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode);
     128        XMLPortParam(OrxonoxOverlay, "pickpoint", setPickPoint, getPickPoint, xmlElement, mode);
    135129        XMLPortParam(OrxonoxOverlay, "position",  setPosition,  getPosition,  xmlElement, mode);
    136130        XMLPortParam(OrxonoxOverlay, "rotation",  setRotation,  getRotation,  xmlElement, mode);
    137         XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection,   getAspectCorrection,   xmlElement, mode);
     131        XMLPortParam(OrxonoxOverlay, "correctaspect", setAspectCorrection,   getAspectCorrection,   xmlElement, mode);
    138132        XMLPortParam(OrxonoxOverlay, "background",    setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode);
    139133    }
     
    141135    void OrxonoxOverlay::changedName()
    142136    {
     137        SUPER(OrxonoxOverlay, changedName);
     138
    143139        OrxonoxOverlay::overlays_s.erase(this->getOldName());
    144140
  • code/branches/objecthierarchy2/src/orxonox/overlays/OrxonoxOverlay.h

    r2256 r2369  
    125125
    126126        //! Gets the rotation angle applied to this overlay in degrees.
    127         const Radian& getRotation() const         { return this->angle_; }
     127        const Degree& getRotation() const         { return this->angle_; }
    128128
    129129        //! Rotates the overlay by angle degrees.
     
    166166        virtual void changedOwner() {}
    167167
     168        inline void setOverlayGroup(OverlayGroup* group)
     169        {
     170            if (group != this->group_)
     171            {
     172                this->group_ = group;
     173                this->changedOverlayGroup();
     174            }
     175        }
     176        inline OverlayGroup* getOverlayGroup() const
     177            { return this->group_; }
     178        virtual void changedOverlayGroup() {}
     179
    168180    protected:
    169181        virtual void angleChanged();
     
    184196        Vector2 position_;                         //!< Position of the pickPoint on the screen.
    185197        Vector2 pickPoint_;                        //!< Point on the overlay to pick when translating
    186         Radian angle_;                             //!< Rotation angle of the overlay
     198        Degree angle_;                             //!< Rotation angle of the overlay
    187199        RotationState rotState_;             //!< horizontal, vertical or inbetween
    188200
     
    195207        static std::map<std::string, OrxonoxOverlay*> overlays_s;
    196208        ControllableEntity* owner_;
     209        OverlayGroup* group_;
    197210  };
    198211
    199212  SUPER_FUNCTION(7, OrxonoxOverlay, changedOwner, false);
     213  SUPER_FUNCTION(8, OrxonoxOverlay, changedOverlayGroup, false);
    200214}
    201215
  • code/branches/objecthierarchy2/src/orxonox/overlays/OverlayGroup.h

    r2256 r2369  
    7373            { return this->owner_; }
    7474
    75     private:
    7675        //! Scales each OrxonoxOverlay individually by scale.
    7776        void scale(const Vector2& scale) { this->setScale(scale * this->scale_); }
     
    8988        OrxonoxOverlay* getElement(unsigned int index);
    9089
     90    private:
    9191        std::map<std::string, OrxonoxOverlay*> hudElements_;    //!< Contains all the OrxonoxOverlays of the this group.
    9292        Vector2 scale_;                                         //!< Current scale (independant of the elements).
  • code/branches/objecthierarchy2/src/orxonox/overlays/OverlayText.cc

    r2087 r2369  
    5050        this->text_->setCharHeight(1.0);
    5151
    52         setFont("Monofur");
    53         setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
    54         setCaption("");
    55         setTextSize(1.0f);
    56         setAlignmentString("left");
     52        this->setFont("Monofur");
     53        this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
     54        this->setCaption("");
     55        this->setTextSize(1.0f);
     56        this->setAlignmentString("left");
    5757
    5858        this->background_->addChild(this->text_);
     
    6969        SUPER(OverlayText, XMLPort, xmlElement, mode);
    7070
    71         XMLPortParam(OverlayText, "font",     setFont,            getFont,            xmlElement, mode);
    72         XMLPortParam(OverlayText, "colour",   setColour,          getColour,          xmlElement, mode);
    73         XMLPortParam(OverlayText, "caption",  setCaption,         getCaption,         xmlElement, mode);
    74         XMLPortParam(OverlayText, "textSize", setTextSize,        getTextSize,        xmlElement, mode);
    75         XMLPortParam(OverlayText, "align",    setAlignmentString, getAlignmentString, xmlElement, mode);
     71        XMLPortParam(OverlayText, "font",       setFont,            getFont,            xmlElement, mode);
     72        XMLPortParam(OverlayText, "colour",     setColour,          getColour,          xmlElement, mode);
     73        XMLPortParam(OverlayText, "caption",    setCaption,         getCaption,         xmlElement, mode);
     74        XMLPortParam(OverlayText, "textsize",   setTextSize,        getTextSize,        xmlElement, mode);
     75        XMLPortParam(OverlayText, "align",      setAlignmentString, getAlignmentString, xmlElement, mode);
     76        XMLPortParam(OverlayText, "spacewidth", setSpaceWidth,      getSpaceWidth,      xmlElement, mode);
    7677    }
    7778
  • code/branches/objecthierarchy2/src/orxonox/overlays/OverlayText.h

    r2087 r2369  
    4747        virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    4848
    49         void setCaption(const std::string& caption) { this->text_->setCaption(caption); }
    50         std::string getCaption() const              { return this->text_->getCaption(); }
     49        inline void setCaption(const std::string& caption) { this->text_->setCaption(caption); }
     50        inline std::string getCaption() const              { return this->text_->getCaption(); }
    5151
    5252        void setFont(const std::string& font);
    53         const std::string& getFont() const { return this->text_->getFontName(); }
     53        inline const std::string& getFont() const { return this->text_->getFontName(); }
    5454
    55         void setColour(const ColourValue& colour) { this->text_->setColour(colour); }
    56         const ColourValue& getColour() const      { return this->text_->getColour(); }
     55        inline void setSpaceWidth(float width) { this->text_->setSpaceWidth(width); }
     56        inline float getSpaceWidth() const     { return this->text_->getSpaceWidth(); }
    5757
    58         void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) { this->text_->setAlignment(alignment); }
    59         Ogre::TextAreaOverlayElement::Alignment getAlignment() const         { return this->text_->getAlignment(); }
     58        inline void setColour(const ColourValue& colour) { this->text_->setColour(colour); }
     59        inline const ColourValue& getColour() const      { return this->text_->getColour(); }
    6060
    61     protected:
    62         virtual void sizeChanged();
     61        inline void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) { this->text_->setAlignment(alignment); }
     62        inline Ogre::TextAreaOverlayElement::Alignment getAlignment() const         { return this->text_->getAlignment(); }
    6363
    6464        void setAlignmentString(const std::string& alignment);
    6565        std::string getAlignmentString() const;
    6666
    67         void setTextSize(float size) { this->setSize(Vector2(size, size)); }
    68         float getTextSize() const    { return this->getSize().y; }
     67        inline void setTextSize(float size) { this->setSize(Vector2(size, size)); }
     68        inline float getTextSize() const    { return this->getSize().y; }
     69
     70    protected:
     71        virtual void sizeChanged();
    6972
    7073        Ogre::TextAreaOverlayElement* text_;
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/CMakeLists.txt

    r2131 r2369  
    44  HUDRadar.cc
    55  HUDSpeedBar.cc
     6  HUDHealthBar.cc
    67  ChatOverlay.cc
    78)
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDBar.cc

    r2087 r2369  
    5151        RegisterObject(BarColour);
    5252
    53         setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
    54         setPosition(0.0);
     53        this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
     54        this->setPosition(0.0);
    5555    }
    5656
     
    8484        this->bar_->setMaterialName(materialname);
    8585
    86         setValue(0.4567654f);
    87         setRightToLeft(false);
    88         setAutoColour(true);
     86        this->setValue(0.0f);
     87        this->setRightToLeft(false);
     88        this->setAutoColour(true);
     89        this->currentColour_ = ColourValue::White;
    8990
    9091        this->background_->addChild(bar_);
     
    101102        SUPER(HUDBar, XMLPort, xmlElement, mode);
    102103
    103         XMLPortParam(HUDBar, "initialValue", setValue,       getValue,       xmlElement, mode);
    104         XMLPortParam(HUDBar, "rightToLeft",  setRightToLeft, getRightToLeft, xmlElement, mode);
    105         XMLPortParam(HUDBar, "autoColour",   setAutoColour,  getAutoColour,  xmlElement, mode);
     104        XMLPortParam(HUDBar, "initialvalue", setValue,       getValue,       xmlElement, mode);
     105        XMLPortParam(HUDBar, "righttoleft",  setRightToLeft, getRightToLeft, xmlElement, mode);
     106        XMLPortParam(HUDBar, "autocolour",   setAutoColour,  getAutoColour,  xmlElement, mode);
     107        XMLPortParam(HUDBar, "bartexture",   setBarTexture,  getBarTexture, xmlElement, mode);
    106108        XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode);
    107109    }
     
    130132                {
    131133                    this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour2);
     134                    this->currentColour_ = colour2;
    132135                }
    133136                else if (value1 < this->value_)
    134137                {
    135138                    this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1);
     139                    this->currentColour_ = colour1;
    136140                }
    137141                else
     
    139143                    //float interpolationfactor = (this->value_ - value2) / (value1 - value2);
    140144                    float interpolationfactor = interpolateSmooth((this->value_ - value2) / (value1 - value2), 0.0f, 1.0f);
    141                     this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1 * interpolationfactor + colour2 * (1 - interpolationfactor));
     145                    this->currentColour_ = colour1 * interpolationfactor + colour2 * (1 - interpolationfactor);
     146                    this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, this->currentColour_);
     147
    142148                }
    143149            }
     
    181187        this->colours_.clear();
    182188    }
     189
     190    void HUDBar::setBarTexture(const std::string& texture)
     191    {
     192        this->textureUnitState_->setTextureName(texture);
     193    }
     194
     195    const std::string& HUDBar::getBarTexture() const
     196    {
     197        return this->textureUnitState_->getTextureName();
     198    }
    183199}
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDBar.h

    r2087 r2369  
    7171        void clearColours();
    7272
    73         void setRightToLeft(bool r2l) { this->right2Left_ = r2l; this->valueChanged(); }
    74         bool getRightToLeft() const   { return this->right2Left_; }
     73        inline void setRightToLeft(bool r2l)
     74        {
     75            if (r2l != this->right2Left_)
     76            {
     77                this->right2Left_ = r2l;
     78                this->valueChanged();
     79            }
     80        }
     81        inline bool getRightToLeft() const
     82            { return this->right2Left_; }
    7583
    76         void setValue(float value)    { this->value_ = clamp(value, 0.0f, 1.0f); this->valueChanged(); }
    77         float getValue() const        { return this->value_; }
     84        inline void setValue(float value)
     85        {
     86            float temp = clamp(value, 0.0f, 1.0f);
     87            if (temp != this->value_)
     88            {
     89                this->value_ = temp;
     90                this->valueChanged();
     91            }
     92        }
     93        inline float getValue() const
     94            { return this->value_; }
    7895
    79         void setAutoColour(bool val)  { this->autoColour_ = val; this->valueChanged(); }
    80         bool getAutoColour() const    { return this->autoColour_; }
     96        inline void setAutoColour(bool val)
     97        {
     98            if (val != this->autoColour_)
     99            {
     100                this->autoColour_ = val;
     101                this->valueChanged();
     102
     103                if (!val)
     104                    this->currentColour_ = ColourValue::White;
     105            }
     106        }
     107        inline bool getAutoColour() const
     108            { return this->autoColour_; }
     109
     110        void setBarTexture(const std::string& texture);
     111        const std::string& getBarTexture() const;
     112
     113        inline const ColourValue& getCurrentBarColour() const
     114            { return this->currentColour_; }
    81115
    82116    protected:
     
    90124        bool autoColour_;                   //!< whether bar changes colour automatically
    91125        float value_;                       //!< progress of bar
     126        ColourValue currentColour_;
    92127
    93128        Ogre::PanelOverlayElement* bar_;
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDSpeedBar.cc

    r2361 r2369  
    5656        if (this->owner_ && this->owner_->getEngine())
    5757        {
    58             float v = this->owner_->getVelocity().length();
    59             float value = v / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor());
    60             if (value != this->getValue())
    61                 this->setValue(value);
     58            float value = this->owner_->getVelocity().length() / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor());
     59            this->setValue(value);
    6260        }
    6361    }
Note: See TracChangeset for help on using the changeset viewer.