int GetNextBBId(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; beh->ActivateInput(0,FALSE); int count = beh->GetParent()->GetSubBehaviorLinkCount(); int result = -1; for (int i=0; i<count; i++) { CKBehaviorLink *link = beh->GetParent()->GetSubBehaviorLink(i); if (link->GetInBehaviorIO() == beh->GetOutput(0)) { result = link->GetOutBehaviorIO()->GetOwner()->GetID(); beh->SetOutputParameterValue(0,&result); break; } } CKBehavior *script = static_cast<CKBehavior*>(ctx->GetObject(result)); if (script) { int bc = script->GetOutputCount(); int bc2 = script->GetInputCount(); } beh->ActivateOutput(0); beh->SetOutputParameterValue(0,&result); return CKBR_OK; }
//************************************ // 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; }
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; }
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; }