/* ******************************************************************* * 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 GBLLDGetSetup::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { CKBehavior *beh; CKContext *context; GBLLDManager *GBLLDMan; XString DBName; CKBOOL logging; XString ODBCName; XString proxyLogin; XString proxyPassword; XString serverAddress; XString serverLogin; XString serverPassword; CKBOOL serverMode; XString userName; int virtoolsUserID; CKBOOL webPlayerMode; int ConnectionID; if ( (beh = behaviorContext.Behavior) == NULL ) return CKBR_BEHAVIORERROR; if ( (context = behaviorContext.Context) == NULL ) return CKBR_BEHAVIORERROR; if ( (GBLLDMan = (GBLLDManager*)context->GetManagerByGuid(GBLLDManagerGUID)) == NULL ) return CKBR_BEHAVIORERROR; beh->ActivateInput( POS_I_IN, FALSE ); // Force the reading of the attributes GBLLDMan->ReadSetup(); ConnectionID = GBLLDMan->GetConnectionID(); DBName = GBLLDMan->GetDBName(); logging = GBLLDMan->IsLogging(); ODBCName = GBLLDMan->GetODBCName(); proxyLogin = GBLLDMan->GetProxyLogin(); proxyPassword = GBLLDMan->GetProxyPassword(); serverAddress = GBLLDMan->GetServerAddress(); serverLogin = GBLLDMan->GetServerLogin(); serverPassword = GBLLDMan->GetServerPassword(); serverMode = GBLLDMan->GetServerMode(); userName = GBLLDMan->GetUserName(); webPlayerMode = GBLLDMan->IsWebplayerMode(); virtoolsUserID = GBLLDMan->GetVirtoolsUserID(); beh->SetOutputParameterValue( POS_OP_CONNECTIONID, &ConnectionID ); beh->SetOutputParameterValue( POS_OP_DBNAME, DBName.CStr(), DBName.Length() ); beh->SetOutputParameterValue( POS_OP_LOGGING, &logging ); beh->SetOutputParameterValue( POS_OP_ODBCNAME, ODBCName.CStr(), ODBCName.Length() ); beh->SetOutputParameterValue( POS_OP_PROXYLOGIN, proxyLogin.CStr(), proxyLogin.Length() ); beh->SetOutputParameterValue( POS_OP_PROXYPASSWORD, proxyPassword.CStr(), proxyPassword.Length() ); beh->SetOutputParameterValue( POS_OP_SERVERADDRESS, serverAddress.CStr(), serverAddress.Length() ); beh->SetOutputParameterValue( POS_OP_SERVERLOGIN, serverLogin.CStr(), serverLogin.Length() ); beh->SetOutputParameterValue( POS_OP_SERVERMODE, &serverMode ); beh->SetOutputParameterValue( POS_OP_SERVERPASSWORD, serverPassword.CStr(), serverPassword.Length() ); beh->SetOutputParameterValue( POS_OP_USERNAME, userName.CStr(), userName.Length() ); beh->SetOutputParameterValue( POS_OP_WEBPLAYERMODE, &webPlayerMode ); beh->SetOutputParameterValue( POS_OP_VIRTOOLSUSERID, &virtoolsUserID ); beh->ActivateOutput( POS_O_OUT, TRUE ); return CKBR_OK; }
CGBLCOError GBLCommon::ResourceTools::SaveObject( CKBeObject*beo, XString filename) { if (!beo) { return CGBLCOError(CGBLCOError::GBLCO_LOCAL,"Invalid Object",GBL_ERROR_ID_GBL_COMMON); } //todo : adding checks for saving ability if(!filename.Length()) { return CGBLCOError(CGBLCOError::GBLCO_LOCAL,"No path specified",GBL_ERROR_ID_GBL_COMMON); } CKERROR res = CK_OK; CKObjectArray* oa = CreateCKObjectArray(); oa->InsertAt(beo->GetID()); res = beo->GetCKContext()->Save(filename.Str(),oa,0xFFFFFFFF,NULL); DeleteCKObjectArray(oa); return CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,CKErrorToString(res),GBL_ERROR_ID_GBL_COMMON); }
//************************************ // Method: GetDocument // FullName: vtPhysics::pFactory::GetDocument // Access: public // Returns: TiXmlDocument* // Qualifier: // Parameter: XString filename //************************************ TiXmlDocument* pFactory::getDocument(XString filename) { XString fname(filename.Str()); if ( fname.Length() ) { XString fnameTest = ResolveFileName(fname.CStr()); if ( fnameTest.Length()) { TiXmlDocument* result = new TiXmlDocument(fnameTest.Str()); result->LoadFile(fnameTest.Str()); result->Parse(fnameTest.Str()); TiXmlNode* node = result->FirstChild( "vtPhysics" ); if (!node) { GetPMan()->m_Context->OutputToConsoleEx("PFactory : Couldn't load Document : %s",filename.Str()); return NULL; }else { return result; } } } return NULL; }
/* ******************************************************************* * 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; }
NxMaterialDesc* pFactory::createMaterialFromEntity(CKBeObject*object) { ////////////////////////////////////////////////////////////////////////// //sanity checks : if (!object ) { return NULL; } if (!object->HasAttribute(GetPMan()->att_surface_props)) { return NULL; } ////////////////////////////////////////////////////////////////////////// CKParameterManager *pm = object->GetCKContext()->GetParameterManager(); int parameterType = pm->ParameterGuidToType(VTE_XML_MATERIAL_TYPE); NxMaterialDesc *result = new NxMaterialDesc(); using namespace vtTools::AttributeTools; XString nodeName; int enumID = GetValueFromAttribute<int>(object,GetPMan()->att_surface_props,0); if (enumID==0) { goto takeFromAttribute; } CKEnumStruct *enumStruct = pm->GetEnumDescByType(parameterType); if ( enumStruct ) { for (int i = 0 ; i < enumStruct->GetNumEnums() ; i ++ ) { if(i == enumID) { nodeName = enumStruct->GetEnumDescription(i); if (nodeName.Length()) { result = createMaterialFromXML(nodeName.CStr(),getDefaultDocument()); if (result) { return result; } } } } } takeFromAttribute : { float dynamicFriction = GetValueFromAttribute<float>(object,GetPMan()->att_surface_props,1); if (dynamicFriction >=0.0f) { result->dynamicFriction =dynamicFriction; } float statFriction = GetValueFromAttribute<float>(object,GetPMan()->att_surface_props,2); if (statFriction>=0.0f) { result->staticFriction=statFriction; } float rest = GetValueFromAttribute<float>(object,GetPMan()->att_surface_props,3); if (rest>=0.0f) { result->restitution=rest; } float dynamicFrictionV = GetValueFromAttribute<float>(object,GetPMan()->att_surface_props,4); if (dynamicFrictionV >=0.0f) { result->dynamicFrictionV =dynamicFrictionV; } float staticFrictionV = GetValueFromAttribute<float>(object,GetPMan()->att_surface_props,5); if (staticFrictionV>=0.0f) { result->staticFriction=staticFrictionV; } VxVector anis = GetValueFromAttribute<VxVector>(object,GetPMan()->att_surface_props,6); if (anis.Magnitude()>=0.01f) { result->dirOfAnisotropy=pMath::getFrom(anis); } int fMode = GetValueFromAttribute<int>(object,GetPMan()->att_surface_props,7); if (fMode !=-1) { result->frictionCombineMode=(NxCombineMode)fMode; } int rMode = GetValueFromAttribute<int>(object,GetPMan()->att_surface_props,8); if (rMode !=-1) { result->restitutionCombineMode=(NxCombineMode)rMode; } return result; } return result; }
void SaveSettings() { HKEY hKey; TCHAR szRegistryKey[MAX_LOADSTRING], szTextSizeKey[MAX_LOADSTRING]; TCHAR szLeftFormatKey[MAX_LOADSTRING], szRightFormatKey[MAX_LOADSTRING]; LoadString(g_hInstance, IDS_REGISTRY, szRegistryKey, MAX_LOADSTRING); LoadString(g_hInstance, IDS_LEFTFORMAT, szLeftFormatKey, MAX_LOADSTRING); LoadString(g_hInstance, IDS_RIGHTFORMAT, szRightFormatKey, MAX_LOADSTRING); LoadString(g_hInstance, IDS_TEXTSIZE, szTextSizeKey, MAX_LOADSTRING); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegistryKey, 0, 0, &hKey) == ERROR_SUCCESS) { RegSetValueEx(hKey, szLeftFormatKey, 0, REG_SZ, (BYTE *) g_xsLeftFormat.GetBuffer(), g_xsLeftFormat.Length() * sizeof(TCHAR)); RegSetValueEx(hKey, szRightFormatKey, 0, REG_SZ, (BYTE *) g_xsRightFormat.GetBuffer(), g_xsRightFormat.Length() * sizeof(TCHAR)); RegSetValueEx(hKey, szTextSizeKey, 0, REG_DWORD, (BYTE *) &g_iTextSize, sizeof(int)); RegCloseKey (hKey); } }
/* ******************************************************************* * 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; }