Exemple #1
0
int GetCurrentCamera(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;

  // Set IO states
	beh->ActivateInput(0,FALSE);
	beh->ActivateOutput(0);

	CKCamera* cam = behcontext.CurrentRenderContext->GetAttachedCamera();

	beh->SetOutputParameterObject(0,cam);

	return CKBR_OK;
}
Exemple #2
0
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLA::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();

	char *arrayName = "laList";
	CKDataArray* array;

	array = (CKDataArray *)ctx->GetObjectByNameAndClass(arrayName,CKCID_DATAARRAY,NULL);

	if ( !array )
	{
		array = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,arrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( array );
	
		array->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );
	}
	else
	{
		array->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(array);
	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, array);
		beh->ActivateOutput(0);
	}
	else
	{
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

    return CKBR_OK;
}
Exemple #3
0
//************************************
// Method:    PWOverlapSphere
// FullName:  PWOverlapSphere
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PWOverlapSphere(const CKBehaviorContext& behcontext)
{

	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	PhysicManager *pm = GetPMan();
	
	pFactory *pf = pFactory::Instance();

	using namespace vtTools::BehaviorTools;
	using namespace vtTools::ParameterTools;

	

	//////////////////////////////////////////////////////////////////////////
	//the object : 
	CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
	if( !target ) return CKBR_OWNERERROR;


	//////////////////////////////////////////////////////////////////////////
	// the world :  
	pWorld *world=GetPMan()->getWorld(target->GetID());
	if (!world)
	{
		beh->ActivateOutput(bbOT_No);
		return 0;
	}

	NxScene *scene =  world->getScene();
	if (!scene)
	{
		beh->ActivateOutput(bbOT_No);
		return 0;
	}

	if( beh->IsInputActive(0) )
	{

		beh->ActivateInput(0,FALSE);


		CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result);
		if (carray)
		{
			//carray->clear();
			carray->Clear();
		}else
		{
			
			CK_OBJECTCREATION_OPTIONS creaoptions = (CK_OBJECTCREATION_OPTIONS)(CK_OBJECTCREATION_NONAMECHECK|CK_OBJECTCREATION_DYNAMIC);
			carray = (CKGroup*)ctx()->CreateObject(CKCID_GROUP,"asdasd",creaoptions);

		}
		
		beh->SetLocalParameterObject(0,carray);

		int hitIndex = 0;
		beh->SetLocalParameterValue(bbS_Index,&hitIndex);
		int hitSize = 0;
		beh->SetLocalParameterValue(bbS_Size,&hitSize);




		//////////////////////////////////////////////////////////////////////////
	
		int types  = GetInputParameterValue<int>(beh,bbI_ShapesType);
		int accurate  = GetInputParameterValue<int>(beh,bbI_Accurate);



		DWORD groupsEnabled;
		DWORD groups = 0xffffffff;
		beh->GetLocalParameterValue(bbS_Groups,&groupsEnabled);
		if (groupsEnabled)
		{
			groups = GetInputParameterValue<int>(beh,bbI_Groups);
		}

		pGroupsMask *gmask = NULL;
		DWORD mask;
		beh->GetLocalParameterValue(bbS_Mask,&mask);
		if (mask)
		{
			CKParameter *maskP = beh->GetInputParameter(bbI_Mask)->GetRealSource();
			gmask->bits0  = GetValueFromParameterStruct<int>(maskP,0);
			gmask->bits1  = GetValueFromParameterStruct<int>(maskP,1);
			gmask->bits2  = GetValueFromParameterStruct<int>(maskP,2);
			gmask->bits3  = GetValueFromParameterStruct<int>(maskP,3);

		}

		float radius = GetInputParameterValue<float>(beh,bbI_Radius);
		VxVector center = GetInputParameterValue<VxVector>(beh,bbI_Center);

		VxSphere sphere(center,radius);

		CK3dEntity *shape = (CK3dEntity*)beh->GetInputParameterObject(bbI_Ref);

		int nbShapes = world->overlapSphereShapes(sphere,shape,(pShapesType)types,carray,groups,gmask,accurate);
		if (nbShapes)
		{
			beh->ActivateOutput(bbOT_Yes);
			beh->ActivateInput(1,TRUE);

		}else{
			beh->ActivateOutput(bbOT_No);
		}
	}

	if( beh->IsInputActive(1) )
	{

		beh->ActivateInput(1,FALSE);
		CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result);
		
		//////////////////////////////////////////////////////////////////////////
		if (carray)
		{
			if (carray->GetObjectCount())
			{
				CKBeObject *hit = carray->GetObject(carray->GetObjectCount()-1);
				if (hit)
				{


					beh->SetOutputParameterObject(0,hit);
					carray->RemoveObject(hit);
					
					
					

					if (carray->GetObjectCount())
					{
						beh->ActivateOutput(bbOT_Next);
					}else
					{
						beh->ActivateOutput(bbOT_Finish);
						CKDestroyObject(carray);
					}

				}
			}else{
				beh->ActivateOutput(bbOT_Finish);
				CKDestroyObject(carray);
			}
		}else
		{
			beh->ActivateOutput(bbOT_Finish);
			CKDestroyObject(carray);
		}

	}

	return 0;
}
/*
 *******************************************************************
 * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext )
 *
 * Description : The execution function is the function that will be called 
 *               during the process loop of the behavior engine, if the behavior 
 *               is defined as using an execution function. This function is not 
 *               called if the behavior is defined as a graph. This function is the 
 *               heart of the behavior: it should compute the essence of the behavior, 
 *               in an incremental way. The minimum amount of computing should be 
 *               done at each call, to leave time for the other behaviors to run. 
 *               The function receives the delay in milliseconds that has elapsed 
 *               since the last behavioral process, and should rely on this value to 
 *               manage the amount of effect it has on its computation, if the effect 
 *               of this computation relies on time.
 *
 * Paramters :
 *    behaviourContext    r   Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : int, If it is done, it should return CKBR_OK. If it returns 
 *                CKBR_ACTIVATENEXTFRAME, the behavior will again be called 
 *                during the next process loop.
 *
 *******************************************************************
 */
