Esempio n. 1
0
int AddNodalLink(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;
	CKAttributeManager* attman = ctx->GetAttributeManager();
	beh->ActivateInput(0,FALSE);
	beh->ActivateOutput(0);

	CKGroup* group = (CKGroup*)beh->GetInputParameterObject(0);			
	CKParameterOut* param = group->GetAttributeParameter(attman->GetAttributeTypeByName(Network3dName));
	if(!param) throw "Given Group isn't a Network";
	N3DGraph* graph;
	param->GetValue(&graph);

	CK3dEntity* s = (CK3dEntity*)beh->GetInputParameterObject(1);
	CK3dEntity* e = (CK3dEntity*)beh->GetInputParameterObject(2);
	float b;
	beh->GetInputParameterValue(3,&b);
	graph->InsertEdge(s,e,b);
	beh->ActivateOutput(0);





	return CKBR_OK;
}
Esempio n. 2
0
int GetLastFileName(const CKBehaviorContext& behcontext)
{

    CKBehavior* beh = behcontext.Behavior;
    CKContext* ctx = behcontext.Context;

    XString Inpath (ctx->GetLastCmoLoaded());



    CKParameterOut *pout = beh->GetOutputParameter(0);
    pout->SetStringValue(Inpath.Str());

    PathRemoveFileSpec(Inpath.Str());


    CKParameterOut *pout2 = beh->GetOutputParameter(1);
    pout2->SetStringValue(Inpath.Str());



    beh->ActivateOutput(0);


    return 0;

}
Esempio n. 3
0
/*
*******************************************************************
* Function: int RetrieveCICB( const CKBehaviorContext& behaviorContext )
*
* Description : The Behavior Callback function is called by Virtools when various events happen 
*               in the life of a BuildingBlock. Exactly which events trigger a call to the 
*               Behavior Callback function is defined in the Behavior Prototype, along with the 
*               declaration of the function pointer 
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
* Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values.
*
*******************************************************************
*/
CKERROR RetrieveCICB(const CKBehaviorContext& behcontext)
{
	/************************************************************************/
	/*  collecting data :													*/
	/*  																	*/
	CKBehavior *beh = behcontext.Behavior;
	CKContext* ctx = beh->GetCKContext();
	CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager());
	/************************************************************************/
	/*	process virtools callbacks		:																			*/
	/*  																														*/

	switch(behcontext.CallbackMessage)
	{
	
		
		case CKM_BEHAVIOREDITED:
		case CKM_BEHAVIORSETTINGSEDITED:
		{
	
			assert(beh && ctx);
			BOOL getAsString,outputAttriubtes = false;
			beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString);
			beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes);
	       

			//////////////////////////////////////////////////////////////////////////
			// get ci by string
			if(getAsString)
			{
				CKParameterOut* ciValue = beh->GetOutputParameter(0);
				ciValue->SetType(pm->ParameterGuidToType(CKPGUID_STRING));
			}
			
			if(outputAttriubtes)
			{
				beh->CreateOutputParameter("Default Value",CKPGUID_STRING);
                beh->CreateOutputParameter("Unique name",CKPGUID_STRING);                
				beh->CreateOutputParameter("Description",CKPGUID_STRING);
				beh->CreateOutputParameter("Runtime flags",CIPRTFLAGSGUID);
				beh->CreateOutputParameter("Type",CKPGUID_PARAMETERTYPE);

			}

			int p_count  =  beh->GetOutputParameterCount();

			while(   (outputAttriubtes ? BEH_OUT_MAX_COUNT : BEH_OUT_MIN_COUNT )   < p_count )
			{ 
				CKDestroyObject( beh->RemoveOutputParameter( --p_count) );
			}
		
			
			
		}
	}
	return CKBR_OK;
}
Esempio n. 4
0
 /*
 *******************************************************************
 * Function: BOOL	:CreateIO(CKBehavior* behaviour, CKBehavior* script)
 *
 * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching
 *
 * Parameters :
 *    behaviour		  Behavior 1, usually the BG wrapper BB.
 *    script	      Behavior 2, usually the wrapped BG.
 *
 * Returns : BOOL
 *
 *******************************************************************
 */
BOOL	GBLCOBGWrapper::CreateIO(CKBehavior* behaviour, CKBehavior* script)
	{
	int		iIO;
	int		nbPin;
	
	// Input
	nbPin = script->GetInputCount();
	for (iIO = 0; iIO < nbPin; iIO++)
		{
		CKBehaviorIO* pPin = script->GetInput(iIO);
		if (pPin == NULL)
			return FALSE;
		
		if (behaviour->AddInput(pPin->GetName()) != iIO)
			return FALSE;
		}

	// Output
	nbPin = script->GetOutputCount();
	for (iIO = 0; iIO < nbPin; iIO++)
		{
		CKBehaviorIO* pPin = script->GetOutput(iIO);
		if (pPin == NULL)
			return FALSE;
		
		if (behaviour->AddOutput(pPin->GetName()) != iIO)
			return FALSE;
		}

	// Parameter In
	nbPin = script->GetInputParameterCount();
	for (iIO = 0; iIO < nbPin; iIO++)
		{
		CKParameterIn* pPin = script->GetInputParameter(iIO);
		if (pPin == NULL)
			return FALSE;
		
		CKParameterIn* pPin2;
		if ((pPin2 = behaviour->CreateInputParameter(pPin->GetName(), (CKParameterType)pPin->GetType())) == NULL)
			return FALSE;
		}

	// Parameter Out
	nbPin = script->GetOutputParameterCount();
	for (iIO = 0; iIO < nbPin; iIO++)
		{
		CKParameterOut* pPin = script->GetOutputParameter(iIO);
		if (pPin == NULL)
			return FALSE;
		
		if (behaviour->CreateOutputParameter(pPin->GetName(), (CKParameterType)pPin->GetType()) == NULL)
			return FALSE;
		}

	return TRUE;
	}
