#include <platform/sdl2.h>

namespace extra2d {

bool Sdl2::inited_ = false;

bool Sdl2::initCore() {
    if (inited_) return true;
    
    if (SDL_Init(SDL_INIT_EVENTS) != 0) {
        return false;
    }
    
    inited_ = true;
    return true;
}

bool Sdl2::initVideo() {
    if (!initCore()) return false;
    
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
        return false;
    }
    
    return true;
}

bool Sdl2::initAudio() {
    if (!initCore()) return false;
    
    if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) {
        return false;
    }
    
    return true;
}

bool Sdl2::initGamepad() {
    if (!initCore()) return false;
    
    if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) {
        return false;
    }
    
    return true;
}

bool Sdl2::initAll() {
    if (inited_) return true;
    
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        return false;
    }
    
    inited_ = true;
    return true;
}

void Sdl2::shutdown() {
    if (inited_) {
        SDL_Quit();
        inited_ = false;
    }
}

} // namespace extra2d
