Exemple #1
0
CKERROR CallPythonFuncCB2(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);
			
			int p_count  =  beh->GetOutputParameterCount();

			/*while(   (BEH_OUT_MIN_COUNT )   < p_count )
			{ 
				CKDestroyObject( beh->RemoveOutputParameter( --p_count) );
			}*/
			
			XString name("PyFuncX: ");
			name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1));
			if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0)
			{
				XString name("PyFileX: ");
				name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0));
				beh->SetName(name.Str());
				break;
			}
			beh->SetName(name.Str());
			break;
		}
		case CKM_BEHAVIORATTACH:
		case CKM_BEHAVIORLOAD : 
		{
			XString name("PyFuncX: ");
			name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1));
			beh->SetName(name.Str());
			if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0)
			{
				XString name("PyFileX: ");
				name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0));
				beh->SetName(name.Str());
				break;
			}
		}
	}
	return CKBR_OK;
}
/*
*******************************************************************
* 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;
}
Exemple #3
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;
}
/*
 *******************************************************************
 * 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;
}
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;	
}
Exemple #6
0
/*
*******************************************************************
* Function: int GetCIValueCB( 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 GetCIValueCB(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 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);


			//////////////////////////////////////////////////////////////////////////
			//we add beh - in - trigger, if we are in event mode:
			if (outputOnChange)
			{
				beh->AddInput("Stop");

				//change to correct name :
			 	CKBehaviorIO * out_trigger = beh->GetOutput(0);
				out_trigger->SetName("Change detected");
			}else
			{
				//change to correct name :
				CKBehaviorIO * out_trigger = beh->GetOutput(0);
				out_trigger->SetName("Finish");
			}
              

			//remove unecessary beh - input triggers from even-mode :  
			int count = beh->GetInputCount();

			while(  (outputOnChange ? BEH_IN_TRIGGER_MAX_COUNT  : BEH_IN_TRIGGER_MIN_COUNT )  <= count ) 
						beh->DeleteInput( count-- );

			CKParameterIn *ciIn = beh->GetInputParameter(0);
			if( getByName )
			{
				ciIn->SetType(pm->ParameterGuidToType(CKPGUID_STRING));
				ciIn->SetName("unique name of the configurable information");
			}else
			{
				ciIn->SetType(pm->ParameterGuidToType(CIPARAMETERGUID));
				ciIn->SetName("Configurable Information");
			}
			
			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;
}