예제 #1
0
/*
 *******************************************************************
 * Function: CKERROR BGWrapperCB(const CKBehaviorContext& behContext)
 *
 * Description : The Behavior Callback function is called by Virtools 
 *               when various events happen in the life of a BuildingBlock.
 *
 * Parameters :
 *    behaviourContext	      Behavior context reference, which gives access to 
 *                            frequently used global objects ( context, level, manager, etc... )
 *
 * Returns : CKERROR
 *
 *******************************************************************
 */
CKERROR GBLCOBGWrapper::BGWrapperCB(const CKBehaviorContext& behContext)
{
	CKERROR	result = CKBR_GENERICERROR; 

	// Initialize common pointers.	
	CKBehavior *behaviour   = behContext.Behavior;
	CKContext  *context   = behContext.Context;
	CKLevel    *level = behContext.CurrentLevel;
	CKBeObject *owner = behContext.Behavior->GetOwner();
	
	char*name = behaviour->GetName();
	
	if ( behaviour == NULL || context == NULL || level == NULL /*|| owner == NULL*/ )
		return CKBR_OK;
	
	//Get The BG Script Object if exists
	CKBehavior* newBG = NULL;
	CKBehavior* curBG = (CKBehavior*)behaviour->GetLocalParameterObject(EGBLCOBGWRAPPERPARAM_PARAMETER_SCRIPT);

	// Get the BG nms file path. GetStringValue doesn't work with setting...
	char fileName[_MAX_PATH+1];
	memset(fileName,0,_MAX_PATH+1);
	CKParameter* scriptPath  = behaviour->GetLocalParameter(EGBLCOBGWRAPPERPARAM_PARAMETER_NAME);
	if ( scriptPath == NULL )
		return CKBR_OK;
	
	int lenPath  = scriptPath->GetDataSize();
	if ( lenPath >= _MAX_PATH )
		return CKBR_OK;
	
	void*ptrPath = scriptPath->GetReadDataPtr(TRUE);
	if ( ptrPath == NULL )
		return CKBR_OK;
	
	memcpy(fileName,ptrPath,lenPath);

	CKDWORD message = behContext.CallbackMessage;

	switch (message)
		{
		case CKM_BEHAVIORLOAD :				// when the behavior is loaded
		case CKM_BEHAVIORRESET:				// when the behavior is reseted
		case CKM_BEHAVIORSETTINGSEDITED :	// when the settings are edited
			{
				if ( curBG != NULL )
				{
					DestroyCurrentBG(level,behaviour,curBG);
					curBG = NULL;
				}

				newBG = BGLoader( fileName, behContext );
				if ( newBG == NULL )
					return CKBR_OK;
				
				if ( message == CKM_BEHAVIORLOAD || message == CKM_BEHAVIORRESET )
				{
					//context->OutputToConsoleExBeep("%s : LOADED %s",behaviour->GetName(), fileName);
					if ( CheckIO(behaviour, newBG) == TRUE )
						result = CKBR_OK;
					else	
						context->OutputToConsoleExBeep("%s : Too many inputs/outputs changes in %s\r\nPlease reconstruct the wrapper.",behaviour->GetName(), fileName);
				}
				else if ( message == CKM_BEHAVIORSETTINGSEDITED )
				{
					if ( CheckIO(behaviour, newBG) == TRUE )
					{					
						result = CKBR_OK;
					}
					else if (DeleteIO(behaviour) == TRUE)
					{
						if ( CreateIO(behaviour, newBG ) == TRUE )
							result = CKBR_OK;
						else	
							context->OutputToConsoleExBeep("%s : Cannot Create Inputs/Outputs %s",behaviour->GetName(), fileName);
					}
					else
						context->OutputToConsoleExBeep("%s : Cannot Delete Inputs/Outputs %s",behaviour->GetName(), fileName);
				}

				if ( result == CKBR_OK && newBG != NULL )
					SetNewBG(behaviour,newBG);
			}
			break;
	
		case CKM_BEHAVIORDEACTIVATESCRIPT:
			{
				if ( curBG != NULL )
					DesactivateSubBB(curBG);
				result = CKBR_OK;
			}
			break;
		
		case CKM_BEHAVIORDETACH : // when the behavior is deleted
			{
				if (curBG != NULL)
				{
					DestroyCurrentBG(level,behaviour,curBG);
					curBG = NULL;
				}
				result = CKBR_OK;
			}
			break;				
		
		default: 
			{
				result = CKBR_OK;
			}
			break;

		}
		
	if (result != CKBR_OK)
		context->OutputToConsoleExBeep("%s : Problem while manipulating",behaviour->GetName());



	return result;
	}
