Exemplo n.º 1
0
/*
*******************************************************************
* Function: int CGBLBuildCommand::GetNextArgument (CKParameter* nextArgument,CKBehavior* targetBB, const CKBehaviorContext& behaviorContext)
*
* Description : This function sets corresponding outputs with requested argument's 
*				name, type and if the type of arguments is TGBLFCStringFromList, it also
*				provides designer specified list array with GetDesignerSpecifiedList output.
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
*	nextArgument	    r	Required argument to have parameters provided by the command
*
*	targetBB			r	Target GBLWaitForCommand building block
*
* Returns : int, The return value is 0 if no error occured or -1 on error 
*
*******************************************************************
*/
int CGBLBuildCommand::GetNextArgument (CKParameter* nextArgument,CKBehavior* targetBB, const CKBehaviorContext& behaviorContext)
{
	CKBehavior* behavior = behaviorContext.Behavior;
	CKContext*  context = behaviorContext.Context;

	XString typeName = context->GetParameterManager()->ParameterTypeToName(nextArgument->GetType());
	XString argumentName = nextArgument->GetName();

	if (typeName == "TGBLFCStringFromList")
	{
		int inputs = targetBB->GetInputParameterCount();

		for (int i=0; i<inputs; i++)
		{
			CKParameterIn *parameterInput = targetBB->GetInputParameter(i);

			if ( argumentName == parameterInput->GetName() )
			{
				CKParameterOut *parameterOutput = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetDesignerSpecifiedList);

				context->OutputToConsole(context->GetParameterManager()->ParameterTypeToName(parameterOutput->GetType()), FALSE);
				context->OutputToConsole(context->GetParameterManager()->ParameterTypeToName(parameterInput->GetType()), FALSE);
				
				parameterOutput->CopyValue (parameterInput->GetDirectSource());
				break;
			}
		}
	}

	behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetArgumentType, typeName.Str(), strlen (typeName.Str()) + 1 );
	behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetArgumentName, argumentName.Str(), strlen (argumentName.Str()) + 1 );

	behavior->ActivateOutput (EGBLBuildCommandBehOutputs::GetNextParameterValue);

	return 0;
}
Exemplo n.º 2
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;	
}
Exemplo n.º 3
0
int PVSetMotorValues(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;

	CKContext* ctx = behcontext.Context;

	PhysicManager *pm = GetPMan();
	
	pFactory *pf = pFactory::Instance();

	if( beh->IsInputActive(0) )
	{
		beh->ActivateInput(0,FALSE);



		CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
		if( !target )	bbSErrorME(E_PE_REF);

		pRigidBody *body = GetPMan()->getBody(target);
		if (!body)		bbSErrorME(E_PE_NoBody);

		pVehicle *v = body->getVehicle();
		if (!v)			bbSErrorME(E_PE_NoVeh);

		if (!v->isValidEngine())
			bbErrorME("Vehicle is not complete");

		pEngine *engine = v->getEngine();
		if (!engine)			bbErrorME("No valid engine");
		
		
		CK2dCurve* pOCurve = NULL;	//optional 

		BB_DECLARE_PIMAP;//retrieves the parameter input configuration array
		BBSParameter(I_XML);//our bb settings concated as s##I_XML
		BBSParameter(I_Flags);
		BBSParameter(I_Clutch);
		BBSParameter(I_tList);
		BBSParameter(I_maxRPM);
		BBSParameter(I_minRPM);
		BBSParameter(I_maxTorque);
		BBSParameter(I_intertia);
		BBSParameter(I_engineFriction);
		BBSParameter(I_breakCoeff);
		BBSParameter(I_GroundForceFeedBackScale);

		if (sI_XML){
			int xmlLink = GetInputParameterValue<int>(beh,BB_IP_INDEX(I_XML));
		}
		
		if (sI_GroundForceFeedBackScale)
			engine->setForceFeedbackScale(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_GroundForceFeedBackScale)));

		if (sI_Flags)
			engine->setFlags(GetInputParameterValue<int>(beh,BB_IP_INDEX(I_Flags)));
		if (sI_Clutch)
			engine->setClutch(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_Clutch)));

		if (sI_maxTorque)
			engine->setMaxTorque(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxTorque)));

		if (sI_maxTorque)
			engine->setMaxTorque(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxTorque)));
		if (sI_maxRPM)
			engine->setMaxRPM(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_maxRPM)));
		if (sI_minRPM)
			engine->setIdleRPM(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_minRPM)));
		if (sI_engineFriction)
			engine->setFriction(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_engineFriction)));
		if (sI_intertia)
			engine->SetInertia(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_intertia)));

		if (sI_breakCoeff)
			engine->setBrakingCoeff(GetInputParameterValue<float>(beh,BB_IP_INDEX(I_breakCoeff)));


		if (sI_tList){

			CKParameterIn *inP = beh->GetInputParameter(BB_IP_INDEX(I_tList));
			CKParameter *pout= inP->GetDirectSource();
			if (pout)
			{
				
				if (engine->getTorqueCurve())
				{
					pLinearInterpolation &curve = *engine->getTorqueCurve();

					curve.clear();
					IParameter::Instance()->copyTo(curve,pout);
					engine->preStep();

				}
				
			}
			//engine->setTorqueCurve();
		}

	

		//////////////////////////////////////////////////////////////////////////
		//a optinal curve to display ratio between horse power and rpm

