//************************************ // Method: PBGet2 // FullName: PBGet2 // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBGet2(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) ) { ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorldByBody(target); if (!world) { beh->ActivateOutput(0); return 0; } // body exists already ? clean and delete it : pRigidBody*result = world->getBody(target); if(result) { ////////////////////////////////////////////////////////////////////////// //linear damp : DWORD cGroup; beh->GetLocalParameterValue(bbI_CollisionGroup,&cGroup); if (cGroup) { int val = result->getCollisionsGroup(); SetOutputParameterValue<int>(beh,bbI_CollisionGroup,val); } DWORD kine; beh->GetLocalParameterValue(bbI_Kinematic,&kine); if (kine) { int val = result->isKinematic(); SetOutputParameterValue<int>(beh,bbI_Kinematic,val); } DWORD gravity; beh->GetLocalParameterValue(bbI_Gravity,&gravity); if (gravity) { int val = result->getActor()->readBodyFlag(NX_BF_DISABLE_GRAVITY); SetOutputParameterValue<int>(beh,bbI_Gravity,!val); } DWORD col; beh->GetLocalParameterValue(bbI_Collision,&col); if (col) { int val = result->isCollisionEnabled(); SetOutputParameterValue<int>(beh,bbI_Collision,val); } DWORD mass; beh->GetLocalParameterValue(bbI_MassOffset,&mass); if (mass) { VxVector val = result->getMassOffset(); SetOutputParameterValue<VxVector>(beh,bbI_MassOffset,val); } DWORD pivot; beh->GetLocalParameterValue(bbI_ShapeOffset,&pivot); if (mass) { // VxVector val = result->getPivotOffset(); // SetOutputParameterValue<VxVector>(beh,bbI_ShapeOffset,val); } } beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); } return 0; }
//************************************ // Method: PBSetHard // FullName: PBSetHard // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBSetHard(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; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorldByBody(target); if (!world) { if (!body) bbErrorME("No valid world object found"); } body = GetPMan()->getBody(target); if (!body) bbErrorME("No Reference Object specified"); BB_DECLARE_PIMAP; /************************************************************************/ /* retrieve settings state */ /************************************************************************/ BBSParameter(bbI_Vel); BBSParameter(bbI_AVel); BBSParameter(bbI_Torque); BBSParameter(bbI_Momentum); BBSParameter(bbI_Pos); BBSParameter(bbI_Rotation); if (sbbI_Vel) { VxVector velocity= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Vel)); body->setLinearVelocity(velocity); } if (sbbI_AVel) { VxVector aVelocity= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_AVel)); body->setAngularVelocity(aVelocity); } if (sbbI_Torque) { VxVector torque= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Torque)); body->setAngularMomentum(torque); } if (sbbI_Momentum) { VxVector momentum= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Momentum)); body->setLinearMomentum(momentum); } if (sbbI_Pos) { VxVector pos= GetInputParameterValue<VxVector>(beh,BB_IP_INDEX(bbI_Pos)); body->setPosition(pos,target); } if (sbbI_Rotation) { VxQuaternion rot= GetInputParameterValue<VxQuaternion>(beh,BB_IP_INDEX(bbI_Rotation)); body->setRotation(rot,target); } } 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 CGBLFileSystem::BehaviourFunction(const CKBehaviorContext& behContext) { BOOL error = FALSE; // Quick bit of error checking CKBehavior* beh = behContext.Behavior; CKBeObject* beObject = beh->GetTarget(); int fileSystemBrowseMode = 0; if (!beObject) { error = TRUE; } if (!error) { // Reset On input, if active if (beh->IsInputActive(eBehInputOn)) { beh->ActivateInput(eBehInputOn, FALSE); // Clear error message output beh->SetOutputParameterValue(eParamOutputErrorMsg, EMPTY_STRING); } // see which mode we are in beh->GetInputParameterValue(eParamInputMode, &fileSystemBrowseMode); } if (!error) { // See if we have the special case char *currentFolder = NULL; currentFolder = (char*)(beh->GetInputParameterReadDataPtr(eParamInputCurrentFolder)); XString scannedFolder = currentFolder; if (currentFolder) { // special case takes priority over FILES / FOLDER mode if (strcmp(currentFolder,SPECIAL_CASE)==0) { beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(),scannedFolder.Length()+1 ); if (fileSystemBrowseMode == eFolder) { if (GetLogicalDrives(beh)) { // Everythings gone ok we have a list of the logical drives beh->ActivateOutput(eBehOutputDone, TRUE); } else { // Something went wrong beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan The Logical Drives"); beh->ActivateOutput(eBehOutputError, TRUE); } } else { // Cant scan for files in the SPECIAL_CASE // Get the destination data array and clear it out CKDataArray* dataArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputDataArray)); if (!dataArray) { CGBLWidget::OutputBBErrorMsg(beh, "Please attatch an array to the BB"); } else { dataArray->Clear(); dataArray->AddRow(); int currentRow = dataArray->GetRowCount()-1; // 0 index dataArray->SetElementStringValue(currentRow,NAME_COLUMN,NOT_FOUND); beh->ActivateOutput(eBehOutputDone, TRUE); } } } else { // add a "\" to the end, it makes the ouput consistent. int len = strlen (scannedFolder.CStr()); if ((scannedFolder[len-1])!=SINGLE_SEPERATOR) { scannedFolder << SINGLE_SEPERATOR; } // Try to scan the passed folder if (GetData(beh,fileSystemBrowseMode)==FALSE) { // Error Handling we can handle errors here // We most likely got here because the user doesnt have access to the folder. if (fileSystemBrowseMode == eFile) { beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Files"); } else { beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Folders"); } beh->ActivateOutput(eBehOutputDone, TRUE); // Handleable, recoverable errors, so dont set the error flag //beh->ActivateOutput(eBehOutputError, TRUE); } else { // No errors beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(), scannedFolder.Length() + 1); beh->ActivateOutput(eBehOutputDone, TRUE); } } } else { // Dont think we can ever get here becuase "" is a valid folder. // Just in case though. beh->SetOutputParameterValue(eParamOutputErrorMsg, "Please Supply a Folder To Scan"); beh->ActivateOutput(eBehOutputError, TRUE); } } 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 ARTPlusPatternTransformation(const CKBehaviorContext& BehContext) { CKBehavior* beh = BehContext.Behavior; CKBOOL detected = FALSE; int patternID = -1; int markerId = -1; float buffer[16]; float patternWidth = 8.0f; CK3dEntity* Object = NULL; VxQuaternion quat = VxQuaternion(); VxVector pos = VxVector(); VxVector scale = VxVector(); float gl_para[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f} }; float gl_tmp[4][4] = { {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f} }; float koordSys[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f} }; float koordSys2[4][4] = { {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f} }; beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); if(ARTPlusInitialized == true) { // get object Object = CK3dEntity::Cast(beh->GetInputParameterObject(IN_OBJECT)); if(Object==NULL) return CKBR_BEHAVIORERROR; if(markerInfo!=NULL && numMarkers>0) { // Get pattern id beh->GetInputParameterValue(IN_PATTERN_NUMBER, &patternID); // Get pattern width beh->GetInputParameterValue(IN_PATTERN_WIDTH, &patternWidth); // define size of the marker tracker->setPatternWidth(patternWidth); markerId = findMarker(patternID); if( markerId>=0 && markerInfo[markerId].id==patternID) { ARFloat patt_center[2] = {0.0f, 0.0f}; tracker->calcOpenGLMatrixFromMarker(&markerInfo[markerId], patt_center, patternWidth, (float *)buffer); detected = TRUE; for( int j = 0; j < 4; j++ ) { for( int i = 0; i < 4; i++ ) { gl_para[j][i] = buffer[j*4+i]; } } for( int j = 0; j < 4; j++ ) { for( int i = 0; i < 4; i++ ) { gl_tmp[j][i] = 0.0; for(int k=0 ; k<4 ; k++) { gl_tmp[j][i] += koordSys[j][k]*gl_para[k][i]; } } } for( int j = 0; j < 4; j++ ) { for( int i = 0; i < 4; i++ ) { gl_para[j][i] = 0.0; for(int k=0 ; k<4 ; k++) { gl_para[j][i] += gl_tmp[j][k]*koordSys2[k][i]; } } } } } VxMatrix mat = VxMatrix(gl_para); Vx3DDecomposeMatrix(mat, quat, pos, scale); // Set true, if marker is detected beh->SetOutputParameterValue(OUT_DETECTED, &detected, 0); // Set marker id beh->SetOutputParameterValue(OUT_MARKERID, &patternID, 0); // Set Position beh->SetOutputParameterValue(OUT_POSITION, &pos, 0); // Set quaternion beh->SetOutputParameterValue(OUT_QUATERNION, &quat, 0); // Set matrix beh->SetOutputParameterValue(OUT_TRANSFORM_MATRIX, &mat, 0); //Check object visibility if(detected==TRUE) { // Transform object Object->SetPosition(&pos, NULL, FALSE); Object->SetQuaternion(&quat, NULL, FALSE, FALSE); Object->Show(CKSHOW); } else { Object->Show(CKHIERARCHICALHIDE); } } return CKBR_OK; }
/* ******************************************************************* * Function: * * Description: * * Parameters: * * Returns: * ******************************************************************* */ int NSUnlockObject(const CKBehaviorContext& behcontext) { using namespace vtTools::BehaviorTools; CKBehavior* beh = behcontext.Behavior; CKMessageManager* mm = behcontext.MessageManager; CKContext* ctx = behcontext.Context; bbNoError(E_NWE_OK); //network ok ? xNetInterface *cin = GetNM()->GetClientNetInterface(); if (!cin) { bbError(E_NWE_NO_CONNECTION); return 0; } if (!cin->getMyClient()) { bbError(E_NWE_INTERN); return 0; } ISession *sInterface = cin->getSessionInterface(); int connectionID = GetInputParameterValue<int>(beh,BB_IP_CONNECTION_ID); ////////////////////////////////////////////////////////////////////////// // // Check states : // xDistributedClient *myClient = cin->getMyClient(); if (!myClient) { bbError(E_NWE_INTERN); return 0; } if (!myClient->getClientFlags().test(1 << E_CF_SESSION_JOINED)) { bbError(E_NWE_NO_SESSION); return 0; } xDistributedSession *session = cin->getCurrentSession(); if (!session) { bbError(E_NWE_NO_SUCH_SESSION); return 0; } if (beh->IsInputActive(0)) { beh->ActivateInput(0,FALSE); if (myClient->getUserID() != session->getUserID()) { bbError(E_NWE_NOT_SESSION_MASTER); return 0; } beh->ActivateInput(0,FALSE); sInterface->unlockSession(myClient->getUserID(),session->getSessionID()); } if (session->isLocked()) { beh->ActivateOutput(BB_O_UNLOCKED); return 0; }else { beh->ActivateOutput(BB_O_WAITING); } return CKBR_ACTIVATENEXTFRAME; }
/* ******************************************************************* * Function: * * Description: * * Parameters: * * Returns: * ******************************************************************* */ int NSRemoveUser(const CKBehaviorContext& behcontext) { using namespace vtTools::BehaviorTools; CKBehavior* beh = behcontext.Behavior; CKMessageManager* mm = behcontext.MessageManager; CKContext* ctx = behcontext.Context; //network ok ? xNetInterface *cin = GetNM()->GetClientNetInterface(); if (!cin) { Error(beh,"No connection at the moment",BB_OP_SESSION_ERROR,TRUE,BB_O_ERROR); return 0; } IDistributedObjects *oInterface = cin->getDistObjectInterface(); ISession *sInterface = cin->getSessionInterface(); int connectionID = GetInputParameterValue<int>(beh,BB_IP_CONNECTION_ID); int userID = GetInputParameterValue<int>(beh,BB_IP_USER_ID); ////////////////////////////////////////////////////////////////////////// // // Check states : // xDistributedClient *myClient = cin->getMyClient(); xDistributedClient *client = (xDistributedClient*)oInterface->getByUserID(userID,E_DC_BTYPE_CLIENT); xDistributedSession *session = cin->getCurrentSession(); if (!session) { Error(beh,"There doesn't exist such session",BB_OP_SESSION_ERROR,TRUE,BB_O_ERROR); xLogger::xLog(ELOGERROR,E_LI_SESSION,"There doesn't exist such session!"); XL_BB_SIGNATURE; return 0; } if (!client) { Error(beh,"There doesn't exist such client object",BB_OP_SESSION_ERROR,TRUE,BB_O_ERROR); xLogger::xLog(ELOGERROR,E_LI_SESSION,"There doesn't exist such client object :%d",userID); XL_BB_SIGNATURE; return 0; } if (!session->isClientJoined(userID)) { Error(beh,"Client not joint on this session!",BB_OP_SESSION_ERROR,TRUE,BB_O_ERROR); xLogger::xLog(ELOGERROR,E_LI_SESSION,"Client not joint on this session! %d",userID); XL_BB_SIGNATURE; return 0; } if (beh->IsInputActive(0)) { beh->ActivateInput(0,FALSE); sInterface->removeClient(client,session->getSessionID(),false); beh->ActivateOutput(0); } return 0; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOStringBuilder::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBeObject* beObject = beh->GetTarget(); CKBOOL error = FALSE; XString outString = NULL; // error check to ensure virtools is working ok if (!beObject) { error = TRUE; CKParameterOut *parameterOutError = beh->GetOutputParameter(EGBLStringBuilderParamOutputs::eParamGetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_FATAL,LOI_ERROR_NO_BEHAVIOUR_STATE,LOI_ERROR_NO_BEHAVIOUR_DESC); beh->SetOutputParameterValue(eParamGetError, parameterOutError); beh->ActivateOutput(eBehOutputError, TRUE); } int lengthOfSource = 0; int lengthOfInsert = 0; int insertPosition = 0; if (!error) { // Reset On input, if active if (beh->IsInputActive(eBehInputOn)) { beh->ActivateInput(eBehInputOn, FALSE); } // get the BB params into variables to work with XString sourceString = NULL; sourceString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetSourceString)); XString insertString = NULL; insertString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetInsertString)); beh->GetInputParameterValue(eParamSetInsertPosition,&insertPosition); lengthOfSource = strlen(sourceString.Str()); lengthOfInsert = strlen(insertString.Str()); // Simple bounds checking and error recovery if (insertPosition<0) { insertPosition=0; } if (insertPosition>lengthOfSource) { outString = sourceString; outString += insertString; } else { // a little more error checking and simple recovery // deal with the special cases first if (lengthOfSource<=0) { // an empty source outString = insertString; } else if (insertPosition == 0) { outString = insertString; outString += sourceString; } else { // build up the new string XString start = NULL; XString end = NULL; start = sourceString.Substring(0,insertPosition); end = sourceString.Substring(insertPosition,lengthOfSource); outString = start ; outString += insertString; outString += end; } } } if (!error) { int newCartPos = insertPosition+lengthOfInsert; beh->SetOutputParameterValue(eParamGetCarretPosition,&newCartPos); beh->SetOutputParameterValue(eParamGetNewText, outString.CStr(), outString.Length() + 1); beh->ActivateOutput(eBehOutputDone, TRUE); } return CKBR_OK; }
//************************************ // Method: PCGroupTriggerEvent // FullName: PCGroupTriggerEvent // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PCGroupTriggerEvent(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); using namespace vtTools::BehaviorTools; ////////////////////////////////////////////////////////////////////////// //the object : CKGroup *target = (CKGroup *) beh->GetTarget(); if( !target ) return CKBR_OWNERERROR; //int extraFilter = GetInputParameterValue<int>(beh,0); //int remove = GetInputParameterValue<int>(beh,1); int nbOfEvents = getEventCount(); if (!nbOfEvents) { beh->ActivateOutput(bbO_None); return 0; } /************************************************************************/ /* handle init */ /************************************************************************/ if( beh->IsInputActive(bbI_Init) ) { beh->ActivateInput(bbI_Init,FALSE); int index = 0;beh->SetLocalParameterValue(0,&index); //we have some, forward to in 1:next if (nbOfEvents) { beh->ActivateInput(bbI_Next,TRUE); beh->ActivateOutput(bbO_HasMore); } } /************************************************************************/ /* handle trigger 'next' */ /************************************************************************/ if( beh->IsInputActive(bbI_Next) ) { beh->ActivateInput(bbI_Next,FALSE); int index = 0;beh->GetLocalParameterValue(0,&index); for (int i = index ; i < GetPMan()->getTriggers().Size(); i++ ) { pTriggerEntry &entry = *GetPMan()->getTriggers().At(i); if (!entry.triggered) { if (isInGroup(target,entry.triggerShapeEnt)) { beh->SetOutputParameterObject(0,entry.triggerShapeEnt); beh->SetOutputParameterObject(1,entry.otherObject); SetOutputParameterValue<int>(beh,2,entry.triggerEvent); entry.triggered = true; //trigger out if(entry.triggerEvent == NX_TRIGGER_ON_ENTER) { beh->ActivateOutput(bbO_Enter); } if(entry.triggerEvent == NX_TRIGGER_ON_STAY) { beh->ActivateOutput(bbO_Stay); } if(entry.triggerEvent == NX_TRIGGER_ON_LEAVE) { beh->ActivateOutput(bbO_Leave); } //store index beh->SetLocalParameterValue(1,&index); int nbOfLeftEvents = getEventCount(); if (nbOfLeftEvents) { beh->ActivateOutput(bbO_HasMore); return 0; }else { beh->ActivateOutput(bbO_None); return 0; } } } } } /************************************************************************/ /* */ /************************************************************************/ return 0; }
/* ******************************************************************* * Function: int GetCIValue( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int GetCIValue(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); BOOL getByName,getAsString,outputAttriubtes,outputOnChange = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_BY_NAME,&getByName); beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); beh->GetLocalParameterValue(BEH_SETTINGS_OUTPUT_ON_CHANGE,&outputOnChange); // Beh Input 1 activated : switch of on event mode ///////////////////////////////////////////////// if( outputOnChange && beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); return CKBR_OK; } using namespace GBLCommon::BehaviorTools; using namespace Customisation::typedefs; Customisation::typedefs::CIS* currentCIS = cman->GetCIS(); if( !currentCIS) { return CKBR_PARAMETERERROR; } CGBLCI *currentCI = NULL; //get by uniquie name mode ? if( getByName ) { CISIterator it = currentCIS->Find( new CGBLCIID (GetInputParameterValue<CKSTRING>(beh,0) , 0 ) ); if (it == currentCIS->End() ) { return CKBR_PARAMETERERROR; }else { currentCI = *it; } //////// then get the custom parameter : }else { CKParameter *ciPar = beh->GetInputParameter(0)->GetRealSource(); currentCI = static_cast<CGBLCI *>(ciPar->GetAppData()); if (!currentCI) { return CKBR_PARAMETERERROR; } } ////////////////////////////////////////////////////////////////////////// // output values : CKParameterOut *pout = beh->GetOutputParameter(0); if(getAsString) { //output the value VxScratch sbuffer(currentCI->realValue->GetDataSize()); CKSTRING buffer = (CKSTRING)sbuffer.Mem(); currentCI->realValue->GetStringValue(buffer); pout->SetStringValue(buffer); }else { CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); if ( beh->GetOutputParameter(0)->GetType() == currentCI->realValue->GetType() ) { pout->CopyValue(currentCI->realValue); }else { pout->SetType(currentCI->realValue->GetType()); return CKBR_PARAMETERERROR; } } using namespace GBLCommon::ParameterTools; ////////////////////////////////////////////////////////////////////////// // output custom attributes : if(outputAttriubtes) { //output unique name : CKParameterOut *poutName = beh->GetOutputParameter(BEH_OUT_INDEX_UNAME); poutName->SetStringValue(currentCI->name.Str()); //output description : CKParameterOut *poutDescription = beh->GetOutputParameter(BEH_OUT_INDEX_DESCRIPTION); poutDescription->SetStringValue(currentCI->description.Str()); //output default value : CKParameterOut *poutDefaultValue = beh->GetOutputParameter(BEH_OUT_INDEX_DEFAULTVALUE); TypeCheckedParameterCopy(poutDefaultValue,currentCI->defaultValue); if(getAsString) { XString outDefValue = GBLCommon::ParameterTools::GetParameterAsString(currentCI->defaultValue); poutDefaultValue->SetStringValue( outDefValue.Str() ); }else{ poutDefaultValue->CopyValue(currentCI->defaultValue,TRUE); } //output flags : int flags = 0 ; beh->SetOutputParameterValue(BEH_OUT_INDEX_FLAGS,¤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; }
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; }
int PlayFFEffect(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx2 = behcontext.Context; ctx = ctx2; HWND mWin = (HWND )ctx->GetMainWindow(); //init and load effect if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); HRESULT result = InitDirectInput(mWin); HRESULT sa = S_OK; if (InitDirectInput(mWin) == S_OK) { XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); OnReadFile(mWin,filename.Str()); beh->ActivateOutput(0); return CKBR_OK; }else{ beh->ActivateOutput(4); return CKBR_OK; } } //play if( beh->IsInputActive(1) ){ beh->ActivateInput(1,FALSE); if (OnPlayEffects2(NULL) != S_OK ){ beh->ActivateOutput(4); return CKBR_OK; } beh->ActivateOutput(1); return CKBR_OK; } //stop the effect if( beh->IsInputActive(2) ){ beh->ActivateInput(2,FALSE); // Stop all previous forces g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); beh->ActivateOutput(2); return CKBR_OK; } // [11/7/2004] //save device release if( beh->IsInputActive(3) ){ beh->ActivateInput(3,FALSE); if ( g_pFFDevice) g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); FreeDirectInput2(); beh->ActivateOutput(3); return CKBR_OK; } return CKBR_OK; }
/* ******************************************************************* * 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 CGBLLAECreateLAE::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; 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) { int dlaeid = laeid; beh->SetOutputParameterValue(0, &dlaeid); //add users to lae if (userIDList) { CGBLCOError res = CGBLLAEAddUser::AddUsers (behaviorContext, laeid, userIDList); if(CGBLCOError::GBLCO_OK != res) { CKParameterOut *parameterOutError = beh->GetOutputParameter(1); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_ADDUSER,GBLLAE_ERROR_ADDUSER_DESC); beh->ActivateOutput(1); } else { beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); } } else { beh->ActivateInput(0, FALSE); beh->ActivateOutput(0); } } else { CKParameterOut *parameterOutError = beh->GetOutputParameter(1); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_STORELAE,GBLLAE_ERROR_STORELAE_DESC); beh->ActivateOutput(1); } return CKBR_OK; }
/* ******************************************************************* * Function: int PacketIterator( 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 PacketIterator(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); CGBLCONetwork *networkInterface = cman->GetNetworkInterface(); ////////////////////////////////////////////////////////////////////////// /* check network -interace : */ if(!networkInterface->IsValid()) { //try to init the network interface : if ( networkInterface->Init() != CGBLCOError::GBLCO_OK ) { return CKBR_PARAMETERERROR; } } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// //output packet info, this infos /*get the last index */ int index = 0; beh->GetLocalParameterValue(0, &index); /* bounding check for the index: if out of range, set to zero and save it.*/ if(index >= networkInterface->GetOutgoingPackets()->Size() ) { index = 0; beh->SetLocalParameterValue(0,&index); beh->ActivateOutput(0); return CKBR_OK; } /*************************************/ /* behavior trigger event processing : */ /* */ /* */ /* Reset/On : sets the index to zero and save it */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); index = 0 ; beh->SetLocalParameterValue(0,&index); beh->ActivateInput(1,TRUE); } /* Loop In : */ if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); if(networkInterface->GetOutgoingPackets()->Size() && index < networkInterface->GetOutgoingPackets()->Size() ) { //the following call is virtual. Both versions of ForwardPacketToScript are passing parameters to this building block. cman->GetNetworkInterface()->ForwardPacketToScript(beh,index); index++; beh->SetLocalParameterValue(0,&index); return CKBR_OK; } } 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; }
int DOUserValueModified(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKMessageManager* mm = behcontext.MessageManager; CKContext* ctx = behcontext.Context; ////////////////////////////////////////////////////////////////////////// //connection id : int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0); if (beh->IsInputActive(1)) { beh->ActivateInput(1,FALSE); beh->ActivateOutput(1); return 0; } ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1); if (!obj) { beh->ActivateOutput(3); return CKBR_ACTIVATENEXTFRAME; } ////////////////////////////////////////////////////////////////////////// //network ok ? xNetInterface *cin = GetNM()->GetClientNetInterface(); if (!cin) { CKParameterOut *pout = beh->GetOutputParameter(2); XString errorMesg("distributed object creation failed,no network connection !"); pout->SetStringValue(errorMesg.Str()); beh->ActivateOutput(3); return CKBR_ACTIVATENEXTFRAME; } //use objects name, if not specified : CKSTRING name= obj->GetName(); IDistributedObjects*doInterface = cin->getDistObjectInterface(); IDistributedClasses*cInterface = cin->getDistributedClassInterface(); XString className((CKSTRING) beh->GetLocalParameterReadDataPtr(0)); XString parameterName((CKSTRING) beh->GetLocalParameterReadDataPtr(1)); xDistributedClass *_class = cInterface->get(className.CStr()); ////////////////////////////////////////////////////////////////////////// //dist class ok ? if (_class==NULL) { beh->ActivateOutput(3); ctx->OutputToConsoleEx("Distributed Class doesn't exists : %s",className.CStr()); return CKBR_ACTIVATENEXTFRAME; } const char * cNAme = _class->getClassName().getString(); int classType = _class->getEnitityType(); int bcount = beh->GetInputParameterCount(); ////////////////////////////////////////////////////////////////////////// //we come in by input 0 : xDistributedObject *dobjDummy = NULL; xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID()); if (!dobj) { beh->ActivateOutput(3); return CKBR_ACTIVATENEXTFRAME; } if (dobj) { xDistributedProperty * prop = dobj->getUserProperty(parameterName.CStr()); if (prop) { if ( dobj->getGhostUpdateBits().testStrict(1 << prop->getBlockIndex())) { CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager()); CKParameterOut *ciIn = beh->GetOutputParameter(1); CKParameterType pType = ciIn->GetType(); int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType)); int userType = xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType); if ( userType ==sType ) { beh->ActivateOutput(2); dobj->getGhostUpdateBits().set(1 << prop->getBlockIndex(),false); switch(xDistTools::ValueTypeToSuperType(prop->getPropertyInfo()->mValueType)) { case vtFLOAT: { xDistributedPoint1F *propValue = static_cast<xDistributedPoint1F*>(prop); if (propValue) { float ovalue = propValue->mLastServerValue; beh->SetOutputParameterValue(1,&ovalue); break; } } case vtVECTOR2D: { xDistributedPoint2F *propValue = static_cast<xDistributedPoint2F*>(prop); if (propValue) { Point2F ovalue = propValue->mLastServerValue; Vx2DVector ovaluex(ovalue.x,ovalue.y); beh->SetOutputParameterValue(1,&ovaluex); break; } } case vtVECTOR: { xDistributedPoint3F *propValue = static_cast<xDistributedPoint3F*>(prop); if (propValue) { Point3F ovalue = propValue->mLastServerValue; VxVector ovaluex(ovalue.x,ovalue.y,ovalue.z); beh->SetOutputParameterValue(1,&ovaluex); break; } } case vtQUATERNION: { xDistributedQuatF*propValue = static_cast<xDistributedQuatF*>(prop); if (propValue) { QuatF ovalue = propValue->mLastServerValue; VxQuaternion ovaluex(ovalue.x,ovalue.y,ovalue.z,ovalue.w); beh->SetOutputParameterValue(1,&ovaluex); break; } } case vtSTRING: { xDistributedString*propValue = static_cast<xDistributedString*>(prop); if (propValue) { TNL::StringPtr ovalue = propValue->mCurrentValue; CKParameterOut *pout = beh->GetOutputParameter(1); XString errorMesg(ovalue.getString()); pout->SetStringValue(errorMesg.Str()); break; } } case vtINTEGER: { xDistributedInteger*propValue = static_cast<xDistributedInteger*>(prop); if (propValue) { int ovalue = propValue->mLastServerValue; beh->SetOutputParameterValue(1,&ovalue); break; } } } } } } } return CKBR_ACTIVATENEXTFRAME; if (beh->IsInputActive(0)) { beh->ActivateOutput(0); } /* ////////////////////////////////////////////////////////////////////////// //we come in by input 0 : if (beh->IsInputActive(0)) { beh->ActivateOutput(0); for (int i = BEH_IN_INDEX_MIN_COUNT ; i < beh->GetInputParameterCount() ; i++ ) { beh->ActivateInput(0,FALSE); xDistributedObject *dobj = doInterface->get(name); if (!dobj) { beh->ActivateOutput(0); return 0; } CKParameterIn *ciIn = beh->GetInputParameter(i); CKParameterType pType = ciIn->GetType(); int sType = vtTools::ParameterTools::GetVirtoolsSuperType(ctx,pam->ParameterTypeToGuid(pType)); xDistributedPropertyArrayType &props = *dobj->getDistributedPorperties(); int propID = _class->getInternalUserFieldIndex(i - BEH_IN_INDEX_MIN_COUNT); if (propID==-1 || propID > props.size() ) { beh->ActivateOutput(1); return 0; } xDistributedProperty *prop = props[propID]; if (prop) { xDistributedPropertyInfo*propInfo = prop->getPropertyInfo(); if (propInfo) { if (xDistTools::ValueTypeToSuperType(propInfo->mValueType) ==sType ) { TNL::U32 currentTime = TNL::Platform::getRealMilliseconds(); switch(propInfo->mValueType) { case E_DC_PTYPE_3DVECTOR: { xDistributedPoint3F * dpoint3F = (xDistributedPoint3F*)prop; if (dpoint3F) { VxVector vvalue; beh->GetInputParameterValue(i,&vvalue); bool update = dpoint3F->updateValue(xMath::getFrom(vvalue),currentTime); } break; } case E_DC_PTYPE_FLOAT: { xDistributedPoint1F * dpoint3F = (xDistributedPoint1F*)prop; if (dpoint3F) { float vvalue; beh->GetInputParameterValue(i,&vvalue); bool update = dpoint3F->updateValue(vvalue,currentTime); } break; } } } } } } beh->ActivateOutput(0); } */ ////////////////////////////////////////////////////////////////////////// //we come in by loop : return 0; }
int DOOwnerChanged(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKMessageManager* mm = behcontext.MessageManager; CKContext* ctx = behcontext.Context; ////////////////////////////////////////////////////////////////////////// //connection id : int connectionID = vtTools::BehaviorTools::GetInputParameterValue<int>(beh,0); ////////////////////////////////////////////////////////////////////////// //we come in by input 0 : if (beh->IsInputActive(0)) { beh->ActivateOutput(0); beh->ActivateInput(0,FALSE); } if (beh->IsInputActive(1)) { beh->ActivateOutput(1); beh->ActivateInput(1,FALSE); return 0; } ////////////////////////////////////////////////////////////////////////// //the object : CK3dEntity *obj= (CK3dEntity*)beh->GetInputParameterObject(1); if (!obj) { beh->ActivateOutput(4); return CKBR_ACTIVATENEXTFRAME; } ////////////////////////////////////////////////////////////////////////// //network ok ? xNetInterface *cin = GetNM()->GetClientNetInterface(); if (!cin) { CKParameterOut *pout = beh->GetOutputParameter(1); XString errorMesg("distributed object creation failed,no network connection !"); pout->SetStringValue(errorMesg.Str()); beh->ActivateOutput(4); return CKBR_ACTIVATENEXTFRAME; } IDistributedObjects*doInterface = cin->getDistObjectInterface(); ////////////////////////////////////////////////////////////////////////// //we come in by input 0 : xDistributedObject *dobj = doInterface->getByEntityID(obj->GetID()); if (!dobj) { CKParameterOut *pout = beh->GetOutputParameter(1); XString errorMesg("There is no such an object"); pout->SetStringValue(errorMesg.Str()); beh->ActivateOutput(4); } else { if (dobj->getOwnershipState().test(1 << E_DO_OS_RELEASED) && dobj->getOwnershipState().test( 1 << E_DO_OS_OWNERCHANGED) ) { beh->ActivateOutput(3); } if (dobj->getOwnershipState().testStrict(1 << E_DO_OS_OWNERCHANGED)) { dobj->getOwnershipState().set( 1<<E_DO_OS_OWNERCHANGED ,false ); int newCLientID = dobj->getUserID(); beh->SetOutputParameterValue(0,&newCLientID); beh->ActivateOutput(2); } } return CKBR_ACTIVATENEXTFRAME; }
//************************************ // 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; }
int GeneralCameraOrbit(const CKBehaviorContext& behcontext,INPUTPROCESSFUNCTION InputFunction) { // Get the behavior CKBehavior* beh = behcontext.Behavior; float delta = behcontext.DeltaTime; // Current state of the behavior CKBOOL stopping; // Indicates the behavior we are stopping if returns, stop otherwise CKBOOL Returns = TRUE; beh->GetLocalParameterValue(LOCAL_RETURN,&Returns); // Stop Entrance, we stop if (beh->IsInputActive(1)) { // Set IO State beh->ActivateInput(1,FALSE); // A protection in case we stop the behavior before having started it VxVector InitialAngles; beh->GetLocalParameterValue(LOCAL_INIT,&InitialAngles); // Get current position VxVector RotationAngles; beh->GetLocalParameterValue(LOCAL_ROT,&RotationAngles); // Stopping Now stopping = TRUE; beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); if ( !Returns || ((RotationAngles.x == 0) && (RotationAngles.y == 0)) ) { beh->ActivateOutput(1,TRUE); return CKBR_OK; } } // Gets the current camera CKCamera *Camera = (CKCamera *) beh->GetTarget(); if( !Camera ) return CKBR_OWNERERROR; // Gets the target informations VxVector TargetPosition; beh->GetInputParameterValue(IN_TARGET_POS,&TargetPosition); CK3dEntity* TargetRef = (CK3dEntity*)beh->GetInputParameterObject(IN_TARGET_REF); ////////////////////////////////////////////// // Gets the input parameters of the behavior ////////////////////////////////////////////// VxVector InitialAngles(0,0,0), RotationAngles(0,0,0); // First entrance, sets the initial values here only if (beh->IsInputActive(0)) { // Sets IO State beh->ActivateInput(0,FALSE); beh->ActivateOutput(0,TRUE); // Not Stopping stopping = FALSE; beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); // Compute the Initial Angles, the radius VxVector InitialPosition; Camera->GetPosition(&InitialPosition, TargetRef); InitialPosition -= TargetPosition; InitialAngles.z = Magnitude(InitialPosition); if ( InitialAngles.z == 0.0f ) { InitialAngles.x = 0.0f; InitialAngles.y = 0.0f; } else { // Vertical Polar Angle float d; InitialPosition.Normalize(); d = DotProduct(InitialPosition,VxVector::axisY()); // bound the value of d to avoid errors due to precision. if (d < -1) d = -1; else if (d > 1) d = 1; InitialAngles.y = acosf(d); // Horizontal Polar Angle InitialPosition.y = 0; if ( (InitialPosition.x == 0.0f) && (InitialPosition.y == 0.0f) && (InitialPosition.z == 0.0f) ) InitialAngles.x = PI/2; else { InitialPosition.Normalize(); d = DotProduct(InitialPosition,VxVector::axisX()); // bound the value of d to avoid eroors due to precision. if (d < -1) d = -1; else if (d > 1) d = 1; InitialAngles.x = acosf(d); d = DotProduct(InitialPosition,VxVector::axisZ()); if (d < 0) InitialAngles.x *= -1; } // In case the camera has the head down, we need to inverse the commands when we go // Up otherwise, the user will have the feeling to turn on the wrong direction. VxVector CamUp; Camera->GetOrientation(NULL,&CamUp,NULL,NULL); if ( CamUp.y < 0 ) { InitialAngles.x += PI; InitialAngles.y *= -1; InitialAngles.x = (float)fmod(InitialAngles.x,2*PI); } } // Reset stopping stopping = FALSE; // Sets the values in memory beh->SetLocalParameterValue(LOCAL_INIT,&InitialAngles); beh->SetLocalParameterValue(LOCAL_ROT,&RotationAngles); beh->SetLocalParameterValue(LOCAL_STOPPING,&stopping); // Only initialization on "On" entrance return CKBR_ACTIVATENEXTFRAME; } // Auto-activation of the behavior beh->GetLocalParameterValue(LOCAL_INIT,&InitialAngles); beh->GetLocalParameterValue(LOCAL_ROT,&RotationAngles); beh->GetLocalParameterValue(LOCAL_STOPPING,&stopping); // Get the input manager CKInputManager *input = (CKInputManager*)behcontext.Context->GetManagerByGuid(INPUT_MANAGER_GUID); // Call the input processing function InputFunction (&RotationAngles,beh,input,delta,Returns,stopping); // Do nothing when initial angle were not initialized. // Simply stop the BB. No output activated. if ( (InitialAngles.x == INF) || (RotationAngles.x == INF) ) return CKBR_OK; // When we are exactly on the top or the bottom of the target, +/-90°, // The LookAt BB won't rotate the camera when we turn right or left as // it already looks at the target. Therefore, when we are at +/-90°, we // add or remove a little something. if ( (RotationAngles.y==PI/2) || (RotationAngles.y == -PI/2) ) { // Get Min, Max // If equals, nothing to change, it is the given value. float MinH = -PI/2; float MaxH = PI/2; beh->GetInputParameterValue(IN_MIN_H, &MinH); beh->GetInputParameterValue(IN_MAX_H, &MaxH); if ( MaxH - MinH > 2 * STEP ) { float sign = (RotationAngles.y > 0) ? 1.0f : -1.0f; if ( MaxH >= sign * PI/2 + STEP ) RotationAngles.y += STEP; else RotationAngles.y -= STEP; } } // We memorize the new state with modulos RotationAngles.x = (float)fmod(RotationAngles.x,2*PI); RotationAngles.y = (float)fmod(RotationAngles.y,2*PI); beh->SetLocalParameterValue(LOCAL_ROT,&RotationAngles); // Computes the coordinates of the camera in the target referential thanks to the // current polar angles and radius informations. And moves the camera VxVector Position; Position = InitialAngles + RotationAngles; Position = Position.z * (cosf(Position.x) * sinf(Position.y) * VxVector::axisX() + sinf(Position.x) * sinf(Position.y) * VxVector::axisZ() + cosf(Position.y) * VxVector::axisY()); Position += TargetPosition; Camera->SetPosition(&Position, TargetRef, FALSE); // Does the camera has a Target ? CK3dEntity *CameraTarget; CKBOOL CameraHasTarget = CKIsChildClassOf(Camera,CKCID_TARGETCAMERA) && (CameraTarget=((CKTargetCamera*)Camera)->GetTarget()); // Orients the Camera. The LookAt implies that when the camera reach // the 90°, it may be flipped and suddently have the head up and down. // Therefore we use the target for target cameras as we have to use the // target. But for free cameras, we do our own look at using our rotation // angle to avoid this problem. if (CameraHasTarget) CameraTarget->SetPosition(&TargetPosition, TargetRef, TRUE); else { // New direction VxVector Dir; Dir = TargetPosition - Position; // Temp Right Value VxMatrix mat; VxVector R(0,0,-1); // Up for (0,0) angle Vx3DMatrixFromRotationAndOrigin(mat,VxVector::axisY(),VxVector(0,0,0),InitialAngles.x + RotationAngles.x); R.Rotate(mat); // Get Up VxVector Up; Up = CrossProduct(R,Dir); Camera->SetOrientation(&Dir,&Up,NULL,TargetRef); //Camera->LookAt(&TargetPosition,TargetRef); } // Stop is finished, reset values. if ( stopping && ((RotationAngles.x == 0) && (RotationAngles.y == 0)) ) { beh->ActivateOutput(1,TRUE); return CKBR_OK; } else // Come back next frame return CKBR_ACTIVATENEXTFRAME; }
/* ******************************************************************* * Function: int CISIteratorBB( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * Parameters : * behaviourContext r Behavior context reference, which gives access to * frequently used global objects ( context, level, manager, etc... ) * * Returns : int, If it is done, it should return CKBR_OK. If it returns * CKBR_ACTIVATENEXTFRAME, the behavior will again be called * during the next process loop. * ******************************************************************* */ int CISIteratorBB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); /*get the last index */ int index = 0; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX, &index); BOOL getFromDB = false; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB); using namespace GBLCommon::BehaviorTools; using namespace GBLCommon::ParameterTools; using namespace Customisation::typedefs; /************************************************************************/ /* behavior trigger event processing : */ /* */ /* */ /* Reset/On : sets the index to zero and save it */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); if (getFromDB) { CKDataArray * resultArray = NULL; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray); if (resultArray) { resultArray->Clear(); while ( resultArray->GetColumnCount() ) resultArray->RemoveColumn(0); } else { resultArray = static_cast<CKDataArray*>(ctx->CreateObject( CKCID_DATAARRAY, "IGBLSMConfigurationAccess::CIS_IDLIST", CK_OBJECTCREATION_DYNAMIC )); } ctx->GetCurrentLevel()->AddObject( resultArray ); ////////////////////////////////////////////////////////////////////////// retrieve list of CI ID's : CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); int idCIS = GetInputParameterValue<int>(beh,BEH_IN_PAR_CIS_ID); smCIS->RetrieveCIList(resultArray,CGBLCISID(idCIS)); beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray,sizeof(CKDataArray*)); int cis_size = resultArray->GetRowCount(); beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cis_size); }else { Customisation::typedefs::CIS* currentCIS = cman->GetCIS(); if(!currentCIS) Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CIS"); } //reset counter : index = 0 ; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateInput(1,TRUE); } //get LA_ID : int cisSize; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIS_SIZE,&cisSize); /* bounding check for the index: if out of range, set to zero and save it.*/ if(index > cisSize -1 ) { index = 0; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateOutput(0); return CKBR_OK; } /* Loop In : */ if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); CGBLCI *currentCI = NULL; //ctx->OutputToConsole("asfasdf"); if (getFromDB) { CKDataArray * resultArray = NULL; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&resultArray); if (resultArray) { CGBLSMStorageManager *storageManager = static_cast<CGBLSMStorageManager *>(ctx->GetManagerByGuid(GBLSMStorageManagerGUID)); IGBLSMConfigurationAccess* smCIS = storageManager->GetConfigurationInterface(); CGBLCIConfigurationController* cman=static_cast<CGBLCIConfigurationController*>(ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID)); IGBLCIAccessInterface * accessInterface = cman->GetCISAccessInterface(); currentCI = new CGBLCI("temp",CKPGUID_INT); int idCI; resultArray->GetElementValue(index,0,&idCI); accessInterface->GetCI(currentCI,idCI); beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_DB_INDEX,&idCI); }else { ctx->OutputToConsole("wrong array"); } }else { Customisation::typedefs::CISIterator it = cman->GetCIS()->GetIteratorByIndex(index); currentCI = (CGBLCI *)*it; } if (currentCI) { //output name : CKParameterOut *outName = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_UNAME); outName->SetStringValue(currentCI->name.Str()); //output description: CKParameterOut *outDescr = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DESCRIPTION); outDescr->SetStringValue(currentCI->description.Str()); //output type int type = ctx->GetParameterManager()->ParameterGuidToType(currentCI->type); beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_TYPE,&type); //output value: CKParameterOut *outStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_VALUE); outStrValue->SetStringValue(GetParameterAsString(currentCI->realValue)); //output default value: CKParameterOut *outDefaultStrValue = beh->GetOutputParameter(BEH_OUT_PAR_INDEX_DEFAULTVALUE); outDefaultStrValue->SetStringValue(GetParameterAsString(currentCI->defaultValue)); //output flags : beh->SetOutputParameterValue(BEH_OUT_PAR_INDEX_FLAGS,¤tCI->flags); }else { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"CISIterator : couldn't find CI Parameter"); } //increase counter : index++; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_INDEX,&index); beh->ActivateOutput(1); } return CKBR_OK; }
//************************************ // Method: PVGet // FullName: PVGet // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PVGet(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); CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); if( !target ) bbErrorME("No Reference Object specified"); pRigidBody *body = NULL; body = GetPMan()->getBody(target); if (!body) bbSErrorME(E_PE_NoBody); pVehicle *v = body->getVehicle(); if (!v) { bbSErrorME(E_PE_NoVeh); } BB_DECLARE_PMAP; /************************************************************************/ /* retrieve settings state */ /***** *******************************************************************/ BBSParameter(O_StateFlags); BBSParameter(O_Acceleration); BBSParameter(O_Steering); BBSParameter(O_MTorque); BBSParameter(O_MPH); BBSParameter(O_RPM); BBSParameter(O_MRPM); BBSParameter(O_WRPM); BBSParameter(O_Gear); /************************************************************************/ /* */ /************************************************************************/ BB_O_SET_VALUE_IF(int,O_StateFlags,v->getStateFlags()); BB_O_SET_VALUE_IF(float,O_Acceleration,v->_cAcceleration); BB_O_SET_VALUE_IF(float,O_Steering,v->_cSteering); BB_O_SET_VALUE_IF(float,O_MPH,v->getMPH()); float wRPM = v->_computeRpmFromWheels(); BB_O_SET_VALUE_IF(float,O_WRPM,wRPM); //---------------------------------------------------------------- // // output new engine values // if (v->isValidEngine()) { BB_O_SET_VALUE_IF(float,O_MTorque,v->getEngine()->GetEngineTorque()); BB_O_SET_VALUE_IF(float,O_RPM,v->getRPM()); BB_O_SET_VALUE_IF(int,O_Gear,v->getGear()); }
//************************************ // 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; }
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; }
//************************************ // 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; }
int PMaterialIterator(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); pFactory *pf = pFactory::Instance(); if (beh->IsInputActive(0)) { beh->ActivateInput(0,FALSE); ////////////////////////////////////////////////////////////////////////// //we reset our session counter int sessionIndex=-1; beh->SetOutputParameterValue(0,&sessionIndex); LMaterials*sResults = NULL; beh->GetLocalParameterValue(0,&sResults); if (!sResults) { sResults = new LMaterials(); }else sResults->clear(); NxScene * scene = GetPMan()->getDefaultWorld()->getScene(); for(int i = 0 ; i < GetPMan()->getDefaultWorld()->getScene()->getNbMaterials() ; i ++) { NxMaterial *currentMaterial = scene->getMaterialFromIndex(i); sResults->push_back(currentMaterial); } beh->SetLocalParameterValue(0,&sResults); if (sResults->size()) { beh->ActivateInput(1); }else { beh->ActivateOutput(0); return 0; } } if( beh->IsInputActive(1) ) { beh->ActivateInput(1,FALSE); int currentIndex=0; CKParameterOut *pout = beh->GetOutputParameter(0); pout->GetValue(¤tIndex); currentIndex++; LMaterials *sResults = NULL; beh->GetLocalParameterValue(0,&sResults); if (!sResults) { beh->ActivateOutput(0); return 0; } if (currentIndex>=sResults->size()) { sResults->clear(); beh->ActivateOutput(0); return 0; } NxMaterial * material = sResults->at(currentIndex); if (material!=NULL) { int sIndex = currentIndex+1; beh->SetOutputParameterValue(0,&sIndex); //SetOutputParameterValue<int>(beh,O_XML,material->xmlLinkID); SetOutputParameterValue<float>(beh,O_DFRICTION,material->getDynamicFriction()); SetOutputParameterValue<float>(beh,O_SFRICTION,material->getStaticFriction()); SetOutputParameterValue<float>(beh,O_RES,material->getRestitution()); SetOutputParameterValue<float>(beh,O_DFRICTIONV,material->getDynamicFrictionV()); SetOutputParameterValue<float>(beh,O_SFRICTIONV,material->getStaticFrictionV()); SetOutputParameterValue<VxVector>(beh,O_ANIS,getFrom(material->getDirOfAnisotropy())); SetOutputParameterValue<int>(beh,O_FCMODE,material->getFrictionCombineMode()); SetOutputParameterValue<int>(beh,O_RCMODE,material->getFrictionCombineMode()); SetOutputParameterValue<int>(beh,O_FLAGS,material->getFlags()); } if(material->userData ) { pMaterial *bMaterial = static_cast<pMaterial*>(material->userData); if (bMaterial && bMaterial->xmlLinkID ) { int xid = bMaterial->xmlLinkID; XString nodeName = vtAgeia::getEnumDescription(GetPMan()->GetContext()->GetParameterManager(),VTE_XML_MATERIAL_TYPE,xid); CKParameterOut *nameStr = beh->GetOutputParameter(O_NAME); nameStr->SetStringValue(nodeName.Str()); } } //pFactory::Instance()->copyTo(beh->GetOutputParameter(O_MATERIAL),material); beh->ActivateOutput(0); } return 0; }
//************************************ // Method: JD6SetParameters // FullName: JD6SetParameters // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int JD6SetParameters(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(0); if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,JT_D6)) { return CK_OK; } // the world : pWorld *worldA=GetPMan()->getWorldByBody(target); pWorld *worldB=GetPMan()->getWorldByBody(targetB); 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); if(bodyA || bodyB) { pJointD6 *joint =static_cast<pJointD6*>(worldA->getJoint(target,targetB,JT_D6)); VxVector linVel = GetInputParameterValue<VxVector>(beh,1); VxVector aVel = GetInputParameterValue<VxVector>(beh,2); VxVector pos = GetInputParameterValue<VxVector>(beh,3); VxQuaternion rot = GetInputParameterValue<VxQuaternion>(beh,4); float ratio = GetInputParameterValue<float>(beh,5); joint->setDriveLinearVelocity(linVel); joint->setDriveAngularVelocity(aVel); joint->setRatio(ratio); joint->setDrivePosition(pos); joint->setDriveRotation(rot); } beh->ActivateOutput(0); } return 0; }
/* ******************************************************************* * Function: BehaviourFunction() * * Description : Is called every frame from Virtools. Executes the behaviour of the BB. * * Parameters : * behContext, r: Passed in from Virtools * * Returns : A CKBR_... return value * ******************************************************************* */ int CGBLListBox::BehaviourFunction(const CKBehaviorContext& behContext) { static VxRect fullUVRect(0.0f, 0.0f, 1.0f, 1.0f); // The default return code is CKBR_ACTIVATENEXTFRAME which forces BehaviourFunction() to be called next frame CK_BEHAVIOR_RETURN behReturn = CKBR_ACTIVATENEXTFRAME; CKBehavior* beh = behContext.Behavior; // Call the helper class to implement our base class functionality // If it returns FALSE, we must return the error code and not perform any behavioural functionality CKBOOL isFocussed = FALSE; if (!CGBLWidget::ExecuteBaseBehaviour(behContext, &isFocussed, &behReturn)) { return behReturn; } // Check for mouse and keyboard inputs CKInputManager* inputManager = (CKInputManager*)behContext.Context->GetManagerByGuid(INPUT_MANAGER_GUID); if (!inputManager) { assert(NULL); return CKBR_OK; } // Get material CKMaterial* material = (CKMaterial*)beh->GetInputParameterObject(eParamInputMaterial); if (!material) { // Output an error - we need a material CGBLWidget::OutputBBErrorMsg(beh, "Please attach a material to the building block"); return CKBR_OK; } // Get font VirtoolsSource::CKTextureFont* font = CGBLWidget::GetFont(behContext.Context, beh); if (!font) { // Output an error - we need a font attached CGBLWidget::OutputBBErrorMsg(beh, "Please attach a font to the building block"); return CKBR_OK; } // Are we using proportional scaling? CKBOOL isPropScaling = CGBLWidget::IsProportionalScaling(beh); // Get the font height CKRenderContext* renderContext = behContext.Context->GetPlayerRenderContext(); float fontHeight = CGBLWidget::GetFontHeight(font, renderContext, isPropScaling); // Get columns array, doesn't matter if we can't get it CKDataArray* columnsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputColumnsArray)); int numColumns = columnsArray ? columnsArray->GetRowCount() : 1; CKSTRING errMsg = ValidateColumnsArray(columnsArray); if (errMsg) { CGBLWidget::OutputBBErrorMsg(beh, errMsg); return CKBR_OK; } // Get the string list array and check it's of the right type CKDataArray* stringListArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputStringListArray)); errMsg = CGBLWidget::ValidateStringListArray(stringListArray, numColumns - 1); if (errMsg) { CGBLWidget::OutputBBErrorMsg(beh, errMsg); return CKBR_OK; } CKBeObject* beObject = beh->GetTarget(); CKRenderObject* renderObject = CKRenderObject::Cast(beObject); // Add a render callback to allow our widget to render itself next frame renderObject->AddPostRenderCallBack(RenderCallback, (void *)behContext.Behavior->GetID(), TRUE); CK2dEntity* ent = CK2dEntity::Cast(renderObject); VxRect clientRect; ent->GetExtents(fullUVRect, clientRect); // Check for Select b-in if (beh->IsInputActive(eBehInputSelect)) { // Reset b-in beh->ActivateInput(eBehInputSelect, FALSE); int select = 0; beh->GetInputParameterValue(eParamInputSelectedItem, &select); // Check we are in single selection mode int selectionType = 0; beh->GetLocalParameterValue(eLocalParamSelectionType, &selectionType); if (selectionType == eSelectionTypeSingleSelection) { // Is this row selectable? CKBOOL selectable = FALSE; stringListArray->GetElementValue(select, CGBLWidget::eStringListArrayColumnSelectable, &selectable); if (selectable || (select < 0) || (select >= stringListArray->GetRowCount()) ) { // Select only this row for (int selRow = 0;selRow < stringListArray->GetRowCount();selRow++) { CKBOOL bSelect = (selRow == select); stringListArray->SetElementValue(selRow, CGBLWidget::eStringListArrayColumnSelected, &bSelect); } // Set focus to this item too if (selectable) beh->SetLocalParameterValue(eLocalParamFocussedItem, &select); // Update selected item p-out beh->SetOutputParameterValue(eParamOutputSelectedItem, &select); // Activate new selection b-out beh->ActivateOutput(eBehOutputNewSelection); // Do we need to scroll? int scrollOffset; beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (!CGBLWidget::GetListRowRect(stringListRect, select, scrollOffset, stringListArray->GetRowCount(), fontHeight, NULL)) { // Set the scroll offset to the focussed item scrollOffset = select; beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); } } } } // Check for Focus b-in if (beh->IsInputActive(eBehInputFocus)) { // Reset b-in beh->ActivateInput(eBehInputFocus, FALSE); // Set focus int nFocus = 0; beh->GetInputParameterValue(eParamInputFocusItem, &nFocus); // Copy to focus item and scroll offset beh->SetLocalParameterValue(eLocalParamFocussedItem, &nFocus); // Do we need to scroll? int scrollOffset; beh->GetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (!CGBLWidget::GetListRowRect(stringListRect, nFocus, scrollOffset, stringListArray->GetRowCount(), fontHeight, NULL)) { // Set the scroll offset to the focussed item scrollOffset = nFocus; beh->SetLocalParameterValue(eLocalParamScrollOffset, &scrollOffset); } } // Only handle mouse clicks and keyboard input when enabled if (CGBLWidget::IsWidgetEnabled(beh)) { // Handle the clicking of the scroll buttons HandleScrollButtonClicks(beh, inputManager, ent, clientRect, fontHeight, behContext.DeltaTime); // Get the string list area VxRect stringListRect = GetRectStringList(clientRect, fontHeight, columnsArray); if (isFocussed) { // Handle the pressing of the arrow keys HandleArrowKeyPresses(beh, inputManager, behContext.DeltaTime, stringListRect, fontHeight, stringListArray); // Handle the pressing of the space bar to select HandleSpaceBarPress(beh, inputManager, stringListArray); } // Handle clicking on the rows HandleListItemClicks(beh, inputManager, ent, stringListRect, stringListArray, fontHeight); } return behReturn; }
/* ******************************************************************* * 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 CGBLLAEGetLAE::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { CKBehavior* beh = behaviorContext.Behavior; CKContext* ctx = behaviorContext.Context; IGBLSMProfileAccess* pin = NULL; CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID); IGBLSMLAAccess *laInterface = storageManager->GetLAInterface(); IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface(); char *laListArrayName = "laList"; CKDataArray* laListArray; laListArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laListArrayName, CK_OBJECTCREATION_DYNAMIC); behaviorContext.CurrentLevel->AddObject( laListArray ); laListArray->InsertColumn( -1, CKARRAYTYPE_INT, "LAID" ); char *laeArrayName = "laeidList"; CKDataArray* laeArray; laeArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laeArrayName, CK_OBJECTCREATION_DYNAMIC); behaviorContext.CurrentLevel->AddObject( laeArray ); laeArray->InsertColumn( -1, CKARRAYTYPE_INT, "LAEID" ); char *laelaArrayName = "laelaIDList"; CKDataArray* laelaArray; laelaArray = (CKDataArray *)ctx->GetObjectByNameAndClass(laelaArrayName,CKCID_DATAARRAY,NULL); if ( !laelaArray ) { laelaArray = (CKDataArray *)ctx->CreateObject(CKCID_DATAARRAY,laelaArrayName, CK_OBJECTCREATION_DYNAMIC); behaviorContext.CurrentLevel->AddObject( laelaArray ); laelaArray->InsertColumn( -1, CKARRAYTYPE_INT, "LAEID" ); laelaArray->InsertColumn( -1, CKARRAYTYPE_STRING, "LAID" ); } else { laelaArray->Clear(); } CGBLCOError res = laInterface->RetrieveLAList(laListArray); if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { int count = laListArray->GetRowCount(); for (int i=0; i < count; i++) { //get list of laes for given la and add it to results list XString xLAID; CKSTRING valueField = NULL; int labelLength = laListArray->GetElementStringValue(i, 0, NULL); valueField = new CKCHAR[labelLength]; labelLength = laListArray->GetElementStringValue(i, 0, valueField); xLAID = valueField; delete valueField; CGBLLAID laid; laid.FromString(xLAID); CGBLCOError res = laeInterface->RetrieveLAEList(laeArray,laid); if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { int count = laeArray->GetRowCount(); for (int j=0; j < count; j++) { CKSTRING valueField = NULL; int labelLength = laeArray->GetElementStringValue(j, 0, NULL); valueField = new CKCHAR[labelLength]; labelLength = laeArray->GetElementStringValue(j, 0, valueField); laelaArray->AddRow(); laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 0, valueField); laelaArray->SetElementStringValue(laelaArray->GetRowCount()-1, 1, xLAID.Str()); delete valueField; } } } beh->ActivateInput(0, FALSE); beh->SetOutputParameterObject(0, laelaArray); beh->ActivateOutput(0); } else { beh->ActivateInput(0, FALSE); CKParameterOut *parameterOutError = beh->GetOutputParameter(1); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_GETLISTOFLAIDS,GBLLAE_ERROR_GETLISTOFLAIDS_DESC); beh->ActivateOutput(1); } behaviorContext.CurrentLevel->RemoveObject(laListArray); ctx->DestroyObject(laListArray); behaviorContext.CurrentLevel->RemoveObject(laeArray); ctx->DestroyObject(laeArray); return CKBR_OK; }
int SetCIConnectionDetails(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; MeasuredObjectiveControllerMgr* mman=(MeasuredObjectiveControllerMgr*)ctx->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID); CGBLSyncInterface * syninterface = CGBLLOArrayHandler::Instance()->GetSynInterface(); /************************************************************************/ /* check interface : */ /* */ if (!syninterface->isValidInterface()) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"interface wrong"); //try to init the network interface : if (!syninterface->Init(ctx)) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"not loaded"); return CKBR_BEHAVIORERROR; } } /************************************************************************/ /* process building block events : */ /* */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); XString message((CKSTRING) beh->GetInputParameterReadDataPtr(0)); int connectionID = -1; beh->GetInputParameterValue(1,&syninterface->connectionID); CKAttributeManager *aMan = static_cast<CKAttributeManager*>(ctx->GetAttributeManager()); ////////////////////////////////////////////////////////////////////////// //store connection details in the scipt dummies attribute : CKAttributeType gblNetworkAtt = aMan->GetAttributeTypeByName( GBL_API_ENTRY("NetworkDetails")); if (!syninterface->messageDummy->HasAttribute(gblNetworkAtt) ) { syninterface->messageDummy->SetAttribute(gblNetworkAtt); } GBLCommon::ParameterTools::SetParameterStructureValue<int>(syninterface->messageDummy->GetAttributeParameter(gblNetworkAtt),0,syninterface->connectionID); GBLCommon::ParameterTools::SetParameterStructureValue<CKSTRING>(syninterface->messageDummy->GetAttributeParameter(gblNetworkAtt),1,syninterface->messageName.Str()); ////////////////////////////////////////////////////////////////////////// //activate and execute the script : behcontext.CurrentScene->Activate(syninterface->synchronizeScript,true); behcontext.CurrentScene->Activate(syninterface->messageDummy,FALSE); syninterface->synchronizeScript->Execute(1); beh->ActivateOutput(0); } return CKBR_OK; }
/* ******************************************************************* * 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; }