当前位置: 首页>>代码示例>>C++>>正文


C++ FSM::addTask方法代码示例

本文整理汇总了C++中FSM::addTask方法的典型用法代码示例。如果您正苦于以下问题:C++ FSM::addTask方法的具体用法?C++ FSM::addTask怎么用?C++ FSM::addTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FSM的用法示例。


在下文中一共展示了FSM::addTask方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildFSM


//.........这里部分代码省略.........
			//	2. Create transitions
			std::map< std::string, std::list< Transition * > >::iterator stItr = fsmDescrip._transitions.begin();
			for ( ; stItr != fsmDescrip._transitions.end(); ++stItr ) {
				const std::string fromName = stItr->first;
				std::list< Transition * > & tList = stItr->second;

				// Determine if the origin state is valid
				if ( fsmDescrip._stateNameMap.find( fromName ) == fsmDescrip._stateNameMap.end() ) {
					logger << Logger::ERR_MSG << "Transition with invalid from node name: " << fromName << ".";
					delete fsm;
					return 0x0;
				}

				// Try to connect the transitions to the destination(s)
				std::list< Transition * >::iterator tItr = tList.begin();
				for ( ; tItr != tList.end(); ++tItr ) {
					Transition * t = *tItr;
					if ( ! t->connectStates( fsmDescrip._stateNameMap ) ) {
						delete fsm;
						return 0x0;
					}
					fsm->addTransition( stateNameMap[ fromName ], t );
				}
				tList.clear();
			}
			fsmDescrip._transitions.clear();

			//////////////

			// copy over the velocity modifiers
			vItr = fsmDescrip._velModifiers.begin();
			for ( ; vItr != fsmDescrip._velModifiers.end(); ++vItr ) {   //TODO: replace global vel mod initalizer
				fsm->addVelModifier( *vItr );  

			}
			fsmDescrip._velModifiers.clear();

			// 3. Query simulator and fsm for possible reasons to have a task
			fsm->collectTasks();
			for ( std::list< Task * >::iterator itr = fsmDescrip._tasks.begin();
				itr != fsmDescrip._tasks.end();
				++itr ) {
				fsm->addTask( (*itr) );
			}
			fsmDescrip._tasks.clear();

			// spatial query and elevation tasks
			fsm->addTask( SPATIAL_QUERY->getTask() );
			if ( sim->getElevationInstance() ) {
				// NOTE: The elevation instance is null because none were specified.
				//	Eventually, the default elevation will be set.
				// HOWEVER, if the default ever changes such that it requires a task,
				//	this won't catch it!!!  So, make sure the default never requires
				//	a task.
				fsm->addTask( sim->getElevationInstance()->getTask() );
			}

			logger << Logger::INFO_MSG << "There are " << fsm->getTaskCount() << " registered tasks.\n";
			fsm->doTasks();

			

			//	5. Initialize all agents
			if ( VERBOSE ) logger << Logger::INFO_MSG << "Initializing agents:\n";
			Agents::SimulatorState * initState = sim->getInitialState();

			for ( size_t a = 0; a < AGT_COUNT; ++a ) {
				Agents::BaseAgent * agt = sim->getAgent( a );
				// update current state to class-appropriate value
				const std::string stateName = initState->getAgentState( agt->_id );

				std::map< std::string, size_t >::iterator stateIDItr = stateNameMap.find( stateName );
				if ( stateIDItr == stateNameMap.end() ) {
					logger << Logger::ERR_MSG << "Agent " << agt->_id << " requested to start in an unknown state: " << stateName << ".";
					delete fsm;
					return 0x0;
				}
				size_t stateID = stateIDItr->second;

				// initialize velocity to preferred velocity
				State * cState = fsm->getNode( stateID );
				if ( VERBOSE ) {
					logger << Logger::INFO_MSG << "Agent " << agt->_id << " starts in " << cState->getName() << ".";
				}
				fsm->setCurrentState( agt, stateID );
				cState->enter( agt );
				// TODO: Restore support for defining inital velocity state: zero or preferred
				agt->_vel.set( Vector2( 0.f, 0.f ) );

				//register the agent for all vel modifiers
				vItr = fsm->_velModifiers.begin();
				for ( ; vItr != fsm->_velModifiers.end(); ++vItr ) {   //TODO: replace global vel mod initalizer
					( *vItr )->registerAgent(agt);  
				}
			}

			ACTIVE_FSM = fsm;

			return fsm;
		}
开发者ID:argenos,项目名称:Menge,代码行数:101,代码来源:buildFSM.cpp


注:本文中的FSM::addTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。