Esempio n. 5
0
//************************************
// Method:    vt_SetOutVal
// FullName:  vt_SetOutVal
// Access:    public static 
// Returns:   PyObject *
// Qualifier:
// Parameter: PyObject * self
// Parameter: PyObject * args
//************************************
static PyObject *vt_SetOutVal( PyObject * self, PyObject * args )
{
	
	int size = PyTuple_Size(args);
	PyObject *val;
	int bid, index;
	PyArg_ParseTuple(args, "iiO", &bid, &index,&val); 

	CK_ID cid = bid; 
	CKBehavior *beh = static_cast<CKBehavior*>(pym->m_Context->GetObject(cid)); 
	if (size!=3)
	{

		pym->m_Context->OutputToConsole("PyError : This function only accepts 3 arguments : \n\t bid,index,value ");
		Py_RETURN_NONE;
	}
	
	using namespace vtTools;
	
	if (beh && val &&  index < beh->GetOutputParameterCount() )
	{
		if (PyInt_Check(val))
		{
			long ret = PyInt_AsLong(val);
			int retx = static_cast<int>(ret);
			beh->SetOutputParameterValue(index,&retx);
			Py_RETURN_NONE;
		}
		if (PyFloat_Check(val))
		{
			double ret = PyFloat_AsDouble(val);
			float retx  = static_cast<float>(ret);
			beh->SetOutputParameterValue(index,&retx);
			Py_RETURN_NONE;
		}
		if (PyString_Check(val))
		{
			std::string ret;
			CKParameterOut * pout = beh->GetOutputParameter(index);
			XString retx(ret.c_str());
			pout->SetStringValue(retx.Str());
			Py_RETURN_NONE;
		}
		if (PyTuple_Check(val))
		{
			std::string outList = to_string(val);
			CKParameterOut * pout = beh->GetOutputParameter(index);
			XString retx(outList.c_str());
			pout->SetStringValue(retx.Str());
			Py_RETURN_NONE;
		}

		
	}
	Py_RETURN_NONE;
}
Esempio n. 6
0
int DirToArray(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;

	XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0));
	XString Mask((CKSTRING) beh->GetInputParameterReadDataPtr(1));
		
	int rec;

	beh->GetInputParameterValue(2,&rec);

	

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

		flist.erase(flist.begin(),flist.end());

		CKDirectoryParser MyParser(filename.Str(),Mask.Str(),rec);
		char* str = NULL;
		while(str = MyParser.GetNextFile())
			flist.push_back(XString(str));

		counter = 0;
		beh->ActivateInput(1,TRUE);

		
	}


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

		if ( counter < flist.size() ){
			XString entry = flist.at(counter);
			CKParameterOut * pout = beh->GetOutputParameter(0);
			pout->SetStringValue(entry.Str() );
				
			counter++;
			beh->SetOutputParameterValue(1,&counter);
			beh->ActivateOutput(1);

		}else{

			beh->SetOutputParameterValue(1,&counter);
			counter = 0 ; 
			beh->ActivateOutput(0);
		}
	}
	return 0;
}
Esempio n. 7
0
 /*
 *******************************************************************
 * Function: BOOL CheckIO(CKBehavior* behaviour, CKBehavior* script)
 *
 * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching
 *
 * Parameters :
 *    behaviour		  Behavior 1, usually the BG wrapper BB.
 *    script	      Behavior 2, usually the wrapped BG.
 *
 * Returns : BOOL
 *
 *******************************************************************
 */
BOOL GBLCOBGWrapper::CheckIO(CKBehavior* behaviour, CKBehavior* script)
	{
	int		iParam;
	int		nbPin0, nbPin1;
	int		flag = 0;
	
	// Input
	nbPin0 = behaviour->GetInputCount();
	nbPin1 = script->GetInputCount();
	if (nbPin0 != nbPin1)
		return FALSE;

	// Ouput
	nbPin0 = behaviour->GetOutputCount();
	nbPin1 = script->GetOutputCount();
	if (nbPin0 != nbPin1)
		return FALSE;

	// Parameter In
	nbPin0 = behaviour->GetInputParameterCount();
	nbPin1 = script->GetInputParameterCount();
	if (nbPin0 != nbPin1)
		return FALSE;
	for (iParam = 0; iParam < nbPin0; iParam++)
		{
		CKParameterIn* pSin = script->GetInputParameter(iParam);
		CKParameterIn* pBin = behaviour->GetInputParameter(iParam);
		if (pSin == NULL || pBin == NULL)
			return FALSE;
		if (pSin->GetType() != pBin->GetType())
			return FALSE;
		}

	// Parameter Out
	nbPin0 = behaviour->GetOutputParameterCount();
	nbPin1 = script->GetOutputParameterCount();
	if (nbPin0 != nbPin1)
		return FALSE;
	for (iParam = 0; iParam < nbPin0; iParam++)
		{
		CKParameterOut* pSout = script->GetOutputParameter(iParam);
		CKParameterOut* pBout = behaviour->GetOutputParameter(iParam);
		if (pSout == NULL || pBout == NULL)
			return FALSE;
		if (pSout->GetType() != pBout->GetType())
			return FALSE;
		}

	return TRUE;
	}
