[10077] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: Patrick Boenzli |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
| 17 | |
---|
| 18 | #include "emitter_node.h" |
---|
| 19 | |
---|
| 20 | #include "particle_system.h" |
---|
| 21 | |
---|
| 22 | #include "util/loading/load_param.h" |
---|
| 23 | #include "debug.h" |
---|
| 24 | |
---|
| 25 | ObjectListDefinition(EmitterNode); |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * standard constructor |
---|
| 29 | */ |
---|
| 30 | EmitterNode::EmitterNode( float lifetime) |
---|
| 31 | { |
---|
| 32 | this->registerObject(this, EmitterNode::_objectList); |
---|
| 33 | |
---|
| 34 | this->system = NULL; |
---|
| 35 | this->emitter = NULL; |
---|
| 36 | this->lifeCycle = 0.0; |
---|
| 37 | this->lifeSpan = lifetime; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * standard destructor |
---|
| 42 | |
---|
| 43 | removes the EmitterSystem from the ParticleEngine |
---|
| 44 | */ |
---|
| 45 | EmitterNode::~EmitterNode () |
---|
| 46 | { |
---|
| 47 | this->emitter->setSystem(NULL); |
---|
| 48 | delete this->emitter; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * loads a EmitterNode from a XML-element |
---|
| 53 | * @param root the XML-element to load from |
---|
| 54 | */ |
---|
| 55 | void EmitterNode::loadParams(const TiXmlElement* root) |
---|
| 56 | { |
---|
| 57 | PNode::loadParams(root); |
---|
| 58 | |
---|
| 59 | LoadParam(root, "life-time", this, EmitterNode, setLifetime) |
---|
| 60 | .describe("Amount of time this emitter node shall remain"); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void EmitterNode::start() |
---|
| 64 | { |
---|
| 65 | this->started = true; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void EmitterNode::tick(float dt) |
---|
| 69 | { |
---|
| 70 | if( !this->started) |
---|
| 71 | return; |
---|
| 72 | |
---|
| 73 | this->lifeCycle += dt/this->lifeSpan; |
---|
| 74 | if (unlikely(this->lifeCycle >= 1)) |
---|
| 75 | { |
---|
| 76 | this->removeNode(); |
---|
| 77 | } |
---|
| 78 | this->setAbsCoor(this->getAbsCoor() + (this->velocity * dt)); |
---|
| 79 | } |
---|