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


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

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


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

示例1: buildFSM

		FSM * buildFSM( FSMDescrip & fsmDescrip, Agents::SimulatorInterface * sim, bool VERBOSE ) {
			// Acquire the spatial query instance
			SPATIAL_QUERY = sim->getSpatialQuery();

			//Global Simulator interface
			SIMULATOR = sim;

			bool valid = true;
			const size_t AGT_COUNT = sim->getNumAgents();
			FSM * fsm = new FSM( sim );

			// Build the fsm
			
			//we'll need this iterator later
			std::vector< VelModifier * >::iterator vItr;


			// Map of state names to state IDs.
			std::map< std::string, size_t > stateNameMap;
			
			// Copy the GoalSets
			fsm->_goalSets.clear();
			fsm->_goalSets.insert( fsmDescrip._goalSets.begin(), fsmDescrip._goalSets.end() );
			fsmDescrip._goalSets.clear();

			//	1. Create states
			//		a. Add velocity components and actions
			//		b. add to fsm

			std::list< StateDescrip * >::const_iterator sItr = fsmDescrip._states.begin();
			for ( ; sItr != fsmDescrip._states.end(); ++sItr ) {
				StateDescrip * sData = *sItr;
				State * s = fsmDescrip.addState( sData ); 

				if ( s == 0x0 ) {
					logger << Logger::ERR_MSG << "Error creating state!";
					delete fsm;
					return 0x0;
				}
				if ( VERBOSE ) logger << Logger::INFO_MSG << "\tAdding state: " << s->getName() << "(" << s->getID() << ")\n";
				

				// State's goal selector
				GoalSelector * gs = sData->_goalSelector;
				if ( gs == 0x0 ) {
					logger << Logger::WARN_MSG << "The state " << sData->_name << " doesn't specify a goal selector.  The identity goal selector will be used.";
					gs = new IdentityGoalSelector();
				}

				try {
					gs->setGoalSet( fsm->getGoalSets() );	// possibly throws GoalSelectorException
					s->setGoalSelector( gs );				// possibly throws GoalSelectorException
				} catch ( GoalSelectorException ) {
					logger << Logger::ERR_MSG << "Problem initializing the goal selector for the state " << s->getName() << ".";
					delete fsm;
					return 0x0;
				}
				sData->_goalSelector = 0x0;

				// construct each velocity component
				if ( sData->_velComponent == 0x0 ) {
					logger << Logger::WARN_MSG << "The state " << sData->_name << " doesn't specify a velocity component.  The zero velocity component will be used.";
					s->setVelComponent( new ZeroVelComponent() );
				} else {
					s->setVelComponent( sData->_velComponent );
					sData->_velComponent = 0x0;
				}
				
				// transfer each action
				std::list< Action * >::iterator aItr = sData->_actions.begin();
				for ( ; aItr != sData->_actions.end(); ++aItr ) {
					s->addAction( *aItr );
				}
				sData->_actions.clear();

				//transfer velocity modifiers from the state description
				vItr = sData->_velModifiers.begin();
				for ( ; vItr != sData->_velModifiers.end(); ++vItr ) {
					s->addVelModifier( *vItr );
				}
				sData->_velModifiers.clear();


				// Set start node
				size_t stateID = fsm->addNode( s );
				stateNameMap[ sData->_name ] = stateID;
			}

			// Connect all shared goal selectors
			std::map< std::string, size_t >::iterator stateItr = stateNameMap.begin();
			for ( ; stateItr != stateNameMap.end(); ++stateItr ) {
				std::string stateName = stateItr->first;
				size_t stateID = stateItr->second;
				State * state = fsm->getNode( stateID );
				SharedGoalSelector * gs = dynamic_cast< SharedGoalSelector * >( state->getGoalSelector() );
				if ( gs != 0x0 ) {
					if ( stateNameMap.count( gs->_stateName ) == 0 ) {
						logger << Logger::ERR_MSG << "Found shared goal selector defined on line " << gs->_lineNo << ", but unable to locate state with the provided name: \"" << gs->_stateName << "\".";
						delete fsm;
						return 0x0;
//.........这里部分代码省略.........
开发者ID:argenos,项目名称:Menge,代码行数:101,代码来源:buildFSM.cpp


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