int CGBLLAEGetLAE::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;


	IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
	IGBLSMLAAccess *laInterface = storageManager->GetLAInterface();
	IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface();

	char *laListArrayName = "laList";
	CKDataArray* laListArray;
	laListArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laListArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laListArray );
	laListArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAID" );

	char *laeArrayName = "laeidList";
	CKDataArray* laeArray;
	laeArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laeArrayName, CK_OBJECTCREATION_DYNAMIC);
	behaviorContext.CurrentLevel->AddObject( laeArray );
	laeArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );


	char *laelaArrayName = "laelaIDList";
	CKDataArray* laelaArray;
	laelaArray = (CKDataArray *)ctx->GetObjectByNameAndClass(laelaArrayName,CKCID_DATAARRAY,NULL);

	if ( !laelaArray )
	{
		laelaArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laelaArrayName, CK_OBJECTCREATION_DYNAMIC);
		behaviorContext.CurrentLevel->AddObject( laelaArray );
	
		laelaArray->InsertColumn( -1, CKARRAYTYPE_INT,	 "LAEID" );
		laelaArray->InsertColumn( -1, CKARRAYTYPE_STRING,	 "LAID" );
	}
	else
	{
		laelaArray->Clear();
	}

	CGBLCOError res = laInterface->RetrieveLAList(laListArray);

	if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		int count = laListArray->GetRowCount();
		for (int i=0; i < count; i++)
		{
			//get list of laes for given la and add it to results list

			XString xLAID;

			CKSTRING valueField = NULL;
			int labelLength =  laListArray->GetElementStringValue(i, 0, NULL);
			valueField = new CKCHAR[labelLength];
			labelLength =  laListArray->GetElementStringValue(i, 0, valueField);
			xLAID = valueField;
			delete valueField;


			CGBLLAID laid; 
			laid.FromString(xLAID);

			CGBLCOError res = laeInterface->RetrieveLAEList(laeArray,laid);
			if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
			{
				int count = laeArray->GetRowCount();
				for (int j=0; j < count; j++)
				{
					CKSTRING valueField = NULL;
					int labelLength =  laeArray->GetElementStringValue(j, 0, NULL);
					valueField = new CKCHAR[labelLength];

					labelLength =  laeArray->GetElementStringValue(j, 0, valueField);

					laelaArray->AddRow();
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 0, valueField);
					laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 1, xLAID.Str());

					delete valueField;
				}
			}
		}
		beh->ActivateInput(0, FALSE);
		beh->SetOutputParameterObject(0, laelaArray);
		beh->ActivateOutput(0);
	}
	else
	{
		
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(1);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC);
		beh->ActivateOutput(1);
	}

	behaviorContext.CurrentLevel->RemoveObject(laListArray);
	ctx->DestroyObject(laListArray);
	behaviorContext.CurrentLevel->RemoveObject(laeArray);
	ctx->DestroyObject(laeArray);
    return CKBR_OK;
}
Exemple #5
0
//************************************
// Method:    PCGroupTriggerEvent
// FullName:  PCGroupTriggerEvent
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PCGroupTriggerEvent(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	PhysicManager *pm = GetPMan();
	
	pFactory *pf = pFactory::Instance();

	using namespace vtTools::BehaviorTools;
	

	//////////////////////////////////////////////////////////////////////////
	//the object : 
	CKGroup *target = (CKGroup *) beh->GetTarget();
	if( !target ) return CKBR_OWNERERROR;

	//int extraFilter = GetInputParameterValue<int>(beh,0);
	//int remove = GetInputParameterValue<int>(beh,1);

	int nbOfEvents = getEventCount();
	if (!nbOfEvents)
	{
		beh->ActivateOutput(bbO_None);
		return 0;
	}

	/************************************************************************/
	/* handle init                                                                     */
	/************************************************************************/
	if( beh->IsInputActive(bbI_Init) )
	{
		beh->ActivateInput(bbI_Init,FALSE);

		int index = 0;beh->SetLocalParameterValue(0,&index);
		
		//we have some, forward to in 1:next
		if (nbOfEvents)
		{
			beh->ActivateInput(bbI_Next,TRUE);
			beh->ActivateOutput(bbO_HasMore);
		}
	}

	/************************************************************************/
	/* handle trigger 'next'                                                                     */
	/************************************************************************/
	if( beh->IsInputActive(bbI_Next) )
	{
		beh->ActivateInput(bbI_Next,FALSE);

		int index = 0;beh->GetLocalParameterValue(0,&index);
		for (int i  = index ; i < GetPMan()->getTriggers().Size(); i++ )
		{
			pTriggerEntry &entry  = *GetPMan()->getTriggers().At(i);
			if (!entry.triggered)
			{
				if (isInGroup(target,entry.triggerShapeEnt))
				{
					beh->SetOutputParameterObject(0,entry.triggerShapeEnt);
					beh->SetOutputParameterObject(1,entry.otherObject);

					SetOutputParameterValue<int>(beh,2,entry.triggerEvent);
					entry.triggered = true;

					//trigger out 
					if(entry.triggerEvent == NX_TRIGGER_ON_ENTER)
					{
						beh->ActivateOutput(bbO_Enter);
					}
					if(entry.triggerEvent == NX_TRIGGER_ON_STAY)
					{
						beh->ActivateOutput(bbO_Stay);
					}
					if(entry.triggerEvent == NX_TRIGGER_ON_LEAVE)
					{
						beh->ActivateOutput(bbO_Leave);
					}

					//store index
					beh->SetLocalParameterValue(1,&index);
					int nbOfLeftEvents = getEventCount();
					if (nbOfLeftEvents)
					{
						beh->ActivateOutput(bbO_HasMore);
						return 0;
					}else
					{
						beh->ActivateOutput(bbO_None);
						return 0;
					}
				}
			}
		}
	}

	/************************************************************************/
	/*                                                                      */
	/************************************************************************/
	return 0;
}