X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Finit.cpp;h=a0ea7b51ba5d614a3df13814c4eee90468d6fe1d;hb=4727825186798902f68df5b99a6a32f0ef618454;hp=1cc0c2485b50db7e79a5fdd5baf242ef4201a72d;hpb=5d2da8a07411ad6417d6ed8d1be997189cf5ce89;p=blank.git diff --git a/src/app/init.cpp b/src/app/init.cpp index 1cc0c24..a0ea7b5 100644 --- a/src/app/init.cpp +++ b/src/app/init.cpp @@ -1,8 +1,10 @@ #include "init.hpp" #include +#include #include #include +#include #include #include @@ -19,10 +21,50 @@ std::string sdl_error_append(std::string msg) { return msg; } +std::string net_error_append(std::string msg) { + const char *error = SDLNet_GetError(); + if (*error != '\0') { + msg += ": "; + msg += error; + } + return msg; +} + +std::string alut_error_append(ALenum num, std::string msg) { + const char *error = alutGetErrorString(num); + if (*error != '\0') { + msg += ": "; + msg += error; + } + return msg; +} + } namespace blank { +AlutError::AlutError(ALenum num) +: std::runtime_error(alutGetErrorString(num)) { + +} + +AlutError::AlutError(ALenum num, const std::string &msg) +: std::runtime_error(alut_error_append(num, msg)) { + +} + + +NetError::NetError() +: std::runtime_error(SDLNet_GetError()) { + +} + +NetError::NetError(const std::string &msg) +: std::runtime_error(net_error_append(msg)) { + +} + + SDLError::SDLError() : std::runtime_error(SDL_GetError()) { @@ -35,8 +77,8 @@ SDLError::SDLError(const std::string &msg) InitSDL::InitSDL() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - throw SDLError("SDL_Init(SDL_INIT_VIDEO)"); + if (SDL_Init(SDL_INIT_EVENTS) != 0) { + throw SDLError("SDL_Init(SDL_INIT_EVENTS)"); } } @@ -45,6 +87,19 @@ InitSDL::~InitSDL() { } +InitVideo::InitVideo() { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + throw SDLError("SDL_InitSubSystem(SDL_INIT_VIDEO)"); + } + // SDL seems to start out in text input state + SDL_StopTextInput(); +} + +InitVideo::~InitVideo() { + SDL_QuitSubSystem(SDL_INIT_VIDEO); +} + + InitIMG::InitIMG() { if (IMG_Init(IMG_INIT_PNG) == 0) { throw SDLError("IMG_Init(IMG_INIT_PNG)"); @@ -56,6 +111,17 @@ InitIMG::~InitIMG() { } +InitNet::InitNet() { + if (SDLNet_Init() != 0) { + throw SDLError("SDLNet_Init()"); + } +} + +InitNet::~InitNet() { + SDLNet_Quit(); +} + + InitTTF::InitTTF() { if (TTF_Init() != 0) { throw SDLError("TTF_Init()"); @@ -67,6 +133,19 @@ InitTTF::~InitTTF() { } +InitAL::InitAL() { + if (!alutInit(nullptr, nullptr)) { + throw AlutError(alutGetError(), "alutInit"); + } +} + +InitAL::~InitAL() { + if (!alutExit()) { + throw AlutError(alutGetError(), "alutExit"); + } +} + + InitGL::InitGL(bool double_buffer, int sample_size) { if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0) { throw SDLError("SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)"); @@ -164,8 +243,14 @@ InitGLEW::InitGLEW() { } -Init::Init(bool double_buffer, int sample_size) +InitHeadless::InitHeadless() : init_sdl() +, init_net() { + +} + +Init::Init(bool double_buffer, int sample_size) +: init_video() , init_img() , init_ttf() , init_gl(double_buffer, sample_size)