summaryrefslogtreecommitdiffstats
path: root/wrapsdl2.cpp
blob: 393bff6aec1dd38a347dfdf657f63cb7b1f30cce (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
#include "wsdl2.hpp"
#include "debug.hpp"

#ifdef WRAPSDL2_EXCEPTIONS
#include <exception>
#endif

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

bool wsdl2::initialize(void) {
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
        throw std::runtime_error("failed to initialize SDL video subsystem");
        return false;
    }

    if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
        throw std::runtime_error("failed to initialzie SDL events subsystem");
        return false;
    }

    npdebug("initialized SDL2");

    return true;
}

void wsdl2::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 wsdl2::delay(unsigned ms) {
    SDL_Delay(ms);
}