Esempio n. 8
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;
}
Esempio n. 9
0
int DOOwnerChanged(const CKBehaviorContext& behcontext)
{
    CKBehavior* beh = behcontext.Behavior;
    CKMessageManager* mm = behcontext.MessageManager;
    CKContext* ctx = behcontext.Context;

    //////////////////////////////////////////////////////////////////////////
    //connection id :
    int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0);

    //////////////////////////////////////////////////////////////////////////
    //we come in by input 0 :
    if (beh->IsInputActive(0))
    {
        beh->ActivateOutput(0);
        beh->ActivateInput(0,FALSE);
    }

    if (beh->IsInputActive(1))
    {
        beh->ActivateOutput(1);
        beh->ActivateInput(1,FALSE);
        return 0;
    }

    //////////////////////////////////////////////////////////////////////////
    //the object :
    CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1);
    if (!obj)
    {
        beh->ActivateOutput(4);
        return CKBR_ACTIVATENEXTFRAME;
    }

    //////////////////////////////////////////////////////////////////////////
    //network ok  ?
    xNetInterface *cin  = GetNM()->GetClientNetInterface();
    if (!cin)
    {
        CKParameterOut *pout = beh->GetOutputParameter(1);
        XString errorMesg("distributed object creation failed,no network connection !");
        pout->SetStringValue(errorMesg.Str());
        beh->ActivateOutput(4);
        return CKBR_ACTIVATENEXTFRAME;
    }


    IDistributedObjects*doInterface  = cin->getDistObjectInterface();
    //////////////////////////////////////////////////////////////////////////
    //we come in by input 0 :
    xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID());
    if (!dobj)
    {
        CKParameterOut *pout = beh->GetOutputParameter(1);
        XString errorMesg("There is no such an object");
        pout->SetStringValue(errorMesg.Str());
        beh->ActivateOutput(4);
    } else
    {
        if (dobj->getOwnershipState().test(1 << E_DO_OS_RELEASED) && dobj->getOwnershipState().test( 1 << E_DO_OS_OWNERCHANGED) )
        {
            beh->ActivateOutput(3);
        }

        if (dobj->getOwnershipState().testStrict(1 << E_DO_OS_OWNERCHANGED))
        {
            dobj->getOwnershipState().set( 1<<E_DO_OS_OWNERCHANGED ,false );
            int newCLientID   = dobj->getUserID();
            beh->SetOutputParameterValue(0,&newCLientID);
            beh->ActivateOutput(2);
        }
    }
    return CKBR_ACTIVATENEXTFRAME;
}
Esempio n. 10
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;	
}
Esempio n. 11
0
int GBLCOCreateError::BehaviourFunction( const CKBehaviorContext& behContext )
{
	CKBehavior	*behaviour = behContext.Behavior;
	CKContext	*context = behContext.Context;

	if ( behaviour == NULL || context == NULL )
		return CKBR_GENERICERROR;

	behaviour->ActivateInput(ECGBLCOCreateErrorBehInputs::In, FALSE);

	CGBLCOErrorManager *errorManager = (CGBLCOErrorManager *)context->GetManagerByGuid(CGBLCOErrorManagerGUID);
	if ( errorManager == NULL )
		return CKBR_GENERICERROR;

	// Get Parameters Inputs Source.
	CKParameterOut *poutError = behaviour->GetOutputParameter(ECGBLCOCreateErrorParamOutputs::GetError);
	if ( poutError == NULL )
		return CKBR_GENERICERROR;
	
	CKParameterIn*pinCode = behaviour->GetInputParameter(ECGBLCOCreateErrorParamInputs::SetErrorCode);
	CKParameterIn*pinDesc = behaviour->GetInputParameter(ECGBLCOCreateErrorParamInputs::SetErrorDescription);
	CKParameterIn*pinType = behaviour->GetInputParameter(ECGBLCOCreateErrorParamInputs::SetErrorType);
	 
	if ( pinCode == NULL || pinDesc == NULL || pinType == NULL )
		return CKBR_GENERICERROR;
	
	CKParameter*paraCode = pinCode->GetRealSource();
	CKParameter*paraDesc = pinDesc->GetRealSource();
	CKParameter*paraType = pinType->GetRealSource();

	if ( paraCode == NULL || paraDesc == NULL || paraType == NULL )
		return CKBR_GENERICERROR;
	
	// Get Parameters Inputs Values (code,desc,type).
	int code = 0;
	paraCode->GetValue(&code);

	XString desc;
	int paramsize = paraDesc->GetStringValue(NULL);
	if (paramsize) 
	{
		XAP<char> paramstring(new char[paramsize]);
		paraDesc->GetStringValue(paramstring,TRUE);
		desc << (char*)paramstring;
	} 

	CGBLCOError::EGBLCOErrorType type;
	paraType->GetValue(&type);
	
	// Create the TGBLError parameter output.
	TGBLError::SetTGBLError(poutError,type,code,(CKSTRING)desc.CStr());
	CK_CLASSID cid = poutError->GetClassID();
	
	// 
	if ( type != CGBLCOError::EGBLCOErrorType::GBLCO_FATAL )
	{
		behaviour->ActivateOutput(ECGBLCOCreateErrorBehOutputs::OutHandled, FALSE);
		behaviour->ActivateOutput(ECGBLCOCreateErrorBehOutputs::OutUnhandled, TRUE);
		return CKBR_OK;
	}

	errorManager->NotifyError(type,code,(CKSTRING)desc.CStr());
	behaviour->ActivateOutput(ECGBLCOCreateErrorBehOutputs::OutHandled, TRUE);
	behaviour->ActivateOutput(ECGBLCOCreateErrorBehOutputs::OutUnhandled, FALSE);
  	
	return CKBR_OK;
}
Esempio n. 12
0
//************************************
// Method:    PBPhysicalize
// FullName:  PBPhysicalize
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PBPhysicalize(const CKBehaviorContext& behcontext)
{
	
	using namespace vtTools::BehaviorTools;
	using namespace vtTools;
	using namespace vtTools::AttributeTools;

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

	

	//////////////////////////////////////////////////////////////////////////
	//settings
	int useDWorld;	beh->GetLocalParameterValue(bbS_USE_DEFAULT_WORLD,&useDWorld);
//	int useWorldSS;	beh->GetLocalParameterValue(bbS_USE_WORLD_SLEEP_SETTINGS,&useWorldSS);
//	int useWorldDS;	beh->GetLocalParameterValue(bbS_USE_WORLD_DAMPING_SETTINGS,&useWorldDS);
	int useWorldM;	beh->GetLocalParameterValue(bbS_USE_WORLD_MATERIAL,&useWorldM);
	int addAttributes;	beh->GetLocalParameterValue(bbS_ADD_ATTRIBUTES,&addAttributes);


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

	

	//////////////////////////////////////////////////////////////////////////
	//the world  :  
	CK3dEntity*worldRef = NULL;
	if (!useDWorld)
	{
		worldRef = (CK3dEntity *) beh->GetInputParameterObject(bbI_TargetWorld);
	}

	// the world :  
	pWorld *world=GetPMan()->getWorld(worldRef,referenceObject); 
	if (!world)
	{
		beh->ActivateOutput(0);
		return 0;

	}

	pRigidBody*result = world->getBody(referenceObject);
	if (result)
	{
		beh->ActivateOutput(0);
		return 0;
	}


	//////////////////////////////////////////////////////////////////////////
	//pick up some parameters :  
	int flags  = GetInputParameterValue<int>(beh,bbI_Flags);
	int hType = GetInputParameterValue<int>(beh,bbI_HullType);
	float density  = GetInputParameterValue<float>(beh,bbI_Density);
	float skinWidth = GetInputParameterValue<float>(beh,bbI_SkinWidth);
	int hierarchy  = GetInputParameterValue<int>(beh,bbI_Hierachy);
	float newDensity = GetInputParameterValue<float>(beh,bbI_NewDensity);
	float totalMass = GetInputParameterValue<float>(beh,bbI_TotalMass);




	VxVector massOffset  = GetInputParameterValue<VxVector>(beh,bbI_MassShift);
	VxVector shapeOffset  = GetInputParameterValue<VxVector>(beh,bbI_ShapeShift);


	//////////////////////////////////////////////////////////////////////////
	// we remove the old physic attribute : 
	if (referenceObject->HasAttribute(GetPMan()->GetPAttribute()))
	{
		referenceObject->RemoveAttribute(GetPMan()->GetPAttribute());
	}
	referenceObject->SetAttribute(GetPMan()->GetPAttribute());
	
	SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_HIRARCHY,&hierarchy);
	SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_HULLTYPE,&hType);
	SetAttributeValue<int>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_BODY_FLAGS,&flags);
	SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_DENSITY,&density);
	SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_NEW_DENSITY,&newDensity);
	SetAttributeValue<float>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_TOTAL_MASS,&totalMass);
	SetAttributeValue<VxVector>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_MASS_OFFSET,&massOffset);
	//SetAttributeValue<VxVector>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_MASS_OFFSET,&massOffset);

	CK_ID wID  = world->getReference()->GetID();
	AttributeTools::SetAttributeValue<CK_ID>(referenceObject,GetPMan()->GetPAttribute(),E_PPS_WORLD,&wID);
	


	//////////////////////////////////////////////////////////////////////////
	//Material : 
	if (!useWorldM)
	{
		if (referenceObject->HasAttribute(GetPMan()->att_surface_props))
		{
			referenceObject->RemoveAttribute(GetPMan()->att_surface_props);
		}
		
		referenceObject->SetAttribute(GetPMan()->att_surface_props);

		CKParameterIn *pMatIn = beh->GetInputParameter(bbI_Material);
		CKParameter *pMat  = pMatIn->GetRealSource();
		CKParameterOut* pout = referenceObject->GetAttributeParameter(GetPMan()->att_surface_props);
		int error  = pout->CopyValue(pMat);
		pout->Update();
	}

	pRigidBody *body = pFactory::Instance()->createRigidBodyFull(referenceObject,worldRef);
	if (body)
	{
		body->translateLocalShapePosition(shapeOffset);
	}
	//GetPMan()->checkWorlds();

	if (!addAttributes)
	{
		referenceObject->RemoveAttribute(GetPMan()->GetPAttribute());
		referenceObject->RemoveAttribute(GetPMan()->att_surface_props);
	}

	beh->ActivateOutput(0);

	return 0;
}
Esempio n. 13
0
/*
 *******************************************************************
 * Function: int GetCIValue( 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.
 *
 * Parameters :
 *    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 GetCIValue(const CKBehaviorContext& behcontext)
{
	/************************************************************************/
	/*  collecting data :													*/
	/*  																	*/
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID);

	BOOL getByName,getAsString,outputAttriubtes,outputOnChange = false;
	beh->GetLocalParameterValue(BEH_SETTINGS_GET_BY_NAME,&getByName);
	beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString);
	beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes);
	beh->GetLocalParameterValue(BEH_SETTINGS_OUTPUT_ON_CHANGE,&outputOnChange);


	// Beh Input 1 activated : switch of on event mode /////////////////////////////////////////////////
	if( outputOnChange && beh->IsInputActive(1) )
	{
		beh->ActivateInput(1,FALSE);
		return CKBR_OK;
	}

	using namespace GBLCommon::BehaviorTools;
	using namespace Customisation::typedefs;

	Customisation::typedefs::CIS* currentCIS = cman->GetCIS();

	if( !currentCIS)
	{
		return CKBR_PARAMETERERROR;
	}
	
	CGBLCI *currentCI = NULL;
	
	//get  by uniquie name mode  ? 
	if( getByName )
	{
		CISIterator it = currentCIS->Find( new CGBLCIID (GetInputParameterValue<CKSTRING>(beh,0) , 0  ) );
		if (it  == currentCIS->End() )
		{
			return CKBR_PARAMETERERROR;
		}else
		{
			currentCI = *it;
		}
		//////// then get the custom parameter : 
	}else
	{
		CKParameter *ciPar = beh->GetInputParameter(0)->GetRealSource();
		currentCI = static_cast<CGBLCI *>(ciPar->GetAppData());
		if (!currentCI)
		{
			return CKBR_PARAMETERERROR;
		}
	}
	//////////////////////////////////////////////////////////////////////////
	// output values :
	CKParameterOut *pout = beh->GetOutputParameter(0);
	if(getAsString)
	{
		//output  the value 
		VxScratch sbuffer(currentCI->realValue->GetDataSize());
		CKSTRING buffer = (CKSTRING)sbuffer.Mem();
		currentCI->realValue->GetStringValue(buffer);
		pout->SetStringValue(buffer);
	}else
	{
		
		CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager());
		if ( beh->GetOutputParameter(0)->GetType() == currentCI->realValue->GetType() )
		{
			pout->CopyValue(currentCI->realValue);
		}else
		{
			pout->SetType(currentCI->realValue->GetType());
			return CKBR_PARAMETERERROR;
		}
	}

	using namespace GBLCommon::ParameterTools;
	
	//////////////////////////////////////////////////////////////////////////
	// output custom attributes :
	if(outputAttriubtes)
	{
		//output unique name : 
		CKParameterOut *poutName = beh->GetOutputParameter(BEH_OUT_INDEX_UNAME);
		poutName->SetStringValue(currentCI->name.Str());		
		//output description : 
		CKParameterOut *poutDescription = beh->GetOutputParameter(BEH_OUT_INDEX_DESCRIPTION);
		poutDescription->SetStringValue(currentCI->description.Str());

		//output default value : 
		CKParameterOut *poutDefaultValue = beh->GetOutputParameter(BEH_OUT_INDEX_DEFAULTVALUE);
		TypeCheckedParameterCopy(poutDefaultValue,currentCI->defaultValue);

		if(getAsString)
		{
			XString outDefValue  = GBLCommon::ParameterTools::GetParameterAsString(currentCI->defaultValue);
			poutDefaultValue->SetStringValue( outDefValue.Str() );
		}else{
			poutDefaultValue->CopyValue(currentCI->defaultValue,TRUE);
		}


		//output flags :
		int flags = 0 ;
		beh->SetOutputParameterValue(BEH_OUT_INDEX_FLAGS,&currentCI->flags);

		//output type 
		int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type);
		beh->SetOutputParameterValue(BEH_OUT_INDEX_TYPE,&type);

	}
	
	if (outputOnChange && (currentCI->ciState & CGBLCI::GBL_CI_STATE::GBL_CI_CHANGED) )
	{
		//reset state :
		currentCI->ciState = 0L;
		beh->ActivateOutput(0);
	}


	if (!outputOnChange)
	{
		beh->ActivateOutput(0);
	}

	return outputOnChange ?  CKBR_ACTIVATENEXTFRAME : CKBR_OK;

}
Esempio n. 14
0
int PMaterialIterator(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);

		//////////////////////////////////////////////////////////////////////////
		//we reset our session counter
		int sessionIndex=-1;
		beh->SetOutputParameterValue(0,&sessionIndex);


		LMaterials*sResults = NULL;
		beh->GetLocalParameterValue(0,&sResults);
		if (!sResults)
		{
			sResults = new LMaterials();
		}else
			sResults->clear();


		NxScene * scene = GetPMan()->getDefaultWorld()->getScene();
		for(int i = 0 ; i < GetPMan()->getDefaultWorld()->getScene()->getNbMaterials() ; i ++)
		{
		
			NxMaterial *currentMaterial = scene->getMaterialFromIndex(i);

			sResults->push_back(currentMaterial);
		}

		beh->SetLocalParameterValue(0,&sResults);



		if (sResults->size())
		{
			beh->ActivateInput(1);
		}else
		{
			beh->ActivateOutput(0);
			return 0;
		}
	}




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

		int currentIndex=0;	CKParameterOut *pout = beh->GetOutputParameter(0);		pout->GetValue(&currentIndex);
		currentIndex++;



		LMaterials *sResults = NULL;	beh->GetLocalParameterValue(0,&sResults);
		if (!sResults)		{			beh->ActivateOutput(0);			return 0;		}

		if (currentIndex>=sResults->size())
		{
			sResults->clear();
			beh->ActivateOutput(0);
			return 0;
		}

		NxMaterial * material =  sResults->at(currentIndex);
		if (material!=NULL)
		{

			int sIndex = currentIndex+1;
			beh->SetOutputParameterValue(0,&sIndex);

			

					
			//SetOutputParameterValue<int>(beh,O_XML,material->xmlLinkID);
			SetOutputParameterValue<float>(beh,O_DFRICTION,material->getDynamicFriction());
			SetOutputParameterValue<float>(beh,O_SFRICTION,material->getStaticFriction());

			SetOutputParameterValue<float>(beh,O_RES,material->getRestitution());

			SetOutputParameterValue<float>(beh,O_DFRICTIONV,material->getDynamicFrictionV());
			SetOutputParameterValue<float>(beh,O_SFRICTIONV,material->getStaticFrictionV());

			SetOutputParameterValue<VxVector>(beh,O_ANIS,getFrom(material->getDirOfAnisotropy()));
			SetOutputParameterValue<int>(beh,O_FCMODE,material->getFrictionCombineMode());
			SetOutputParameterValue<int>(beh,O_RCMODE,material->getFrictionCombineMode());
			SetOutputParameterValue<int>(beh,O_FLAGS,material->getFlags());
		}

		if(material->userData )
		{
			pMaterial *bMaterial  = static_cast<pMaterial*>(material->userData);

			if (bMaterial && bMaterial->xmlLinkID )
			{
			
				int xid = bMaterial->xmlLinkID;
				XString nodeName = vtAgeia::getEnumDescription(GetPMan()->GetContext()->GetParameterManager(),VTE_XML_MATERIAL_TYPE,xid);
				CKParameterOut *nameStr = beh->GetOutputParameter(O_NAME);
				nameStr->SetStringValue(nodeName.Str());
			}
		}
		//pFactory::Instance()->copyTo(beh->GetOutputParameter(O_MATERIAL),material);


		beh->ActivateOutput(0);
	}
	return 0;
}
Esempio n. 15
0
int DOUserValueModified(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKMessageManager* mm = behcontext.MessageManager;
	CKContext* ctx = behcontext.Context;

	//////////////////////////////////////////////////////////////////////////
	//connection id : 
	int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0);





	if (beh->IsInputActive(1))
	{
		beh->ActivateInput(1,FALSE);
		beh->ActivateOutput(1);
		return 0;
	}



	//////////////////////////////////////////////////////////////////////////
	//the object :
	CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1);
	if (!obj)
	{
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	//////////////////////////////////////////////////////////////////////////
	//network ok  ? 
	xNetInterface *cin  = GetNM()->GetClientNetInterface();
	if (!cin)
	{
		CKParameterOut *pout = beh->GetOutputParameter(2);
		XString errorMesg("distributed object creation failed,no network connection !");
		pout->SetStringValue(errorMesg.Str());
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	//use objects name, if not specified : 
	CKSTRING name= obj->GetName();
	
	IDistributedObjects*doInterface  = cin->getDistObjectInterface();
	IDistributedClasses*cInterface = cin->getDistributedClassInterface();
    
	XString className((CKSTRING) beh->GetLocalParameterReadDataPtr(0));
	XString parameterName((CKSTRING) beh->GetLocalParameterReadDataPtr(1));

	xDistributedClass *_class = cInterface->get(className.CStr());
	
	
	//////////////////////////////////////////////////////////////////////////
	//dist class ok  ? 
	if (_class==NULL)
	{
		beh->ActivateOutput(3);
		ctx->OutputToConsoleEx("Distributed Class doesn't exists : %s",className.CStr());
		return CKBR_ACTIVATENEXTFRAME;
	}
	const char * cNAme  = _class->getClassName().getString();

	int classType  = _class->getEnitityType();
	int bcount = beh->GetInputParameterCount();

	//////////////////////////////////////////////////////////////////////////
	//we come in by input 0 : 

	

	xDistributedObject *dobjDummy = NULL;
	xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID());
	if (!dobj)
	{
		beh->ActivateOutput(3);
		return CKBR_ACTIVATENEXTFRAME;
	}

	if (dobj)
	{
		xDistributedProperty * prop  = dobj->getUserProperty(parameterName.CStr());
		if (prop)
		{
			if ( dobj->getGhostUpdateBits().testStrict(1 << prop->getBlockIndex()))
			{
				CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager());
				CKParameterOut *ciIn = beh->GetOutputParameter(1);
				CKParameterType pType  = ciIn->GetType();

				int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType));	
				int userType = xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType);
				if ( userType ==sType )
				{
					beh->ActivateOutput(2);
					dobj->getGhostUpdateBits().set(1 << prop->getBlockIndex(),false);
					switch(xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType))
					{
						case vtFLOAT:
						{
							xDistributedPoint1F *propValue  = static_cast<xDistributedPoint1F*>(prop);
							if (propValue)
							{
								float ovalue = propValue->mLastServerValue;
								beh->SetOutputParameterValue(1,&ovalue);
								break;
							}
						}

						case vtVECTOR2D:
						{
							xDistributedPoint2F *propValue  = static_cast<xDistributedPoint2F*>(prop);
							if (propValue)
							{
								Point2F ovalue = propValue->mLastServerValue;
								Vx2DVector ovaluex(ovalue.x,ovalue.y);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtVECTOR:
						{
							xDistributedPoint3F *propValue  = static_cast<xDistributedPoint3F*>(prop);
							if (propValue)
							{
								Point3F ovalue = propValue->mLastServerValue;
								VxVector ovaluex(ovalue.x,ovalue.y,ovalue.z);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtQUATERNION:
						{
							xDistributedQuatF*propValue  = static_cast<xDistributedQuatF*>(prop);
							if (propValue)
							{
								QuatF ovalue = propValue->mLastServerValue;
								VxQuaternion ovaluex(ovalue.x,ovalue.y,ovalue.z,ovalue.w);
								beh->SetOutputParameterValue(1,&ovaluex);
								break;
							}
						}
						case vtSTRING:
						{
							xDistributedString*propValue  = static_cast<xDistributedString*>(prop);
							if (propValue)
							{
								TNL::StringPtr ovalue = propValue->mCurrentValue;
								CKParameterOut *pout = beh->GetOutputParameter(1);
								XString errorMesg(ovalue.getString());
								pout->SetStringValue(errorMesg.Str());
								break;
							}
						}
						case vtINTEGER:
						{
							xDistributedInteger*propValue  = static_cast<xDistributedInteger*>(prop);
							if (propValue)
							{
								int ovalue = propValue->mLastServerValue;
								beh->SetOutputParameterValue(1,&ovalue);
								break;
							}
						}
					}
				}
			}
		}
	}

	return CKBR_ACTIVATENEXTFRAME;
	if (beh->IsInputActive(0))
	{
		beh->ActivateOutput(0);
	}



	/*
	//////////////////////////////////////////////////////////////////////////
	//we come in by input 0 : 
	if (beh->IsInputActive(0))
	{
		beh->ActivateOutput(0);

	
		for (int i = BEH_IN_INDEX_MIN_COUNT  ; i < beh->GetInputParameterCount() ; i++ )
		{
			beh->ActivateInput(0,FALSE);

			xDistributedObject *dobj = doInterface->get(name);
			if (!dobj)
			{
				beh->ActivateOutput(0);
				return 0;
			}

			CKParameterIn *ciIn = beh->GetInputParameter(i);
			CKParameterType pType  = ciIn->GetType();
			int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType));	
			xDistributedPropertyArrayType &props = *dobj->getDistributedPorperties();
			
			int propID = _class->getInternalUserFieldIndex(i - BEH_IN_INDEX_MIN_COUNT);
			if (propID==-1 ||  propID > props.size() )
			{
				beh->ActivateOutput(1);
				return 0;
			}
			
			xDistributedProperty *prop  = props[propID];
			if (prop)
			{
				xDistributedPropertyInfo*propInfo  = prop->getPropertyInfo();
				if (propInfo)
				{
					
					if (xDistTools::ValueTypeToSuperType(propInfo->mValueType) ==sType )
					{
						TNL::U32 currentTime = TNL::Platform::getRealMilliseconds();

						switch(propInfo->mValueType)
						{
							case E_DC_PTYPE_3DVECTOR:
							{

								xDistributedPoint3F * dpoint3F  = (xDistributedPoint3F*)prop;
								if (dpoint3F)
								{
									VxVector vvalue;
									beh->GetInputParameterValue(i,&vvalue);
									bool update = dpoint3F->updateValue(xMath::getFrom(vvalue),currentTime);
								}
                                break;
							}

							case E_DC_PTYPE_FLOAT:
								{

									xDistributedPoint1F * dpoint3F  = (xDistributedPoint1F*)prop;
									if (dpoint3F)
									{
										float vvalue;
										beh->GetInputParameterValue(i,&vvalue);
										bool update = dpoint3F->updateValue(vvalue,currentTime);
									}
									break;
								}
						}
					}
				}
			}
		}
			
		beh->ActivateOutput(0);
	}

	
	*/
	//////////////////////////////////////////////////////////////////////////
	//we come in by loop : 
	return 0;
}
Esempio n. 16
0
/*
 *******************************************************************
 * Function: int CISIteratorBB( 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.
 *
 * Parameters :
 *    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 CISIteratorBB(const CKBehaviorContext& behcontext)
{
	
	/************************************************************************/
	/* collecting data :													*/
	/*  																	*/
	
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID);
	

    	
	/*get the last index */
	int index = 0;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX, &index);

	BOOL getFromDB = false;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB);
    
	using namespace GBLCommon::BehaviorTools;
	using namespace GBLCommon::ParameterTools;

	using namespace Customisation::typedefs;


	/************************************************************************/
	/*   behavior trigger event processing  :							    */
	/*																		*/
	/*																		*/
    


	/* Reset/On : sets the index to zero and save it  */
	if( beh->IsInputActive(0) )
	{
		beh->ActivateInput(0,FALSE);
		

		if (getFromDB)
		{
			CKDataArray * resultArray = NULL; 
			beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray);
			if (resultArray)
			{
				resultArray->Clear();
				while ( resultArray->GetColumnCount() )
					resultArray->RemoveColumn(0);
			}
			else
			{
				resultArray  = static_cast<CKDataArray*>(ctx->CreateObject( CKCID_DATAARRAY, "IGBLSMConfigurationAccess::CIS_IDLIST", CK_OBJECTCREATION_DYNAMIC ));
			}
			ctx->GetCurrentLevel()->AddObject( resultArray );
			
			////////////////////////////////////////////////////////////////////////// retrieve list of CI ID's  :
			CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
			IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();

			int idCIS = GetInputParameterValue<int>(beh,BEH_IN_PAR_CIS_ID);
			smCIS->RetrieveCIList(resultArray,CGBLCISID(idCIS));
			
			beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray,sizeof(CKDataArray*));
			
			int cis_size = resultArray->GetRowCount();
			beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cis_size);
		}else
		{
			Customisation::typedefs::CIS* currentCIS = cman->GetCIS();
			if(!currentCIS)
				Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CIS");	

		}
		//reset counter : 
		index = 0 ;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateInput(1,TRUE);
	}

	//get LA_ID :

	
	
	int cisSize;
	beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cisSize);
	    

	/* bounding check for the index: if out of range, set to zero and save it.*/ 
	if(index > cisSize -1  )
	{
		index = 0;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateOutput(0);
		return CKBR_OK;
	}


	/* Loop In :  */
	if( beh->IsInputActive(1)  ) 
	{ 
		 beh->ActivateInput(1,FALSE);


		 CGBLCI *currentCI = NULL;
		 //ctx->OutputToConsole("asfasdf");

		 if (getFromDB)
		 {
			 CKDataArray * resultArray = NULL;
			 beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray);
			 if (resultArray)
			 {
				 CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
				 IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();

				 CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID));
				 IGBLCIAccessInterface * accessInterface  = cman->GetCISAccessInterface(); 
				 
				 currentCI = new CGBLCI("temp",CKPGUID_INT);
                 
				 int idCI;
				 resultArray->GetElementValue(index,0,&idCI);
				 accessInterface->GetCI(currentCI,idCI);
				 beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_DB_INDEX,&idCI);

			 }else
			 {
				 ctx->OutputToConsole("wrong array");
			 }
		 }else
		 {
			 Customisation::typedefs::CISIterator it = cman->GetCIS()->GetIteratorByIndex(index);
			 currentCI = (CGBLCI *)*it;
		 }
        if (currentCI)
        {
			//output name : 
			CKParameterOut *outName = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_UNAME);
			outName->SetStringValue(currentCI->name.Str());
			
			//output description:
			CKParameterOut *outDescr = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DESCRIPTION);
			outDescr->SetStringValue(currentCI->description.Str());
			
			//output type 
			int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type);
			beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_TYPE,&type);
			
			//output  value: 
			CKParameterOut *outStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_VALUE);
			outStrValue->SetStringValue(GetParameterAsString(currentCI->realValue));

			//output default value: 
			CKParameterOut *outDefaultStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DEFAULTVALUE);
			outDefaultStrValue->SetStringValue(GetParameterAsString(currentCI->defaultValue));
                            
			//output flags : 
			beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_FLAGS,&currentCI->flags);

		}else
		{            
			Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CI Parameter");	
		}

		//increase counter :
		index++;
		beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index);
		beh->ActivateOutput(1);
	}
	return CKBR_OK;
}
Esempio n. 17
0
int pFactory::copyTo(pWheelDescr *dst,CKParameter *src)
{

	int result  = 1;
	if (!src || !dst)
	{
		return NULL;
	}

	using namespace vtTools::ParameterTools;
	dst->setToDefault();


	dst->wheelSuspension = GetValueFromParameterStruct<float>(src,E_WD_SUSPENSION);
	dst->springRestitution= GetValueFromParameterStruct<float>(src,E_WD_SPRING_RES);
	dst->springBias = GetValueFromParameterStruct<float>(src,E_WD_SPRING_BIAS);
	dst->springDamping= GetValueFromParameterStruct<float>(src,E_WD_DAMP);

	dst->maxBrakeForce= GetValueFromParameterStruct<float>(src,E_WD_MAX_BFORCE);
	dst->frictionToSide= GetValueFromParameterStruct<float>(src,E_WD_FSIDE);
	dst->frictionToFront= GetValueFromParameterStruct<float>(src,E_WD_FFRONT);
	
	CKParameterOut *pOld  = GetParameterFromStruct(src,E_WD_INVERSE_WHEEL_MASS);
	if (pOld)
	{
		if (pOld->GetGUID()  == CKPGUID_FLOAT)
		{
			dst->inverseWheelMass= GetValueFromParameterStruct<float>(src,E_WD_INVERSE_WHEEL_MASS);
		}

		if (pOld->GetGUID()  == CKPGUID_INT)
		{
			dst->wheelApproximation= GetValueFromParameterStruct<int>(src,E_WD_INVERSE_WHEEL_MASS);
		}
	}

	//dst->wheelApproximation= GetValueFromParameterStruct<int>(float,E_WD_INVERSE_WHEEL_MASS);

	dst->wheelFlags= (WheelFlags)GetValueFromParameterStruct<int>(src,E_WD_FLAGS);
	dst->wheelShapeFlags=(WheelShapeFlags) GetValueFromParameterStruct<int>(src,E_WD_SFLAGS);


	CKParameterOut *parLatFunc = GetParameterFromStruct(src,E_WD_LAT_FUNC);
	CKParameterOut *parLongFunc = GetParameterFromStruct(src,E_WD_LONG_FUNC);



	/************************************************************************/
	/* XML Setup ?                                                                     */
	/************************************************************************/
	int xmlLinkId= GetValueFromParameterStruct<int>(src,E_WD_XML);
	bool wIsXML=false;
	bool latIsXML= false;
	bool longIsXML=false;

	XString nodeName;
	if ( xmlLinkId !=0 )
	{
		nodeName = vtAgeia::getEnumDescription(GetPMan()->GetContext()->GetParameterManager(),VTE_XML_WHEEL_SETTINGS,xmlLinkId);
		loadWheelDescrFromXML(*dst,nodeName.CStr(),getDefaultDocument());
		wIsXML =true;
		if (!dst->isValid())
		{
			xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"Wheel Description was invalid");
		}


		if (dst->latFunc.xmlLink!=0)
		{
			latIsXML=true;
		}

		if (dst->longFunc.xmlLink!=0)
		{
			longIsXML=true;
		}
	}



	if (!latIsXML)
	{
		dst->latFunc = createTireFuncFromParameter(parLatFunc);
	}


	if (!longIsXML)
	{
		dst->longFunc= createTireFuncFromParameter(parLongFunc);
	}

	if (wIsXML)
	{
		copyTo((CKParameterOut*)src,dst);
	}

	
	if (longIsXML)
	{
		copyTo(GetParameterFromStruct(src,E_WD_LONG_FUNC),dst->longFunc);
	}

	if (latIsXML)
	{
		copyTo(GetParameterFromStruct(src,E_WD_LAT_FUNC),dst->latFunc);
	}
	
	return result;
}
Esempio n. 18
0
int LogEntry(const CKBehaviorContext& behcontext)
{

	CKBehavior* beh = behcontext.Behavior;
	CKMessageManager* mm = behcontext.MessageManager;
	CKContext* ctx = behcontext.Context;
	CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager());


	XString File((CKSTRING) beh->GetInputParameterReadDataPtr(0));
	

	if (GetPMan()->GetLastLogEntry().Length())
	{
			CKParameterOut *pout  = beh->GetOutputParameter(0);
			pout->SetStringValue(GetPMan()->GetLastLogEntry().Str());
			GetPMan()->SetLastLogEntry("");


			vtTools::BehaviorTools::SetOutputParameterValue<int>(beh,1,xLogger::GetInstance()->lastTyp);
			int descriptionS = xLogger::GetInstance()->getItemDescriptions().size();

			int compo  = xLogger::GetInstance()->lastComponent;
			
			XString compoStr;
			/*if(compo<= xLogger::GetInstance()->getItemDescriptions().size() )
				compoStr.Format("%s",xLogger::GetInstance()->getItemDescriptions().at(compo));*/



			beh->ActivateOutput(0,TRUE);
			switch (xLogger::GetInstance()->lastTyp)
			{

			case ELOGERROR:
				beh->ActivateOutput(1,TRUE);

				case ELOGWARNING:
					beh->ActivateOutput(2,TRUE);
				
				case ELOGINFO:
					beh->ActivateOutput(3,TRUE);
				
				case ELOGTRACE:
					beh->ActivateOutput(4,TRUE);

				case ELOGDEBUG:
					beh->ActivateOutput(5,TRUE);
				default:
					beh->ActivateOutput(0,TRUE);

			}

		
			
	}


	//	Steering	
	if( beh->IsInputActive(1) )
	{
		beh->ActivateOutput(0,FALSE);

		return 1;
	}
	return CKBR_ACTIVATENEXTFRAME;
}
/*
 *******************************************************************
 * Function: int DecodeAndSendCommand (XString commandString, char separator, const CKBehaviorContext& behaviorContext)
 *
 * Description :    Decodes the string message passed in into the separate parameters for the command and 
 *                  sets the output parameter valuess of the corresponding GBLWaitForCommand BB.
 *		
 * Paramters :
 *
 *    commandString     r   command string
 *    separator         r   parameter separator
 *    behaviorContext   r   behavior context    
 *
 * Returns : 
 *              0 on success, otherwise error
 *
 *******************************************************************
 */
