Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 14, 2008, 1:47:33 AM (15 years ago)
Author:
landauf
Message:

fixed Backlight initialization with a workaround, but there are still strange crashes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc

    r2182 r2207  
    3535#include "core/Core.h"
    3636#include "core/CoreIncludes.h"
     37#include "core/Executor.h"
    3738#include "core/XMLPort.h"
    3839#include "objects/Scene.h"
     
    5152        this->width_ = 0;
    5253        this->length_ = 1.0f;
    53         this->lifetime_ = 1.0f;
     54        this->lifetime_ = 0.001f;
     55        this->turnofftime_ = 0.5f;
     56        this->bTurningOff_ = false;
    5457        this->maxelements_ = 1;
     58
     59        this->tickcount_ = 0;
    5560
    5661        if (Core::showsGraphics())
     
    6166
    6267            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
     68            this->ribbonTrail_->addNode(this->getNode());
    6369            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
    6470            this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
    65             this->ribbonTrail_->addNode(this->getNode());
    66 
    67             this->ribbonTrail_->setMaxChainElements(this->maxelements_);
    68             this->ribbonTrail_->setTrailLength(this->length_);
    69             this->ribbonTrail_->setInitialWidth(0, this->width_);
     71            this->ribbonTrail_->setInitialWidth(0, 0);
    7072        }
    7173
     
    9799        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
    98100        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
     101        XMLPortParam(Backlight, "turnofftime",   setTurnOffTime,   getTurnOffTime,   xmlelement, mode).defaultValues(0.5f);
    99102        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
    100103    }
     
    113116        Billboard::changedColour();
    114117
    115         if (this->ribbonTrail_ && this->isActive())
     118        if (this->ribbonTrail_ && this->isActive() && this->tickcount_ >= 2)
    116119            this->ribbonTrail_->setInitialColour(0, this->getColour());
    117120    }
     
    119122    void Backlight::update_width()
    120123    {
    121         if (this->ribbonTrail_)
     124        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    122125            this->ribbonTrail_->setInitialWidth(0, this->width_);
    123126        this->update_lifetime();
     
    126129    void Backlight::update_lifetime()
    127130    {
    128         if (this->ribbonTrail_)
     131        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    129132        {
    130133            this->ribbonTrail_->setWidthChange(0, this->width_ / this->lifetime_/* * Backlight::timeFactor_s*/);
     
    135138    void Backlight::update_length()
    136139    {
    137 //        if (this->ribbonTrail_)
    138 //            this->ribbonTrail_->setTrailLength(this->length_);
     140        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     141            this->ribbonTrail_->setTrailLength(this->length_);
    139142    }
    140143
    141144    void Backlight::update_maxelements()
    142145    {
    143         if (this->ribbonTrail_)
     146        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    144147            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
    145148    }
     
    147150    void Backlight::update_trailmaterial()
    148151    {
    149         if (this->ribbonTrail_)
     152        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    150153            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
    151154    }
     
    168171                this->ribbonTrail_->setInitialColour(0, this->getColour());
    169172            else
    170                 this->ribbonTrail_->setInitialColour(0, 0, 0, 0, 0);
    171         }
    172     }
    173 
    174     void Backlight::notifyAttached()
    175     {
    176         Billboard::notifyAttached();
    177 
    178 //        if (this->ribbonTrail_)
    179 //            this->ribbonTrail_->clearChain(0);
    180 
    181 //        if (this->ribbonTrail_)
    182 //            this->ribbonTrail_->setTrailLength(this->length_);
     173            {
     174                this->bTurningOff_ = true;
     175                this->turnofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&Backlight::stopturnoff)));
     176            }
     177        }
     178    }
     179
     180    void Backlight::stopturnoff()
     181    {
     182        this->bTurningOff_ = false;
    183183    }
    184184
    185185    void Backlight::tick(float dt)
    186186    {
    187         if (this->ribbonTrail_)
    188             this->ribbonTrail_->setTrailLength(this->length_);
     187        if (this->tickcount_ < 2)
     188        {
     189            ++this->tickcount_;
     190            if (this->tickcount_ == 2)
     191            {
     192                this->changedColour();
     193                this->update_width();
     194                this->update_lifetime();
     195                this->update_length();
     196                this->update_maxelements();
     197                this->update_trailmaterial();
     198            }
     199        }
     200
     201        if (this->bTurningOff_ && this->ribbonTrail_)
     202        {
     203            this->ribbonTrail_->setInitialColour(0, this->ribbonTrail_->getInitialColour(0) - this->getColour() / this->turnofftime_ * dt);
     204        }
    189205    }
    190206
Note: See TracChangeset for help on using the changeset viewer.