예제 #1
0
int TextureSinus(const CKBehaviorContext& behcontext)
{
    CKBehavior* beh = behcontext.Behavior;

    // we get the amount value
    float xamp=0.1f;
    beh->GetInputParameterValue(0, &xamp);

    // we get the amount value
    float yamp=0.1f;
    beh->GetInputParameterValue(1, &yamp);

    float l= 1.0f;
    beh->GetInputParameterValue(2, &l);

    // we get the saved uv's
    VxUV* savedUV = (VxUV*) beh->GetLocalParameterReadDataPtr(0);

    // we get the interpolated mesh
    CKMesh *mesh = (CKMesh*) beh->GetInputParameterObject(4);

    int channel = -1;
    beh->GetInputParameterValue(3, &channel);
    int channelcount = mesh->GetChannelCount();
    if (channel < -1 || channel >= channelcount) {
        beh->ActivateInput(0, FALSE);
        beh->ActivateOutput(0);
        return CKBR_PARAMETERERROR;
    }

    CKDWORD Stride;
    VxUV *uvarray = (VxUV*) mesh->GetModifierUVs(&Stride,channel);
    int pointsNumber = mesh->GetModifierUVCount(channel);

    float time;
    beh->GetLocalParameterValue(1, &time);

    float t;
    for( int i=0 ; i<pointsNumber ; i++, uvarray =(VxUV *)((BYTE *)uvarray + Stride)) {
        t = ((float)i/pointsNumber-0.5f)*4.0f+time*l;
        uvarray->u = savedUV[i].u + ( 0.5f - savedUV[i].u ) * xamp * cosf(t);
        uvarray->v = savedUV[i].v + ( 0.5f - savedUV[i].v ) * yamp * sinf(t);
    }
    mesh->ModifierUVMove(channel);

    float pi = 3.1415926535f;
    time += behcontext.DeltaTime * 0.001f;

    if(l*time > 2*pi)
        time -= (2*pi / l);

    beh->SetLocalParameterValue(1, &time);

    beh->ActivateInput(0, FALSE);
    beh->ActivateOutput(0);
    return CKBR_OK;
}
예제 #2
0
파일: MidiEvent.cpp 프로젝트: gbaumgart/vt
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, &note);
    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;
}
예제 #3
0
int NeoSetMousePos(const CKBehaviorContext& BehContext)
{
	CKBehavior* beh = BehContext.Behavior;
	int x, y;
	
 	beh->GetInputParameterValue(0,&x);
	beh->GetInputParameterValue(1,&y);
	SetCursorPos(x,y);
	beh->ActivateOutput(0);
	CKBOOL keepActive;
	beh->GetInputParameterValue(2,&keepActive);
	if(keepActive)return CKBR_ACTIVATENEXTFRAME;
	return CKBR_OK;
}
예제 #4
0
int AddNodalLink(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;
	CKContext* ctx = behcontext.Context;
	CKAttributeManager* attman = ctx->GetAttributeManager();
	beh->ActivateInput(0,FALSE);
	beh->ActivateOutput(0);

	CKGroup* group = (CKGroup*)beh->GetInputParameterObject(0);			
	CKParameterOut* param = group->GetAttributeParameter(attman->GetAttributeTypeByName(Network3dName));
	if(!param) throw "Given Group isn't a Network";
	N3DGraph* graph;
	param->GetValue(&graph);

	CK3dEntity* s = (CK3dEntity*)beh->GetInputParameterObject(1);
	CK3dEntity* e = (CK3dEntity*)beh->GetInputParameterObject(2);
	float b;
	beh->GetInputParameterValue(3,&b);
	graph->InsertEdge(s,e,b);
	beh->ActivateOutput(0);





	return CKBR_OK;
}
예제 #5
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 CGBLLAESetLoadState::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior* beh = behaviorContext.Behavior;
  	CKContext* ctx = behaviorContext.Context;

	CGBLLAEManager *laeManager = (CGBLLAEManager *)ctx->GetManagerByGuid(GBLLAEManagerGUID);

	if (laeManager)
	{
		int state = 0;
		beh->GetInputParameterValue(0, &state);
		laeManager->SetLoadState(state);
		
		beh->ActivateInput(0, FALSE);
		beh->ActivateOutput(0);
	}
	else
	{
		beh->ActivateInput(0, FALSE);
		CKParameterOut *parameterOutError = beh->GetOutputParameter(0);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_CANTSETLAEIDENTITY,GBLLAE_ERROR_CANTSETLAEIDENTITY_DESC);
		beh->ActivateOutput(1);
	}

    return CKBR_OK;
}
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;
}
/*
 *******************************************************************
 * 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 CGBLCHChatMoveHomogeneous::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
	CKBehavior *beh = behaviorContext.Behavior;
	CKContext *ctx = behaviorContext.Context;
	

	CK2dEntity *chatFrame = (CK2dEntity *)beh->GetInputParameterObject(0);

	if (chatFrame)
	{
		float left, top, right, bottom;

		beh->GetInputParameterValue(3, &left);
		beh->GetInputParameterValue(3, &top);
		beh->GetInputParameterValue(2, &right);
		right += left;
		beh->GetInputParameterValue(1, &bottom);
		bottom += top;

		VxRect rect(left, top, right, bottom);
		chatFrame->SetHomogeneousCoordinates ( 1 );
		int res = chatFrame->SetHomogeneousRect ( rect );
		if (res == 0)
		{
			beh->ActivateInput (0, 0);
			beh->ActivateOutput (0);
		}
		else
		{
			beh->ActivateInput (0, 0);
			beh->ActivateOutput (1);
		}
	}
	else
	{
		beh->ActivateInput (0, 0);
		beh->ActivateOutput (1);
	}
		
    return CKBR_OK;
}
예제 #8
0
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;
}
예제 #9
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;
}
예제 #10
0
파일: SetZoom.cpp 프로젝트: gbaumgart/vt
int SetZoom(const CKBehaviorContext& behcontext)
{
	CKBehavior* beh = behcontext.Behavior;

	CKCamera *cam = (CKCamera *) beh->GetTarget();
  if( !cam ) return CKBR_OWNERERROR;

  float zoom = 50; // Zoom in mm
  beh->GetInputParameterValue(0, &zoom);

  float fov = 2.0f * atanf(18.0f / zoom);
  cam->SetFov( fov );

  beh->ActivateInput(0, FALSE);
	beh->ActivateOutput(0);

	return CKBR_OK;
}
예제 #11
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 CGBLLAESetLAEData::BehaviourFunction( const CKBehaviorContext& behaviorContext )
{
    CKBehavior* beh = behaviorContext.Behavior;
    CKContext* ctx = behaviorContext.Context;

    IGBLSMProfileAccess* pin = NULL;
    CGBLSMStorageManager *storageManager = (CGBLSMStorageManager *)ctx->GetManagerByGuid(GBLSMStorageManagerGUID);
    IGBLSMLAEAccess *laeInterface = storageManager->GetLAEInterface();

    int cisid;
    CGBLLAID laid;
    XString xlaid;
    XString laeName;
    int laeState = 0;

    CKDataArray *userIDList = NULL;

    CGBLLAEID laeid = 0;

    int dlaeid;
    beh->GetInputParameterValue(1, &dlaeid);
    laeid = dlaeid;

    GBLLAEDataType::GetGBLLAEData(beh->GetInputParameter(0)->GetRealSource(), cisid, laeName, laeState, xlaid, &userIDList );

    laid.FromString(xlaid);

    CGBLCOError res = laeInterface->StoreLAE (laeState, cisid, laid, laeName, &laeid);
    if ( res == CGBLCOError::EGBLCOErrorType::GBLCO_OK)
    {
        beh->ActivateInput(0, FALSE);
        beh->ActivateOutput(0);
    }
    else
    {
        CKParameterOut *parameterOutError = beh->GetOutputParameter(0);
        TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLLAE_ERROR_STORELAE,GBLLAE_ERROR_STORELAE_DESC);
        beh->ActivateOutput(1);

    }

    return CKBR_OK;
}
예제 #12
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;
}
예제 #13
0
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;
}
예제 #14
0
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;

}
예제 #15
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;
}
예제 #16
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;
}
예제 #17
0
/*
*******************************************************************
* Function: int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext)
*
* Description : Read next provided argument from SetParameterString p-in and add it to command string
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
*******************************************************************
*/
int CGBLBuildCommand::DoReadNextParameterValue (const CKBehaviorContext& behaviorContext)
{
	CKBehavior* behavior = behaviorContext.Behavior;
  	CKContext* context = behaviorContext.Context;

	int gblBuildCommandState;
	behavior->GetLocalParameterValue (gblBuildCommandStateLocalPos, &gblBuildCommandState);

	switch (gblBuildCommandState)
	{
		case EGBLBuildCommandState::Initial:
		{
			CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
			TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE,GBLFC_ERROR_BUILDCOMMAND_INVALID_STATE_DESC);
			behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
			return CKBR_OK;
		}
		break;

		case EGBLBuildCommandState::GetTargets:
		{
			//check if the array of recipients is provided
			void* recipients = NULL;
			recipients = behavior->GetInputParameter (EGBLBuildCommandParamInputs::SetDests)->GetDirectSource()->GetValueObject();
			if (recipients == NULL)
			{
				CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
				TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS,GBLFC_ERROR_BUILDCOMMAND_NO_DESTS_DESC);
				behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
				return CKBR_OK;
			}

			int targetID = 0;
			behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID);

			XString commandString;
			commandString << targetID << CGBLCommandUtil::commandSeparator;
			
			behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 );

			//check if there are more arguments
			return DoHandleNextNetworkArgument (behaviorContext);
		}
		break;

		case EGBLBuildCommandState::AwaitingParametersForNetwork:
		case EGBLBuildCommandState::AwaitingParametersForUntargeted:
		{

			CKSTRING commandString = (CKSTRING) behavior->GetLocalParameter(commandStringLocalPos)->GetReadDataPtr();
			CKSTRING argumentString = (CKSTRING) behavior->GetInputParameter(EGBLBuildCommandParamInputs::SetParameterString)->GetReadDataPtr();

			//char commandString[512];
			//char argumentString[512];
			//behavior->GetLocalParameterValue(commandStringLocalPos,&commandString);

			//behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetParameterString, &argumentString);

			if (strlen (argumentString) == 0)
			{
				behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue);
				return CKBR_OK;
			}

			CKSTRING argumentType = (CKSTRING) behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetArgumentType)->GetReadDataPtr(); 
			if (  (strcmp (argumentType, "Integer") == 0) || (strcmp (argumentType, "Float") == 0))
			{
				bool isArgumentNumeric = CGBLCommandUtil::IsNumeric(argumentString);
				if (!isArgumentNumeric)
				{
					behavior->ActivateOutput (EGBLBuildCommandBehOutputs::InvalidValue);
					return CKBR_OK;
				}
			}

			XString updatedCommandString;
			updatedCommandString << commandString << argumentString << CGBLCommandUtil::commandSeparator;
			
			behavior->SetLocalParameterValue(commandStringLocalPos, updatedCommandString.Str(), strlen(updatedCommandString.Str()) + 1 );

			if (gblBuildCommandState == EGBLBuildCommandState::AwaitingParametersForUntargeted)
			{
				return DoHandleNextLocalArgument (behaviorContext);
			}

			return DoHandleNextNetworkArgument (behaviorContext);

		}
		break;

		default:
		break;
	}
	return CKBR_OK;
}
예제 #18
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 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;
}
예제 #20
0
/*
*******************************************************************
* Function: int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext)
*
* Description : Starts building the command. Find required GBLWaitForCommand BB,
*				determine its target (GBLTarget) and take corresponded actions.
*
* Parameters :
*    behaviourContext    r   Behavior context reference, which gives 
*                            access to frequently used global objects 
*                            ( context, level, manager, etc... )
*
*******************************************************************
*/
int CGBLBuildCommand::DoBuildCommand(const CKBehaviorContext& behaviorContext)
{
	CKBehavior* behavior = behaviorContext.Behavior;
  	CKContext* context = behaviorContext.Context;

	//set to initial state
	int stateValue = EGBLBuildCommandState::Initial;
	behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos, &stateValue);

	int initialParameterPosition = 0;
	behavior->SetLocalParameterValue (currentParameterPositionLocalPos, &initialParameterPosition);

	char *emptyString = "";
	behavior->SetLocalParameterValue(commandStringLocalPos, emptyString, strlen(emptyString)+1);

	ClearParameterOutputs(behaviorContext);


	int targetID = 0;
	behavior->GetInputParameterValue (EGBLBuildCommandParamInputs::SetCommandID, &targetID);


	CKBehavior* targetBB = CGBLCommandUtil::GetTargetCommand (targetID, behaviorContext);

	if (targetBB == NULL)
	{
		CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
		TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND,GBLFC_ERROR_BUILDCOMMAND_TARGET_NOT_FOUND_DESC);

		behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
		return CKBR_OK;
	}
	CK_ID targetBBID = targetBB->GetID();
	behavior->SetLocalParameterValue (targetBBLocalPos, &targetBBID);

	int gblTatgetType = -1;
	targetBB->GetLocalParameterValue (CGBLWaitForCommand::EGBLWaitForCommandLocalVariables::EGBLFCTarget, &gblTatgetType);

	switch (gblTatgetType)
	{
	case CGBLWaitForCommand::EGBLFCTarget::Untargeted:
		{
			XString commandString;
			commandString << targetID << CGBLCommandUtil::commandSeparator;

			behavior->SetLocalParameterValue(commandStringLocalPos, commandString.Str(), strlen(commandString.Str()) + 1 );

			return DoHandleNextLocalArgument (behaviorContext);
		}
		break;

		case CGBLWaitForCommand::EGBLFCTarget::Player:
		case CGBLWaitForCommand::EGBLFCTarget::Team:
		{
			//set state to GetTargets
			int stateValue = EGBLBuildCommandState::GetTargets;
			behavior->SetLocalParameterValue (gblBuildCommandStateLocalPos,&stateValue);

			//get list of recipients
			behavior->SetOutputParameterValue (EGBLBuildCommandParamOutputs::GetTarget, &gblTatgetType); 
			behavior->ActivateOutput (EGBLBuildCommandBehOutputs::ListRecipients);
			return CKBR_OK;
		}
		break;

		default:
			CKParameterOut *parameterOutError = behavior->GetOutputParameter(EGBLBuildCommandParamOutputs::GetError);
			TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT,GBLFC_ERROR_BUILDCOMMAND_UNSPECIFIED_RECIPIENT_DESC);

			behavior->ActivateOutput (EGBLBuildCommandBehOutputs::Error);
		break;
	}
	return CKBR_OK;
}