From 6b213984c6f67695a1ed037a7126c62a4e3eae4c Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 2 Jul 2017 09:47:37 +0800 Subject: [PATCH] Add experimental constructor of SDLSystem --- SDLWrapper/SDLSystem.cpp | 85 ++++++++++++++++++++++++++-------------- SDLWrapper/SDLSystem.h | 6 +++ 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/SDLWrapper/SDLSystem.cpp b/SDLWrapper/SDLSystem.cpp index c8d0c48..bb3febe 100644 --- a/SDLWrapper/SDLSystem.cpp +++ b/SDLWrapper/SDLSystem.cpp @@ -1,6 +1,46 @@ #include "SDLSystem.h" #include "_caster.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& flag_sdl, const std::initializer_list& flag_img, const std::initializer_list& flag_mix, @@ -22,42 +62,29 @@ SDLSystem::SDLSystem(const std::initializer_list& flag_sdl, mix_flag |= _internal::getIntFromMixInitFlag(v); } - int ret=SDL_Init(sdl_flag); - if(ret!=0) + try { - ErrorViewer e; - e.fetch(); - throw e; + _init(sdl_flag,img_flag,mix_flag,init_ttf); } - - ret=IMG_Init(img_flag); - if(ret!=img_flag) /// IMG_Init returns its parameter on success. + catch(ErrorViewer& e) { - ErrorViewer e; - e.fetch(); 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(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf) throw (ErrorViewer) +{ + try + { + _init(sdl_flag,img_flag,mix_flag,init_ttf); + } + catch(ErrorViewer& e) + { + throw e; + } +} + + SDLSystem::~SDLSystem() { if(TTF_WasInit()) diff --git a/SDLWrapper/SDLSystem.h b/SDLWrapper/SDLSystem.h index 6d16477..67ff90e 100644 --- a/SDLWrapper/SDLSystem.h +++ b/SDLWrapper/SDLSystem.h @@ -19,6 +19,8 @@ public: const std::initializer_list& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} , const std::initializer_list& flag_mix = {MixInitFlag::MP3} , bool init_ttf = true ) throw (ErrorViewer); + /// Experimental Constructor + SDLSystem(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf) throw (ErrorViewer); ~SDLSystem(); static void Delay(int ms); @@ -66,5 +68,9 @@ public: static std::string GetExternal(); static void* GetJNIEnv(); }; + +private: + void _init(Uint32,Uint32,Uint32,bool) throw (ErrorViewer); + void _quit(); }; #include "end_code.h"