Homepage Demos Overview Downloads Tutorials 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 "SoundPlay/SoundManager.h"
00005 #include "Events/EventRouter.h"
00006 
00007 /*! @deprecated, use the version of the constructor where you can pass a name */
00008 Transition::Transition() : BehaviorBase("Transition"), srcs(), dsts(), sound() {}
00009 
00010 /*! @deprecated, use the version of the constructor where you can pass a name */
00011 Transition::Transition(StateNode* destination)
00012   : BehaviorBase("Transition"), srcs(), dsts(), sound()
00013 {
00014   addDestination(destination);
00015 }
00016 
00017 
00018 /*! @deprecated: use #fire() instead (just a better name) */
00019 void Transition::activate() {
00020   serr->printf("Transition::activate() is deprecated.  Use Transition::fire() instead.\n");
00021   fire();
00022 }
00023 
00024 void Transition::fire() {
00025   //serr->printf("%s fire() - enter %d\n",getName().c_str(),get_time());
00026 
00027   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
00028 
00029   if(sound.size()!=0)
00030     sndman->PlayFile(sound);
00031 
00032   erouter->postEvent(EventBase::stateTransitionEGID,reinterpret_cast<int>(this),EventBase::statusETID,0,getName(),1);
00033 
00034   for(unsigned int i=0; i<srcs.size(); i++)
00035     if(srcs[i]->isActive()) //It's usually a bad idea to call DoStop/DoStart when it's already stopped/started...
00036       srcs[i]->DoStop();
00037   for(unsigned int i=0; i<dsts.size(); i++)
00038     if(!dsts[i]->isActive())
00039       dsts[i]->DoStart();
00040 
00041   //serr->printf("%s fire() - leave %d\n",getName().c_str(),get_time());
00042   RemoveReference();
00043 }
00044 
00045 std::string Transition::getName() const {
00046   if(instanceName != className) {
00047     return instanceName;
00048   } else {
00049     std::string ans;
00050     ans+='{';
00051     for(unsigned int i=0; i<srcs.size(); i++)
00052       ans+=srcs[i]->getName()+(i<srcs.size()-1?',':'}');
00053     ans+="--"+instanceName+"-->";
00054     ans+='{';
00055     for(unsigned int i=0; i<dsts.size(); i++)
00056       ans+=dsts[i]->getName()+(i<srcs.size()-1?',':'}');
00057     return ans;
00058   }
00059 } 
00060 
00061 /*! @file
00062  * @brief Implements Transition, represents a transition between StateNodes.
00063  * @author ejt (Creator)
00064  *
00065  * $Author: ejt $
00066  * $Name: tekkotsu-2_2_2 $
00067  * $Revision: 1.13 $
00068  * $State: Exp $
00069  * $Date: 2004/12/17 05:51:32 $
00070  */
00071 

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0