Joystick System::create_joystick() { SDL_Joystick* joystick = nullptr; log_info("SDL_NumJoysticks: %d", SDL_NumJoysticks()); if (SDL_NumJoysticks() > 0) { joystick = SDL_JoystickOpen(0); return Joystick(joystick); } else { return Joystick(); } }
/* ================ idUsercmdGenLocal::UsercmdInterrupt Called asyncronously ================ */ void idUsercmdGenLocal::UsercmdInterrupt( void ) { // dedicated servers won't create usercmds if ( !initialized ) { return; } // init the usercmd for com_ticNumber+1 InitCurrent(); // process the system mouse events Mouse(); // process the system keyboard events Keyboard(); // process the system joystick events Joystick(); // create the usercmd for com_ticNumber+1 MakeCurrent(); // save a number for debugging cmdDemos and networking cmd.sequence = com_ticNumber+1; buffered[(com_ticNumber+1) & (MAX_BUFFERED_USERCMD-1)] = cmd; }
static int HandleJoystickForAllPlayers() { int i; int result = 0; for (i = 0; i < MAX_PLAYERS; i++) { byte joy_action = 0; /* if (!setup.input[i].use_joystick) continue; */ joy_action = Joystick(i); result |= joy_action; if (!setup.input[i].use_joystick) continue; stored_player[i].action = joy_action; } return result; }
JoystickDriver::JoystickCollection JoystickDriverLinux::getJoysticks() const { if (!m_initialized) { return JoystickCollection(); } JoystickCollection joysticks = { Joystick(m_joy_fd, m_name, m_numberOfAxis, m_numberOfButtons) }; return joysticks; }
void Application::initializeJoystickDevices() { closeJoysticks(); const int numJoysticks = SDL_NumJoysticks(); for (int which=0; which<numJoysticks; ++which) { SDL_Joystick *handle = SDL_JoystickOpen(which); if (handle) { TRACE(string("Joystick ") + SDL_JoystickName(which) + " Successfully opened."); } joysticks.push_back(Joystick(handle, which)); } }
void OS_X11::probe_joystick(int p_id) { #ifndef __FreeBSD__ if (p_id == -1) { for (int i=0; i<JOYSTICKS_MAX; i++) { probe_joystick(i); }; return; }; if (joysticks[p_id].fd != -1) close_joystick(p_id); const char *joy_names[] = { "/dev/input/js%d", "/dev/js%d", NULL }; int i=0; while(joy_names[i]) { char fname[64]; sprintf(fname, joy_names[i], p_id); int fd = open(fname, O_RDONLY|O_NONBLOCK); if (fd != -1) { //fcntl( fd, F_SETFL, O_NONBLOCK ); joysticks[p_id] = Joystick(); // this will reset the axis array joysticks[p_id].fd = fd; String name; char namebuf[255] = {0}; if (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) >= 0) { name = namebuf; } else { name = "error"; }; input->joy_connection_changed(p_id, true, name); break; // don't try the next name }; ++i; }; #endif };
/* ================ idUsercmdGenLocal::GetDirectUsercmd ================ */ usercmd_t idUsercmdGenLocal::GetDirectUsercmd( void ) { // initialize current usercmd InitCurrent(); // process the system mouse events Mouse(); // process the system keyboard events Keyboard(); // process the system joystick events Joystick(); // create the usercmd MakeCurrent(); cmd.duplicateCount = 0; return cmd; }
void OS_X11::probe_joystick(int p_id) { #ifndef __FreeBSD__ if (p_id == -1) { for (int i=0; i<JOYSTICKS_MAX; i++) { probe_joystick(i); }; return; }; close_joystick(p_id); const char *joy_names[] = { "/dev/input/js%d", "/dev/js%d", NULL }; int i=0; while(joy_names[i]) { char fname[64]; sprintf(fname, joy_names[i], p_id); int fd = open(fname, O_RDONLY); if (fd != -1) { fcntl( fd, F_SETFL, O_NONBLOCK ); joysticks[p_id] = Joystick(); // this will reset the axis array joysticks[p_id].fd = fd; break; // don't try the next name }; ++i; }; #endif };
Joystick Manager::joystick( int i ) const { ASSERT( i >= 0 && i < gManagerImpl->mJoystickNumber ); return Joystick( &gManagerImpl->mJoysticks[ i ] ); }
Joystick button(unsigned int button) { return Joystick(id, button); }
CJoystickCtl::CJoystickCtl() { stick = Joystick(); }
void GameLoop( sf::RenderWindow &app, bool &bczyGra, bool &bMenu ) { ResetGame(); bool pauseGame = false; sf::Mouse::setPosition( sf::Vector2i( Width / 2, Height / 2 ), app ); app.setMouseCursorVisible( false ); sounds[2].play(); while ( bczyGra ) { LoopTime = TimeLoop.GetElapsedSeconds(); TimeLoop.Reset(); sf::Event event; while (app.pollEvent(event)) { if (event.type == sf::Event::Closed) { bczyGra = false; bMenu = false; app.close(); } else if (event.type == sf::Event::Resized) { ChangeSize( event.size.width, event.size.height ); } else if ( ( event.type == sf::Event::KeyReleased ) && ( event.key.code == sf::Keyboard::Escape ) ){ bczyGra = false; bMenu = true; } if ( ( ( event.type == sf::Event::JoystickButtonReleased ) && ( event.joystickButton.button == 0 ) ) || ( event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::P ) ){ pauseGame = !pauseGame; if ( pauseGame == true ) { app.setMouseCursorVisible( true ); sounds[2].pause(); } else { sf::Mouse::setPosition( sf::Vector2i( Width / 2, Height / 2 ), app ); app.setMouseCursorVisible( false ); LoopTime = 0.0f; TimeLoop.Reset(); sounds[2].play(); } } } KeyControl( LoopTime, app ); if ( !pauseGame ) { MoveMouse( sf::Mouse::getPosition( app ).x, sf::Mouse::getPosition( app ).y, app ); MouseControl( LoopTime ); Joystick( LoopTime, app ); if ( Player.getLife() < 0 ) { bczyGra = false; bMenu = true; } Logika( LoopTime ); RenderScene(); app.display(); } } sounds[2].stop(); hud.sendScore(); }
bool Proxy::JoystickButtonsDisabled(int stick) { wpi_assert(stick >= 1 && stick <= 4); if(disableAxes[stick-1]==0) return false; return Joystick(stick).GetRawButton(disableButtons[stick-1]); }