当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_JoystickUpdate函数代码示例

本文整理汇总了C++中SDL_JoystickUpdate函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickUpdate函数的具体用法?C++ SDL_JoystickUpdate怎么用?C++ SDL_JoystickUpdate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_JoystickUpdate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SDL_JoystickUpdate

  int JoystickInput::getEvent(bool ignoreConfig, bool checkLock)
  {
#ifdef HAVE_SDL_H
    if (!haveJoystick)
      return 0;
    mutex_.lock();
    if ((!ignoreConfig && !config.enableJoystick) || (checkLock && lockFlag)) {
      mutex_.unlock();
      return 0;
    }
    if (eventIndex < eventCnt) {
      // consume any buffered events first
      int     retval = events[eventIndex];
      if (++eventIndex == eventCnt) {
        eventCnt = 0;
        eventIndex = 0;
      }
      mutex_.unlock();
      return retval;
    }
    {
      double  t = updateTimer.getRealTime();
      if (t < 0.005) {
        mutex_.unlock();
        return 0;
      }
      // poll joystick input at 5 ms intervals
      updateTimer.reset((t - 0.005) * 0.5);
    }
    SDL_JoystickUpdate();
    eventCnt = 0;
    eventIndex = 0;
    if (!ignoreConfig) {
      int     thresholdInt = int(config.axisThreshold * 32767.0 + 0.5);
      bool    autoFireState = false;
      double  pwmPhase = 0.0;
      if (config.enablePWM) {
        double  tt = 1.0 / config.pwmFrequency;
        double  t = pwmTimer.getRealTime();
        if (t >= tt) {
          t = std::fmod(t, tt);
          pwmTimer.reset(t);
        }
        pwmPhase = t * config.pwmFrequency;
        pwmPhase *= (1.0 - config.axisThreshold);
        pwmPhase += (config.axisThreshold * 0.5);
      }
      if (config.enableAutoFire) {
        double  tt = 1.0 / config.autoFireFrequency;
        double  t = autoFireTimer.getRealTime();
        if (t >= tt) {
          t = std::fmod(t, tt);
          autoFireTimer.reset(t);
        }
        autoFireState = (t < (tt * config.autoFirePulseWidth));
      }
      for (int i = 0; i < axisCnt; i++) {
        int     newState =
            int(SDL_JoystickGetAxis(reinterpret_cast<SDL_Joystick *>(
                                        sdlDevices[axes[i].devNum]),
                                    axes[i].axisNum));
        if (!config.enablePWM) {
          if (newState > axes[i].prvInputState) {
            if (newState >= (-thresholdInt)) {
              if (axes[i].prvOutputState < 0)
                events[eventCnt++] = -(keyCodeBase + (i << 1));
              if (newState >= thresholdInt) {
                if (axes[i].prvOutputState <= 0)
                  events[eventCnt++] = (keyCodeBase + (i << 1) + 1);
                axes[i].prvOutputState = 1;
              }
              else
                axes[i].prvOutputState = 0;
            }
          }
          else if (newState < axes[i].prvInputState) {
            if (newState < thresholdInt) {
              if (axes[i].prvOutputState > 0)
                events[eventCnt++] = -(keyCodeBase + (i << 1) + 1);
              if (newState < (-thresholdInt)) {
                if (axes[i].prvOutputState >= 0)
                  events[eventCnt++] = (keyCodeBase + (i << 1));
                axes[i].prvOutputState = -1;
              }
              else
                axes[i].prvOutputState = 0;
            }
          }
        }
        else {
          int     newOutputState = 0;
          if (newState > 0) {
            if ((double(newState) * (1.0 / 32768.0)) >= pwmPhase)
              newOutputState = 1;
          }
          else if (newState < 0) {
            if ((double(newState) * (-1.0 / 32768.0)) > pwmPhase)
              newOutputState = -1;
          }
          if (newOutputState != axes[i].prvOutputState) {
//.........这里部分代码省略.........
开发者ID:lgblgblgb,项目名称:ep128emu,代码行数:101,代码来源:joystick.cpp

示例2: update_joysticks

/* update joystick states */
void update_joysticks(void)
{
  SDL_JoystickUpdate();
}
开发者ID:uekstrom,项目名称:airstrike,代码行数:5,代码来源:joystick.c

示例3: get_binds

static void get_binds(config_file_t *conf, int player, int joypad)
{
   if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) < 0)
   {
      fprintf(stderr, "Failed to init joystick subsystem.\n");
      exit(1);
   }

   SDL_Joystick *joystick;
   int num = SDL_NumJoysticks();
   if (joypad >= num)
   {
      fprintf(stderr, "Cannot find joystick at index #%d, only have %d joystick(s) available ...\n", joypad, num);
      exit(1);
   }

   joystick = SDL_JoystickOpen(joypad);
   if (!joystick)
   {
      fprintf(stderr, "Cannot open joystick.\n");
      exit(1);
   }

   int last_axis = -1;
   bool block_axis = false;

   int num_axes = SDL_JoystickNumAxes(joystick);
   int *initial_axes = (int*)calloc(num_axes, sizeof(int));
   assert(initial_axes);

   SDL_PumpEvents();
   SDL_JoystickUpdate();
   for (int i = 0; i < num_axes; i++)
   {
      Sint16 initial = SDL_JoystickGetAxis(joystick, i);
      if (abs(initial) < 20000)
         initial = 0;

      // Certain joypads (such as XBox360 controller on Linux) has a default negative axis for shoulder triggers,
      // which makes configuration very awkward.
      // If default negative, we can't trigger on the negative axis, and similar with defaulted positive axes.

      if (initial)
         fprintf(stderr, "Axis %d is defaulted to %s axis value of %d\n", i, initial > 0 ? "positive" : "negative", (int)initial);

      initial_axes[i] = initial;
   }

   fprintf(stderr, "Configuring binds for player #%d on joypad #%d (%s)\n",
         player + 1, joypad, SDL_JoystickName(joypad));
   fprintf(stderr, "Press Ctrl-C to exit early.\n");
   fprintf(stderr, "\n");

   for (unsigned i = 0; i < sizeof(binds) / sizeof(struct bind) && (g_use_misc || !binds[i].is_misc) ; i++)
   {
      fprintf(stderr, "%s\n", binds[i].keystr);

      bool done = false;
      SDL_Event event;
      int value;
      const char *quark;
      unsigned player_index = binds[i].is_misc ? 0 : player;

      while (SDL_WaitEvent(&event) && !done)
      {
         switch (event.type)
         {
            case SDL_JOYBUTTONDOWN:
               fprintf(stderr, "\tJoybutton pressed: %d\n", (int)event.jbutton.button);
               done = true;
               config_set_int(conf, binds[i].confbtn[player_index], event.jbutton.button);
               break;

            case SDL_JOYAXISMOTION:
            {
               bool same_axis        = last_axis == event.jaxis.axis;
               bool require_negative = initial_axes[event.jaxis.axis] > 0;
               bool require_positive = initial_axes[event.jaxis.axis] < 0;

               // Block the axis config until we're sure axes have returned to their neutral state.
               if (same_axis)
               {
                  if (abs(event.jaxis.value) < 10000 ||
                        (require_positive && event.jaxis.value < 0) ||
                        (require_negative && event.jaxis.value > 0))
                     block_axis = false;
               }

               // If axes are in their neutral state, we can't allow it.
               if (require_negative && event.jaxis.value >= 0)
                  break;
               if (require_positive && event.jaxis.value <= 0)
                  break;

               if (block_axis)
                  break;

               if (abs(event.jaxis.value) > 20000)
               {
                  last_axis = event.jaxis.axis;
//.........这里部分代码省略.........
开发者ID:damariei,项目名称:RetroArch-Rpi,代码行数:101,代码来源:retroarch-joyconfig.c

示例4: configure

int
configure()
{
	SDL_Event mevent;
	int option=1,i;

	drawConfigure(option);

	while(1) {
		while(SDL_PollEvent(&mevent)) {
    			if (mevent.type==SDL_QUIT)
    				return 0;

			/* joystick control for the menu */
			if(joy[0])
			{
				SDL_JoystickUpdate();

				i=SDL_JoystickGetAxis(joy[0],1);
				if(i>4200)
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_DOWN;
				}
				if(i<-4200)
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_UP;
				}

				if(SDL_JoystickGetButton(joy[0], 0))
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_RETURN;
				}

				if(SDL_JoystickGetButton(joy[0], 1))
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_ESCAPE;
				}
			}

			if(mevent.type==SDL_KEYDOWN) {
				if(mevent.key.keysym.sym==SDLK_ESCAPE)
					return 1;
				if(mevent.key.keysym.sym==SDLK_DOWN ||
					mevent.key.keysym.sym==SDLK_s) {
					option++;
					if(option>4)
						option=1;
					drawConfigure(option);
				}
				if(mevent.key.keysym.sym==SDLK_UP ||
					mevent.key.keysym.sym==SDLK_w) {
					option--;
					if(option<1)
						option=4;
					drawConfigure(option);
				}
				if(mevent.key.keysym.sym==SDLK_RETURN) {
					switch(option) {
						default:
						break;
						case 1:
							if(joy[0]) {
								conf.control[0]=conf.control[0] ? 0 : 1;
								drawConfigure(option);
							}
						break;
						case 2:
							if(joy[1]) {
								conf.control[1]=conf.control[1] ? 0 : 1;
								drawConfigure(option);
							}
						break;
						case 3:
							conf.sound--;
							if(conf.sound<0)
								conf.sound=3;

							if(sound) {
								if(bgm) {
									Mix_FreeMusic(bgm);
									bgm=NULL;
								}

								for(i=0;i<NUM_EFX;i++)
									if(efx[i]) {
										Mix_FreeChunk(efx[i]);
										efx[i]=NULL;
									}
								Mix_CloseAudio();
							}

							if(conf.sound!=NO_SOUND) {
								switch(conf.sound) {
										default:
										case SOUND_HI:
											i=44100;
//.........这里部分代码省略.........
开发者ID:OS2World,项目名称:GAMES-ACTION-DodginDiamondII-,代码行数:101,代码来源:menu.c

示例5: getName

int
getName(char *name, int place, int playern)
{
	Uint32 tick;
	SDL_Event mevent;
	int pos=0, i=0;
	char ckey='a';

	if(joy[playern-1] && player[playern-1].joy)
	{
		name[pos]=ckey;
		name[pos+1]=0;
	}

	drawGetName(name,place,playern);

	tick=SDL_GetTicks();
	while(1) {
		while(SDL_PollEvent(&mevent)) {
    			if (mevent.type==SDL_QUIT)
    				return 0;

			/* joystick control */
			if(joy[playern-1] && player[playern-1].joy)
			{
				SDL_JoystickUpdate();

				i=SDL_JoystickGetAxis(joy[playern-1],1);
				if(i>4200)
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_DOWN;
				}
				if(i<-4200)
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_UP;
				}
				i=SDL_JoystickGetAxis(joy[playern-1],0);
				if(i>4200)
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_RIGHT;
				}

				if(SDL_JoystickGetButton(joy[playern-1], 0))
				{
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_RETURN;
				}

				if(SDL_JoystickGetButton(joy[playern-1], 1))
				{
					pos++;
					mevent.type=SDL_KEYDOWN;
					mevent.key.keysym.sym=SDLK_BACKSPACE;
				}
			}

		
			if(mevent.type==SDL_KEYDOWN) {
				if(mevent.key.keysym.sym==SDLK_ESCAPE) {
					if(!name[0])
						strcpy(name,"nobody");
					return 1;
				}

				if(mevent.key.keysym.sym==SDLK_DOWN)
				{
					ckey--;

					if(ckey<'0')
						ckey='z';
					if(ckey+1=='a')
						ckey='9';

					name[pos]=ckey;
					name[pos+1]=0;
					drawGetName(name,place,playern);

					continue;
				}

				if(mevent.key.keysym.sym==SDLK_UP)
				{
					ckey++;

					if(ckey>'z')
						ckey='0';
					if(ckey-1=='9')
						ckey='a';

					name[pos]=ckey;
					name[pos+1]=0;
					drawGetName(name,place,playern);

					continue;
				}
			
				if(mevent.key.keysym.sym==SDLK_RIGHT)
//.........这里部分代码省略.........
开发者ID:OS2World,项目名称:GAMES-ACTION-DodginDiamondII-,代码行数:101,代码来源:menu.c

示例6: state_main_menu

int state_main_menu(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    TTF_Font *font_credit = font_load("res/asia.ttf", 20);
    image *bg_image = image_load("res/main.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
    const int item_nb = 2;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;
	//bool is_in_game = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
    bool timerset = false;
    #endif

    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
       if ((now-start)>50) {
            timerset=false;
            SDL_JoystickUpdate();
            int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
            switch (joystate){
                case SDL_HAT_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                break;
                case SDL_HAT_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                break;
            }
       }
       #endif



        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                done = true;
                break;
            case SDL_KEYUP:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                    break;
                case SDLK_RETURN:
                    while (choice_current == IN_GAME)
                    {
                        unit_default_param(g_game.v_unit, g_game.unit_nb);
                        choice_current = state_in_game(screen);
                        if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                        {
                            choice_current = IN_GAME;
                            break;
                        }
                    }
                    if (choice_current == OPTION)state_options(screen);
                    break;

                default:
                    break;
                }
            break;
            case SDL_JOYBUTTONDOWN:
                switch(event.jbutton.button)
                {
//.........这里部分代码省略.........
开发者ID:odrevet,项目名称:GE,代码行数:101,代码来源:main.c

示例7: state_options

int state_options(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    image *bg_image = image_load("res/options.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
	//int initial_unit_nb = g_game.unit_nb;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
        unsigned int start=0;
        int timerset = false;
    #endif
SDL_EnableKeyRepeat(50, 10);
    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
           if ((now-start)>50) {
                timerset=false;
                SDL_JoystickUpdate();
                int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                       if (choice_current <= 1){
                        sample_play(select);
                        choice_current++;
                        }
                    break;
                    case SDL_HAT_UP:
                        if (choice_current > 1){
                            sample_play(select);
                            choice_current--;
                        }
                    break;
                    case SDL_HAT_LEFT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill >= 0.01)
                                g_game.block_fill -= 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb > 2)
                            {
                                g_game.unit_nb -= 1;
                            }
                        }
                    break;
                    case SDL_HAT_RIGHT:
                        if (choice_current == 2)
                        {
                            if (g_game.block_fill < 0.99)
                                g_game.block_fill += 0.01;
                        }
                        else if (choice_current == 1)
                        {
                            if (g_game.unit_nb < UNIT_MAX)
                            {
                                g_game.unit_nb++;
                            }
                        }
                    break;
                    default:
                    break;
                }
           }
        #endif


        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                exit(EXIT_SUCCESS);
                break;
                case SDL_JOYBUTTONDOWN:
                    if(event.jbutton.button == 6){
                        done = true;
                    }
                break;
            case SDL_KEYDOWN:
                switch ( event.key.keysym.sym )
                {
//.........这里部分代码省略.........
开发者ID:odrevet,项目名称:GE,代码行数:101,代码来源:main.c

示例8: mrb_sdl2_joystick_joystick_update

static mrb_value
mrb_sdl2_joystick_joystick_update(mrb_state *mrb, mrb_value self)
{
  SDL_JoystickUpdate();
  return self;
}
开发者ID:Moon4u,项目名称:mruby-sdl2,代码行数:6,代码来源:sdl2_joystick.c

示例9: SDL_GetMouseState

//
// UpdateJoystick
//
uint32_t Xbox::UpdateJoystick(void *obj, uint32_t ival, void *arg)
{
	int16_t     axis_x = 0, axis_y = 0;
	int16_t     move_x = 0, move_y = 0;
	int         mouse_x, mouse_y;
	uint8_t     button;
	uint8_t     hat;

	if(!SDL_JoystickOpened(JOYPAD1) || !OpenedJoy)
		return false;

	// Get the cursor position
	SDL_GetMouseState(&mouse_x, &mouse_y);

	// Get the current joystick state
	SDL_JoystickUpdate();

	// Left Stick X Axis
	axis_x = SDL_JoystickGetAxis(OpenedJoy, JOY_AXIS_LX);
	// Left Stick Y Axis
	axis_y = SDL_JoystickGetAxis(OpenedJoy, JOY_AXIS_LY);

	if(axis_x || axis_y)
	{
		if(axis_x > JOY_DEADZONE)
			axis_x -= JOY_DEADZONE;
		else if(axis_x < -JOY_DEADZONE)
			axis_x += JOY_DEADZONE;
		else
			axis_x = 0;

		if(axis_y > JOY_DEADZONE)
			axis_y -= JOY_DEADZONE;
		else if(axis_y < -JOY_DEADZONE)
			axis_y += JOY_DEADZONE;
		else
			axis_y = 0;

		move_x = mouse_x;
		move_y = mouse_y;

		if(axis_x)
			move_x += axis_x / 2000;
		if(axis_y)
			move_y += axis_y / 2000;

		// Move the cursor
		if(move_x != mouse_x || move_y != mouse_y)
			SDL_WarpMouse(move_x, move_y);
	}

	// Get all the button states
	for(int i = 0; i < JOY_BTTN_TOTAL; i++)
	{
		SDL_Event ev;

		button = SDL_JoystickGetButton(OpenedJoy, i);

		// Mouse Button Translations
		if(i == JOY_BTTN_A)
		{
			if(button && !BPressed[i])
			{
				ev.button.type = SDL_MOUSEBUTTONDOWN;
				ev.button.state = SDL_PRESSED;
			}
			else if(!button && BPressed[i])
			{
				ev.button.type = SDL_MOUSEBUTTONUP;
				ev.button.state = SDL_RELEASED;
			}
			else
				continue;

			ev.button.which = 0;
			ev.button.button = SDL_BUTTON_LEFT;
			ev.button.x = mouse_x;
			ev.button.y = mouse_y;
		}
		// Keyboard Translations
		else if(i == JOY_BTTN_B || i == JOY_BTTN_LTRIG || i == JOY_BTTN_RTRIG)
		{
			if(button && !BPressed[i])
			{
				ev.key.type = SDL_KEYDOWN;
				ev.key.state = SDL_PRESSED;
			}
			else if(!button && BPressed[i])
			{
				ev.key.type = SDL_KEYUP;
				ev.key.state = SDL_RELEASED;
			}
			else
				continue;

			if(i == JOY_BTTN_B)
				ev.key.keysym.sym = SDLK_RETURN;
//.........这里部分代码省略.........
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:101,代码来源:xbox_main.cpp

示例10: handleInput

void handleInput(Ogre::Real elapsedRealTime)
{
	// This variable can be used to keep keys from repeating too fast.
	static Ogre::Real toggleTimer = 0;
	if (toggleTimer >= 0)
	{
		toggleTimer -= elapsedRealTime;
	}

	OIS::Keyboard* keyboard = gEngine.getKeyboard();

	if (keyboard->isKeyDown(OIS::KC_W))
	{
		gCar->forward();
	}
	else if (keyboard->isKeyDown(OIS::KC_S))
	{
		gCar->reverse();
	}
	else
	{
		gCar->idle();
	}

	if (keyboard->isKeyDown(OIS::KC_A))
	{
		gCar->setSteering(-1);
	}
	else if (keyboard->isKeyDown(OIS::KC_D))
	{
		gCar->setSteering(1);
	}
	else
	{
		gCar->setSteering(0);
	}

	// If available, get data from the game controller.
	if (gGamePad)
	{
		// Update the game controller state.
		SDL_JoystickUpdate();

		Ogre::Real joy0X = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 0) / 
			(Ogre::Real)32768;
		Ogre::Real joy0Y = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 1) / 
			(Ogre::Real)32768;
		Ogre::Real joy1X = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 4) / 
			(Ogre::Real)32768;
		Ogre::Real joy1Y = (Ogre::Real)SDL_JoystickGetAxis(gGamePad, 3) / 
			(Ogre::Real)32768;

		if (fabs(joy0Y) > 0.1)
		{
			gCar->setThrottle(-joy0Y);
		}
		else
		{
			gCar->idle();
		}

		if (fabs(joy0X) > 0.1)
		{
			gCar->setSteering(joy0X);
		}
		else
		{
			gCar->setSteering(0);
		}

		if (joy1X > 0.2 || joy1X < -0.2)
		{
			Ogre::Degree rotAroundY = -Ogre::Degree(joy1X);
			gEngine.getCamera()->yawRelative(rotAroundY.valueDegrees());
		}

		if (joy1Y > 0.2 || joy1Y < -0.2)
		{
			Ogre::Degree rotAroundX = -Ogre::Degree(joy1Y);
			gEngine.getCamera()->pitchRelative(rotAroundX.valueDegrees());
		}
	}

	// Toggle GUI.
	if (keyboard->isKeyDown(OIS::KC_G) && toggleTimer <= 0)
	{
		Ogre::Overlay* debugOverlay = Ogre::OverlayManager::getSingleton().
			getByName("Verve/Debug");

		if (debugOverlay->isVisible())
        {
			debugOverlay->hide();
			gAgentDebugger->setDisplayEnabled(false);
		}
		else
		{
			debugOverlay->show();
			gAgentDebugger->setDisplayEnabled(true);
		}

//.........这里部分代码省略.........
开发者ID:sub77,项目名称:hobbycode,代码行数:101,代码来源:main.cpp

示例11: ReadAnalogEvent

int ReadAnalogEvent(int padnum, int analognum, int analogdir)
{
	SDL_Joystick *js;
	int i, changed = 0, t;
	Sint16 axis;
	
	if (g.cfg.PadDef[padnum].DevNum >= 0) {
		js = SDL_JoystickOpen(g.cfg.PadDef[padnum].DevNum);
		SDL_JoystickEventState(SDL_IGNORE);
	} else {
		js = NULL;
	}
	
	for (t = 0; t < 1000000 / 1000; t++) {
		// check joystick events
		if (js != NULL) {
			SDL_JoystickUpdate();
			
			for (i = 0; i < SDL_JoystickNumButtons(js); i++) {
				if (SDL_JoystickGetButton(js, i)) {
					g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].JoyEvType = BUTTON;
					g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Button = i;
					changed = 1;
					goto end;
				}
			}
			
			for (i = 0; i < NUM_AXES(js); i++) {
				axis = SDL_JoystickGetAxis(js, i);
				if (abs(axis) > 16383 && (abs(axis - PrevAxisPos[i]) > 4096 || abs(axis - InitialAxisPos[i]) > 4096)) {
					g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].JoyEvType = AXIS;
					g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Axis = (i + 1) * (axis > 0 ? 1 : -1);
					changed = 1;
					goto end;
				}
				PrevAxisPos[i] = axis;
			}
			
			for (i = 0; i < SDL_JoystickNumHats(js); i++) {
				axis = SDL_JoystickGetHat(js, i);
				if (axis != SDL_HAT_CENTERED) {
					g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].JoyEvType = HAT;
					
					if (axis & SDL_HAT_UP) {
						g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_UP);
					} else if (axis & SDL_HAT_DOWN) {
						g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_DOWN);
					} else if (axis & SDL_HAT_LEFT) {
						g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_LEFT);
					} else if (axis & SDL_HAT_RIGHT) {
						g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].J.Hat = ((i << 8) | SDL_HAT_RIGHT);
					}
					
					changed = 1;
					goto end;
				}
			}
		}
		
		// check keyboard events
		i = CheckKeyDown();
		if (i != 0) {
			if (i != (kVK_Escape + 1)) g.cfg.PadDef[padnum].AnalogDef[analognum][analogdir].Key = i;
			changed = 1;
			goto end;
		}
		
		// check mouse events
		if (GetCurrentButtonState()) {
			changed = 2;
			goto end;
		}
		
		usleep(1000);
	}
	
end:
	if (js != NULL) {
		SDL_JoystickClose(js);
	}
	
	return changed;
}
开发者ID:Devil084,项目名称:pcsxr,代码行数:83,代码来源:cfg.c

示例12: sdl_joypad_poll

static void sdl_joypad_poll(void)
{
   SDL_JoystickUpdate();
}
开发者ID:CatalystG,项目名称:RetroArch,代码行数:4,代码来源:sdl_joypad.c

示例13: sal_Input

static u32 sal_Input(int held)
{
#if 1
    SDL_Event event;
    int i=0;
    u32 timer=0;
#ifdef GCW_JOYSTICK
    int    deadzone = 10000;
    Sint32 x_move   = 0;
    Sint32 y_move   = 0;

#endif

    if (!SDL_PollEvent(&event))
    {
        if (held)
            return inputHeld;
        return 0;
    }

    Uint8 type = (event.key.state == SDL_PRESSED);
    switch(event.key.keysym.sym)
    {
        CASE( LCTRL,     A      );
        CASE( LALT,      B      );
        CASE( SPACE,     X      );//this triggers for some reason on the gcw0 when analogue joystick is on and in a diagonal position if sdl_updatejoystick is called before this point.
        CASE( LSHIFT,    Y      );
        CASE( TAB,       L      );
        CASE( BACKSPACE, R      );
        CASE( RETURN,    START  );
        CASE( ESCAPE,    SELECT );
        CASE( UP,        UP     );
        CASE( DOWN,      DOWN   );
        CASE( LEFT,      LEFT   );
        CASE( RIGHT,     RIGHT  );
        CASE( HOME,      MENU   );
    default:
        break;
    }
#ifdef GCW_JOYSTICK
    if(analogJoy && !key_repeat_enabled)
    {
        static int j_left = 0;
        static int j_right = 0;
        static int j_up = 0;
        static int j_down = 0;

        //Update joystick position
        if (SDL_NumJoysticks() > 0)
        {
            SDL_Joystick *joy;
            joy    = SDL_JoystickOpen(0);
            SDL_JoystickUpdate();
            x_move = SDL_JoystickGetAxis(joy, 0);
            y_move = SDL_JoystickGetAxis(joy, 1);
        }

        //Emulate keypresses with joystick
        if (x_move < -deadzone || x_move > deadzone)
        {
            if (x_move < -deadzone) inputHeld |= SAL_INPUT_LEFT;
            if (x_move >  deadzone) inputHeld |= SAL_INPUT_RIGHT;
            if (x_move < -deadzone) j_left     = 1;
            if (x_move >  deadzone) j_right    = 1;
        } else
        {
            //stop movement if previously triggered by analogue stick
            if (j_left)
            {
                j_left = 0;
                inputHeld &= ~(SAL_INPUT_LEFT );
            }
            if (j_right)
            {
                j_right = 0;
                inputHeld &= ~(SAL_INPUT_RIGHT );
            }
        }

        if (y_move < -deadzone || y_move > deadzone)
        {
            if (y_move < -deadzone) inputHeld |= SAL_INPUT_UP;
            if (y_move >  deadzone) inputHeld |= SAL_INPUT_DOWN;
            if (y_move < -deadzone) j_up       = 1;
            if (y_move >  deadzone) j_down     = 1;
        } else
        {
            //stop movement if previously triggered by analogue stick
            if (j_up)
            {
                j_up = 0;
                inputHeld &= ~(SAL_INPUT_UP );
            }
            if (j_down)
            {
                j_down = 0;
                inputHeld &= ~(SAL_INPUT_DOWN );
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:DavidKnight247,项目名称:PocketSNES,代码行数:101,代码来源:sal.c

示例14: EXPORT_C_

EXPORT_C_(void) PADupdate(int pad)
{
	// Poll keyboard.
	PollForKeyboardInput(pad);

	// joystick info
	SDL_JoystickUpdate();

	for (int i = 0; i < MAX_KEYS; i++)
	{
		int cpad = PadEnum[pad][0];

		if (JoystickIdWithinBounds(key_to_joystick_id(cpad, i)))
		{
			JoystickInfo* pjoy = s_vjoysticks[key_to_joystick_id(cpad, i)];
			int pad = (pjoy)->GetPAD();

			switch (type_of_key(cpad, i))
			{
				case PAD_JOYBUTTONS:
				{
					int value = SDL_JoystickGetButton((pjoy)->GetJoy(), key_to_button(cpad, i));

					if (value)
						clear_bit(status[pad], i); // released
					else
						set_bit(status[pad], i); // pressed
					break;
				}
			case PAD_HAT:
				{
					int value = SDL_JoystickGetHat((pjoy)->GetJoy(), key_to_axis(cpad, i));

					if (key_to_hat_dir(cpad, i) == value)
					{
						clear_bit(status[pad], i);
						//PAD_LOG("Registered %s\n", HatName(value), i);
						//PAD_LOG("%s\n", KeyName(cpad, i).c_str());
					}
					else
					{
						set_bit(status[pad], i);
					}
					break;
				}
			case PAD_POV:
				{
					int value = pjoy->GetAxisFromKey(cpad, i);

					PAD_LOG("%s: %d (%d)\n", KeyName(cpad, i).c_str(), value, key_to_pov_sign(cpad, i));
					if (key_to_pov_sign(cpad, i) && (value < -2048))
					{
						//PAD_LOG("%s Released+.\n", KeyName(cpad, i).c_str());
						clear_bit(status[pad], i);
					}
					else if (!key_to_pov_sign(cpad, i) && (value > 2048))
					{
						//PAD_LOG("%s Released-\n", KeyName(cpad, i).c_str());
						clear_bit(status[pad], i);
					}
					else
					{
						//PAD_LOG("%s Pressed.\n", KeyName(cpad, i).c_str());
						set_bit(status[pad], i);
					}
					break;
				}
				case PAD_JOYSTICK:
				{
					int value = pjoy->GetAxisFromKey(cpad, i);

					switch (i)
					{
						case PAD_LX:
						case PAD_LY:
						case PAD_RX:
						case PAD_RY:
							if (abs(value) > (pjoy)->GetDeadzone(value))
								Analog::ConfigurePad(pad, i, value);
							else
								Analog::ResetPad(pad, i);
							break;
					}
					break;
				}
			default: break;
			}
		}
	}
}
开发者ID:mauzus,项目名称:progenitor,代码行数:90,代码来源:linux.cpp

示例15: IN_Xbox360ControllerMove

/*
===============
IN_Xbox360ControllerMove
===============
*/
static void IN_Xbox360ControllerMove()
{
	bool     joy_pressed[ ARRAY_LEN( joy_keys ) ];
	unsigned int axes = 0;
	unsigned int hat = 0;
	int          total = 0;
	int          i = 0;

	if ( !stick )
	{
		return;
	}

	if ( !in_joystick->integer )
	{
		return;
	}

	SDL_JoystickUpdate();

	memset( joy_pressed, '\0', sizeof( joy_pressed ) );

	// query the stick buttons...
	total = SDL_JoystickNumButtons( stick );

	if ( total > 0 )
	{
		if ( total > (int) ARRAY_LEN( stick_state.buttons ) )
		{
			total = ARRAY_LEN( stick_state.buttons );
		}

		for ( i = 0; i < total; i++ )
		{
			bool pressed = ( SDL_JoystickGetButton( stick, i ) != 0 );

			if ( pressed != stick_state.buttons[ i ] )
			{
				Com_QueueEvent( 0, sysEventType_t::SE_KEY, K_XBOX360_A + i, pressed, 0, nullptr );

				if ( in_xbox360ControllerDebug->integer )
				{
					Log::Notice( "xbox button = %i to key = Q:0x%02x(%s)\n", i, K_XBOX360_A + i, Key_KeynumToString( K_XBOX360_A + i ) );
				}

				stick_state.buttons[ i ] = pressed;
			}
		}
	}

	// look at the hats...
	total = SDL_JoystickNumHats( stick );
	hat = SDL_JoystickGetHat( stick, 0 );

	// update hat state
	if ( hat != stick_state.oldhats )
	{
		if ( hat != stick_state.oldhats )
		{
			int       key;

			const int allHatDirections = ( SDL_HAT_UP |
			                               SDL_HAT_RIGHT |
			                               SDL_HAT_DOWN |
			                               SDL_HAT_LEFT );

			if ( in_xbox360ControllerDebug->integer )
			{
				switch ( hat & allHatDirections )
				{
					case SDL_HAT_UP:
						key = K_XBOX360_DPAD_UP;
						break;

					case SDL_HAT_RIGHT:
						key = K_XBOX360_DPAD_RIGHT;
						break;

					case SDL_HAT_DOWN:
						key = K_XBOX360_DPAD_DOWN;
						break;

					case SDL_HAT_LEFT:
						key = K_XBOX360_DPAD_LEFT;
						break;

					case SDL_HAT_RIGHTUP:
						key = K_XBOX360_DPAD_RIGHTUP;
						break;

					case SDL_HAT_RIGHTDOWN:
						key = K_XBOX360_DPAD_RIGHTDOWN;
						break;

					case SDL_HAT_LEFTUP:
//.........这里部分代码省略.........
开发者ID:ChunHungLiu,项目名称:Unvanquished,代码行数:101,代码来源:sdl_input.cpp


注:本文中的SDL_JoystickUpdate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。