summaryrefslogtreecommitdiffstats
path: root/wrapsdl2.cpp
blob: 3828abcfd3e19b39107d2f6f34f1a28d5f5169d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "wrapsdl2.hpp"
#include "debug.hpp"

#ifdef WRAPSDL2_EXCEPTIONS
#include <exception>
#endif

extern "C" {
#include <SDL2/SDL.h>
}

bool wrapsdl2::initialize(void) {
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
#ifdef WRAPSDL2_EXCEPTIONS
        throw std::runtime_error("failed to initialize sdl video subsystem");
#endif
        return false;
    }

    if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
#ifdef WRAPSDL2_EXCEPTIONS
        throw std::runtime_error("failed to initialzie sdl events subsystem");
#endif
        return false;
    }

    npdebug("initialized sdl2");

    return true;
}

void wrapsdl2::quit(void) {
    if (SDL_WasInit(SDL_INIT_VIDEO))
        SDL_QuitSubSystem(SDL_INIT_VIDEO);

    if (SDL_WasInit(SDL_INIT_EVENTS))
        SDL_QuitSubSystem(SDL_INIT_EVENTS);

    SDL_Quit();

    npdebug("deinitialized (quit) sdl2");
}



void wrapsdl2::delay(unsigned ms) {
    SDL_Delay(ms);
}