CKERROR PMaterialIteratorCB(const CKBehaviorContext& behcontext) { CKBehavior *beh = behcontext.Behavior; CKContext *ctx = beh->GetCKContext(); switch(behcontext.CallbackMessage) { case CKM_BEHAVIORLOAD: case CKM_BEHAVIORATTACH: { break; } case CKM_BEHAVIORSETTINGSEDITED: { } } return CKBR_OK; }
CKERROR CallPythonFuncCB2(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); int p_count = beh->GetOutputParameterCount(); /*while( (BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); }*/ XString name("PyFuncX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1)); if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0) { XString name("PyFileX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0)); beh->SetName(name.Str()); break; } beh->SetName(name.Str()); break; } case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD : { XString name("PyFuncX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1)); beh->SetName(name.Str()); if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0) { XString name("PyFileX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0)); beh->SetName(name.Str()); break; } } } return CKBR_OK; }
/* ******************************************************************* * Function: int RetrieveCICB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR RetrieveCICB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); BOOL getAsString,outputAttriubtes = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); ////////////////////////////////////////////////////////////////////////// // get ci by string if(getAsString) { CKParameterOut* ciValue = beh->GetOutputParameter(0); ciValue->SetType(pm->ParameterGuidToType(CKPGUID_STRING)); } if(outputAttriubtes) { beh->CreateOutputParameter("Default Value",CKPGUID_STRING); beh->CreateOutputParameter("Unique name",CKPGUID_STRING); beh->CreateOutputParameter("Description",CKPGUID_STRING); beh->CreateOutputParameter("Runtime flags",CIPRTFLAGSGUID); beh->CreateOutputParameter("Type",CKPGUID_PARAMETERTYPE); } int p_count = beh->GetOutputParameterCount(); while( (outputAttriubtes ? BEH_OUT_MAX_COUNT : BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); } } } return CKBR_OK; }
/* ******************************************************************* * Function: int CISIteratorCB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR CISIteratorCB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); CGBLCIConfigurationController* cman=(CGBLCIConfigurationController*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIORRESET: { CKDataArray *array = NULL; beh->SetLocalParameterValue(BEH_LOCAL_PAR_INDEX_CIID_LIST,&array); break; } case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED : { assert(beh && ctx); BOOL getFromDB = false; beh->GetLocalParameterValue(BEH_LOCAL_PAR_INDEX_DB_MODE,&getFromDB); if( getFromDB && ( beh->GetInputParameterCount() == BEH_IN_INDEX_MIN_COUNT ) ) { beh->CreateInputParameter("CIS ID", CKPGUID_INT); } ////////////////////////////////////////////////////////////////////////// //remove all pIns : int p_count = beh->GetInputParameterCount(); while( (getFromDB ? BEH_IN_INDEX_MAX_COUNT : BEH_IN_INDEX_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveInputParameter( --p_count) ); } break; } } 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 CGBLCHPopulateAvailableRecipients::BehaviourFunction( const CKBehaviorContext& behaviorContext ) { enum { GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID }; enum { AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID }; CKBehavior *beh = behaviorContext.Behavior; CGBLCOError localError(CGBLCOError::EGBLCOErrorType::GBLCO_OK); if (!beh) { assert(NULL); return CKBR_BEHAVIORERROR; } // Get profile controller CGBLProfileManager* profileManager = static_cast<CGBLProfileManager*>(beh->GetCKContext()->GetManagerByGuid(GBLProfileManagerGUID)); if (!profileManager) { assert(NULL); return CKBR_BEHAVIORERROR; } // Get GBL Loader manager GBLLDManager* loaderManager = static_cast<GBLLDManager*>(beh->GetCKContext()->GetManagerByGuid(GBLLDManagerGUID)); if (!profileManager) { assert(NULL); return CKBR_BEHAVIORERROR; } // Check we have been passed an array CKDataArray* availableRecipientsArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputAvailableRecipientsArray)); if (!availableRecipientsArray) { return CKBR_BEHAVIORERROR; } // Clear array and set up structure availableRecipientsArray->Clear(); while (availableRecipientsArray->GetColumnCount()) availableRecipientsArray->RemoveColumn(0); availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_STRING, "Name"); availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_INT, "VirtoolsUserID"); availableRecipientsArray->InsertColumn(-1, CKARRAYTYPE_PARAMETER, "GBLTeamID", GUID_TEAM_ID); // Create a temporary array of active players to be filled in by the Profile Controller CKDataArray* tmpActivePlayersArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY, "CGBLCHPopulateAvailableRecipients temp array", CK_OBJECTCREATION_DYNAMIC); if (!tmpActivePlayersArray) { assert(NULL); return CKBR_BEHAVIORERROR; } // Create temporary array for team names to be filled in by the Profile Controller CKDataArray* tmpTeamNameArray = (CKDataArray*)beh->GetCKContext()->CreateObject(CKCID_DATAARRAY, "CGBLCHPopulateAvailableRecipients temp array 2", CK_OBJECTCREATION_DYNAMIC); if (!tmpTeamNameArray) { assert(NULL); return CKBR_BEHAVIORERROR; } // Get active players localError = profileManager->GetActivePlayers(tmpActivePlayersArray); if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK) { localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION); localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError); } else { // Collate Team IDs into local array CGBLTeamID teamID; XArray<CGBLTeamID> arrayOfTeamIDs; XArray<XString> arrayOfTeamNames; char* stringBuffer = NULL; for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++) { // Get Team ID teamID = 0; if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_GBLTEAMID, &teamID)) { if ((int)teamID) { // Have we already got this team ID in the array? if (arrayOfTeamIDs.End() == arrayOfTeamIDs.Find(teamID)) { // No, add it to the array arrayOfTeamIDs.PushBack(teamID); } } } } // Copy team IDs and names into AvailableRecipients array for (int team = 0;team < arrayOfTeamIDs.Size();team++) { availableRecipientsArray->AddRow(); int row = availableRecipientsArray->GetRowCount() - 1; assert(row == team); // Get team name teamID = arrayOfTeamIDs[team]; localError = profileManager->GetProfileField((const)teamID, "Name", tmpTeamNameArray); if (localError != CGBLCOError::EGBLCOErrorType::GBLCO_OK) { localError.SetCode(GBLCH_ERRORCODE_UNABLETOGETPROFILEINFORMATION); localError.SetDescription((XString)"An error occurred while attempting to retrieve profile information: " + (const char*)localError); break; } // Place team name into destination array stringBuffer = new char[tmpTeamNameArray->GetElementStringValue(0, 0, NULL) + 1]; tmpTeamNameArray->GetElementStringValue(0, 0, stringBuffer); availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer); delete stringBuffer; stringBuffer = NULL; // Set user ID as 0 int virtoolsUserID = 0; availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID); // Set team ID availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &arrayOfTeamIDs[team]); } } if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { CGBLTeamID teamID; char* stringBuffer = NULL; int virtoolsUserID; // Now copy players (which includes facilitators) into the destination array for (int row = 0;row < tmpActivePlayersArray->GetRowCount();row++) { // Get User ID virtoolsUserID = 0; if (tmpActivePlayersArray->GetElementValue(row, GETACTIVEPLAYERSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID)) { // Check this user ID valid if (virtoolsUserID) { // Add new row to destination array availableRecipientsArray->AddRow(); int row = availableRecipientsArray->GetRowCount() - 1; // Set Virtools user ID availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserID); // Get name and put into dest array stringBuffer = new char[tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, NULL) + 1]; tmpActivePlayersArray->GetElementStringValue(row, GETACTIVEPLAYERSARRAY_COLUMN_USERNAME, stringBuffer); availableRecipientsArray->SetElementStringValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_USERNAME, stringBuffer); delete stringBuffer; stringBuffer = NULL; // Set team ID to 0 teamID = 0; availableRecipientsArray->SetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_GBLTEAMID, &teamID); } } } } if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Remove the current user from the array // Get current Virtools User ID from GBL Loader int currentVirtoolsUserID = loaderManager->GetVirtoolsUserID(); for (int row = availableRecipientsArray->GetRowCount() - 1;row >= 0;row--) { int virtoolsUserId = 0; availableRecipientsArray->GetElementValue(row, AVAILABLERECIPIENTSARRAY_COLUMN_VIRTOOLSUSERID, &virtoolsUserId); if (virtoolsUserId == currentVirtoolsUserID) { // This row is the current user. Remove it availableRecipientsArray->RemoveRow(row); } } } // Free temporary arrays beh->GetCKContext()->DestroyObject(tmpActivePlayersArray); beh->GetCKContext()->DestroyObject(tmpTeamNameArray); // Did an error occur? if (localError == CGBLCOError::EGBLCOErrorType::GBLCO_OK) { // Output success beh->ActivateOutput(eBehOutputDone); } else { // Output the error TGBLError::SetTGBLError(beh->GetOutputParameter(eParamOutputError), localError, localError, (CKSTRING)(const char*)localError); beh->ActivateOutput(eBehOutputError); } // All done return CKBR_OK; }
/* ******************************************************************* * Function: int GetCIValueCB( const CKBehaviorContext& behaviorContext ) * * Description : The Behavior Callback function is called by Virtools when various events happen * in the life of a BuildingBlock. Exactly which events trigger a call to the * Behavior Callback function is defined in the Behavior Prototype, along with the * declaration of the function pointer * * Parameters : * behaviourContext r Behavior context reference, which gives * access to frequently used global objects * ( context, level, manager, etc... ) * * Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. * ******************************************************************* */ CKERROR GetCIValueCB(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); BOOL getByName,getAsString,outputAttriubtes,outputOnChange = false; beh->GetLocalParameterValue(BEH_SETTINGS_GET_BY_NAME,&getByName); beh->GetLocalParameterValue(BEH_SETTINGS_GET_AS_STRING,&getAsString); beh->GetLocalParameterValue(BEH_SETTINGS_GET_CUSTOM_ATTRIBUTES,&outputAttriubtes); beh->GetLocalParameterValue(BEH_SETTINGS_OUTPUT_ON_CHANGE,&outputOnChange); ////////////////////////////////////////////////////////////////////////// //we add beh - in - trigger, if we are in event mode: if (outputOnChange) { beh->AddInput("Stop"); //change to correct name : CKBehaviorIO * out_trigger = beh->GetOutput(0); out_trigger->SetName("Change detected"); }else { //change to correct name : CKBehaviorIO * out_trigger = beh->GetOutput(0); out_trigger->SetName("Finish"); } //remove unecessary beh - input triggers from even-mode : int count = beh->GetInputCount(); while( (outputOnChange ? BEH_IN_TRIGGER_MAX_COUNT : BEH_IN_TRIGGER_MIN_COUNT ) <= count ) beh->DeleteInput( count-- ); CKParameterIn *ciIn = beh->GetInputParameter(0); if( getByName ) { ciIn->SetType(pm->ParameterGuidToType(CKPGUID_STRING)); ciIn->SetName("unique name of the configurable information"); }else { ciIn->SetType(pm->ParameterGuidToType(CIPARAMETERGUID)); ciIn->SetName("Configurable Information"); } if(outputAttriubtes) { beh->CreateOutputParameter("Default Value",CKPGUID_STRING); beh->CreateOutputParameter("Unique name",CKPGUID_STRING); beh->CreateOutputParameter("Description",CKPGUID_STRING); beh->CreateOutputParameter("Runtime flags",CIPRTFLAGSGUID); beh->CreateOutputParameter("Type",CKPGUID_PARAMETERTYPE); } int p_count = beh->GetOutputParameterCount(); while( (outputAttriubtes ? BEH_OUT_MAX_COUNT : BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); } } } return CKBR_OK; }