Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6623 in orxonox.OLD for trunk/src/lib/particles/particle_system.cc


Ignore:
Timestamp:
Jan 20, 2006, 12:54:20 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: particle Systems and Emitters are loaded and cleaned up nicely

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/particle_system.cc

    r6621 r6623  
    4444
    4545  this->setMaxCount(maxCount);
    46 }
    47 
    48 /**
    49  * @brief creates a Particle System out of a XML-element
    50  * @param root: the XML-element to load from
    51  */
    52 ParticleSystem::ParticleSystem(const TiXmlElement* root)
    53 {
    54   this->init();
    55 
    56   this->loadParams(root);
    5746}
    5847
     
    7867     }
    7968
    80    if (this->material)
    81      delete this->material;
     69     while(!this->emitters.empty())
     70     {
     71       this->removeEmitter(this->emitters.front());
     72     }
     73
    8274}
    8375
     
    8981  this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem");
    9082
    91   this->material = NULL;
    9283  this->setMaxCount(PARTICLE_DEFAULT_MAX_COUNT);
    9384  this->count = 0;
     
    9687  this->setConserve(1);
    9788  this->setLifeSpan(1);
    98   this->glID = NULL;
    9989
    10090  this->toList(OM_ENVIRON);
     
    120110      .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)");
    121111
    122   LoadParam(root, "texture", this, ParticleSystem, setMaterialTexture);
    123   LoadParamXML(root, "emitter", this, ParticleSystem, addEmitterXML);
     112  LoadParamXML(root, "emitters", this, ParticleSystem, loadEmitters);
    124113
    125114  LOAD_PARAM_START_CYCLE(root, element);
     
    140129
    141130/**
     131 * @brief loads the Emitters from An XML-Root
     132 * @param root the XML-Element to load all emitters from
     133 */
     134void ParticleSystem::loadEmitters(const TiXmlElement* root)
     135{
     136  LOAD_PARAM_START_CYCLE(root, element);
     137  {
     138    BaseObject* emitter = Factory::fabricate(element);
     139    if (emitter->isA(CL_PARTICLE_EMITTER))
     140      this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter));
     141    else
     142    {
     143      PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n",
     144                emitter->getClassName(), this->getClassName(), this->getName());
     145      delete emitter;
     146    }
     147  }
     148  LOAD_PARAM_END_CYCLE(element);
     149}
     150
     151/**
    142152* @param maxCount the maximum count of particles that can be emitted
    143153 */
     
    148158
    149159// setting properties
    150 /**
    151  *  sets the material to an external material
    152  * @param material: the material to set this material to.
    153 
    154    !! important if the extern material gets deleted it MUST be unregistered here or segfault !!
    155 */
    156 void ParticleSystem::setMaterial(Material* material)
    157 {
    158   this->material = material;
    159 }
    160 
    161 void ParticleSystem::setMaterialTexture(const char* textureFile)
    162 {
    163   if (this->material != NULL)
    164     this->material->setDiffuseMap(textureFile);
    165 }
    166 
    167160/**
    168161 *  Sets the lifespan of newly created particles
     
    237230    emitter->getSystem()->removeEmitter(emitter);
    238231  this->emitters.push_back(emitter);
    239 }
    240 
    241 void ParticleSystem::addEmitterXML(const TiXmlElement* emitterRoot)
    242 {
    243   ParticleEmitter* emitter = new ParticleEmitter(emitterRoot);
    244   this->addEmitter(emitter);
    245232}
    246233
Note: See TracChangeset for help on using the changeset viewer.