Ejemplo n.º 1
0
	int WaitFramesState::GetFrames(Agent* pAgent) const
	{
		if (this->m_frames_var)
		{
			BEHAVIAC_ASSERT(this->m_frames_var);
			TProperty<int>* pP = (TProperty<int>*)this->m_frames_var;
			uint64_t frames = pP->GetValue(pAgent);

			return (frames == ((uint64_t)-1) ? -1 : (int)frames);
		}
		else if (this->m_frames_method)
		{
			//ParentType pt = this->m_frames_method->GetParentType();
			Agent* pParent = pAgent;
			/*if (pt == PT_INSTANCE)
			{*/
			pParent = Agent::GetInstance(this->m_frames_method->GetInstanceNameString(), pParent->GetContextId());
			BEHAVIAC_ASSERT(pParent);
			/*}*/

			this->m_frames_method->run(pParent, pAgent);

			int frames = this->m_frames_method->GetReturnValue<int>(pParent);

			return frames;
		}

		return 0;
	}
Ejemplo n.º 2
0
	EBTStatus ActionTask::update(Agent* pAgent, EBTStatus childStatus)
	{
		BEHAVIAC_UNUSED_VAR(pAgent);
		BEHAVIAC_UNUSED_VAR(childStatus);

		BEHAVIAC_ASSERT(Action::DynamicCast(this->GetNode()));
		Action* pActionNode = (Action*)(this->GetNode());

		if (!this->CheckPredicates(pAgent))
		{
			return pActionNode->m_resultPreconditionFail;
		}

		EBTStatus result = BT_SUCCESS;

		if (pActionNode->m_method)
		{
//#if BEHAVIAC_ENABLE_PROFILING
//			BEHAVIAC_PROFILE("Node");
//#endif
			ParentType pt = pActionNode->m_method->GetParentType();
			Agent* pParent = pAgent;
			if (pt == PT_INSTANCE)
			{
				pParent = Agent::GetInstance(pActionNode->m_method->GetInstanceNameString(), pParent->GetContextId());
				BEHAVIAC_ASSERT(pParent);
			}

			int nodeId = this->GetId();
			int slot = SetNodeId(nodeId);
			BEHAVIAC_ASSERT(slot != -1, "no empty slot found!");

			pActionNode->m_method->run(pParent, pAgent);

			if (pActionNode->m_resultOption != BT_INVALID)
			{
				result = pActionNode->m_resultOption;
			}
			else if (pActionNode->m_resultFunctor)
			{
				ParentType pt = pActionNode->m_resultFunctor->GetParentType();
				Agent* pParentCheckResult = pAgent;
				if (pt == PT_INSTANCE)
				{
					pParentCheckResult = Agent::GetInstance(pActionNode->m_resultFunctor->GetInstanceNameString(), pParentCheckResult->GetContextId());
					BEHAVIAC_ASSERT(pParentCheckResult);
				}

				result = (EBTStatus)pActionNode->m_method->CheckReturn(pParent, pParentCheckResult, pActionNode->m_resultFunctor);
			}
			else
			{
				pActionNode->m_method->CheckReturn(pParent, result);
			}

			ClearNodeId(slot);
		}
		else
		{
//#if BEHAVIAC_ENABLE_PROFILING
//			BEHAVIAC_PROFILE("ActionGenerated");
//#endif
			result = pActionNode->update_impl(pAgent, childStatus);
		}

		return result;
	}