Add experimental constructor of SDLSystem

This commit is contained in:
Kirigaya Kazuto 2017-07-02 09:47:37 +08:00
parent e080389709
commit 6b213984c6
2 changed files with 62 additions and 29 deletions

View File

@ -1,6 +1,46 @@
#include "SDLSystem.h" #include "SDLSystem.h"
#include "_caster.h" #include "_caster.h"
#include "begin_code.h" #include "begin_code.h"
// private
void SDLSystem::_init(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf) throw (ErrorViewer)
{
int ret=SDL_Init(sdl_flag);
if(ret!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
Uint32 uret=0;
uret=IMG_Init(img_flag);
if(uret!=img_flag) /// IMG_Init returns its parameter on success.
{
ErrorViewer e;
e.fetch();
throw e;
}
uret=Mix_Init(mix_flag);
if(uret!=mix_flag) /// Mix_Init returns its parameter on success.
{
ErrorViewer e;
e.fetch();
throw e;
}
if(init_ttf)
{
ret=TTF_Init();
if(ret!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
}
SDLSystem::SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl, SDLSystem::SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl,
const std::initializer_list<IMGInitFlag>& flag_img, const std::initializer_list<IMGInitFlag>& flag_img,
const std::initializer_list<MixInitFlag>& flag_mix, const std::initializer_list<MixInitFlag>& flag_mix,
@ -22,41 +62,28 @@ SDLSystem::SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl,
mix_flag |= _internal::getIntFromMixInitFlag(v); mix_flag |= _internal::getIntFromMixInitFlag(v);
} }
int ret=SDL_Init(sdl_flag); try
if(ret!=0) {
_init(sdl_flag,img_flag,mix_flag,init_ttf);
}
catch(ErrorViewer& e)
{ {
ErrorViewer e;
e.fetch();
throw e; throw e;
} }
}
ret=IMG_Init(img_flag); SDLSystem::SDLSystem(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf) throw (ErrorViewer)
if(ret!=img_flag) /// IMG_Init returns its parameter on success. {
try
{
_init(sdl_flag,img_flag,mix_flag,init_ttf);
}
catch(ErrorViewer& e)
{ {
ErrorViewer e;
e.fetch();
throw e; throw e;
} }
}
ret=Mix_Init(mix_flag);
if(ret!=mix_flag) /// Mix_Init returns its parameter on success.
{
ErrorViewer e;
e.fetch();
throw e;
}
if(init_ttf)
{
ret=TTF_Init();
if(ret!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
}
SDLSystem::~SDLSystem() SDLSystem::~SDLSystem()
{ {

View File

@ -19,6 +19,8 @@ public:
const std::initializer_list<IMGInitFlag>& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} , const std::initializer_list<IMGInitFlag>& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} ,
const std::initializer_list<MixInitFlag>& flag_mix = {MixInitFlag::MP3} , const std::initializer_list<MixInitFlag>& flag_mix = {MixInitFlag::MP3} ,
bool init_ttf = true ) throw (ErrorViewer); bool init_ttf = true ) throw (ErrorViewer);
/// Experimental Constructor
SDLSystem(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf) throw (ErrorViewer);
~SDLSystem(); ~SDLSystem();
static void Delay(int ms); static void Delay(int ms);
@ -66,5 +68,9 @@ public:
static std::string GetExternal(); static std::string GetExternal();
static void* GetJNIEnv(); static void* GetJNIEnv();
}; };
private:
void _init(Uint32,Uint32,Uint32,bool) throw (ErrorViewer);
void _quit();
}; };
#include "end_code.h" #include "end_code.h"