<commit_before>#ifdef USE_SDL

#include <SDL.h>
#include "joystick.h"
#include "util/debug.h"
#include <string>
#include <vector>

#include <exception>

using std::string;
using std::vector;

class ButtonMapping{
public:
    ButtonMapping(){
    }

    virtual ~ButtonMapping(){
    }

    virtual int toNative(int button) = 0;
    virtual int fromNative(int button) = 0;
    virtual Joystick::Key toKey(int button) = 0;
    virtual void axisMotionEvents(int axis, int motion, vector<Joystick::Event> & events) = 0;
    virtual void hatMotionEvents(int motion, vector<Joystick::Event> & events) = 0;
};

class DefaultButtonMapping: public ButtonMapping {
public:
    int toNative(int button){
        return button;
    }

    int fromNative(int button){
        return button;
    }

    Joystick::Key toKey(int button){
        switch (button){
            case 0: return Joystick::Button1;
            case 1: return Joystick::Button2;
            case 2: return Joystick::Button3;
            case 3: return Joystick::Button4;
            case 4: return Joystick::Quit;
            case 5: return Joystick::Button5;
            case 6: return Joystick::Button6;
            default: return Joystick::Invalid;
        }
    }
    
    virtual void hatMotionEvents(int motion, vector<Joystick::Event> & events){
        bool up = false;
        bool down = false;
        bool left = false;
        bool right = false;
        switch (motion){
            case SDL_HAT_CENTERED: break;
            case SDL_HAT_UP: up = true; break;
            case SDL_HAT_RIGHT: right = true; break;
            case SDL_HAT_DOWN: down = true; break;
            case SDL_HAT_LEFT: left = true; break;
            case SDL_HAT_RIGHTUP: right = true; up = true; break;
            case SDL_HAT_RIGHTDOWN: right = true; down = true; break;
            case SDL_HAT_LEFTUP: left = true; up = true; break;
            case SDL_HAT_LEFTDOWN: left = true; down = true; break;
        }

        events.push_back(Joystick::Event(Joystick::Left, left));
        events.push_back(Joystick::Event(Joystick::Right, right));
        events.push_back(Joystick::Event(Joystick::Down, down));
        events.push_back(Joystick::Event(Joystick::Up, up));
    }

    void axisMotionEvents(int axis, int motion, vector<Joystick::Event> & events){
        if (axis == 0){
            if (motion < 0){
                events.push_back(Joystick::Event(Joystick::Left, true));
            } else if (motion > 0){
                events.push_back(Joystick::Event(Joystick::Right, true));
            } else {
                events.push_back(Joystick::Event(Joystick::Left, false));
                events.push_back(Joystick::Event(Joystick::Right, false));
            }
        } else if (axis == 1){
            if (motion < 0){
                events.push_back(Joystick::Event(Joystick::Up, true));
            } else if (motion > 0){
                events.push_back(Joystick::Event(Joystick::Down, true));
            } else {
                events.push_back(Joystick::Event(Joystick::Up, false));
                events.push_back(Joystick::Event(Joystick::Down, false));
            }
        }
    }
};

/* used when a ps3 controller is plugged into a usb port of a normal pc */
class Playstation3Controller: public ButtonMapping {
public:
    enum Buttons{
        Cross = 14,
        Circle = 13,
        Triangle = 12,
        Square = 15,
        Start = 3,
        Select = 0,
        Up = 4,<commit_msg>different fix for joystick bug<commit_after>#ifdef USE_SDL

#include <SDL.h>
#include "joystick.h"
#include "util/debug.h"
#include <string>
#include <vector>

#include <exception>

using std::string;
using std::vector;

class ButtonMapping{
public:
    ButtonMapping(){
    }

    virtual ~ButtonMapping(){
    }

    virtual int toNative(int button) = 0;
    virtual int fromNative(int button) = 0;
    virtual Joystick::Key toKey(int button) = 0;
    virtual void axisMotionEvents(int axis, int motion, vector<Joystick::Event> & events) = 0;
    virtual void hatMotionEvents(int motion, vector<Joystick::Event> & events) = 0;
};

class DefaultButtonMapping: public ButtonMapping {
public:
    int toNative(int button){
        return button;
    }

    int fromNative(int button){
        return button;
    }

    Joystick::Key toKey(int button){
        switch (button){
            case 0: return Joystick::Button1;
            case 1: return Joystick::Button2;
            case 2: return Joystick::Button3;
            case 3: return Joystick::Button4;
            case 4: return Joystick::Quit;
            case 5: return Joystick::Button5;
            case 6: return Joystick::Button6;
            default: return Joystick::Invalid;
        }
    }
    
    virtual void hatMotionEvents(int motion, vector<Joystick::Event> & events){
        bool up = false;
        bool down = false;
        bool left = false;
        bool right = false;
        switch (motion){
            case SDL_HAT_CENTERED: break;
            case SDL_HAT_UP: up = true; break;
            case SDL_HAT_RIGHT: right = true; break;
            case SDL_HAT_DOWN: down = true; break;
            case SDL_HAT_LEFT: left = true; break;
            case SDL_HAT_RIGHTUP: right = true; up = true; break;
            case SDL_HAT_RIGHTDOWN: right = true; down = true; break;
            case SDL_HAT_LEFTUP: left = true; up = true; break;
            case SDL_HAT_LEFTDOWN: left = true; down = true; break;
        }

        events.push_back(Joystick::Event(Joystick::Left, left));
        events.push_back(Joystick::Event(Joystick::Right, right));
        events.push_back(Joystick::Event(Joystick::Down, down));
        events.push_back(Joystick::Event(Joystick::Up, up));
    }

    void axisMotionEvents(int axis, int motion, vector<Joystick::Event> & events){
        bool up = false;
        bool down = false;
        bool left = false;
        bool right = false;
        if (axis == 0){
            if (motion < 0){
                left = true;
            } else if (motion > 0){
                right = true;
            }
        } else if (axis == 1){
            if (motion < 0){
                up = true;
            } else if (motion > 0){
                down = true;
            }
        }
        
        events.push_back(Joystick::Event(Joystick::Left, left));
        events.push_back(Joystick::Event(Joystick::Right, right));
        events.push_back(Joystick::Event(Joystick::Down, down));
        events.push_back(Joystick::Event(Joystick::Up, up));
    }
};

/* used when a ps3 controller is plugged into a usb port of a normal pc */
class Playstation3Controller: public ButtonMapping {
public:
    enum Buttons{
        Cross = 14,
        Circle = 13,
        Triangle = 12,
        Square = 15,
        Start = 3,
        Select = 0,
        Up = 4,
{'fraction_non_alphanumeric': 0.11279953243717125, 'fraction_numerical': 0.01081239041496201, 'mean_word_length': 2.216635338345865, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '3928987', 'n_tokens_mistral': 2186, 'n_tokens_neox': 1993, 'n_words': 547}