示例#1
0
文件: actor.cpp 项目: Duion/GuideBot
void Actor::updateEffectors()
{
	GB_ASSERT(m_state,"Actor::updateEffectors: actor doesn't have state");
	
	//delete actions
	ActionSet::iterator ita = m_actionsToDelete.begin();
	ActionSet::iterator enda = m_actionsToDelete.end();
	while(ita!=enda)
	{
		Action* action = *ita;
		GB_SAFE_DELETE(action);
		ita++;
	}
	m_actionsToDelete.clear();

	//update actions
	Actions actionsToUpdate;
	m_rootAction->getChilds(actionsToUpdate, true);
/*
	for (Actions::reverse_iterator rit=actionsToUpdate.rbegin(), rend = actionsToUpdate.rend();
			rit!=rend; rit++)
*/
	for (Actions::iterator it=actionsToUpdate.begin(), end = actionsToUpdate.end();
		it!=end; it++)
	{
		Action* action = *it; //*rit;
		//check whether action wasn't terminated yet
		if (action->getTerminationStatus()==Action::NONE)
		{
			action->update();
		}
	}
	
	//notify actions about acquiring(activating) effectors
	for (ActivatedEffectorsMap::iterator it = m_activatedEffectors.begin(),end = m_activatedEffectors.end();
		it!=end; it++)
	{
		Action* action = it->first;
		EffectorIDVector& effectors = it->second;

		//check action activity on effectors
		EffectorIDVector::iterator jt = effectors.begin();
		while(jt!=effectors.end())
		{
			Effector* effector = getEffector(*jt);
			if (effector->isActive(action))
				jt++;
			else
				jt = effectors.erase(jt);
		}

		if (!effectors.empty())
		{
			//GB_INFO("Actor::update: reacquiring %s (%p)",action->getDescString().c_str(), action);
			action->acquireEffectors(effectors);
		}
	}
	m_activatedEffectors.clear();
}
示例#2
0
文件: actor.cpp 项目: Duion/GuideBot
bool Actor::checkEffectors(Action* action, Action* parentAction,EffectorIDVector &acquiredEffectors)
{
	acquiredEffectors.clear();

	bool principalAcquired = true;
	const Action::EffectorInfoMap &requiredEffectors = action->getRequiredEffectorInfos();
	for (Action::EffectorInfoMap::const_iterator it = requiredEffectors.begin(),end = requiredEffectors.end();
			it!=end; it++)
	{
		EffectorID effectorID = it->first;
		
		Effector* effector = getEffector(effectorID);
		GB_ASSERT(effector, format("Actor::getEffector: actor doesn't have effector %s", Effector::convertToString(effectorID)));
		
		bool principal = it->second.principal;

		
		
		//check if effector will be acquired by action when action is setting to parent
		bool isAcquired = false;

		Actions parentChain;
		Action* responsibleParent = getResponsibleParent(effectorID,parentAction,&parentChain);
		if (effector->isActive(responsibleParent))
		{
			isAcquired = true;
			int customActionPriority = action->getEffectorPriority(effectorID);
			Action* currentAction = parentChain.size()>1 ? parentChain[parentChain.size()-2] : action;
			Action* settedAction =  effector->getActiveChildAction(responsibleParent);
			//in our case, this can be done simpler, because comparing is based on action's priority 
			//and doesn't depend on action(so action can be used instead of currentAction)
			if (!settedAction || compareActions(settedAction,currentAction,effectorID,
										settedAction->getEffectorPriority(effectorID),customActionPriority))
			{
				isAcquired = true;
				acquiredEffectors.push_back(effectorID);
			}	
		}

		if (principal && !isAcquired)
		{
			principalAcquired = false;
		}
	}

	return principalAcquired;
}