Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Transition.cc

Go to the documentation of this file.
00001 #include "Transition.h"
00002 #include "StateNode.h"
00003 #include "Wireless/Wireless.h"
00004 #include "Sound/SoundManager.h"
00005 #include "Events/EventRouter.h"
00006 
00007 void Transition::fire() {
00008   //serr->printf("%s fire() - enter %d\n",getName().c_str(),get_time());
00009 
00010   AddReference(); //just in case a side effect of this transition is to dereference the transition, we don't want to be deleted while still transitioning
00011 
00012   if(sound.size()!=0)
00013     sndman->playFile(sound);
00014 
00015   erouter->postEvent(EventBase::stateTransitionEGID,reinterpret_cast<size_t>(this),EventBase::activateETID,0,getName(),1);
00016 
00017   for(unsigned int i=0; i<srcs.size(); i++)
00018     if(srcs[i]->isActive()) //It's usually a bad idea to call DoStop/DoStart when it's already stopped/started...
00019       srcs[i]->DoStop();
00020   for(unsigned int i=0; i<dsts.size(); i++)
00021     if(!dsts[i]->isActive())
00022       dsts[i]->DoStart();
00023 
00024   erouter->postEvent(EventBase::stateTransitionEGID,reinterpret_cast<size_t>(this),EventBase::deactivateETID,0,getName(),0);
00025   
00026   //serr->printf("%s fire() - leave %d\n",getName().c_str(),get_time());
00027   RemoveReference();
00028 }
00029 
00030 std::string Transition::getName() const {
00031   if(instanceName != className) {
00032     return instanceName;
00033   } else {
00034     std::string ans;
00035     ans+='{';
00036     for(unsigned int i=0; i<srcs.size(); i++)
00037       ans+=srcs[i]->getName()+(i<srcs.size()-1?',':'}');
00038     ans+="--"+instanceName+"-->";
00039     ans+='{';
00040     for(unsigned int i=0; i<dsts.size(); i++)
00041       ans+=dsts[i]->getName()+(i<dsts.size()-1?',':'}');
00042     return ans;
00043   }
00044 } 
00045 
00046 /*! @file
00047  * @brief Implements Transition, represents a transition between StateNodes.
00048  * @author ejt (Creator)
00049  *
00050  * $Author: ejt $
00051  * $Name: tekkotsu-4_0 $
00052  * $Revision: 1.19 $
00053  * $State: Exp $
00054  * $Date: 2007/03/02 17:20:51 $
00055  */
00056 

Tekkotsu v4.0
Generated Thu Nov 22 00:54:56 2007 by Doxygen 1.5.4