Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 7, 2008, 2:06:41 AM (16 years ago)
Author:
landauf
Message:

added support for isVisible() and isActive() to all objects.
those functions are provided by BaseObject, combined with virtual functions changedVisibility and changedActivity respectively.
use them, to make orxonox scriptable, say: to change the state of objects with 2 simple functions instead of changing all meshes and emitters and billboards of an object. don't forget to pass calls to changedVisibility and changedActivity to the parent class.

additionally there is a new function, isInitialized(), provided by BaseObject too. this returns true if the constructor of BaseObject passed the object registration. this allows you, to check whether an object was properly initialized or if the constructor returned (as this is the case while creating the class hierarchy). use isInitialized() in your destructor before deleting something.

Location:
code/trunk/src/orxonox
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r1552 r1558  
    6666  // objects
    6767  class Ambient;
     68  class Backlight;
    6869  class Camera;
    6970  class Fighter;
  • code/trunk/src/orxonox/objects/BillboardProjectile.cc

    r1552 r1558  
    6060        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    6161    }
     62
     63    void BillboardProjectile::changedVisibility()
     64    {
     65        Projectile::changedVisibility();
     66        this->billboard_.setVisible(this->isVisible());
     67    }
    6268}
  • code/trunk/src/orxonox/objects/BillboardProjectile.h

    r1552 r1558  
    4343            BillboardProjectile(SpaceShip* owner = 0);
    4444            virtual ~BillboardProjectile();
     45
    4546            virtual void setColour(const ColourValue& colour);
     47            virtual void changedVisibility();
    4648
    4749        private:
  • code/trunk/src/orxonox/objects/Model.cc

    r1552 r1558  
    9696      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9797    }
     98
     99    void Model::changedVisibility()
     100    {
     101        WorldEntity::changedVisibility();
     102        this->mesh_.setVisible(this->isVisible());
     103    }
    98104}
  • code/trunk/src/orxonox/objects/Model.h

    r1505 r1558  
    4444            virtual ~Model();
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4647            void setMesh(const std::string& meshname);
    4748            virtual bool create();
  • code/trunk/src/orxonox/objects/ParticleProjectile.cc

    r1552 r1558  
    5555            delete this->particles_;
    5656    }
     57
     58    void ParticleProjectile::changedVisibility()
     59    {
     60        BillboardProjectile::changedVisibility();
     61        this->particles_->setEnabled(this->isVisible());
     62    }
    5763}
  • code/trunk/src/orxonox/objects/ParticleProjectile.h

    r1553 r1558  
    4343            ParticleProjectile(SpaceShip* owner = 0);
    4444            virtual ~ParticleProjectile();
     45            virtual void changedVisibility();
    4546
    4647        private:
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1554 r1558  
    8282        WorldEntity::tick(dt);
    8383
     84        if (!this->isActive())
     85            return;
     86
    8487        float radius;
    8588        for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it)
  • code/trunk/src/orxonox/objects/RotatingProjectile.cc

    r1552 r1558  
    7373    void RotatingProjectile::tick(float dt)
    7474    {
    75         this->time_ += dt;
     75        if (this->isActive())
     76        {
     77            this->time_ += dt;
    7678
    77         this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20));
    78         this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20));
     79            this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20));
     80            this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20));
     81        }
    7982
    8083        Projectile::tick(dt);
    8184    }
     85
     86    void RotatingProjectile::changedVisibility()
     87    {
     88        BillboardProjectile::changedVisibility();
     89        this->rotatingBillboard1_.setVisible(this->isVisible());
     90        this->rotatingBillboard2_.setVisible(this->isVisible());
     91    }
    8292}
  • code/trunk/src/orxonox/objects/RotatingProjectile.h

    r1552 r1558  
    1515            void setConfigValues();
    1616            virtual void tick(float dt);
     17            virtual void changedVisibility();
    1718
    1819        private:
  • code/trunk/src/orxonox/objects/Skybox.cc

    r1505 r1558  
    5454    }
    5555
    56     void Skybox::loadParams(TiXmlElement* xmlElem)
     56    void Skybox::setSkybox(const std::string& skyboxname)
    5757    {
    58         if (xmlElem->Attribute("src"))
    59         {
    60                 skyboxSrc_ = xmlElem->Attribute("src");
    61         this->create();
     58        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);
     59    }
    6260
    63                 COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl;
    64         }
    65    }
     61    void Skybox::setSkyboxSrc(const std::string& src)
     62    {
     63        this->skyboxSrc_ = src;
     64    }
    6665
    67    void Skybox::setSkybox(const std::string& skyboxname)
    68    {
    69         GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);
    70    }
    71 
    72    void Skybox::setSkyboxSrc(const std::string& src){
    73      skyboxSrc_ = src;
    74    }
    75    
    7666    /**
    7767        @brief XML loading and saving.
     
    8777        create();
    8878    }
    89    
    90     bool Skybox::create(){
    91       this->setSkybox(skyboxSrc_);
    92       return Synchronisable::create();
     79
     80    bool Skybox::create()
     81    {
     82        this->setSkybox(this->skyboxSrc_);
     83        return Synchronisable::create();
    9384    }
    94    
    95     void Skybox::registerAllVariables(){
    96       registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
     85
     86    void Skybox::registerAllVariables()
     87    {
     88        registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
    9789    }
    98    
     90
     91    void Skybox::changedVisibility()
     92    {
     93        BaseObject::changedVisibility();
     94        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_);
     95    }
    9996}
  • code/trunk/src/orxonox/objects/Skybox.h

    r1505 r1558  
    4343            virtual ~Skybox();
    4444
    45             void loadParams(TiXmlElement* xmlElem);
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4747            void setSkybox(const std::string& skyboxname);
    48            
     48
    4949            virtual bool create();
    5050            void registerAllVariables();
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1553 r1558  
    251251    }
    252252
     253    void SpaceShip::changedVisibility()
     254    {
     255        Model::changedVisibility();
     256
     257        this->tt1_->setEnabled(this->isVisible());
     258        this->tt2_->setEnabled(this->isVisible());
     259        this->redBillboard_.setVisible(this->isVisible());
     260        this->greenBillboard_.setVisible(this->isVisible());
     261        this->crosshairNear_.setVisible(this->isVisible());
     262        this->crosshairFar_.setVisible(this->isVisible());
     263    }
     264
     265    void SpaceShip::changedActivity()
     266    {
     267        Model::changedActivity();
     268
     269        this->tt1_->setEnabled(this->isVisible());
     270        this->tt2_->setEnabled(this->isVisible());
     271        this->redBillboard_.setVisible(this->isVisible());
     272        this->greenBillboard_.setVisible(this->isVisible());
     273        this->crosshairNear_.setVisible(this->isVisible());
     274        this->crosshairFar_.setVisible(this->isVisible());
     275    }
     276
    253277    void SpaceShip::setCamera(const std::string& camera)
    254278    {
     
    347371    void SpaceShip::tick(float dt)
    348372    {
     373        if (!this->isActive())
     374            return;
     375
    349376        currentDir_ = getOrientation()*initialDir_;
    350377                currentOrth_ = getOrientation()*initialOrth_;
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1552 r1558  
    5353            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5454            virtual void tick(float dt);
     55            virtual void changedVisibility();
     56            virtual void changedActivity();
    5557
    5658            void setCamera(const std::string& camera = "");
  • code/trunk/src/orxonox/objects/SpaceShipAI.cc

    r1553 r1558  
    208208    void SpaceShipAI::tick(float dt)
    209209    {
     210        if (!this->isActive())
     211            return;
     212
    210213        if (this->target_)
    211214            this->aimAtTarget();
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1552 r1558  
    8080    void WorldEntity::tick(float dt)
    8181    {
    82         if (!this->bStatic_)
     82        if (!this->bStatic_ && this->isActive())
    8383        {
    8484//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
     
    132132    void WorldEntity::registerAllVariables()
    133133    {
     134      // register inheritec variables from BaseObject
     135      registerVar( (void*) &(this->bActive_), sizeof(this->bActive_), network::DATA, 0x3);
     136      registerVar( (void*) &(this->bVisible_), sizeof(this->bVisible_), network::DATA, 0x3);
    134137      // register coordinates
    135138      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
  • code/trunk/src/orxonox/tools/BillboardSet.h

    r1505 r1558  
    3333
    3434#include <string>
     35#include <OgreBillboardSet.h>
    3536
    36 #include <OgreBillboardSet.h>
    3737#include "util/Math.h"
    3838
     
    5252                { return this->billboardSet_->getName(); }
    5353
     54            inline void setVisible(bool visible)
     55                { this->billboardSet_->setVisible(visible); }
     56            inline bool getVisible() const
     57                { return this->billboardSet_->getVisible(); }
     58
    5459        private:
    5560            static unsigned int billboardSetCounter_s;
  • code/trunk/src/orxonox/tools/Mesh.h

    r1505 r1558  
    5151                { return this->entity_->getName(); }
    5252
     53            inline void setVisible(bool visible)
     54                { this->entity_->setVisible(visible); }
     55            inline bool getVisible() const
     56                { return this->entity_->getVisible(); }
     57
    5358        private:
    5459            static unsigned int meshCounter_s;
Note: See TracChangeset for help on using the changeset viewer.