Example #1
0
int GBLCOBGWrapper::BehaviourFunction( const CKBehaviorContext& behContext )
{
	CKBehavior	*behaviour = behContext.Behavior;
	CKContext	*context = behContext.Context;
	int			iPin, nbPin;

	CKBehavior* script = (CKBehavior*)behaviour->GetLocalParameterObject(EGBLCOBGWRAPPERPARAM_PARAMETER_SCRIPT);

	if (script == NULL)
		return CKBR_GENERICERROR;

	// Activate the right inputs
	nbPin = behaviour->GetInputCount();
	for (iPin = 0; iPin < nbPin; iPin++)
		{
		if (behaviour->IsInputActive(iPin))
			{
			script->ActivateInput(iPin, TRUE);
			behaviour->ActivateInput(iPin, FALSE);
			}
		}
	
	// Deactivate all the outputs
	nbPin = script->GetOutputCount();
	for (iPin = 0; iPin < nbPin; iPin++)
		{
		behaviour->ActivateOutput(iPin, FALSE);
		}

	// Parameter In: Set Source
	int nbPinBB = behaviour->GetInputParameterCount();
	int nbPinBG = script->GetInputParameterCount();

	if (nbPinBB != nbPinBG)
		return CKBR_GENERICERROR;

	for (iPin = 0; iPin < nbPinBB; iPin++)
	{
		CKParameterIn *pBin = behaviour->GetInputParameter(iPin);
		CKParameter* pSource = pBin->GetDirectSource();

		CKParameterIn *pSin = script->GetInputParameter(iPin);
		pSin->SetDirectSource(pSource);
	}

	// Execute the contained script
	CKERROR result = script->Execute(behContext.DeltaTime);

	// The script loop on itself too much times
	if (result == CKBR_INFINITELOOP) 
		{
		context->OutputToConsoleExBeep("Execute Script : Script %s Executed too much times",script->GetName());
		script->Activate(FALSE,FALSE);
		return CKBR_OK;
		}

	// Activate the right outputs 
	nbPin = script->GetOutputCount();
	for (iPin = 0; iPin < nbPin; iPin++)
		{
		if (script->IsOutputActive(iPin))
			{
			behaviour->ActivateOutput(iPin);
			script->ActivateOutput(iPin, FALSE);
			}
		}

	// Update Parameters Out
	nbPin = behaviour->GetOutputParameterCount();
	for (iPin = 0; iPin < nbPin; iPin++)  
		{
		CKParameterOut *pBout = behaviour->GetOutputParameter(iPin);
		CKParameterOut *pSout = script->GetOutputParameter(iPin);
		pBout->CopyValue(pSout, TRUE);
		}

	
	// Test if there are any active sub-behaviors, restart the next frame if any
	BOOL bActivateNextFrame = FALSE;
	ActivateNextFrameSubBB(script,bActivateNextFrame);
	if (bActivateNextFrame)
		return CKBR_ACTIVATENEXTFRAME;

	// return the execute value
	return result;	
}
Example #2
0
bool pWheel2::onWheelContactModify(int& changeFlags,pWheelContactModifyData* contact)
{



	bool result = true;
	//----------------------------------------------------------------
	//
	// sanity checks
	//
	if (!contact)
		return true;
	
	//----------------------------------------------------------------
	//
	// keep some informationens for our self
	//
	if( getProcessOptions() & pVPO_Wheel_UsePHYSX_Load &&
		getProcessOptions() & pVPO_Wheel_UsePHYSX_CONTACT_DATA && getVehicle() 
		)
	{
		load = contact->contactNormal.y;

		if (load > 1500)
			load = 1500;

		if (load <= 0)
			load = 1000;


	}

	CKBehavior * beh  = (CKBehavior*)GetPMan()->GetContext()->GetObject(getWheelContactScript());
	if (beh && CKGetObject(ctx(),getEntID()))
	{
		
		SetInputParameterValue<CK_ID>(beh,bbIWC_SrcObject,getEntID());

		SetInputParameterValue<VxVector>(beh,bbIWC_Point,contact->contactPoint);
		SetInputParameterValue<VxVector>(beh,bbIWC_Normal,contact->contactNormal);
		SetInputParameterValue<float>(beh,bbIWC_Position,contact->contactPosition);
		SetInputParameterValue<float>(beh,bbIWC_NormalForce,contact->normalForce);
		SetInputParameterValue<int>(beh,bbIWC_OtherMaterialIndex,contact->otherMaterialIndex);
		//----------------------------------------------------------------
		//
		// execute:
		//
		beh->Execute(lastStepTimeSec);

		//----------------------------------------------------------------
		//
		// refuse contact 
		//
		result = GetOutputParameterValue<int>(beh,bbOWC_CreateContact);
		if (!result)
			return false;

		//----------------------------------------------------------------
		//
		// nothing changed, return true
		//
		changeFlags = GetOutputParameterValue<int>(beh,bbOWC_ModificationFlags);
		if (changeFlags == 0 )
		{
			return true;
		}

		//----------------------------------------------------------------
		//
		// pickup data, according to change flags
		//
		if (changeFlags & CWCM_ContactPoint )
			contact->contactPoint = GetOutputParameterValue<VxVector>(beh,bbOWC_Point);

		if (changeFlags & CWCM_ContactNormal)
			contact->contactNormal= GetOutputParameterValue<VxVector>(beh,bbOWC_Normal);
		
		if (changeFlags & CWCM_ContactPosition )
			contact->contactPosition= GetOutputParameterValue<float>(beh,bbOWC_Position);

		if (changeFlags & CWCM_NormalForce )
			contact->normalForce = GetOutputParameterValue<float>(beh,bbOWC_NormalForce);
	}

		

	return true;

}