Esempio n. 1
0
/**Part of the mouse interactor:
 * Interpret mouse wheel as a zoom operation.
 */
void ViewWrapper2D::mouseWheelSlot(int x, int y, int delta, int orientation, Qt::MouseButtons buttons)
{
	// scale zoom in log space
	double val = log10(mZoom2D->getFactor());
	val += delta / 120.0 / 20.0; // 120 is normal scroll resolution, x is zoom resolution
	double newZoom = pow(10.0, val);

	mZoom2D->setFactor(newZoom);

	Navigation(mServices).centerToTooltip(); // side effect: center on tool
}
Esempio n. 2
0
int Interpret(const char *cmd, int redirect,char *target,int bg)
{
    //解析执行一条命令
    //cmd中包含两部分,一是命令执行文件本省,第二是argv[]
    if(strlen(cmd)==0) return 1;
    int argc;
    char **argv=ResolveCmd(cmd,&argc);
    if(!strcmp(argv[0],"cd"))
    {
        if(argc>1) ChangeDir(argv[1]);
        else    //开启文件导航系统
        {
            char finalpath[path_max];
            Navigation(finalpath);
            ChangeDir(finalpath);
        }
    }
    else if(!strcmp(argv[0],"jobs"))
    {
        ShowJobs();
    }
    else if(!strcmp(argv[0],"fg"))
    {   //前台运行
        ForeGround(argv[1]);
    }
    else if(!strcmp(argv[0],"stop"))
        StopPid(argv[1]);
    else if(!strcmp(argv[0],"continue"))
        ContinuePid(argv[1]);
    else if(!strcmp(argv[0],"bg"))  //后台继续运行
        ContinuePid(argv[1]);
    else if(!strcmp(argv[0],"history"))
        catHistory();
    else if(!strcmp(argv[0],"echopath"))
        EchoPath();
    else if(!strcmp(argv[0],"addpath"))
        AddPath(argv[1]);
    else if(!strcmp(argv[0],"exit"))
        return Exit();
    else
    {
        int i=0,find=0;
        char filepath[PATH_MAX+1]={'\0'};
        find=isEXE(argv[0]);    //输入的命令是否带'/',可能指向EXEfile
        if(find)
            strcpy(filepath,argv[0]);
        else    //从环境变量的目录中搜索
        {
            while(!find && i<envpath_num)
            {
                //依次从各个环境变量的路径中寻找
                find=SearchFile(envpath[i++],argv[0],filepath);
            }
        }
        if(find && bg==0)   //找到命令,前台运行
        {
            int pid=fork(); run_pid=pid; strcpy(run_cmd,cmd);
            if(pid>0) {
                waitpid(pid,NULL,WUNTRACED); run_pid=0; run_cmd[0]='\0';
            }
            else
            {
                if(redirect==1) OutputRedirect(target);
                else if(redirect==0) InputRedirect(target);
                mask_signals();     //子进程屏蔽信号
                if(execv(filepath,argv)==-1)
                    printf("不能打开指定文件\n");
                exit(0);
            }
           
        }
        else if(find && bg==1)  //找到命令,后台运行
        {
            //后台运行
            int pid=fork();
            if(pid>0)
            {
                //父进程把后台进程添加到job管理系统中
                int pos=0;  //找空位置,优先填满前面被删掉的位置
                while(pos<jobmanager.jobnum && jobmanager.jobs[pos].status>0)
                    pos++;
                //结果是pos占到了jobnum之前的被删位置,或者是pos==jobnum
                jobmanager.jobs[pos].pid=pid;
                int i=0;
                for(;i<strlen(cmd);i++)
                    jobmanager.jobs[pos].cmd[i]=cmd[i]; //保存cmd信息
                jobmanager.jobs[pos].cmd[i++]='&'; //保存cmd信息
                jobmanager.jobs[pos].cmd[i]='\0'; //结尾
                jobmanager.jobs[pos].status=1;   //正常运行 
                if(pos==jobmanager.jobnum) {
                    jobmanager.jobnum++;    //只有pos开辟了新的坑位时,才占位
                    if(jobmanager.jobnum>jobnum_max)
                        printf("jobs中的后台程序即将达到上限\n");
                }
                printf("[%d] %d\n",pos+1,pid);
            }
            else
            {
                //子进程负责后台执行
                if(redirect==1) OutputRedirect(target);
                else if(redirect==0) InputRedirect(target);
                mask_signals();     //信号屏蔽
                if(execv(filepath,argv)==-1)
                    printf("不能打开指定文件\n");
                exit(0);
                //有个问题:子进程退了之后,父进程怎么查询?会出现相同pid的情况吗?貌似不会
            }
        }
        else printf("Unknwon cmd.\n");
    }
     //程序结束后要清理argv
    int i=0;
    for(;i<argc;i++)
    {
        free(argv[i]);
    }
    free(argv);

    return 1;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Run this Bot's AI for one tick.
//-----------------------------------------------------------------------------
void CSDKBot::BotThink()
{
	// Make sure we stay being a bot
	AddFlag( FL_FAKECLIENT );

	if ( IsEFlagSet(EFL_BOT_FROZEN) )
		return;

	CUserCmd cmd;
	Q_memset( &cmd, 0, sizeof( cmd ) );

	ConVarRef bot_freeze("bot_freeze");

	if ( !IsAlive() )
	{
		HandleRespawn(cmd);
	}
	else if (bot_mimic.GetBool())
	{
		CBasePlayer *pPlayer = UTIL_PlayerByIndex( bot_mimic.GetInt()  );
		if ( pPlayer && pPlayer->GetLastUserCommand() )
		{
			cmd = *pPlayer->GetLastUserCommand();

			ConVarRef bot_mimic_yaw_offset("bot_mimic_yaw_offset");
			cmd.viewangles[YAW] += bot_mimic_yaw_offset.GetFloat();

			ConVarRef bot_crouch("bot_crouch");
			if( bot_crouch.GetInt() )
				cmd.buttons |= IN_DUCK;
		}
	}
	else if (!bot_freeze.GetBool())
	{
		trace_t tr_front;
		Vector Forward;
		AngleVectors(GetLocalAngles(), &Forward);
		UTIL_TraceHull( GetLocalOrigin()+Vector(0,0,5), GetLocalOrigin() + Vector(0,0,5) + (Forward * 50), GetPlayerMins(), GetPlayerMaxs(), MASK_PLAYERSOLID, this, COLLISION_GROUP_NONE, &tr_front );

		// enemy acquisition
		if( !GetEnemy() || RecheckEnemy() || !GetEnemy()->IsAlive() )
		{
			if( GetEnemy() && !GetEnemy()->IsAlive() )
				ResetNavigationParams();

			AcquireEnemy();

			m_flTimeToRecheckEnemy = gpGlobals->curtime + 1.0f;
		}

		// assume we have an enemy from now on

		InfoGathering();

		Attack(cmd);

		if( m_flTimeToRecheckStuck < gpGlobals->curtime )
			CheckStuck(cmd);

		if( m_flNextDealObstacles < gpGlobals->curtime )
			DealWithObstacles(tr_front.m_pEnt, cmd);

		Navigation(cmd);

		CheckNavMeshAttrib(&tr_front, cmd);
	}

	// debug waypoint related position
	/*for( int i=0; i<m_Waypoints.Count(); i++ )
	{
	NDebugOverlay::Cross3DOriented( m_Waypoints[i].Center, QAngle(0,0,0), 5*i+1, 200, 0, 0, false, -1 );
	}*/

	RunPlayerMove( cmd, gpGlobals->frametime );
}
Esempio n. 4
0
File: main.c Progetto: APROB/APROB
int main(int argc, char** argv)
{
    // Initialise le microcontroleur
    Settings();
    DelayN1ms(30);
    // Initialise l'UART
    InitTextIO();
    // Initialise les interruptions
    ISR_Settings();

    initAsservissement();
    initOdometrie();

    // Configure tous les moteurs à l'arret
    OC1RS = 0;
    OC2RS = 0;
    OC3RS = 0;
    OC4RS = 0;

    // Active les modules pour les PWM
    OC1CONbits.OCM = 0b110;
    OC2CONbits.OCM = 0b110;
    OC3CONbits.OCM = 0b110;
    OC4CONbits.OCM = 0b110;

    uartNextOut = 0;
    uartCommande = 0;

    Cycle1 = 0;
    Cycle2 = 0;
    CYCLE1_FLAG = 0;
    CYCLE2_FLAG = 0;

    // Temporisation de 1 seconde
    RtTimer = 10;
    // Boucle Principale
    while(1)
    {
        if(PID_CALC_FLAG)
        {
            Pid1();
            Pid2();

            compteurVitesse ++;
            if(compteurVitesse == 10)
            {
                Vitesse[L] = VitesseCpteur[L]/400; // 400 = 10 échantillons x 40 pour le 1/40 mm/s => Le résultat est en mm/s
                Vitesse[R] = VitesseCpteur[R]/400;
                compteurVitesse = 0;
                VitesseCpteur[L] = 0;
                VitesseCpteur[R] = 0;
            }
            PID_CALC_FLAG = 0;
        }

        if(CYCLE1_FLAG)
        {
            Odometrie();
            if(ordreEnCours != DEBUG)
            {
                Orientation();
            }
            CYCLE1_FLAG=0;
        }

        if(CYCLE2_FLAG)
        {
            Navigation();
            CYCLE2_FLAG=0;
        }

        // blink LED
        if (RtTimer <= 0)
        {
            RtTimer = 10;
            LED_BLINK = !LED_BLINK;
        }



 
        if( uartCommande )
        {
            GererCommande();
        }
    }
    return (EXIT_SUCCESS);
}