CKERROR MidiEventCallBack(const CKBehaviorContext& behcontext){ CKBehavior *beh = behcontext.Behavior; MidiManager *mm = (MidiManager *) behcontext.Context->GetManagerByGuid( MIDI_MANAGER_GUID ); switch( behcontext.CallbackMessage ){ case CKM_BEHAVIOREDITED: { int c_pin = beh->GetInputParameterCount(); char name[20]; CKParameterIn *pin; for( int a=2 ; a<c_pin ; a++){ pin = beh->GetInputParameter(a); sprintf( name, "Note %d", a); pin->SetName( name ); pin->SetGUID( CKPGUID_INT ); } } break; case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD: { mm->AddMidiBBref(); } break; case CKM_BEHAVIORDETACH: { mm->RemoveMidiBBref(); } break; } return CKBR_OK; }
int GBLCOSetID::BehaviourFunction( const CKBehaviorContext& behContext ) { CKBehavior *behaviour = behContext.Behavior; CKContext *context = behContext.Context; behaviour->ActivateInput(ECGBLCOSetLAIDBehInputs::InSetIdentity, FALSE); CKAttributeManager*attributeManager = context->GetAttributeManager(); if (attributeManager != NULL) { CKLevel *level = context->GetCurrentLevel(); if ( level != NULL ) { int attributeType = attributeManager->GetAttributeTypeByName("GBLCOLAID"); if (attributeType == -1) attributeType = attributeManager->RegisterNewAttributeType("GBLCOLAID", GUID_TGBLLAID, CKCID_BEOBJECT); else if ( level->HasAttribute(attributeType) ) level->RemoveAttribute(attributeType); attributeManager->SetAttributeCategory(attributeType,"GBL"); level->SetAttribute(attributeType); CKParameter*attribute = level->GetAttributeParameter(attributeType); if ( attribute != NULL ) { CKParameterIn*pin = behaviour->GetInputParameter(ECGBLCOSetLAIDBehInputs::InSetIdentity); CKParameter*laid = pin->GetDirectSource(); if ( laid != NULL ) { CKERROR err = attribute->CopyValue(laid); if ( err == CK_OK ) { behaviour->ActivateOutput(ECGBLCOSetLAIDBehOutputs::OutIdentitySet, TRUE); behaviour->ActivateOutput(ECGBLCOSetLAIDBehOutputs::OutError, FALSE); return CKBR_OK; } } } } } CKParameterOut *parameterOutError = behaviour->GetOutputParameter(ECGBLCOSetLAIDParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLCO_ERROR_SETID_ATTRIBUTE,GBLCO_ERROR_SETID_ATTRIBUTE_DESC); behaviour->ActivateOutput(ECGBLCOSetLAIDBehOutputs::OutIdentitySet, FALSE); behaviour->ActivateOutput(ECGBLCOSetLAIDBehOutputs::OutError, TRUE); return CKBR_GENERICERROR; }
/* ******************************************************************* * 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. * * Paramters : * 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 CGBLLAESetLAEData::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { CKBehavior* beh = behaviorContext.Behavior; CKContext* ctx = behaviorContext.Context; IGBLSMProfileAccess* pin = NULL; CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID); IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface(); int cisid; CGBLLAID laid; XString xlaid; XString laeName; int laeState = 0; CKDataArray *userIDList = NULL; CGBLLAEID laeid = 0; int dlaeid; beh->GetInputParameterValue(1, &dlaeid); laeid = dlaeid; GBLLAEDataType::GetGBLLAEData(beh->GetInputParameter(0)->GetRealSource(), cisid, laeName, laeState, xlaid, &userIDList ); laid.FromString(xlaid); CGBLCOError res = laeInterface->StoreLAE (laeState, cisid, laid, laeName, &laeid); if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); } else { CKParameterOut *parameterOutError = beh->GetOutputParameter(0); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_STORELAE,GBLLAE_ERROR_STORELAE_DESC); beh->ActivateOutput(1); } return CKBR_OK; }
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; }
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; }
//************************************ // 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; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : Returns the number of plugins in this DLL * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOGetMOStatus::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBOOL localError = false; CGBLCOError retVal(CGBLCOError::EGBLCOErrorType::GBLCO_OK); MeasuredObjectiveControllerMgr* MOMngr = static_cast<MeasuredObjectiveControllerMgr*>(behContext.Context->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID)); // Check to see if we got the manager ok if (!MOMngr) { assert(NULL); return CKBR_OK; } if (beh->IsInputActive(eBehInputStart)) { // Get the details of the MO P-In CKParameterIn *pIn = beh->GetInputParameter(eParamInputMO); CKParameter *moParam = pIn->GetRealSource(); // Ensure we read the P-In ok if (!moParam) { // Report the error CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_PARAM_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } if (!localError) { // Get the data from the P-In CGBLMOData *moData = static_cast<CGBLMOData*>(moParam->GetAppData()); if (moData) { // Get the name from the MO and use this to get the // runtime MO from the controller XString moName = moData->GetName(); CGBLLOMeasuredObjective *mo=NULL; retVal=MOMngr->GetRunTimeMO(moName,mo); // See if the controller gave us the MO if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(mo)) { // Get the status of the MO bool moStatus=mo->GetMOStatus(); // return the status of the MO back to Virtools Dev beh->SetOutputParameterValue(eParamOutputGetStatus, &moStatus); } } else { // Report the fact that we couldnt create a runtime MO from the param CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_DATA_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } } } if (localError) { // error allready dealt with } else if (retVal!=CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Report the error back to Virtools dev CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); const char* errorString = retVal; TGBLError::SetTGBLError(pOut, retVal,retVal,(CKSTRING)errorString); beh->ActivateOutput(eBehOutputError, TRUE); } else { // We are ok beh->ActivateOutput(eBehOutputDone, TRUE); } return CKBR_OK; }
/* ******************************************************************* * 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, ¤tParameterPosition); CKParameter* nextArgument = CGBLCommandUtil::GetCommandArgument(*targetBB, currentParameterPosition); currentParameterPosition++; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, ¤tParameterPosition); 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; } }
//************************************ // Method: PJRevolute // FullName: PJRevolute // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PJRevolute(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); ////////////////////////////////////////////////////////////////////////// //the object A: CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(bI_ObjectB); if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,JT_Revolute)) { return CK_OK; } // the world : pWorld *worldA=GetPMan()->getWorldByBody(target); pWorld *worldB=GetPMan()->getWorldByBody(targetB); if (!worldA && ! worldB ) { return 0; } if (!worldA) { worldA = worldB; } if (!worldA) { beh->ActivateOutput(0); return 0; } // the physic object A : pRigidBody*bodyA= worldA->getBody(target); pRigidBody*bodyB= worldA->getBody(targetB); //anchor : VxVector anchor = GetInputParameterValue<VxVector>(beh,bI_Anchor); VxVector anchorOut = anchor; CK3dEntity*anchorReference = (CK3dEntity *) beh->GetInputParameterObject(bI_AnchorRef); if (anchorReference) { anchorReference->Transform(&anchorOut,&anchor); } //swing axis VxVector Axis = GetInputParameterValue<VxVector>(beh,bI_Axis); VxVector axisOut = Axis; CK3dEntity*axisReference = (CK3dEntity *) beh->GetInputParameterObject(bI_AxisRef); if (axisReference) { VxVector dir,up,right; axisReference->GetOrientation(&dir,&up,&right); axisReference->TransformVector(&axisOut,&up); } ////////////////////////////////////////////////////////////////////////// //limit high : pJointLimit limitH; pJointLimit limitL; DWORD limit; beh->GetLocalParameterValue(1,&limit); if (limit) { CKParameterIn *par = beh->GetInputParameter(bbI_HighLimit); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { limitH = pFactory::Instance()->createLimitFromParameter(rPar); } } } if (limit) { CKParameterIn *par = beh->GetInputParameter(bbI_LowLimit); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { limitL = pFactory::Instance()->createLimitFromParameter(rPar); } } } ////////////////////////////////////////////////////////////////////////// DWORD spring; pSpring sSpring; beh->GetLocalParameterValue(0,&spring); if (spring) { CKParameterIn *par = beh->GetInputParameter(bbI_Spring); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { sSpring = pFactory::Instance()->createSpringFromParameter(rPar); } } } pMotor motor; DWORD hasMotor; beh->GetLocalParameterValue(2,&hasMotor); if (hasMotor) { CKParameterIn *par = beh->GetInputParameter(bbI_Motor); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { motor = pFactory::Instance()->createMotorFromParameter(rPar); } } } int col = GetInputParameterValue<int>(beh,bbI_Collision); ProjectionMode mode =GetInputParameterValue<ProjectionMode>(beh,bbI_PMode); float distance = GetInputParameterValue<float>(beh,bbI_PDistance); float angle= GetInputParameterValue<float>(beh,bbI_PAngle); ////////////////////////////////////////////////////////////////////////// // pJointRevolute *joint = static_cast<pJointRevolute*>(worldA->getJoint(target,targetB,JT_Revolute)); if(bodyA || bodyB) { ////////////////////////////////////////////////////////////////////////// //joint create ? if (!joint) { joint = static_cast<pJointRevolute*>(pFactory::Instance()->createRevoluteJoint(target,targetB,anchorOut,axisOut)); } ////////////////////////////////////////////////////////////////////////// Modification : if (joint) { joint->setGlobalAxis(axisOut); joint->setGlobalAnchor(anchorOut); if (mode!=0) { joint->setProjectionMode(mode); joint->setProjectionDistance(distance); joint->setProjectionAngle(angle); } ////////////////////////////////////////////////////////////////////////// if(limit) { joint->setHighLimit(limitH); joint->setLowLimit(limitL); } ////////////////////////////////////////////////////////////////////////// if (spring) { joint->setSpring(sSpring); } if (hasMotor) { joint->setMotor(motor); } joint->enableCollision(col); } } beh->ActivateOutput(0); } return 0; }
//************************************ // Method: PBPhysicalizeEx // FullName: PBPhysicalizeEx // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBPhysicalizeEx(const CKBehaviorContext& behcontext) { using namespace vtTools::BehaviorTools; using namespace vtTools; using namespace vtTools::AttributeTools; using namespace vtTools::ParameterTools; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // // objects // CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) bbErrorME("No Reference Object specified"); //the world reference, optional used CK3dEntity*worldRef = NULL; //the world object, only used when reference has been specified pWorld *world = NULL; //final object description pObjectDescr *oDesc = new pObjectDescr(); pRigidBody *body = NULL; XString errMesg; //---------------------------------------------------------------- // // sanity checks // // rigid body GetPMan()->getBody(target); if( body){ errMesg.Format("Object %s already registered.",target->GetName()); bbErrorME(errMesg.Str()); } //---------------------------------------------------------------- // // // if (!GetPMan()->isValid()) GetPMan()->performInitialization(); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // // Collecting data. Stores all settings in a pObjectDescr. // //get the parameter array BB_DECLARE_PIMAP; //---------------------------------------------------------------- // // generic settings // oDesc->hullType = (HullType)GetInputParameterValue<int>(beh,bbI_HullType); oDesc->flags = (BodyFlags)GetInputParameterValue<int>(beh,bbI_Flags); oDesc->density = GetInputParameterValue<float>(beh,bbI_Density); //---------------------------------------------------------------- // optional // world // BBSParameterM(bbI_World,BB_SSTART); if (sbbI_World) { worldRef = (CK3dEntity *) beh->GetInputParameterObject(BB_IP_INDEX(bbI_World)); if (worldRef) { world = GetPMan()->getWorld(worldRef,target); if (!world) { xLogger::xLog(ELOGERROR,E_LI_MANAGER,"World reference has been specified but no valid world object found. Switching to default world"); goto errorFound; } } } //---------------------------------------------------------------- // optional // Pivot // BBSParameterM(bbI_Pivot,BB_SSTART); if (sbbI_Pivot) { CKParameter*pivotParameter = beh->GetInputParameter(BB_IP_INDEX(bbI_Pivot))->GetRealSource(); if (pivotParameter) { IParameter::Instance()->copyTo(oDesc->pivot,pivotParameter); oDesc->mask |= OD_Pivot; } } //---------------------------------------------------------------- // optional // mass // BBSParameterM(bbI_Mass,BB_SSTART); if (sbbI_Mass) { CKParameter*massParameter = beh->GetInputParameter(BB_IP_INDEX(bbI_Mass))->GetRealSource(); if (massParameter) { IParameter::Instance()->copyTo(oDesc->mass,massParameter); oDesc->mask |= OD_Mass; } } //---------------------------------------------------------------- // optional // collision // BBSParameterM(bbI_Collision , BB_SSTART); if (sbbI_Collision) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Collision))->GetRealSource(); if (par) { oDesc->collisionGroup = GetValueFromParameterStruct<int>(par,PS_BC_GROUP,false); CKParameterOut* maskPar = GetParameterFromStruct(par,PS_BC_GROUPSMASK); if (maskPar) { oDesc->groupsMask.bits0 = GetValueFromParameterStruct<int>(maskPar,0); oDesc->groupsMask.bits1 = GetValueFromParameterStruct<int>(maskPar,1); oDesc->groupsMask.bits2 = GetValueFromParameterStruct<int>(maskPar,2); oDesc->groupsMask.bits3 = GetValueFromParameterStruct<int>(maskPar,3); } oDesc->skinWidth = GetValueFromParameterStruct<float>(par,PS_BC_SKINWITDH,false); IParameter::Instance()->copyTo(oDesc->collision,par); oDesc->mask |= OD_Collision; } } //---------------------------------------------------------------- // optional // collision : CCD // BBSParameterM(bbI_CCD, BB_SSTART); if (sbbI_CCD) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_CCD))->GetRealSource(); if (par) { IParameter::Instance()->copyTo(oDesc->ccd,par); oDesc->mask |= OD_CCD; } } //---------------------------------------------------------------- // optional // optimization // BBSParameterM(bbI_Optimization, BB_SSTART); if (sbbI_Optimization) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Optimization))->GetRealSource(); if (par) { IParameter::Instance()->copyTo(oDesc->optimization,par); oDesc->mask |= OD_Optimization; } } //---------------------------------------------------------------- // optional // Material // BBSParameterM(bbI_Material, BB_SSTART); if (sbbI_Material) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Material))->GetRealSource(); if (par) { pFactory::Instance()->copyTo(oDesc->material,par); oDesc->mask |= OD_Material; } } //---------------------------------------------------------------- // optional // capsule // BBSParameterM(bbI_Capsule, BB_SSTART); if (sbbI_Capsule) { if (oDesc->hullType == HT_Capsule) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_Capsule))->GetRealSource(); if (par) { IParameter::Instance()->copyTo(oDesc->capsule,par); oDesc->mask |= OD_Capsule; } }else{ errMesg.Format("You attached a capsule parameter but the hull type is not capsule"); bbWarning(errMesg.Str()); } } //---------------------------------------------------------------- // optional // convex cylinder // BBSParameterM(bbI_CCylinder, BB_SSTART); if (sbbI_CCylinder) { if (oDesc->hullType == HT_ConvexCylinder) { CKParameter*par = beh->GetInputParameter(BB_IP_INDEX(bbI_CCylinder))->GetRealSource(); if (par) { pFactory::Instance()->copyTo(oDesc->convexCylinder,par,true); oDesc->mask |= OD_ConvexCylinder; } }else{ errMesg.Format("You attached a convex cylinder parameter but the hull type is not a convex cylinder"); bbWarning(errMesg.Str()); } } oDesc->version = pObjectDescr::E_OD_VERSION::OD_DECR_V1; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // // body creation // if (!body) { if(! (oDesc->flags & BF_SubShape) ) { body = pFactory::Instance()->createRigidBody(target,*oDesc); } } if (!body) { SAFE_DELETE(oDesc); bbErrorME("No Reference Object specified"); } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // // attribute creation, attach settings // if (oDesc->flags & BF_AddAttributes ) { //body->saveToAttributes(oDesc); GetPMan()->copyToAttributes(*oDesc,target); } //---------------------------------------------------------------- // // update input parameters // if (sbbI_Material) { CKParameterOut *par = (CKParameterOut*)beh->GetInputParameter(BB_IP_INDEX(bbI_Material))->GetRealSource(); if (par) { pFactory::Instance()->copyTo(par,oDesc->material); } } //---------------------------------------------------------------- // // cleanup // //SAFE_DELETE(oDesc); //---------------------------------------------------------------- // // error out // errorFound: { beh->ActivateOutput(0); return CKBR_GENERICERROR; } //---------------------------------------------------------------- // // All ok // allOk: { beh->ActivateOutput(0); return CKBR_OK; } return 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; }
/* ******************************************************************* * Function: int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) * * Description : Read next provided argument from SetParameterString p-in and add it to command string * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * ******************************************************************* */ int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; int gblBuildCommandState; behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState); switch (gblBuildCommandState) { case EGBLBuildCommandState::Initial: { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } break; case EGBLBuildCommandState::GetTargets: { //check if the array of recipients is provided void* recipients = NULL; recipients = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests)->GetDirectSource()->GetValueObject(); if (recipients == NULL) { CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); return CKBR_OK; } int targetID = 0; behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID); XString commandString; commandString << targetID << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 ); //check if there are more arguments return DoHandleNextNetworkArgument (behaviorContext); } break; case EGBLBuildCommandState::AwaitingParametersForNetwork: case EGBLBuildCommandState::AwaitingParametersForUntargeted: { CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr(); CKSTRING argumentString = (CKSTRING) behavior->GetInputParameter(EGBLBuildCommandParamInputs::SetParameterString)->GetReadDataPtr(); //char commandString[512]; //char argumentString[512]; //behavior->GetLocalParameterValue(commandStringLocalPos,&commandString); //behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetParameterString, &argumentString); if (strlen (argumentString) == 0) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } CKSTRING argumentType = (CKSTRING) behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetArgumentType)->GetReadDataPtr(); if ( (strcmp (argumentType, "Integer") == 0) || (strcmp (argumentType, "Float") == 0)) { bool isArgumentNumeric = CGBLCommandUtil::IsNumeric(argumentString); if (!isArgumentNumeric) { behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue); return CKBR_OK; } } XString updatedCommandString; updatedCommandString << commandString << argumentString << CGBLCommandUtil::commandSeparator; behavior->SetLocalParameterValue(commandStringLocalPos, updatedCommandString.Str(), strlen(updatedCommandString.Str()) + 1 ); if (gblBuildCommandState == EGBLBuildCommandState::AwaitingParametersForUntargeted) { return DoHandleNextLocalArgument (behaviorContext); } return DoHandleNextNetworkArgument (behaviorContext); } break; default: break; } return CKBR_OK; }
//************************************ // Method: vt_GetInVal // FullName: vt_GetInVal // Access: public static // Returns: PyObject * // Qualifier: // Parameter: PyObject * self // Parameter: PyObject * args //************************************ static PyObject *vt_GetInVal( PyObject * self, PyObject * args ) { int size = PyTuple_Size(args); int bid, index; PyArg_ParseTuple(args, "ii", &bid, &index); CK_ID cid = bid; CKBehavior *beh = static_cast<CKBehavior*>(pym->m_Context->GetObject(cid)); if (size!=2) { pym->m_Context->OutputToConsole("PyError : This function needs 2 arguments : \n\t bid,index"); Py_RETURN_NONE; } using namespace vtTools; using namespace vtTools::Enums; CKParameterManager *pam = static_cast<CKParameterManager *>(pym->m_Context->GetParameterManager()); if (index < beh->GetInputParameterCount() ) { CKParameterIn *ciIn = beh->GetInputParameter(index); CKParameterType pType = ciIn->GetType(); vtTools::Enums::SuperType sType = ParameterTools::GetVirtoolsSuperType(pym->m_Context,pam->ParameterTypeToGuid(pType)); PyObject *val; switch (sType) { case vtSTRING: { val = PyString_FromString( vtTools::BehaviorTools::GetInputParameterValue<CKSTRING>(beh,index )); break; } case vtFLOAT: { val = PyFloat_FromDouble(static_cast<float>(vtTools::BehaviorTools::GetInputParameterValue<float>(beh,index ))); break; } case vtINTEGER: { val = PyInt_FromLong( static_cast<long>(vtTools::BehaviorTools::GetInputParameterValue<int>(beh,index ))); break; } default : XString err("wrong input parameter type: "); err << ciIn->GetName() << "Only Types derivated from Interger,Float or String are acceptable"; pym->m_Context->OutputToConsole(err.Str(),FALSE ); Py_RETURN_NONE; } if (!val) { Py_DECREF(val); } return val; } Py_RETURN_NONE; }
//************************************ // Method: PWOverlapSphere // FullName: PWOverlapSphere // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PWOverlapSphere(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; using namespace vtTools::ParameterTools; ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorld(target->GetID()); if (!world) { beh->ActivateOutput(bbOT_No); return 0; } NxScene *scene = world->getScene(); if (!scene) { beh->ActivateOutput(bbOT_No); return 0; } if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result); if (carray) { //carray->clear(); carray->Clear(); }else { CK_OBJECTCREATION_OPTIONS creaoptions = (CK_OBJECTCREATION_OPTIONS)(CK_OBJECTCREATION_NONAMECHECK|CK_OBJECTCREATION_DYNAMIC); carray = (CKGroup*)ctx()->CreateObject(CKCID_GROUP,"asdasd",creaoptions); } beh->SetLocalParameterObject(0,carray); int hitIndex = 0; beh->SetLocalParameterValue(bbS_Index,&hitIndex); int hitSize = 0; beh->SetLocalParameterValue(bbS_Size,&hitSize); ////////////////////////////////////////////////////////////////////////// int types = GetInputParameterValue<int>(beh,bbI_ShapesType); int accurate = GetInputParameterValue<int>(beh,bbI_Accurate); DWORD groupsEnabled; DWORD groups = 0xffffffff; beh->GetLocalParameterValue(bbS_Groups,&groupsEnabled); if (groupsEnabled) { groups = GetInputParameterValue<int>(beh,bbI_Groups); } pGroupsMask *gmask = NULL; DWORD mask; beh->GetLocalParameterValue(bbS_Mask,&mask); if (mask) { CKParameter *maskP = beh->GetInputParameter(bbI_Mask)->GetRealSource(); gmask->bits0 = GetValueFromParameterStruct<int>(maskP,0); gmask->bits1 = GetValueFromParameterStruct<int>(maskP,1); gmask->bits2 = GetValueFromParameterStruct<int>(maskP,2); gmask->bits3 = GetValueFromParameterStruct<int>(maskP,3); } float radius = GetInputParameterValue<float>(beh,bbI_Radius); VxVector center = GetInputParameterValue<VxVector>(beh,bbI_Center); VxSphere sphere(center,radius); CK3dEntity *shape = (CK3dEntity*)beh->GetInputParameterObject(bbI_Ref); int nbShapes = world->overlapSphereShapes(sphere,shape,(pShapesType)types,carray,groups,gmask,accurate); if (nbShapes) { beh->ActivateOutput(bbOT_Yes); beh->ActivateInput(1,TRUE); }else{ beh->ActivateOutput(bbOT_No); } } if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); CKGroup *carray = (CKGroup*)beh->GetLocalParameterObject(bbS_Result); ////////////////////////////////////////////////////////////////////////// if (carray) { if (carray->GetObjectCount()) { CKBeObject *hit = carray->GetObject(carray->GetObjectCount()-1); if (hit) { beh->SetOutputParameterObject(0,hit); carray->RemoveObject(hit); if (carray->GetObjectCount()) { beh->ActivateOutput(bbOT_Next); }else { beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } } }else{ beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } }else { beh->ActivateOutput(bbOT_Finish); CKDestroyObject(carray); } } return 0; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : Returns the number of plugins in this DLL * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOStopTimer::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBOOL localError = false; CGBLCOError retVal(CGBLCOError::EGBLCOErrorType::GBLCO_OK); MeasuredObjectiveControllerMgr* MOMngr = static_cast<MeasuredObjectiveControllerMgr*>(behContext.Context->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID)); // Check to see if we got the manager ok if (!MOMngr) { assert(NULL); return CKBR_OK; } if (beh->IsInputActive(eBehInputStart)) { // Get the details of the MO P-In CKParameterIn *pInMO = beh->GetInputParameter(eParamInputMO); CKParameter *moParam = pInMO->GetRealSource(); // Get the details of the Measurement P-In CKParameterIn *pInMeas= beh->GetInputParameter(eParamInputMeasurement); CKParameter *measParam = pInMeas->GetRealSource(); // Ensure we read the P-In ok if (!moParam) { // Report the error CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_PARAM_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } if (!localError) { // Get the data from the P-In CGBLMOData *moData = static_cast<CGBLMOData*>(moParam->GetAppData()); if (moData) { // Get the name from the MO and use this to get the // runtime MO from the controller XString moName = moData->GetName(); CGBLLOMeasuredObjective *mo=NULL; retVal=MOMngr->GetRunTimeMO(moName,mo); // See if the controller gave us the MO if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(mo)) { // Get the data from the P-In CGBLMeasurementData *measData = static_cast<CGBLMeasurementData*>(measParam->GetAppData()); if (measData) { // Get the measurement XString measName = measData->GetName(); EGBLLOMeasurementType measType=measData->GetType(); CGBLMeasurement *meas=NULL; retVal=mo->GetMeasurement(measName,meas); // See if the MO gave us the measurement if((retVal==CGBLCOError::EGBLCOErrorType::GBLCO_OK)&&(meas)) { // Based on the measurement type, get the value from the P-Im // and pass the value to the measurement. switch (measType) { case eTimer: { CGBLLOMeasurementTimer *timeMeas=NULL; timeMeas=static_cast<CGBLLOMeasurementTimer*>(meas); retVal=timeMeas->StopTimer(); } break; default: { CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_TRIED_START_TIMER_NOT,GBLLO_ERROR_TRIED_START_TIMER_NOT_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } break; } } } } } else { // Report the fact that we couldnt create a runtime MO from the param CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); TGBLError::SetTGBLError(pOut, CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_NO_DATA_FROM_BB,GBLLO_ERROR_NO_DATA_FROM_BB_DESC); beh->ActivateOutput(eBehOutputError, TRUE); localError = true; } } } if (localError) { // error allready dealt with } else if (retVal!=CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Report the error back to Virtools dev CKParameterOut *pOut = beh->GetOutputParameter(eParamOutputGetError); const char* errorString = retVal; TGBLError::SetTGBLError(pOut, retVal,retVal,(CKSTRING)errorString); beh->ActivateOutput(eBehOutputError, TRUE); } else { // We are ok beh->ActivateOutput(eBehOutputDone, TRUE); } return CKBR_OK; }
/* ******************************************************************* * 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; }
/* ******************************************************************* * 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,¤tCI->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; }
//************************************ // Method: PVWSet // FullName: PVWSet // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PVWSet(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) bbErrorME("No Reference Object specified"); pRigidBody *body = NULL; body = GetPMan()->getBody(target); if (!body) bbErrorME("No Reference Object specified"); pWheel *wheel = body->getWheel(target); if (!wheel)bbErrorME("pWheel object doesnt exist!"); pWheel2 *wheel2 = wheel->castWheel2(); if (!wheel2)bbErrorME("Couldnt cast a pWheel2 object"); BB_DECLARE_PIMAP; /************************************************************************/ /* engel kuehne un partner */ /************************************************************************/ /************************************************************************/ /* retrieve settings state */ /************************************************************************/ BBSParameter(bbI_XML); BBSParameter(bbI_AxleSpeed); BBSParameter(bbI_Steer); BBSParameter(bbI_MotorTorque); BBSParameter(bbI_BrakeTorque); BBSParameter(bbI_SuspensionSpring); BBSParameter(bbI_SuspensionTravel); BBSParameter(bbI_Radius); BBSParameter(bbI_WFlags); BBSParameter(bbI_WSFlags); BBSParameter(bbI_LatFunc); BBSParameter(bbI_LongFunc); /************************************************************************/ /* retrieve values */ /************************************************************************/ int xmlValue = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_XML)); float axleVel = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_AxleSpeed)); float steer = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_Steer)); float mTorque = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_MotorTorque)); float bTorque = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_BrakeTorque)); float suspensionTravel = GetInputParameterValue<float>(beh,BB_IP_INDEX(bbI_SuspensionTravel)); int wFlags = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_WFlags)); int wSFlags = GetInputParameterValue<int>(beh,BB_IP_INDEX(bbI_WSFlags)); pSpring sSpring; if (sbbI_SuspensionSpring) { CKParameterIn *par = beh->GetInputParameter(bbI_SuspensionSpring); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { sSpring = pFactory::Instance()->createSpringFromParameter(rPar); NxSpringDesc xsp; xsp.damper = sSpring.damper; xsp.spring = sSpring.spring; xsp.targetValue = sSpring.targetValue; if (xsp.isValid()) { wheel2->setSuspensionSpring(sSpring); }else bbErrorME("Invalid Spring Setings!"); } } } /************************************************************************/ /* Update Object ! */ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// // load some settings from XML if(sbbI_XML) { } if (sbbI_Steer)wheel2->setAngle(steer); if (sbbI_AxleSpeed)wheel2->setAxleSpeed(axleVel); if (sbbI_MotorTorque)wheel2->setMotorTorque(mTorque); if (sbbI_BrakeTorque)wheel2->setBreakTorque(bTorque); if (sbbI_SuspensionSpring)wheel2->setSuspensionSpring(sSpring); if (sbbI_SuspensionTravel)wheel2->setSuspensionTravel(suspensionTravel); if (sbbI_WFlags) { ////////////////////////////////////////////////////////////////////////// // // wheel2->setFlags(wFlags); } if (sbbI_WSFlags) { wheel2->getWheelShape()->setWheelFlags(wSFlags); } if (sbbI_LatFunc) { CKParameterIn *par = beh->GetInputParameter(BB_IP_INDEX(bbI_LatFunc)); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { pTireFunction func = pFactory::Instance()->createTireFuncFromParameter(rPar); if (func.isValid()) { NxTireFunctionDesc xFn; xFn.asymptoteSlip = func.asymptoteSlip; xFn.asymptoteValue = func.asymptoteValue; xFn.extremumSlip= func.extremumSlip; xFn.extremumValue= func.extremumValue; xFn.stiffnessFactor= func.stiffnessFactor; wheel2->getWheelShape()->setLongitudalTireForceFunction(xFn); }else bbErrorME("Invalid Tire Function Settings!"); } } } if (sbbI_LongFunc) { CKParameterIn *par = beh->GetInputParameter(BB_IP_INDEX(bbI_LongFunc)); if (par) { CKParameter *rPar = par->GetRealSource(); if (rPar) { pTireFunction func = pFactory::Instance()->createTireFuncFromParameter(rPar); if (func.isValid()) { NxTireFunctionDesc xFn; xFn.asymptoteSlip = func.asymptoteSlip; xFn.asymptoteValue = func.asymptoteValue; xFn.extremumSlip= func.extremumSlip; xFn.extremumValue= func.extremumValue; xFn.stiffnessFactor= func.stiffnessFactor; wheel2->getWheelShape()->setLongitudalTireForceFunction(xFn); }else bbErrorME("Invalid Tire Function Settings!"); } } } } beh->ActivateOutput(0); return 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 GBLCIGetCIS_IDList(const CKBehaviorContext& behcontext) { ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // Retrieving min data : CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; beh->ActivateInput(0,false); // required managers CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID)); IGBLCIManageInterface *cisFac = cman->GetCISFactoryInterface(); CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); //get LAID from bb : CKParameter *parameterINGetLAID = beh->GetInputParameter(BEH_IN_INDEX_LAID)->GetRealSource(); using namespace GBLCommon::ParameterTools; //contruct c rep of the LAID : CGBLLAID laID( GetValueFromParameterStruct<int>(parameterINGetLAID,0,false), GetValueFromParameterStruct<int>(parameterINGetLAID,1,false) ); // get inout array : CKDataArray * resultArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(BEH_IN_INDEX_TARGETARRAY)); if(resultArray == NULL) { beh->ActivateOutput(1, true); CKParameterOut *pOut = beh->GetOutputParameter(0); CGBLCOError::EGBLCOErrorType tType; tType= CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL; TGBLError::SetTGBLError(pOut, tType , 19021, "Missing or incorrect parameter provided"); return CKBR_OK; } //get error parameter CKParameterOut *parameterOutError = beh->GetOutputParameter(BEH_OUT_INDEX_ERROR); // get cis list CGBLCOError returnValue = smCIS->RetrieveCISIDList(laID,resultArray); // check results and output error if (returnValue == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { 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; }