/*		DWORD outputCurve;	beh->GetLocalParameterValue(BB_PMAP_SIZE(gPIMAP),&outputCurve);//special settings !
		if (outputCurve)
			beh->GetOutputParameterValue(0,&pOCurve);

*/
		


		//////////////////////////////////////////////////////////////////////////
		//
		//			Checking we have to replace of the entire motor object ! 
		//
		if (sI_tList)
		{
			float maxInputRPM =0.0f;			
			float maxInputNM =0.0f;

			//////////////////////////////////////////////////////////////////////////
			//
			// this is only a test run ! 
			pLinearInterpolation nTable;
			//getNewTorqueTable(beh,nTable,maxInputRPM,maxInputNM,NULL);

			if (nTable.getSize() )
			{

				/*
				if (pOCurve)
				{
					while (pOCurve->GetControlPointCount())
					{
						pOCurve->DeleteControlPoint(pOCurve->GetControlPoint(0));
						pOCurve->Update();
					}
				}

				*/
				//////////////////////////////////////////////////////////////////////////
				//	we just copy into the motor we can get !
				
			
				//////////////////////////////////////////////////////////////////////////
				// we make a new torque ratios 

				//getNewTorqueTable(beh,mDesc->torqueCurve,maxInputRPM,maxInputNM,pOCurve);
				
				/*
				if (!mDesc->isValid())					bbErrorME("motor description was invalid,  aborting update ");

				if (!motor)
				{
					motor = pFactory::Instance()->createVehicleMotor(*mDesc);
					v->setMotor(motor);
				}else
				{
					if (mDesc->torqueCurve.getSize())
					{
						motor->loadNewTorqueCurve(mDesc->torqueCurve);
					}
				}*/
			}
		}


		

		//////////////////////////////////////////////////////////////////////////
		//
		//	Flexibility : 
		//
		
		/*
		if (sI_minRDown &&		motor )motor->setMinRpmToGearDown(mDDown);
		if (sI_maxRUp &&			motor )motor->setMaxRpmToGearUp(mDUp);
		if (sI_maxR	&&			motor )motor->setMaxRpm(maxR);
		if (sI_minR	&&			motor )motor->setMinRpm(minR);

		*/
		if ( pOCurve	)
		{
			/*
			#ifdef _DEBUG
						XString error;
						error << "t curve created with " << pOCurve->GetControlPointCount() << " with l : " << pOCurve->GetLength();
						bbErrorME(error.CStr());
			#endif
			*/


			/*
			for (int i  = 0 ; i < pOCurve->GetControlPointCount() ; i++)
			{
				CK2dCurvePoint*  point = pOCurve->GetControlPoint(i);
				point->SetLinear(true);
			}
			pOCurve->Update();
			beh->SetOutputParameterValue(0,&pOCurve);
			*/

		}
		//delete mDesc;
		//mDesc  = NULL;
	}

	beh->ActivateOutput(0);
	return 0;
}
Exemplo n.º 4
0
/*
*******************************************************************
* Function: int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext)
*
* Description : Checks if there are more arguments to be specified for network command
*				and takes corresponded actions
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
*******************************************************************
*/
int CGBLBuildCommand::DoHandleNextNetworkArgument (const CKBehaviorContext& behaviorContext)
{
	CKBehavior* behavior = behaviorContext.Behavior;
  	CKContext* context = behaviorContext.Context;

	int gblBuildCommandState;

	CKBehavior* targetBB = NULL;
	CK_ID targetID;
	behavior->GetLocalParameterValue (targetBBLocalPos, &targetID);
	targetBB = (CKBehavior*)behaviorContext.Context->GetObject(targetID);

	if (targetBB == NULL)
	{
		CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC);

		behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
		return CKBR_OK;
	}

	int currentParameterPosition = 0;
	behavior->GetLocalParameterValue (currentParameterPositionLocalPos, &currentParameterPosition);
	CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition);

	currentParameterPosition++;
	behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &currentParameterPosition);

	if (nextArgument == NULL)
	{
		//no arguments required, build finished
		CKParameter *outputCommandString, *localCommandString;
		CKParameter *outputDests;
		CKParameterIn *inputDests;

		ClearParameterOutputs(behaviorContext);

		outputCommandString = (CKParameter*) behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetCommandString);
		localCommandString = (CKParameter*) behavior->GetLocalParameter (commandStringLocalPos);
		outputCommandString->CopyValue(localCommandString);

		// Copy list of recipients from input to output
		outputDests = (CKParameter*) (behavior->GetOutputParameter (EGBLBuildCommandParamOutputs::GetDests));
		inputDests =  behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests);
		outputDests->CopyValue(inputDests->GetDirectSource());

		gblBuildCommandState = EGBLBuildCommandState::Completed;
		behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState);

        behavior->ActivateOutput (EGBLBuildCommandBehOutputs::HandleTargetedCommand);
		return CKBR_OK;
	}
	else
	{
		//get next argument
		gblBuildCommandState = EGBLBuildCommandState::AwaitingParametersForNetwork;
		behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState);

		GetNextArgument (nextArgument, targetBB, behaviorContext);

		return CKBR_OK;
	}
}