<commit_before>/* -*-c++-*- Present3D - Copyright (C) 1999-2006 <NAME> 
 *
 * This software is open source and may be redistributed and/or modified under  
 * the terms of the GNU General Public License (GPL) version 2.0.
 * The full license is in LICENSE.txt file included with this distribution,.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * include LICENSE.txt for more details.
*/

#include <osgViewer/Viewer>

#include "JoystickDevice.h"

#include <SDL.h>
#include <SDL_events.h>
#include <SDL_joystick.h>

#include <iostream>

JoystickDevice::JoystickDevice()
{
    _verbose = false;

    // init SDL
    if ( SDL_Init(SDL_INIT_JOYSTICK) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);

    int numJoysticks =  SDL_NumJoysticks();
    
    if (_verbose)
    {
        std::cout<<"number of joysticks "<<numJoysticks<<std::endl;
        for(int i=0; i<numJoysticks; ++i)
        {
            std::cout<<"Joystick name '"<<SDL_JoystickName(i)<<"'"<<std::endl;
        }
    }
    
    _joystick = numJoysticks>0 ? SDL_JoystickOpen(0) : 0;
    
    _numAxes = _joystick ? SDL_JoystickNumAxes(_joystick) : 0;
    _numBalls = _joystick ? SDL_JoystickNumBalls(_joystick) : 0;
    _numHats = _joystick ? SDL_JoystickNumHats(_joystick) : 0;
    _numButtons = _joystick ? SDL_JoystickNumButtons(_joystick) : 0;<commit_msg>From <NAME>, "The current version will not compile with SDL version 2, error OpenSceneGraph\src\osgPlugins\sdl\JoystickDevice.cpp(42): error C2664: 'const char *SDL_JoystickName(SDL_Joystick *)' : cannot convert argument 1 from 'int' to 'SDL_Joystick *' due to changes in the SDL api.<commit_after>/* -*-c++-*- Present3D - Copyright (C) 1999-2006 <NAME> 
 *
 * This software is open source and may be redistributed and/or modified under  
 * the terms of the GNU General Public License (GPL) version 2.0.
 * The full license is in LICENSE.txt file included with this distribution,.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * include LICENSE.txt for more details.
*/

#include <osgViewer/Viewer>

#include "JoystickDevice.h"

#include <SDL.h>
#include <SDL_events.h>
#include <SDL_joystick.h>

#include <iostream>

JoystickDevice::JoystickDevice()
{
    _verbose = false;

    // init SDL
    if ( SDL_Init(SDL_INIT_JOYSTICK) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);

    int numJoysticks =  SDL_NumJoysticks();
    
    if (_verbose)
    {
        std::cout<<"number of joysticks "<<numJoysticks<<std::endl;
        for(int i=0; i<numJoysticks; ++i)
        {
#if SDL_VERSION_ATLEAST(2, 0, 0)
            std::cout << "Joystick name '" << SDL_JoystickNameForIndex(i) << "'" << std::endl;
#else
            std::cout << "Joystick name '" << SDL_JoystickName(i) << "'" << std::endl;
#endif
        }
    }
    
    _joystick = numJoysticks>0 ? SDL_JoystickOpen(0) : 0;
    
    _numAxes = _joystick ? SDL_JoystickNumAxes(_joystick) : 0;
    _numBalls = _joystick ? SDL_JoystickNumBalls(_joystick) : 0;
    _numHats = _joystick ? SDL_JoystickNumHats(_joystick) : 0;
    _numButtons = _joystick ? SDL_JoystickNumButtons(_joystick) : 0;
{'fraction_non_alphanumeric': 0.11892655367231639, 'fraction_numerical': 0.014971751412429379, 'mean_word_length': 3.404228855721393, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5699294', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1178, 'n_words': 330}