예제 #2
0
//************************************
// Method:    vt_ActivateOut
// FullName:  vt_ActivateOut
// Access:    public static 
// Returns:   PyObject *
// Qualifier:
// Parameter: PyObject * self
// Parameter: PyObject * args
//************************************
static PyObject *vt_ActivateOut( PyObject * self, PyObject * args )
{
	int size = PyTuple_Size(args);
	int bid, index, value;
	PyArg_ParseTuple(args, "iii", &bid, &index, &value); 

    CK_ID cid = bid; 
	CKBehavior *beh = static_cast<CKBehavior*>(pym->m_Context->GetObject(cid)); 
	if (size!=3)
	{
		
		pym->m_Context->OutputToConsoleEx("PyError:%s : This function only accepts 3 arguments : \n\t bid,index,value ",beh->GetName());
		Py_RETURN_NONE;
	}

	if(beh && index < beh->GetOutputCount())
	{
		beh->ActivateOutput(index,value);
	}
    		

	Py_RETURN_NONE;

}
예제 #3
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;	
}
예제 #4
0
int CallPythonFunc2(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;


	XString File((CKSTRING) beh->GetInputParameterReadDataPtr(0));
	XString Func((CKSTRING) beh->GetInputParameterReadDataPtr(1));
	int reload=false;  //= BehaviorTools::GetInputParameterValue<bool>(beh,2);
	
	beh->GetInputParameterValue(2,&reload);

	vt_python_man *pm = (vt_python_man*)ctx->GetManagerByGuid(INIT_MAN_GUID);
	CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager());

	Python *py = pm->py;
    
	if (!pm->pLoaded)
	{
		pm->m_Context->OutputToConsoleEx("You must load Python before !");
		beh->ActivateOutput(1,false);
		return CKBR_BEHAVIORERROR;

	}


	//////////////////////////////////////////////////////////////////////////
	if( beh->IsInputActive(0) )
	{
		try 
		{
			PyObject *module = pm->InsertPModule(beh->GetID(),File,reload);
			PyObject* val = PyInt_FromLong(beh->GetID());
			PyObject_SetAttrString( module , "bid", val);
            pm->CallPyModule(beh->GetID(),Func);
		
		}
		catch (Python_exception ex)
		{
			pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what());
			std::cout << ex.what() << "pyexeption in beh : " << beh->GetName();
			PyErr_Clear();
			beh->ActivateOutput(1,false);
		}
		beh->ActivateInput(0,false);

	}
	//////////////////////////////////////////////////////////////////////////
	else
	{
		for (int i  = 1 ; i < beh->GetOutputCount() ; i++ )
		{
			
			try 
			{
				PyObject *module = pm->GetPModule(beh->GetID());
				if(module)
					pm->CallPyModule(beh->GetID(),Func);
			}
			catch (Python_exception ex)
			{
				pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what());
				std::cout << ex.what() << "pyexeption in beh : " << beh->GetName();
				beh->ActivateOutput(1,TRUE);
				return CKBR_BEHAVIORERROR;
			}
			beh->ActivateInput(i,false);
		}

	}
	
	return CKBR_OK;

}