int CGBLCommandController::InvokeCommand (XString commandString, const CKBehaviorContext& behaviorContext)
{
	int returnValue = 0; // 0 indicates success
	int separatorPos = 0; //position for string separator
	char separator = CGBLCommandController::commandSeparator;

	if (strlen (commandString.Str()) <=0)
	{
		returnValue = -1;
	}
    else
    {
	    separatorPos = commandString.Find(separator, separatorPos);
    	
	    int commandID = atoi ( (commandString.Substring (0, separatorPos)).Str() );

	    CKBehavior* targetBB = CGBLCommandController::GetTargetCommand (commandID, behaviorContext);

	    if (targetBB == NULL )
	    {
		    returnValue = -1;
	    }
		else if (! (targetBB->IsInputActive(0)) )
		{
			returnValue = -1;
		}
		else
        {
	        int argumentCount = targetBB->GetOutputParameterCount();

			int separatorCount = 0;
			for (unsigned int k=0; k < strlen (commandString.Str()); k++)
			{
				if (commandString.Str()[k] == separator)
				{
					separatorCount++;
				}
			}

			if ( separatorCount != (argumentCount + 1 ) )
			{
				returnValue = -1;
			}
			else
			{
				int prevPos = separatorPos+1;

				for(int i = 0; i < argumentCount ; i++)
				{
					separatorPos = commandString.Find(separator, prevPos);
					if (separatorPos == prevPos)
					{
						CKParameterOut* targetParam = targetBB->GetOutputParameter(i);
						targetParam->SetStringValue ("");
					}
					else
					{
						XString insert = (commandString.Substring (prevPos, separatorPos-prevPos)).Str();
						CKParameterOut* targetParam = targetBB->GetOutputParameter(i);
						targetParam->SetStringValue (insert.Str());
					}
					prevPos = separatorPos+1;
				}
				targetBB->ActivateOutput(0);
			}
        }
    }

    return returnValue;
}
Esempio n. 20
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.
 *
 * Parameters :
 *    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 RetrieveCI(const CKBehaviorContext& behcontext)
{
	/************************************************************************/
	/*  collecting data :													*/
	/*  																	*/
	CKBehavior* beh = behcontext.Behavior;
  	CKContext* ctx = behcontext.Context;
	CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID);
	IGBLCIManageInterface *cisFac   =  cman->GetCISFactoryInterface();
	IGBLCIAccessInterface * accessInterface  = cman->GetCISAccessInterface(); 

	

	BOOL getAsString,outputAttriubtes = false;
	beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString);
	beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes);

	using namespace GBLCommon::BehaviorTools;
	using namespace GBLCommon::ParameterTools;
	using namespace Customisation::typedefs;

	int idCI = GetInputParameterValue<int>(beh,BEH_PAR_INDEX_CI);

	CGBLCI *currentCI = NULL;

	CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID));
	IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface();

	
	currentCI = new CGBLCI("temp",CKPGUID_INT);
	
	CGBLCOError returnValue  = 	accessInterface->GetCI(currentCI,idCI);

	//get error parameter
	CKParameterOut *parameterOutError = beh->GetOutputParameter(BEH_PIN_OUT_INDEX_ERROR);
	// check results and output error
	if (returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
	{
		//////////////////////////////////////////////////////////////////////////
		// output values :
		CKParameterOut *pout = beh->GetOutputParameter(1);
		if(getAsString)
		{
			//output  the value 
			VxScratch sbuffer(currentCI->realValue->GetDataSize());
			CKSTRING buffer = (CKSTRING)sbuffer.Mem();
			currentCI->realValue->GetStringValue(buffer);
			pout->SetStringValue(buffer);
		}else
		{

			CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager());
			if ( beh->GetOutputParameter(0)->GetType() == currentCI->realValue->GetType() )
			{
				pout->CopyValue(currentCI->realValue);
			}else
			{
				pout->SetType(currentCI->realValue->GetType());
				return CKBR_PARAMETERERROR;
			}
		}



		//////////////////////////////////////////////////////////////////////////
		// output custom attributes :
		if(outputAttriubtes)
		{
			//output unique name : 
			CKParameterOut *poutName = beh->GetOutputParameter(BEH_OUT_INDEX_UNAME);
			poutName->SetStringValue(currentCI->name.Str());		
			//output description : 
			CKParameterOut *poutDescription = beh->GetOutputParameter(BEH_OUT_INDEX_DESCRIPTION);
			poutDescription->SetStringValue(currentCI->description.Str());

			//output default value : 
			CKParameterOut *poutDefaultValue = beh->GetOutputParameter(BEH_OUT_INDEX_DEFAULTVALUE);
			TypeCheckedParameterCopy(poutDefaultValue,currentCI->defaultValue);

			if(getAsString)
			{
				XString outDefValue  = GBLCommon::ParameterTools::GetParameterAsString(currentCI->defaultValue);
				poutDefaultValue->SetStringValue( outDefValue.Str() );
			}else{
				poutDefaultValue->CopyValue(currentCI->defaultValue,TRUE);
			}

			//output flags :
			int flags = 0 ;
			beh->SetOutputParameterValue(BEH_OUT_INDEX_FLAGS,&currentCI->flags);

			//output type 
			int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type);
			beh->SetOutputParameterValue(BEH_OUT_INDEX_TYPE,&type);

		}
		TGBLError::SetTGBLError(parameterOutError,returnValue.GetType(),returnValue.GetCode(),(CKSTRING)returnValue.GetDescription());
		beh->ActivateOutput(BEH_PIN_OUT_INDEX_SUCCESS, true);
	}
	else
	{

		CGBLCOError::EGBLCOErrorType tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
		switch((CGBLCOError::EGBLCOErrorType)returnValue)
		{
		case 0:
			tType = CGBLCOError::EGBLCOErrorType::GBLCO_OK;
			break;
		case 1:
			tType = CGBLCOError::EGBLCOErrorType::GBLCO_FATAL;
			break;
		case 2:
			tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
			break;
		case 3:
			tType = CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL;
			break;
		}
		TGBLError::SetTGBLError(parameterOutError,tType,returnValue.GetCode(),(CKSTRING)returnValue.GetDescription());
		beh->ActivateOutput(BEH_PIN_OUT_INDEX_ERROR, true);
	}
	return CKBR_OK;

}