Changeset 2065 for code/branches/objecthierarchy
- Timestamp:
- Oct 30, 2008, 2:44:48 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src
- Files:
-
- 2 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/BaseObject.cc
r2063 r2065 35 35 #include "tinyxml/tinyxml.h" 36 36 #include "CoreIncludes.h" 37 #include "EventIncludes.h" 37 38 #include "XMLPort.h" 38 39 #include "XMLFile.h" … … 79 80 BaseObject::~BaseObject() 80 81 { 82 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 83 (*it)->eventListeners_.erase(this); 81 84 } 82 85 … … 184 187 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 185 188 { 186 this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event)); 189 event->eventListeners_[this] = sectionname; 190 this->events_.push_back(event); 187 191 } 188 192 … … 190 194 { 191 195 unsigned int i = 0; 192 for (std:: set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)196 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 193 197 { 194 198 if (i == index) 195 return (*it) .second;199 return (*it); 196 200 ++i; 197 201 } … … 230 234 Event event(activate, this); 231 235 232 for (std:: set<std::pair<std::string, BaseObject*>>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)233 { 234 event.sectionname_ = (*it).first;235 (*it).second->processEvent(event);236 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 237 { 238 event.sectionname_ = it->second; 239 it->first->processEvent(event); 236 240 } 237 241 } -
code/branches/objecthierarchy/src/core/BaseObject.h
r2063 r2065 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #include <map> 38 40 39 41 #include "CorePrereqs.h" … … 145 147 Gametype* oldGametype_; 146 148 std::set<Template*> templates_; 147 std::set<std::pair<std::string, BaseObject*> > eventListeners_; 149 std::map<BaseObject*, std::string> eventListeners_; 150 std::list<BaseObject*> events_; 148 151 std::map<std::string, EventContainer*> eventContainers_; 149 152 }; -
code/branches/objecthierarchy/src/core/Event.cc
r2063 r2065 29 29 #include "Event.h" 30 30 #include "BaseObject.h" 31 #include "Executor.h" 31 32 32 33 namespace orxonox 33 34 { 35 EventContainer::~EventContainer() 36 { 37 delete this->eventfunction_; 38 } 39 34 40 void EventContainer::process(BaseObject* object, const Event& event) 35 41 { -
code/branches/objecthierarchy/src/core/Event.h
r2063 r2065 31 31 32 32 #include "CorePrereqs.h" 33 #include "Executor.h"34 35 #define SetEvent(classname, eventname, functionname, event) \36 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)37 38 #define SetEventTemplate(classname, eventname, functionname, event, ...) \39 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)40 41 #define SetSubclassEvent(classname, eventname, functionname, event, subclassname) \42 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)43 44 #define SetSubclassEventTemplate(classname, eventname, functionname, event, subclassname, ...) \45 SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)46 47 #define SetEventGeneric(containername, classname, eventname, executor, event, subclassname) \48 orxonox::EventContainer* containername = this->getEventContainer(eventname); \49 if (!containername) \50 { \51 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \52 this->addEventContainer(eventname, containername); \53 } \54 event.castedOriginator_ = dynamic_cast<subclassname*>(event.originator_); \55 containername->process(this, event)56 57 33 58 34 namespace orxonox … … 72 48 public: 73 49 EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {} 74 ~EventContainer() 75 { delete this->eventfunction_; } 50 ~EventContainer(); 76 51 77 52 void process(BaseObject* object, const Event& event); -
code/branches/objecthierarchy/src/core/XMLPort.h
r2019 r2065 480 480 481 481 BaseObject* newObject = identifier->fabricate((BaseObject*)object); 482 assert(newObject); 482 483 newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + " "); 483 // newObject->setFile(((BaseObject*)object)->getFile()); 484 // newObject->setNamespace(((BaseObject*)object)->getNamespace()); 484 485 O* castedObject = dynamic_cast<O*>(newObject); 486 assert(castedObject); 485 487 486 488 if (this->bLoadBefore_) … … 495 497 496 498 COUT(5) << ((BaseObject*)object)->getLoaderIndentation(); 497 (*this->loadexecutor_)(object, newObject);499 (*this->loadexecutor_)(object, castedObject); 498 500 499 501 if (!this->bLoadBefore_) -
code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
r2044 r2065 62 62 objects/worldentities/CameraPosition.cc 63 63 objects/worldentities/SpawnPoint.cc 64 objects/worldentities/ParticleEmitter.cc 65 objects/worldentities/ParticleSpawner.cc 64 66 # objects/worldentities/Backlight.cc 65 # objects/worldentities/ParticleSpawner.cc66 67 67 68 objects/worldentities/triggers/Trigger.cc -
code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h
r2044 r2065 96 96 class BlinkingBillboard; 97 97 class Light; 98 class Backlight; 99 class ParticleEmitter; 100 class ParticleSpawner; 98 101 99 102 class Camera; … … 107 110 class Controller; 108 111 class HumanController; 109 110 class Backlight;111 class ParticleSpawner;112 112 113 113 class Info; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Billboard.cc
r2044 r2065 76 76 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 77 77 this->getNode()->attachObject(this->billboard_.getBillboardSet()); 78 this->billboard_.setVisible(this->isVisible()); 78 79 } 79 80 } … … 90 91 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 91 92 this->getNode()->attachObject(this->billboard_.getBillboardSet()); 93 this->billboard_.setVisible(this->isVisible()); 92 94 } 93 95 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc
r2063 r2065 30 30 #include "BlinkingBillboard.h" 31 31 32 #include "core/Core.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/XMLPort.h" 35 #include "util/Math.h" 34 36 35 37 namespace orxonox … … 44 46 this->frequency_ = 1.0f; 45 47 this->phase_ = 0; 48 this->bQuadratic_ = false; 46 49 this->time_ = 0; 47 50 … … 60 63 XMLPortParam(BlinkingBillboard, "frequency", setFrequency, getFrequency, xmlelement, mode).defaultValues(1.0f); 61 64 XMLPortParam(BlinkingBillboard, "phase", setPhase, getPhase, xmlelement, mode).defaultValues(Degree(0)); 65 XMLPortParam(BlinkingBillboard, "quadratic", setQuadratic, isQuadratic, xmlelement, mode).defaultValues(false); 62 66 } 63 67 64 68 void BlinkingBillboard::registerVariables() 65 69 { 66 REGISTERDATA(this->amplitude_, network::direction::toclient);67 REGISTERDATA(this->frequency_, network::direction::toclient);68 REGISTERDATA(this->phase_, network::direction::toclient);70 // REGISTERDATA(this->amplitude_, network::direction::toclient); 71 // REGISTERDATA(this->frequency_, network::direction::toclient); 72 // REGISTERDATA(this->phase_, network::direction::toclient); 69 73 } 70 74 71 75 void BlinkingBillboard::tick(float dt) 72 76 { 73 this->time_ += dt; 74 this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)); 77 if (Core::isMaster()) 78 { 79 this->time_ += dt; 80 if (this->bQuadratic_) 81 this->setScale(this->amplitude_ * square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_))); 82 else 83 this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)); 84 } 75 85 } 76 86 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.h
r2063 r2065 62 62 { return this->phase_; } 63 63 64 inline void setQuadratic(bool bQuadratic) 65 { this->bQuadratic_ = bQuadratic; } 66 inline bool isQuadratic() const 67 { return this->bQuadratic_; } 68 64 69 private: 65 70 float amplitude_; 66 71 float frequency_; 67 72 Degree phase_; 73 bool bQuadratic_; 68 74 long double time_; 69 75 }; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
r2062 r2065 95 95 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode); 96 96 97 XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);97 XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); 98 98 } 99 99 … … 239 239 else if (this->bControlled_) 240 240 { 241 COUT(2) << "setting client position" << endl;241 // COUT(2) << "setting client position" << endl; 242 242 this->client_velocity_ = this->velocity_; 243 243 this->client_position_ = this->node_->getPosition(); … … 249 249 { 250 250 REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient); 251 252 253 REGISTERDATA(this->client_overwrite_, network::direction::toserver);254 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));255 251 256 252 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); … … 258 254 REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 259 255 256 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 257 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 260 258 261 259 REGISTERDATA(this->client_position_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); … … 301 299 if (this->server_overwrite_ == this->client_overwrite_) 302 300 { 303 COUT(2) << "callback: setting client position" << endl;301 // COUT(2) << "callback: setting client position" << endl; 304 302 this->node_->setPosition(this->client_position_); 305 303 this->server_position_ = this->client_position_; 306 304 } 307 else308 COUT(2) << "callback: not setting client position" << endl;305 // else 306 // COUT(2) << "callback: not setting client position" << endl; 309 307 } 310 308 … … 458 456 else if (this->bControlled_) 459 457 { 460 //this->node_->lookAt(target, relativeTo, localDirectionVector);458 this->node_->lookAt(target, relativeTo, localDirectionVector); 461 459 this->client_orientation_ = this->node_->getOrientation(); 462 460 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.cc
r2044 r2065 165 165 this->light_->setType(this->type_); 166 166 } 167 168 void Light::changedVisibility() 169 { 170 SUPER(Light, changedVisibility); 171 172 this->light_->setVisible(this->isVisible()); 173 } 167 174 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.h
r2044 r2065 49 49 void registerVariables(); 50 50 51 virtual void changedVisibility(); 52 51 53 inline Ogre::Light* getLight() 52 54 { return this->light_; } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.cc
r2040 r2065 76 76 this->getNode()->attachObject(this->mesh_.getEntity()); 77 77 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 78 this->mesh_.setVisible(this->isVisible()); 78 79 } 79 80 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc
r2027 r2065 30 30 #include "ParticleSpawner.h" 31 31 32 #include <OgreSceneManager.h>33 32 #include "core/CoreIncludes.h" 33 #include "core/EventIncludes.h" 34 34 #include "core/Executor.h" 35 #include "core/XMLPort.h" 35 36 #include "tools/ParticleInterface.h" 36 #include "GraphicsEngine.h"37 37 38 38 namespace orxonox … … 40 40 CreateFactory(ParticleSpawner); 41 41 42 ParticleSpawner::ParticleSpawner( )42 ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator) 43 43 { 44 44 RegisterObject(ParticleSpawner); 45 this->particle_ = 0;46 }47 45 48 ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 49 { 50 RegisterObject(ParticleSpawner); 51 this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction); 52 } 46 this->bAutostart_ = true; 47 this->bSuppressStart_ = false; 48 this->bAutoDestroy_ = true; 49 this->bForceDestroy_ = false; 50 this->bLoop_ = false; 51 this->startdelay_ = 0; 52 this->lifetime_ = 0; 53 this->destroydelay_ = 0; 53 54 54 void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 55 { 56 ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner)); 57 this->destroydelay_ = destroydelay; 58 executor->setDefaultValues(lifetime); 59 this->timer_.setTimer(startdelay, false, this, executor); 60 this->particle_ = new ParticleInterface(templateName, detaillevel); 61 this->particle_->addToSceneNode(this->getNode()); 62 this->particle_->setEnabled(false); 63 if (direction != Vector3::ZERO) 64 { 65 this->particle_->getAllEmitters()->setDirection(direction); 66 } 55 this->startParticleSpawner(); 67 56 } 68 57 69 58 ParticleSpawner::~ParticleSpawner() 70 59 { 71 if (this->isInitialized() && this->particle_)72 {73 this->particle_->detachFromSceneNode();74 delete this->particle_;75 }76 };77 78 void ParticleSpawner::destroy()79 {80 this->setPosition(this->getNode()->getParent()->getPosition());81 this->getNode()->getParent()->removeChild(this->getNode());82 this->detachFromParent();83 if (this->particle_)84 this->particle_->setEnabled(false);85 if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)86 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));87 60 } 88 61 89 void ParticleSpawner:: createParticleSpawner(float lifetime)62 void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode) 90 63 { 91 this->particle_->setEnabled(true); 92 if (lifetime != 0) 93 this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); 64 SUPER(ParticleSpawner, XMLPort, xmlelement, mode); 65 66 XMLPortParam(ParticleSpawner, "autostart", setAutoStart, getAutoStart, xmlelement, mode).defaultValues(true); 67 XMLPortParam(ParticleSpawner, "autodestroy", setDestroyAfterLife, getDestroyAfterLife, xmlelement, mode).defaultValues(false); 68 XMLPortParam(ParticleSpawner, "loop", setLoop, getLoop, xmlelement, mode).defaultValues(false); 69 XMLPortParam(ParticleSpawner, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(0.0f); 70 XMLPortParam(ParticleSpawner, "startdelay", setStartdelay, getStartdelay, xmlelement, mode).defaultValues(0.0f); 71 XMLPortParam(ParticleSpawner, "destroydelay", setDestroydelay, getDestroydelay, xmlelement, mode).defaultValues(0.0f); 72 } 73 74 void ParticleSpawner::processEvent(Event& event) 75 { 76 SUPER(ParticleSpawner, processEvent, event); 77 78 SetEvent(ParticleSpawner, "spawn", spawn, event); 79 } 80 81 void ParticleSpawner::configure(float lifetime, float startdelay, float destroydelay, bool autodestroy) 82 { 83 this->bAutoDestroy_ = autodestroy; 84 this->startdelay_ = startdelay; 85 this->lifetime_ = lifetime; 86 this->destroydelay_ = destroydelay; 87 } 88 89 void ParticleSpawner::startParticleSpawner() 90 { 91 if (!this->particles_) 92 return; 93 94 this->particles_->setEnabled(false); 95 96 if (this->bForceDestroy_ || this->bSuppressStart_) 97 return; 98 99 this->timer_.setTimer(this->startdelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner))); 100 } 101 102 void ParticleSpawner::fireParticleSpawner() 103 { 104 this->particles_->setEnabled(true); 105 if (this->lifetime_ != 0) 106 this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner))); 107 } 108 109 void ParticleSpawner::stopParticleSpawner() 110 { 111 this->particles_->setEnabled(false); 112 113 if (this->bAutoDestroy_ || this->bForceDestroy_) 114 { 115 this->setPosition(this->getWorldPosition()); 116 this->detachFromParent(); 117 118 if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) 119 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); 120 } 121 else if (this->bLoop_) 122 { 123 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner))); 124 } 94 125 } 95 126 … … 98 129 delete this; 99 130 } 100 101 void ParticleSpawner::setVisible(bool visible)102 {103 if (this->particle_)104 this->particle_->setEnabled(visible);105 }106 131 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.h
r2044 r2065 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "P ositionableEntity.h"34 #include "ParticleEmitter.h" 35 35 #include "tools/Timer.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport ParticleSpawner : public P ositionableEntity39 class _OrxonoxExport ParticleSpawner : public ParticleEmitter 40 40 { 41 41 public: 42 ParticleSpawner(); 43 ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO); 42 ParticleSpawner(BaseObject* creator); 44 43 virtual ~ParticleSpawner(); 45 void destroy();46 44 47 void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO); 48 inline ParticleInterface* getParticleInterface() const 49 { return this->particle_; } 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void processEvent(Event& event); 50 47 51 void setVisible(bool visible); 48 inline void destroy() 49 { this->bForceDestroy_ = true; this->stopParticleSpawner(); } 50 inline void spawn() 51 { this->bSuppressStart_ = false; this->startParticleSpawner(); } 52 53 void configure(float lifetime = 0, float startdelay = 0, float destroydelay = 0, bool autodestroy = true); 54 55 inline void setAutoStart(bool autostart) 56 { this->bAutostart_ = autostart; this->bSuppressStart_ = !autostart; } 57 inline bool getAutoStart() const 58 { return this->bAutostart_; } 59 60 inline void setDestroyAfterLife(bool destroy) 61 { this->bAutoDestroy_ = destroy; } 62 inline bool getDestroyAfterLife() const 63 { return this->bAutoDestroy_; } 64 65 inline void setLoop(bool loop) 66 { this->bLoop_ = loop; } 67 inline bool getLoop() const 68 { return this->bLoop_; } 69 70 inline void setLifetime(float lifetime) 71 { this->lifetime_ = lifetime; this->startParticleSpawner(); } 72 inline float getLifetime() const 73 { return this->lifetime_; } 74 75 inline void setStartdelay(float startdelay) 76 { this->startdelay_ = startdelay; this->startParticleSpawner(); } 77 inline float getStartdelay() const 78 { return this->startdelay_; } 79 80 inline void setDestroydelay(float destroydelay) 81 { this->destroydelay_ = destroydelay; this->startParticleSpawner(); } 82 inline float getDestroydelay() const 83 { return this->destroydelay_; } 52 84 53 85 private: 54 void createParticleSpawner(float lifetime); 86 void startParticleSpawner(); 87 void fireParticleSpawner(); 88 void stopParticleSpawner(); 55 89 void destroyParticleSpawner(); 56 90 57 91 Timer<ParticleSpawner> timer_; 58 ParticleInterface* particle_; 92 93 bool bSuppressStart_; 94 bool bAutostart_; 95 bool bForceDestroy_; 96 bool bAutoDestroy_; 97 bool bLoop_; 98 float startdelay_; 99 float lifetime_; 59 100 float destroydelay_; 60 101 }; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/SpawnPoint.cc
r2040 r2065 78 78 { 79 79 this->getGametype()->pawnPreSpawn(entity); 80 80 81 this->spawn(entity); 82 81 83 if (this->template_) 82 84 entity->addTemplate(this->template_); 85 83 86 entity->postSpawn(); 87 84 88 this->getGametype()->pawnPostSpawn(entity); 89 90 this->fireEvent(); 85 91 } 86 92 return entity; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h
r2040 r2065 134 134 { parent->attach(this); } 135 135 inline void detachFromParent() 136 { this->parent_->detach(this);}136 { if (this->parent_) { this->parent_->detach(this); } } 137 137 inline WorldEntity* getParent() const 138 138 { return this->parent_; } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc
r2031 r2065 128 128 this->bTriggered_ = (newState & 0x1); 129 129 this->bActive_ = newState & 2; 130 this->fireEvent(this->bActive_); 130 131 this->stateChanges_.pop(); 131 132 if (this->stateChanges_.size() != 0) -
code/branches/objecthierarchy/src/orxonox/tools/Mesh.h
r2019 r2065 21 21 * 22 22 * Author: 23 * ...23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 25 * ... -
code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc
r2019 r2065 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 28 29 /** … … 45 46 namespace orxonox 46 47 { 47 unsigned int ParticleInterface::counter_s = 0; 48 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 49 50 ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) 51 { 52 RegisterRootObject(ParticleInterface); 53 54 assert(scenemanager); 55 56 this->scenemanager_ = scenemanager; 57 this->sceneNode_ = 0; 58 this->bEnabled_ = true; 59 this->detaillevel_ = (unsigned int)detaillevel; 60 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 61 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 62 this->particleSystem_->setSpeedFactor(1.0f); 63 64 if (GraphicsEngine::getInstance().getDetailLevelParticle() < (unsigned int)this->detaillevel_) 65 { 66 this->bVisible_ = false; 67 this->updateVisibility(); 68 } 69 else 70 { 71 this->bVisible_ = true; 72 } 73 } 74 75 ParticleInterface::~ParticleInterface() 76 { 77 this->particleSystem_->removeAllEmitters(); 78 this->scenemanager_->destroyParticleSystem(particleSystem_); 79 } 80 81 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 82 { 83 this->sceneNode_ = sceneNode; 84 this->sceneNode_->attachObject(this->particleSystem_); 85 } 86 87 void ParticleInterface::detachFromSceneNode() 88 { 89 if (this->sceneNode_) 90 { 91 this->sceneNode_->detachObject(this->particleSystem_); 92 this->sceneNode_ = 0; 93 } 94 } 95 96 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 97 { 98 if (this->particleSystem_->getNumEmitters() > 0) 99 { 100 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); 101 this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); 102 return newemitter; 103 } 104 else 105 return 0; 106 } 107 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 108 { 109 if (emitterNr < this->particleSystem_->getNumEmitters()) 110 return this->particleSystem_->getEmitter(emitterNr); 111 else 112 return 0; 113 } 114 void ParticleInterface::removeEmitter(unsigned int emitterNr) 115 { 116 if (emitterNr < this->particleSystem_->getNumEmitters()) 117 this->particleSystem_->removeEmitter(emitterNr); 118 } 119 void ParticleInterface::removeAllEmitters() 120 { 121 this->particleSystem_->removeAllEmitters(); 122 } 123 unsigned int ParticleInterface::getNumEmitters() const 124 { 125 return this->particleSystem_->getNumEmitters(); 126 } 127 128 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 129 { 130 return this->particleSystem_->addAffector(name); 131 } 132 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 133 { 134 if (affectorNr < this->particleSystem_->getNumAffectors()) 135 return this->particleSystem_->getAffector(affectorNr); 136 else 137 return 0; 138 } 139 void ParticleInterface::removeAffector(unsigned int affectorNr) 140 { 141 if (affectorNr < this->particleSystem_->getNumAffectors()) 142 this->particleSystem_->removeAffector(affectorNr); 143 } 144 void ParticleInterface::removeAllAffectors() 145 { 146 this->particleSystem_->removeAllAffectors(); 147 } 148 unsigned int ParticleInterface::getNumAffectors() const 149 { 150 return this->particleSystem_->getNumAffectors(); 151 } 152 153 void ParticleInterface::setEnabled(bool enable) 154 { 155 this->bEnabled_ = enable; 156 this->updateVisibility(); 157 } 158 159 void ParticleInterface::detailLevelChanged(unsigned int newlevel) 160 { 161 if (newlevel >= (unsigned int)this->detaillevel_) 162 this->bVisible_ = true; 163 else 164 this->bVisible_ = false; 165 166 this->updateVisibility(); 167 } 168 169 void ParticleInterface::updateVisibility() 170 { 171 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 172 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bVisible_); 173 } 174 175 void ParticleInterface::setSpeedFactor(float factor) 176 { 177 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 178 this->particleSystem_->setSpeedFactor(1.0f * factor); 179 } 180 float ParticleInterface::getSpeedFactor() const 181 { 182 //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 183 return (this->particleSystem_->getSpeedFactor() / 1.0f); 184 } 185 186 bool ParticleInterface::getKeepParticlesInLocalSpace() const 187 { 188 return this->particleSystem_->getKeepParticlesInLocalSpace(); 189 } 190 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 191 { 192 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 193 } 48 unsigned int ParticleInterface::counter_s = 0; 49 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 50 51 ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) 52 { 53 RegisterRootObject(ParticleInterface); 54 55 assert(scenemanager); 56 57 this->scenemanager_ = scenemanager; 58 this->sceneNode_ = 0; 59 60 this->bEnabled_ = true; 61 this->bVisible_ = true; 62 this->bAllowedByLOD_ = true; 63 64 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 65 this->particleSystem_->setSpeedFactor(1.0f); 66 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 67 68 this->setDetailLevel((unsigned int)detaillevel); 69 } 70 71 ParticleInterface::~ParticleInterface() 72 { 73 this->particleSystem_->removeAllEmitters(); 74 this->detachFromSceneNode(); 75 this->scenemanager_->destroyParticleSystem(particleSystem_); 76 } 77 78 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 79 { 80 if (this->sceneNode_) 81 this->detachFromSceneNode(); 82 83 this->sceneNode_ = sceneNode; 84 this->sceneNode_->attachObject(this->particleSystem_); 85 } 86 87 void ParticleInterface::detachFromSceneNode() 88 { 89 if (this->sceneNode_) 90 { 91 this->sceneNode_->detachObject(this->particleSystem_); 92 this->sceneNode_ = 0; 93 } 94 } 95 96 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 97 { 98 if (this->particleSystem_->getNumEmitters() > 0) 99 { 100 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); 101 this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); 102 return newemitter; 103 } 104 else 105 return 0; 106 } 107 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 108 { 109 if (emitterNr < this->particleSystem_->getNumEmitters()) 110 return this->particleSystem_->getEmitter(emitterNr); 111 else 112 return 0; 113 } 114 void ParticleInterface::removeEmitter(unsigned int emitterNr) 115 { 116 if (emitterNr < this->particleSystem_->getNumEmitters()) 117 this->particleSystem_->removeEmitter(emitterNr); 118 } 119 void ParticleInterface::removeAllEmitters() 120 { 121 this->particleSystem_->removeAllEmitters(); 122 } 123 unsigned int ParticleInterface::getNumEmitters() const 124 { 125 return this->particleSystem_->getNumEmitters(); 126 } 127 128 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 129 { 130 return this->particleSystem_->addAffector(name); 131 } 132 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 133 { 134 if (affectorNr < this->particleSystem_->getNumAffectors()) 135 return this->particleSystem_->getAffector(affectorNr); 136 else 137 return 0; 138 } 139 void ParticleInterface::removeAffector(unsigned int affectorNr) 140 { 141 if (affectorNr < this->particleSystem_->getNumAffectors()) 142 this->particleSystem_->removeAffector(affectorNr); 143 } 144 void ParticleInterface::removeAllAffectors() 145 { 146 this->particleSystem_->removeAllAffectors(); 147 } 148 unsigned int ParticleInterface::getNumAffectors() const 149 { 150 return this->particleSystem_->getNumAffectors(); 151 } 152 153 void ParticleInterface::setEnabled(bool enable) 154 { 155 this->bEnabled_ = enable; 156 157 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 158 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); 159 } 160 161 void ParticleInterface::setVisible(bool visible) 162 { 163 this->bVisible_ = visible; 164 165 this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); 166 } 167 168 void ParticleInterface::setDetailLevel(unsigned int level) 169 { 170 this->detaillevel_ = level; 171 this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); 172 } 173 174 void ParticleInterface::detailLevelChanged(unsigned int newlevel) 175 { 176 if (newlevel >= (unsigned int)this->detaillevel_) 177 this->bAllowedByLOD_ = true; 178 else 179 this->bAllowedByLOD_ = false; 180 181 this->updateVisibility(); 182 } 183 184 void ParticleInterface::updateVisibility() 185 { 186 this->setEnabled(this->isEnabled()); 187 this->setVisible(this->isVisible()); 188 } 189 190 void ParticleInterface::setSpeedFactor(float factor) 191 { 192 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 193 this->particleSystem_->setSpeedFactor(1.0f * factor); 194 } 195 float ParticleInterface::getSpeedFactor() const 196 { 197 //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 198 return (this->particleSystem_->getSpeedFactor() / 1.0f); 199 } 200 201 bool ParticleInterface::getKeepParticlesInLocalSpace() const 202 { 203 return this->particleSystem_->getKeepParticlesInLocalSpace(); 204 } 205 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 206 { 207 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 208 } 194 209 } -
code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.h
r2019 r2065 21 21 * 22 22 * Author: 23 * ...23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 25 * ... … … 45 45 namespace orxonox 46 46 { 47 class _OrxonoxExport ParticleInterface : public OrxonoxClass48 {49 public:50 ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel);51 ~ParticleInterface();47 class _OrxonoxExport ParticleInterface : public OrxonoxClass 48 { 49 public: 50 ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel); 51 virtual ~ParticleInterface(); 52 52 53 inline Ogre::ParticleSystem* getParticleSystem() const54 { return this->particleSystem_; }53 inline Ogre::ParticleSystem* getParticleSystem() const 54 { return this->particleSystem_; } 55 55 56 void addToSceneNode(Ogre::SceneNode* sceneNode);57 void detachFromSceneNode();56 void addToSceneNode(Ogre::SceneNode* sceneNode); 57 void detachFromSceneNode(); 58 58 59 Ogre::ParticleEmitter* createNewEmitter();60 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;61 void removeEmitter(unsigned int emitterNr);62 void removeAllEmitters();63 unsigned int getNumEmitters() const;59 Ogre::ParticleEmitter* createNewEmitter(); 60 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const; 61 void removeEmitter(unsigned int emitterNr); 62 void removeAllEmitters(); 63 unsigned int getNumEmitters() const; 64 64 65 Ogre::ParticleAffector* addAffector(const std::string& name);66 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;67 void removeAffector(unsigned int affectorNr);68 void removeAllAffectors();69 unsigned int getNumAffectors() const;65 Ogre::ParticleAffector* addAffector(const std::string& name); 66 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const; 67 void removeAffector(unsigned int affectorNr); 68 void removeAllAffectors(); 69 unsigned int getNumAffectors() const; 70 70 71 float getSpeedFactor() const;72 void setSpeedFactor(float factor);73 bool getKeepParticlesInLocalSpace() const;74 void setKeepParticlesInLocalSpace(bool keep);71 float getSpeedFactor() const; 72 void setSpeedFactor(float factor); 73 bool getKeepParticlesInLocalSpace() const; 74 void setKeepParticlesInLocalSpace(bool keep); 75 75 76 void setEnabled(bool enable); 77 void detailLevelChanged(unsigned int newlevel); 76 void setEnabled(bool enable); 77 inline bool isEnabled() const 78 { return this->bEnabled_; } 78 79 79 inline void storeThisAsCurrentParticleInterface() 80 { ParticleInterface::currentParticleInterface_s = this; } 81 inline static ParticleInterface* getCurrentParticleInterface() 82 { return ParticleInterface::currentParticleInterface_s; } 80 void setVisible(bool visible); 81 inline bool isVisible() const 82 { return this->bVisible_; } 83 83 84 private:85 void updateVisibility();84 void detailLevelChanged(unsigned int newlevel); 85 void setDetailLevel(unsigned int level); 86 86 87 static ParticleInterface* currentParticleInterface_s; 88 static unsigned int counter_s; 89 Ogre::SceneNode* sceneNode_; 90 Ogre::ParticleSystem* particleSystem_; 91 bool bVisible_; 92 bool bEnabled_; 93 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 94 Ogre::SceneManager* scenemanager_; 95 }; 87 inline void storeThisAsCurrentParticleInterface() 88 { ParticleInterface::currentParticleInterface_s = this; } 89 inline static ParticleInterface* getCurrentParticleInterface() 90 { return ParticleInterface::currentParticleInterface_s; } 91 92 private: 93 void updateVisibility(); 94 95 static ParticleInterface* currentParticleInterface_s; 96 static unsigned int counter_s; 97 98 Ogre::SceneNode* sceneNode_; 99 Ogre::ParticleSystem* particleSystem_; 100 bool bVisible_; 101 bool bEnabled_; 102 bool bAllowedByLOD_; 103 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 104 Ogre::SceneManager* scenemanager_; 105 }; 96 106 } 97 107
Note: See TracChangeset
for help on using the changeset viewer.