/* ******************************************************************* * 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 CGBLBuildCommand::BehaviourFunction(const CKBehaviorContext& behaviorContext) { CKBehavior* behavior = behaviorContext.Behavior; CKContext* context = behaviorContext.Context; if( behavior->IsInputActive(EGBLBuildCommandBehInputs::BuildCommand) ) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); return DoBuildCommand (behaviorContext); } if( behavior->IsInputActive(EGBLBuildCommandBehInputs::CancelOperation)) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); ClearParameterOutputs (behaviorContext); int stateValue = EGBLBuildCommandState::Initial; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); int initialParameterPosition = 0; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition); char *emptyString = ""; behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Cancelled); } if( behavior->IsInputActive(EGBLBuildCommandBehInputs::ReadNextParameterValue)) { DeactivateInputs(behaviorContext); DeactivateOutputs(behaviorContext); int stateValue = 0; behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); if (! ( (stateValue == EGBLBuildCommandState::AwaitingParametersForUntargeted) || (stateValue == EGBLBuildCommandState::AwaitingParametersForNetwork) || (stateValue == EGBLBuildCommandState::GetTargets) ) ) { int stateValue = EGBLBuildCommandState::Initial; behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue); int initialParameterPosition = 0; behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition); char *emptyString = ""; behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1); CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC); behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error); } return DoReadNextParameterValue (behaviorContext); } return CKBR_OK; }
int MidiEvent(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; if( beh->IsInputActive(1) ){ // OFF beh->ActivateInput(1, FALSE); return CKBR_OK; } CKBOOL combiWasOK = FALSE; if( beh->IsInputActive(0) ){ // ON beh->ActivateInput(0, FALSE); beh->SetLocalParameterValue(0, &combiWasOK); } else { beh->GetLocalParameterValue(0, &combiWasOK); } MidiManager *mm = (MidiManager *) behcontext.Context->GetManagerByGuid( MIDI_MANAGER_GUID ); // Channel int channel=0; beh->GetInputParameterValue(0, &channel); int note, count = beh->GetInputParameterCount(); //--- test if all input notes are activated or not for( int a=1 ; a<count ; a++ ){ beh->GetInputParameterValue(a, ¬e); if( !mm->IsNoteActive(note, channel) ) break; } if( a==count ){ // All notes are pressed if( !combiWasOK ){ beh->ActivateOutput(0); combiWasOK = TRUE; beh->SetLocalParameterValue(0, &combiWasOK); return CKBR_ACTIVATENEXTFRAME; } } else { // Not all notes are pressed if( combiWasOK ){ beh->ActivateOutput(1); combiWasOK = FALSE; beh->SetLocalParameterValue(0, &combiWasOK); return CKBR_ACTIVATENEXTFRAME; } } return CKBR_ACTIVATENEXTFRAME; }
int DirToArray(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString Mask((CKSTRING) beh->GetInputParameterReadDataPtr(1)); int rec; beh->GetInputParameterValue(2,&rec); if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); flist.erase(flist.begin(),flist.end()); CKDirectoryParser MyParser(filename.Str(),Mask.Str(),rec); char* str = NULL; while(str = MyParser.GetNextFile()) flist.push_back(XString(str)); counter = 0; beh->ActivateInput(1,TRUE); } if( beh->IsInputActive(1) ){ beh->ActivateInput(1,FALSE); if ( counter < flist.size() ){ XString entry = flist.at(counter); CKParameterOut * pout = beh->GetOutputParameter(0); pout->SetStringValue(entry.Str() ); counter++; beh->SetOutputParameterValue(1,&counter); beh->ActivateOutput(1); }else{ beh->SetOutputParameterValue(1,&counter); counter = 0 ; beh->ActivateOutput(0); } } return 0; }
int FTPLogin(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); HWND win = (HWND)ctx->GetMainWindow(); FtpInit(win); //HFILE hLogFile = _lcreat (LOG_FILE, 0); //FtpLogTo (hLogFile); FtpSetDefaultTimeOut (30); FtpSetPassiveMode(TRUE); FtpSetAsynchronousMode(); int Port; beh->GetInputParameterValue(3,&Port); XString Host((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString User((CKSTRING) beh->GetInputParameterReadDataPtr(1)); XString Pw((CKSTRING) beh->GetInputParameterReadDataPtr(2)); int Login = FtpLogin(Host.Str(),User.Str(),Pw.Str(),win,0); beh->SetOutputParameterValue(0,&Login); if (Login == 0)beh->ActivateOutput(0); else{ beh->ActivateOutput(2); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; } if( beh->IsInputActive(1)){ beh->ActivateInput(1,FALSE); FtpCloseConnection(); FtpRelease (); beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
//************************************ // Method: PCIgnorePair // FullName: PCIgnorePair // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PCIgnorePair(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; CK3dEntity *targetA = (CK3dEntity *) beh->GetInputParameterObject(0); CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(1); int ignore = GetInputParameterValue<int>(beh,2); ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world=GetPMan()->getWorld(target); if(world){ world->cIgnorePair(targetA,targetB,ignore); } beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); } return 0; }
//************************************ // Method: PClothDestroy // FullName: PClothDestroy // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PClothDestroy(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 ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// pCloth *cloth = GetPMan()->getCloth(target->GetID()); if (!cloth) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } pWorld *world = cloth->getWorld(); world->destroyCloth(target->GetID()); beh->ActivateOutput(0); } return 0; }
PyObject *vt_IsInputActive( PyObject * self, PyObject * args ) { PyObject *arg; int size = PyTuple_Size(args); int bid, index, value; PyArg_ParseTuple(args, "ii", &bid, &index); CK_ID cid = bid; if (size!=2) { pym->m_Context->OutputToConsole("PyError : This function only accepts 2 arguments : \n\t bid,index "); Py_RETURN_NONE; } CKBehavior *beh = static_cast<CKBehavior*>(pym->m_Context->GetObject(cid)); if(beh && index < beh->GetInputCount()) { return Py_BuildValue( "i", beh->IsInputActive(index) ? 1:0 ); } Py_RETURN_NONE; }
int LoadCIS(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; GBLConfigurationManager* cman=(GBLConfigurationManager*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); using namespace Customisation::typedefs; using namespace GBLCommon::BehaviorTools; int LA = GetInputParameterValue<int>(beh,0); Customisation::typedefs::CIS* currentCIS = cman->GetCISAccessInterface()->GetCIS(LA); if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); beh->ActivateOutput(1); return CKBR_OK; } return CKBR_OK; }
int SetMousPos(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); DWORD data = 0; DWORD flags = MOUSEEVENTF_ABSOLUTE; // - Has the pointer moved since the last event? flags |= MOUSEEVENTF_MOVE; mouse_event(flags, 100,100, data, 0); beh->ActivateOutput(0); } return 0; }
//************************************ // Method: RegisterAttributeType // FullName: RegisterAttributeType // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int RegisterAttributeType(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); CKAttributeManager* attman = ctx->GetAttributeManager(); CKParameterManager *pMan = ctx->GetParameterManager(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); CKSTRING name = GetInputParameterValue<CKSTRING>(beh,bbI_Name); CKSTRING category = GetInputParameterValue<CKSTRING>(beh,bbI_Category); CKSTRING defValue = GetInputParameterValue<CKSTRING>(beh,bbI_DefValue); int pType = GetInputParameterValue<int>(beh,bbI_PType); CK_CLASSID classId = GetInputParameterValue<CK_CLASSID>(beh,bbI_Class); int attFlags = 0 ; int user = GetInputParameterValue<int>(beh,bbI_User); int save = GetInputParameterValue<int>(beh,bbI_Save); if(user) attFlags|=CK_ATTRIBUT_USER; if(save) attFlags|=CK_ATTRIBUT_TOSAVE; attFlags|=CK_ATTRIBUT_CAN_DELETE; CKAttributeType aIType = attman->GetAttributeTypeByName(name); if (aIType!=-1) { beh->ActivateOutput(1); } int att = attman->RegisterNewAttributeType(name,pMan->ParameterTypeToGuid(pType),classId,(CK_ATTRIBUT_FLAGS)attFlags); if (strlen(category)) { attman->AddCategory(category); attman->SetAttributeCategory(att,category); } if (strlen(defValue)) { attman->SetAttributeDefaultValue(att,defValue); } } pm->populateAttributeFunctions(); pm->_RegisterAttributeCallbacks(); beh->ActivateOutput(0); return 0; }
//************************************ // Method: JDestroy // FullName: JDestroy // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int JDestroy(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: int jointType = GetInputParameterValue<int>(beh,1); CK3dEntity *target = (CK3dEntity *) beh->GetTarget(); CK3dEntity *targetB = (CK3dEntity *) beh->GetInputParameterObject(0); if (!pFactory::Instance()->jointCheckPreRequisites(target,targetB,jointType)) { 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) { pJoint *joint = worldA->getJoint(target,targetB,(JType)jointType); if (joint) { worldA->deleteJoint(joint); } } beh->ActivateOutput(0); } return 0; }
int SetCIConnectionDetails(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; GBLConfigurationManager* cman=(GBLConfigurationManager*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); CGBLSyncInterface *CINetworkInterface = cman->GetSynInterface(); /************************************************************************/ /* check interface : */ /* */ if (!CINetworkInterface->isValidInterface()) { //try to init the network interface : if (!CINetworkInterface->Init(ctx)) { 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,&CINetworkInterface->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 (!CINetworkInterface->messageDummy->HasAttribute(gblNetworkAtt) ) { CINetworkInterface->messageDummy->SetAttribute(gblNetworkAtt); } GBLCommon::ParameterTools::SetParameterStructureValue<int>(CINetworkInterface->messageDummy->GetAttributeParameter(gblNetworkAtt),0,CINetworkInterface->connectionID); GBLCommon::ParameterTools::SetParameterStructureValue<CKSTRING>(CINetworkInterface->messageDummy->GetAttributeParameter(gblNetworkAtt),1,CINetworkInterface->messageName.Str()); ////////////////////////////////////////////////////////////////////////// //activate and execute the script : behcontext.CurrentScene->Activate(CINetworkInterface->synchronizeScript,true); behcontext.CurrentScene->Activate(CINetworkInterface->messageDummy,FALSE); CINetworkInterface->synchronizeScript->Execute(1); beh->ActivateOutput(0); } return CKBR_OK; }
//************************************ // Method: PClothDetachFromShape // FullName: PClothDetachFromShape // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PClothDetachFromShape(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 ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// CK3dEntity*shapeReference = (CK3dEntity *) beh->GetInputParameterObject(bbI_ShapeReference); if (!shapeReference) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } pCloth *cloth = GetPMan()->getCloth(target->GetID()); if (!cloth) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } NxShape *shape = cloth->getWorld()->getShapeByEntityID(shapeReference->GetID()); if(shape) { cloth->detachFromShape((CKBeObject*)shapeReference); } beh->ActivateOutput(0); beh->ActivateOutput(0); } return 0; }
//************************************ // Method: PBSetTriggerMask // FullName: PBSetTriggerMask // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PBSetTriggerMask(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 ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// // the world : pWorld *world = GetPMan()->getWorldByShapeReference(target); if (!world) { beh->ActivateOutput(0); return 0; } if (world) { NxShape *shape = world->getShapeByEntityID(target->GetID()); if (shape) { int onEnter = GetInputParameterValue<int>(beh,bbI_OnEnter); int onStay = GetInputParameterValue<int>(beh,bbI_OnStay); int onLeave = GetInputParameterValue<int>(beh,bbI_OnLeave); shape->setFlag(NX_TRIGGER_ON_ENTER,onEnter); shape->setFlag(NX_TRIGGER_ON_STAY,onStay); shape->setFlag(NX_TRIGGER_ON_LEAVE,onLeave); } } beh->ActivateOutput(0); } return 0; }
int GetFile(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; int Length=0; // Start by In0 if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); XString RemoteFile((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString LocalFile((CKSTRING) beh->GetInputParameterReadDataPtr(1)); char *Type = "Type_B"; int Get = FtpRecvFile ( RemoteFile.Str(),LocalFile.Str(),*Type, FALSE,NULL,NULL); Length = FtpBytesToBeTransferred(); if ( Get !=0 ){ beh->SetOutputParameterValue(3,&Get); beh->ActivateOutput(2); return CKBR_OK; } beh->SetOutputParameterValue(0,&Length); beh->ActivateOutput(0); return CKBR_ACTIVATENEXTFRAME; } beh->GetOutputParameterValue(0,&Length); int down=FtpBytesTransferred(); beh->SetOutputParameterValue(1,&down); float progress=(float)(down*100.0f/Length); // percentage of file downloaded progress /=100.0f; beh->SetOutputParameterValue(2,&progress); if ( down == Length){ beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
//************************************ // Method: PManager // FullName: PManager // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PManager(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); BB_DECLARE_PIMAP; /************************************************************************/ /* retrieve settings state */ /************************************************************************/ BBSParameter(bbI_ReloadXML); /************************************************************************/ /* retrieve values */ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// // load some settings from XML if(sbbI_ReloadXML) { CKSTRING xmlFile = GetInputParameterValue<CKSTRING>(beh,BB_IP_INDEX(bbI_ReloadXML)); pFactory::Instance()->reloadConfig(xmlFile); } } beh->ActivateOutput(0); return 0; }
//************************************ // Method: PClothAttachVertexToPosition // FullName: PClothAttachVertexToPosition // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PClothAttachVertexToPosition(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 ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// pWorld *world = GetPMan()->getDefaultWorld(); if (!world) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } pCloth *cloth = world->getCloth(target); if (!cloth) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } int vertexIndex = GetInputParameterValue<int>(beh,bbI_VertexIndex); VxVector localPosition = GetInputParameterValue<VxVector>(beh,bbI_GlobalPosition); cloth->attachVertexToGlobalPosition(vertexIndex,localPosition); beh->ActivateOutput(0); } return 0; }
/* ******************************************************************* * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) * * Description : The execution function is the function that will be called * during the process loop of the behavior engine, if the behavior * is defined as using an execution function. This function is not * called if the behavior is defined as a graph. This function is the * heart of the behavior: it should compute the essence of the behavior, * in an incremental way. The minimum amount of computing should be * done at each call, to leave time for the other behaviors to run. * The function receives the delay in milliseconds that has elapsed * since the last behavioral process, and should rely on this value to * manage the amount of effect it has on its computation, if the effect * of this computation relies on time. * * 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 CGBLLAETriggerSaving::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { CKBehavior* beh = behaviorContext.Behavior; CKContext* ctx = behaviorContext.Context; CGBLLAEManager *laeManager = (CGBLLAEManager *)ctx->GetManagerByGuid(GBLLAEManagerGUID); if (laeManager) { if ( beh->IsInputActive(0) ) { laeManager->HandleSave ( ctx, beh->GetID() ); beh->ActivateInput(0, FALSE); return CKBR_ACTIVATENEXTFRAME; } } return CKBR_BEHAVIORERROR; }
//************************************ // Method: PClothAddForceAtVertex // FullName: PClothAddForceAtVertex // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int PClothAddForceAtVertex(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 ) return CKBR_OWNERERROR; ////////////////////////////////////////////////////////////////////////// pCloth *cloth = GetPMan()->getCloth(target->GetID()); if (!cloth) { beh->ActivateOutput(0); return CKBR_PARAMETERERROR; } int vertexIndex = GetInputParameterValue<int>(beh,bbI_VertexIndex); VxVector force = GetInputParameterValue<VxVector>(beh,bbI_Force); int forceMode = GetInputParameterValue<int>(beh,bbI_ForceMode); cloth->addForceAtVertex(force,vertexIndex,(ForceMode)forceMode); 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; }
//************************************ // 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; }
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; }
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: 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()); }
/* ******************************************************************* * 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 : 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; }
/* ******************************************************************* * Function: int DecodeAndSendCommand (XString commandString, char separator, const CKBehaviorContext& behaviorContext) * * Description : Decodes the string message passed in into the separate parameters for the command and * sets the output parameter valuess of the corresponding GBLWaitForCommand BB. * * Paramters : * * commandString r command string * separator r parameter separator * behaviorContext r behavior context * * Returns : * 0 on success, otherwise error * ******************************************************************* */ int CGBLCommandController::InvokeCommand (XString commandString, const CKBehaviorContext& behaviorContext) { int returnValue = 0; // 0 indicates success int separatorPos = 0; //position for string separator char separator = CGBLCommandController::commandSeparator; if (strlen (commandString.Str()) <=0) { returnValue = -1; } else { separatorPos = commandString.Find(separator, separatorPos); int commandID = atoi ( (commandString.Substring (0, separatorPos)).Str() ); CKBehavior* targetBB = CGBLCommandController::GetTargetCommand (commandID, behaviorContext); if (targetBB == NULL ) { returnValue = -1; } else if (! (targetBB->IsInputActive(0)) ) { returnValue = -1; } else { int argumentCount = targetBB->GetOutputParameterCount(); int separatorCount = 0; for (unsigned int k=0; k < strlen (commandString.Str()); k++) { if (commandString.Str()[k] == separator) { separatorCount++; } } if ( separatorCount != (argumentCount + 1 ) ) { returnValue = -1; } else { int prevPos = separatorPos+1; for(int i = 0; i < argumentCount ; i++) { separatorPos = commandString.Find(separator, prevPos); if (separatorPos == prevPos) { CKParameterOut* targetParam = targetBB->GetOutputParameter(i); targetParam->SetStringValue (""); } else { XString insert = (commandString.Substring (prevPos, separatorPos-prevPos)).Str(); CKParameterOut* targetParam = targetBB->GetOutputParameter(i); targetParam->SetStringValue (insert.Str()); } prevPos = separatorPos+1; } targetBB->ActivateOutput(0); } } } return returnValue; }
/* ******************************************************************* * 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; }
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; }
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; }