<commit_before>#ifdef USE_SDL

#include <SDL.h>
#include "joystick.h"

void SDLJoystick::poll(){
    events.clear();
}

static bool read_button(SDL_Joystick * joystick, int button){
    return SDL_JoystickGetButton(joystick, button);
}

JoystickInput SDLJoystick::readAll(){
    JoystickInput input;
    if (joystick){
        int buttons = SDL_JoystickNumButtons(joystick);
        switch (buttons > 5 ? 5 : buttons){
            case 5: input.quit = read_button(joystick, 4);
            case 4: input.button4 = read_button(joystick, 3);
            case 3: input.button3 = read_button(joystick, 2);
            case 2: input.button2 = read_button(joystick, 1);
            case 1: input.button1 = read_button(joystick, 0);
            case 0: {
                break;
            }
        }
    }

    int axis = SDL_JoystickNumAxes(joystick);
    if (axis > 0){
        int position = SDL_JoystickGetAxis(joystick, 0);
        if (position < 0){
            input.left = true;
        } else if (position > 0){
            input.right = true;
        }
    }

    if (axis > 1){
        int position = SDL_JoystickGetAxis(joystick, 1);
        if (position < 0){
            input.up = true;
        } else if (position > 0){
            input.down = true;
        }
    }

    int hats = SDL_JoystickNumHats(joystick);
    if (hats > 0){
        int hat = SDL_JoystickGetHat(joystick, 0);
        if ((hat & SDL_HAT_UP) == SDL_HAT_UP){
#ifdef WII
            input.right = true;
#else
            input.up = true;
#endif
        }
        if ((hat & SDL_HAT_DOWN) == SDL_HAT_DOWN){
#ifdef WII
            input.left = true;
#else
            input.down = true;
#endif
        }
        if ((hat & SDL_HAT_LEFT) == SDL_HAT_LEFT){
#ifdef WII
            input.up = true;
#else
            input.left = true;
#endif
        }
        if ((hat & SDL_HAT_RIGHT) == SDL_HAT_RIGHT){
#ifdef WII
            input.down = true;
#else
            input.right = true;
#endif
        }
        if ((hat & SDL_HAT_RIGHTUP) == SDL_HAT_RIGHTUP){
#ifdef WII
            input.down = true;
            input.left = true;
#else
            input.right = true;
            input.up = true;
#endif
        }
        if ((hat & SDL_HAT_RIGHTDOWN) == SDL_HAT_RIGHTDOWN){
#ifdef WII
            input.down = true;
            input.left = true;
#else
            input.right = true;
            input.down = true;
#endif
        }
        if ((hat & SDL_HAT_LEFTDOWN) == SDL_HAT_LEFTDOWN){
#ifdef WII
            input.up = true;
            input.left = true;
#else
            input.left = true;
            input.down = true;
#endif
        }
        if ((hat & SDL_HAT_LEFTUP) == SDL_HAT_LEFTUP){
#ifdef WII
            input.up = true;
            input.right = true;
#else
            input.left = true;
            input.up = true;
#endif
        }
    }

    return input;
}

SDLJoystick::~SDLJoystick(){
    if (joystick){
        SDL_JoystickClose(joystick);
    }
}

SDLJoystick::SDLJoystick():
joystick(NULL){
    if (SDL_NumJoysticks() > 0){
        joystick = SDL_JoystickOpen(0);
    }
}
    
void SDLJoystick::pressButton(int button){
    if (joystick){
        Event event = Invalid;
        switch (button){
            case 0: event = Button1; break;
            case 1: event = Button2; break;
            case 2: event = Button3; break;
            case 3: event = Button4; break;
            case 4: event = Quit; break;
            default: break;<commit_msg>dont need a hack for the wii joystick<commit_after>#ifdef USE_SDL

#include <SDL.h>
#include "joystick.h"

void SDLJoystick::poll(){
    events.clear();
}

static bool read_button(SDL_Joystick * joystick, int button){
    return SDL_JoystickGetButton(joystick, button);
}

JoystickInput SDLJoystick::readAll(){
    JoystickInput input;
    if (joystick){
        int buttons = SDL_JoystickNumButtons(joystick);
        switch (buttons > 5 ? 5 : buttons){
            case 5: input.quit = read_button(joystick, 4);
            case 4: input.button4 = read_button(joystick, 3);
            case 3: input.button3 = read_button(joystick, 2);
            case 2: input.button2 = read_button(joystick, 1);
            case 1: input.button1 = read_button(joystick, 0);
            case 0: {
                break;
            }
        }
    }

    int axis = SDL_JoystickNumAxes(joystick);
    if (axis > 0){
        int position = SDL_JoystickGetAxis(joystick, 0);
        if (position < 0){
            input.left = true;
        } else if (position > 0){
            input.right = true;
        }
    }

    if (axis > 1){
        int position = SDL_JoystickGetAxis(joystick, 1);
        if (position < 0){
            input.up = true;
        } else if (position > 0){
            input.down = true;
        }
    }

    int hats = SDL_JoystickNumHats(joystick);
    if (hats > 0){
        int hat = SDL_JoystickGetHat(joystick, 0);
        if ((hat & SDL_HAT_UP) == SDL_HAT_UP){
            input.up = true;
        }
        if ((hat & SDL_HAT_DOWN) == SDL_HAT_DOWN){
            input.down = true;
        }
        if ((hat & SDL_HAT_LEFT) == SDL_HAT_LEFT){
            input.left = true;
        }
        if ((hat & SDL_HAT_RIGHT) == SDL_HAT_RIGHT){
            input.right = true;
        }
        if ((hat & SDL_HAT_RIGHTUP) == SDL_HAT_RIGHTUP){
            input.right = true;
            input.up = true;
        }
        if ((hat & SDL_HAT_RIGHTDOWN) == SDL_HAT_RIGHTDOWN){
            input.right = true;
            input.down = true;
        }
        if ((hat & SDL_HAT_LEFTDOWN) == SDL_HAT_LEFTDOWN){
            input.left = true;
            input.down = true;
        }
        if ((hat & SDL_HAT_LEFTUP) == SDL_HAT_LEFTUP){
            input.left = true;
            input.up = true;
        }
    }

    return input;
}

SDLJoystick::~SDLJoystick(){
    if (joystick){
        SDL_JoystickClose(joystick);
    }
}

SDLJoystick::SDLJoystick():
joystick(NULL){
    if (SDL_NumJoysticks() > 0){
        joystick = SDL_JoystickOpen(0);
    }
}
    
void SDLJoystick::pressButton(int button){
    if (joystick){
        Event event = Invalid;
        switch (button){
            case 0: event = Button1; break;
            case 1: event = Button2; break;
            case 2: event = Button3; break;
            case 3: event = Button4; break;
            case 4: event = Quit; break;
            default: break;
{'fraction_non_alphanumeric': 0.11608260325406758, 'fraction_numerical': 0.011889862327909888, 'mean_word_length': 1.7723330442324372, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '4793155', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2049, 'n_words': 492}