From ad34163fbfa87ba713d64b5c3f7e349fd6d48214 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 28 Jun 2017 15:13:55 +0800 Subject: [PATCH 01/22] Add some functions to Rect --- SDLWrapper/Renderer.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ SDLWrapper/Renderer.h | 6 ++++++ 2 files changed, 47 insertions(+) diff --git a/SDLWrapper/Renderer.cpp b/SDLWrapper/Renderer.cpp index 3c2c9c9..89a25d7 100644 --- a/SDLWrapper/Renderer.cpp +++ b/SDLWrapper/Renderer.cpp @@ -141,6 +141,47 @@ int Renderer::drawLines(const std::vector& pointvec) return drawLines(pointvec.data(),pointvec.size()); } +int Renderer::fillRects(const std::vector& rectvec) +{ + std::vector thisvec; + for(auto& rectref:rectvec) + { + thisvec.push_back(rectref.toSDLRect()); + } + return fillRects(thisvec); +} + +int Renderer::drawRects(const std::vector& rectvec) +{ + std::vector thisvec; + for(auto& rectref:rectvec) + { + thisvec.push_back(rectref.toSDLRect()); + } + return drawRects(thisvec); +} + +int Renderer::drawPoints(const std::vector& pointvec) +{ + std::vector thisvec; + for(auto& pointref:pointvec) + { + thisvec.push_back(pointref.toSDLPoint()); + } + return drawPoints(thisvec); +} + +int Renderer::drawLines(const std::vector& pointvec) +{ + std::vector thisvec; + for(auto& pointref:pointvec) + { + thisvec.push_back(pointref.toSDLPoint()); + } + return drawLines(thisvec); +} + + int Renderer::setScale(float scaleX, float scaleY) { return SDL_RenderSetScale(_get(),scaleX,scaleY); diff --git a/SDLWrapper/Renderer.h b/SDLWrapper/Renderer.h index 93ac6ba..6faa64e 100644 --- a/SDLWrapper/Renderer.h +++ b/SDLWrapper/Renderer.h @@ -56,6 +56,12 @@ public: int drawPoints(const std::vector& pointvec); int drawLines(const std::vector& pointvec); + /// Slower Functions (Need Convert First, then call Experimental Functions.) + int fillRects(const std::vector& rectvec); + int drawRects(const std::vector& rectvec); + int drawPoints(const std::vector& pointvec); + int drawLines(const std::vector& pointvec); + int setScale(float scaleX,float scaleY); std::tuple getScale() const; From 2d0b1b77a8cbb85b900b78ab5bab662ec1c35f36 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 28 Jun 2017 15:27:13 +0800 Subject: [PATCH 02/22] Enable software Renderer creating in class Renderer --- SDLWrapper/Renderer.cpp | 90 +++++++++++++++++++++++++---------------- SDLWrapper/Renderer.h | 5 +++ 2 files changed, 61 insertions(+), 34 deletions(-) diff --git a/SDLWrapper/Renderer.cpp b/SDLWrapper/Renderer.cpp index 89a25d7..85322ff 100644 --- a/SDLWrapper/Renderer.cpp +++ b/SDLWrapper/Renderer.cpp @@ -20,6 +20,40 @@ SDL_Renderer* Renderer::_get() const return _rnd.get(); } +// private +int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags) +{ + SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags); + if(pSDLRnd!=nullptr) + { + _set(pSDLRnd); + return 0; + } + else + { + return -1; + } +} + +// private +Uint32 Renderer::_rendertype_caster(RendererType Type) +{ + switch(Type) + { + case RendererType::Accelerated: + return SDL_RENDERER_ACCELERATED; + case RendererType::PresentSync: + return SDL_RENDERER_PRESENTVSYNC; + case RendererType::Software: + return SDL_RENDERER_SOFTWARE; + case RendererType::TargetTexture: + return SDL_RENDERER_TARGETTEXTURE; + } + + /// If an error occurs, return 0 by default. + return 0; +} + Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags) throw (ErrorViewer) { if(createRenderer(wnd,RendererFlags)!=0) @@ -28,6 +62,14 @@ Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags } } +Renderer::Renderer(Surface& surf) throw (ErrorViewer) +{ + if(createSoftRenderer(surf)!=0) + { + throw ErrorViewer(); + } +} + int Renderer::createRenderer(Window& wnd,std::initializer_list RendererFlags) { Uint32 flag = 0; @@ -38,6 +80,20 @@ int Renderer::createRenderer(Window& wnd,std::initializer_list Ren return _createRenderer_Real(wnd,flag); } +int Renderer::createSoftRenderer(Surface& surf) +{ + SDL_Renderer* pRnd=SDL_CreateSoftwareRenderer(surf._get()); + if(pRnd!=nullptr) + { + _set(pRnd); + return 0; + } + else + { + return -1; + } +} + int Renderer::setColor(const RGBA& pack) { return SDL_SetRenderDrawColor(_get(), pack.r, pack.g, pack.b, pack.a); @@ -456,38 +512,4 @@ int Renderer::GetDriversNum() return SDL_GetNumRenderDrivers(); } -// private -Uint32 Renderer::_rendertype_caster(RendererType Type) -{ - switch(Type) - { - case RendererType::Accelerated: - return SDL_RENDERER_ACCELERATED; - case RendererType::PresentSync: - return SDL_RENDERER_PRESENTVSYNC; - case RendererType::Software: - return SDL_RENDERER_SOFTWARE; - case RendererType::TargetTexture: - return SDL_RENDERER_TARGETTEXTURE; - } - - /// If an error occurs, return 0 by default. - return 0; -} - -// private -int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags) -{ - SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags); - if(pSDLRnd!=nullptr) - { - _set(pSDLRnd); - return 0; - } - else - { - return -1; - } -} - #include "end_code.h" diff --git a/SDLWrapper/Renderer.h b/SDLWrapper/Renderer.h index 6faa64e..b26084b 100644 --- a/SDLWrapper/Renderer.h +++ b/SDLWrapper/Renderer.h @@ -11,7 +11,10 @@ class Renderer { public: Renderer() = default; + /// Create a Renderer associated with Window Renderer(Window& wnd,std::initializer_list RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw (ErrorViewer); + /// Create a software Renderer + Renderer(Surface& surf) throw (ErrorViewer); ~Renderer() = default; /// If Renderer is current not ready, setRenderer will create Renderer. @@ -31,6 +34,8 @@ public: int createRenderer(Window& wnd,std::initializer_list); + int createSoftRenderer(Surface& surf); + int setColor(const RGBA& pack); RGBA getColor() const; int setBlendMode(BlendMode mode); From 17f12ecc2fbd83a07acad5678561a8127fa2342d Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 14:48:58 +0800 Subject: [PATCH 03/22] Add Nonmoveable --- SDLWrapper/__Nonmoveable.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 SDLWrapper/__Nonmoveable.h diff --git a/SDLWrapper/__Nonmoveable.h b/SDLWrapper/__Nonmoveable.h new file mode 100644 index 0000000..6a6cce1 --- /dev/null +++ b/SDLWrapper/__Nonmoveable.h @@ -0,0 +1,9 @@ +#pragma once +#include "begin_code.h" +class NonMoveable +{ +public: + NonMoveable(NonMoveable&&) =delete; + NonMoveable& operator = (NonMoveable&&)=delete; +}; +#include "end_code.h" From b6f7e70cddfd04a23d5fd8dc5680ce95f19e87b0 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 14:50:01 +0800 Subject: [PATCH 04/22] Remove main function provided in MiniEngine --- MiniEngine.cpp | 24 ------------------------ MiniEngine.h | 10 ---------- 2 files changed, 34 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 687a572..e4b2650 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -130,27 +130,3 @@ bool canexecute(std::string Path) #else /// _MINIENGINE_HAS_UNISTD == 0 /// File Functions will be implied in platform specific source file. #endif - -int _miniengine_argc; -char** _miniengine_argv; - - /// Default Setup Code -int main(int argc, char* argv[]) -{ - _miniengine_argc=argc; - _miniengine_argv=argv; - MiniEngine::SDLSystem::Init(); - int ret = AppMain(); - MiniEngine::SDLSystem::Quit(); - return ret; -} - -int GetArgc() -{ - return _miniengine_argc; -} - -char** GetArgv() -{ - return _miniengine_argv; -} diff --git a/MiniEngine.h b/MiniEngine.h index 6604e92..e48ef73 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -39,13 +39,3 @@ bool canread(std::string Path); bool canwrite(std::string Path); bool isexist(std::string Path); bool canexecute(std::string Path); - - /// Your Program Should Start Here -int AppMain(); - -/// MiniEngine Provides main -int main(int argc,char* argv[]); - -/// MiniEngine Provided API: Get Start Parameters -int GetArgc(); -char** GetArgv(); From 5eb66f6d0da0c8a91acf87ad4966fad51a8ee149 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 15:26:52 +0800 Subject: [PATCH 05/22] Move SDL,IMG,Mix,TTF Init to SDLSystem --- SDLWrapper/SDLSystem.cpp | 120 +++++++++++++++++++------------------ SDLWrapper/SDLSystem.h | 25 ++++---- SDLWrapper/_IMGInitFlag.h | 11 ++++ SDLWrapper/_MixInitFlag.h | 12 ++++ SDLWrapper/_SDLInitFlag.h | 14 +++++ SDLWrapper/__Nonmoveable.h | 2 + SDLWrapper/_caster.cpp | 61 +++++++++++++++++++ SDLWrapper/_caster.h | 6 ++ 8 files changed, 181 insertions(+), 70 deletions(-) create mode 100644 SDLWrapper/_IMGInitFlag.h create mode 100644 SDLWrapper/_MixInitFlag.h create mode 100644 SDLWrapper/_SDLInitFlag.h diff --git a/SDLWrapper/SDLSystem.cpp b/SDLWrapper/SDLSystem.cpp index 738cfc6..b84d86e 100644 --- a/SDLWrapper/SDLSystem.cpp +++ b/SDLWrapper/SDLSystem.cpp @@ -1,69 +1,73 @@ #include "SDLSystem.h" +#include "_caster.h" #include "begin_code.h" -//static -int SDLSystem::SDLInit() +SDLSystem::SDLSystem(const std::initializer_list& flag_sdl, + const std::initializer_list& flag_img, + const std::initializer_list& flag_mix, + bool init_ttf ) throw (ErrorViewer) { - return SDL_Init(SDL_INIT_EVERYTHING); + Uint32 sdl_flag=0; + for(auto& v:flag_sdl) + { + sdl_flag |= _internal::getUint32FromSDLInitFlag(v); + } + int img_flag=0; + for(auto& v:flag_img) + { + img_flag |= _internal::getIntFromIMGInitFlag(v); + } + int mix_flag=0; + for(auto& v:flag_mix) + { + mix_flag |= _internal::getIntFromMixInitFlag(v); + } + + int ret=SDL_Init(sdl_flag); + if(ret!=0) + { + ErrorViewer e; + e.fetch(); + throw e; + } + + ret=IMG_Init(img_flag); + if(ret!=0) + { + ErrorViewer e; + e.fetch(); + throw e; + } + + ret=Mix_Init(mix_flag); + if(ret!=0) + { + ErrorViewer e; + e.fetch(); + throw e; + } + + if(init_ttf) + { + ret=TTF_Init(); + if(ret!=0) + { + ErrorViewer e; + e.fetch(); + throw e; + } + } } -//static -void SDLSystem::SDLQuit() +SDLSystem::~SDLSystem() { - SDL_Quit(); -} + if(TTF_WasInit()) + { + TTF_Quit(); + } -//static -int SDLSystem::IMGInit() -{ - return IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG); -} - -//static -void SDLSystem::IMGQuit() -{ - IMG_Quit(); -} - -//static -int SDLSystem::TTFInit() -{ - return TTF_Init(); -} - -//static -void SDLSystem::TTFQuit() -{ - TTF_Quit(); -} - -//static -int SDLSystem::MixInit() -{ - return Mix_Init(MIX_INIT_MP3); -} - -//static -void SDLSystem::MixQuit() -{ Mix_Quit(); -} - -//static -void SDLSystem::Init() -{ - SDLInit(); - IMGInit(); - TTFInit(); - MixInit(); -} - -//static -void SDLSystem::Quit() -{ - MixQuit(); - TTFQuit(); - IMGQuit(); - SDLQuit(); + IMG_Quit(); + SDL_Quit(); } //static diff --git a/SDLWrapper/SDLSystem.h b/SDLWrapper/SDLSystem.h index 4a5422f..79d704b 100644 --- a/SDLWrapper/SDLSystem.h +++ b/SDLWrapper/SDLSystem.h @@ -2,23 +2,24 @@ #include "include.h" #include "_PowerState.h" #include "_Platform.h" +#include "_SDLInitFlag.h" +#include "_IMGInitFlag.h" +#include "_MixInitFlag.h" +#include "__Noncopyable.h" +#include "__Nonmoveable.h" +#include "ErrorViewer.h" #include #include #include "begin_code.h" -class SDLSystem + +class SDLSystem : public NonCopyable, public NonMoveable { public: - static int SDLInit(); - static void SDLQuit(); - static int IMGInit(); - static void IMGQuit(); - static int TTFInit(); - static void TTFQuit(); - static int MixInit(); - static void MixQuit(); - - static void Init(); - static void Quit(); + SDLSystem(const std::initializer_list& flag_sdl = {SDLInitFlag::All} , + const std::initializer_list& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} , + const std::initializer_list& flag_mix = {MixInitFlag::MP3} , + bool init_ttf = true ) throw (ErrorViewer); + ~SDLSystem(); static void Delay(int ms); diff --git a/SDLWrapper/_IMGInitFlag.h b/SDLWrapper/_IMGInitFlag.h new file mode 100644 index 0000000..ed9085e --- /dev/null +++ b/SDLWrapper/_IMGInitFlag.h @@ -0,0 +1,11 @@ +#pragma once +#include "begin_code.h" +enum class IMGInitFlag +{ + JPG, + PNG, + TIF, + WEBP, + ALL +}; +#include "end_code.h" diff --git a/SDLWrapper/_MixInitFlag.h b/SDLWrapper/_MixInitFlag.h new file mode 100644 index 0000000..8f70ef6 --- /dev/null +++ b/SDLWrapper/_MixInitFlag.h @@ -0,0 +1,12 @@ +#pragma once +#include "begin_code.h" +enum class MixInitFlag +{ + FLAC, + MOD, + MODPLUG, + MP3, + OGG, + FLUIDSYNTH +}; +#include "end_code.h" diff --git a/SDLWrapper/_SDLInitFlag.h b/SDLWrapper/_SDLInitFlag.h new file mode 100644 index 0000000..dfa67df --- /dev/null +++ b/SDLWrapper/_SDLInitFlag.h @@ -0,0 +1,14 @@ +#pragma once +#include "begin_code.h" +enum class SDLInitFlag +{ + Timer, + Audio, + Video, /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ + Joystick, /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */ + Haptic, + GameController, /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */ + Events, + All +}; +#include "end_code.h" diff --git a/SDLWrapper/__Nonmoveable.h b/SDLWrapper/__Nonmoveable.h index 6a6cce1..0d5bca4 100644 --- a/SDLWrapper/__Nonmoveable.h +++ b/SDLWrapper/__Nonmoveable.h @@ -3,6 +3,8 @@ class NonMoveable { public: + NonMoveable()=default; + ~NonMoveable()=default; NonMoveable(NonMoveable&&) =delete; NonMoveable& operator = (NonMoveable&&)=delete; }; diff --git a/SDLWrapper/_caster.cpp b/SDLWrapper/_caster.cpp index df00204..dfa1194 100644 --- a/SDLWrapper/_caster.cpp +++ b/SDLWrapper/_caster.cpp @@ -215,5 +215,66 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode) return SDL_FLIP_NONE; } } + +Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag) +{ + switch(flag) + { + case SDLInitFlag::Timer: + return SDL_INIT_TIMER; + case SDLInitFlag::Audio: + return SDL_INIT_AUDIO; + case SDLInitFlag::Video: + return SDL_INIT_VIDEO; + case SDLInitFlag::Joystick: + return SDL_INIT_JOYSTICK; + case SDLInitFlag::Haptic: + return SDL_INIT_HAPTIC; + case SDLInitFlag::GameController: + return SDL_INIT_GAMECONTROLLER; + case SDLInitFlag::Events: + return SDL_INIT_EVENTS; + case SDLInitFlag::All: + return SDL_INIT_EVERYTHING; + } +} + + +int getIntFromIMGInitFlag(IMGInitFlag flag) +{ + switch(flag) + { + case IMGInitFlag::JPG: + return IMG_INIT_JPG; + case IMGInitFlag::PNG: + return IMG_INIT_PNG; + case IMGInitFlag::TIF: + return IMG_INIT_TIF; + case IMGInitFlag::WEBP: + return IMG_INIT_WEBP; + case IMGInitFlag::ALL: + return ( IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF | IMG_INIT_WEBP ); + } +} + +int getIntFromMixInitFlag(MixInitFlag flag) +{ + switch(flag) + { + case MixInitFlag::FLAC: + return MIX_INIT_FLAC; + case MixInitFlag::MOD: + return MIX_INIT_MOD; + case MixInitFlag::MODPLUG: + return MIX_INIT_MODPLUG; + case MixInitFlag::MP3: + return MIX_INIT_MP3; + case MixInitFlag::OGG: + return MIX_INIT_OGG; + case MixInitFlag::FLUIDSYNTH: + return MIX_INIT_FLUIDSYNTH; + } +} + }/// End of namespace _internal #include "end_code.h" diff --git a/SDLWrapper/_caster.h b/SDLWrapper/_caster.h index 646fa35..171c403 100644 --- a/SDLWrapper/_caster.h +++ b/SDLWrapper/_caster.h @@ -5,6 +5,9 @@ #include "_SystemCursorType.h" #include "_FontStyle.h" #include "_FlipMode.h" +#include "_SDLInitFlag.h" +#include "_IMGInitFlag.h" +#include "_MixInitFlag.h" #include #include "begin_code.h" namespace _internal @@ -18,5 +21,8 @@ SDL_SystemCursor getSDLSystemCursorFromSystemCursorType(SystemCursorType type); int getTTFFontStyleFromFontStyle(FontStyle style); std::vector getFontStyleVecFromMixedTTFFontStyle(int Mixed_TTF_Font_Style); SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode); +Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag); +int getIntFromIMGInitFlag(IMGInitFlag flag); +int getIntFromMixInitFlag(MixInitFlag flag); }/// End of namespace _internal #include "end_code.h" From 46204ba517821d02d368db75b1ba2688f16bcaa9 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 15:39:51 +0800 Subject: [PATCH 06/22] Move clipboard functions to SDLSystem --- SDLWrapper/SDLSystem.cpp | 29 +++++++++++++++++++++++++++++ SDLWrapper/SDLSystem.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/SDLWrapper/SDLSystem.cpp b/SDLWrapper/SDLSystem.cpp index b84d86e..f0d309f 100644 --- a/SDLWrapper/SDLSystem.cpp +++ b/SDLWrapper/SDLSystem.cpp @@ -244,4 +244,33 @@ int SDLSystem::GetSystemRAM() { return SDL_GetSystemRAM(); } + +//static +int SDLSystem::SetClipboardText(const std::string& str) +{ + return SDL_SetClipboardText(str.c_str()); +} + +//static +std::string SDLSystem::GetClipboardText() +{ + char* pstr=SDL_GetClipboardText(); + if(pstr==nullptr) + { + return std::string(); + } + else + { + std::string s(pstr); + SDL_free(pstr); + return s; + } +} + +//static +bool SDLSystem::HasClipboardText() +{ + return SDL_HasClipboardText()==SDL_TRUE; +} + #include "end_code.h" diff --git a/SDLWrapper/SDLSystem.h b/SDLWrapper/SDLSystem.h index 79d704b..6d16477 100644 --- a/SDLWrapper/SDLSystem.h +++ b/SDLWrapper/SDLSystem.h @@ -52,6 +52,10 @@ public: /// RAM is calculated in MB. static int GetSystemRAM(); + static int SetClipboardText(const std::string& str); + static std::string GetClipboardText(); + static bool HasClipboardText(); + class Android { public: From 2fdf701703bd9789034124366344454f7d1ee84c Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 15:46:42 +0800 Subject: [PATCH 07/22] Fix bugs in SDLSystem. Update MiniEngine --- MiniEngine.cpp | 25 ------------------------- MiniEngine.h | 5 ----- SDLWrapper/SDLSystem.cpp | 4 ++-- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index e4b2650..eca5768 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -74,31 +74,6 @@ namespace MiniEngine delete pimpl; } - int SetClipboardText(const std::string& str) - { - return SDL_SetClipboardText(str.c_str()); - } - - std::string GetClipboardText() - { - char* pstr=SDL_GetClipboardText(); - if(pstr==nullptr) - { - return std::string(); - } - else - { - std::string s(pstr); - SDL_free(pstr); - return s; - } - } - - bool HasClipboardText() - { - return SDL_HasClipboardText()==SDL_TRUE; - } - bool GetScanKeyState(SDL_Scancode code) { return SDL_GetKeyboardState(NULL)[code]; diff --git a/MiniEngine.h b/MiniEngine.h index e48ef73..0a7ce45 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -4,7 +4,6 @@ #include #include "SDLWrapper/IncludeAll.h" - namespace MiniEngine { class StringEngine @@ -24,10 +23,6 @@ namespace MiniEngine impl* pimpl; }; - int SetClipboardText(const std::string& str); - std::string GetClipboardText(); - bool HasClipboardText(); - /// Experimental - For Experts: Use SDL ScanCode bool GetScanKeyState(SDL_Scancode); diff --git a/SDLWrapper/SDLSystem.cpp b/SDLWrapper/SDLSystem.cpp index f0d309f..c8d0c48 100644 --- a/SDLWrapper/SDLSystem.cpp +++ b/SDLWrapper/SDLSystem.cpp @@ -31,7 +31,7 @@ SDLSystem::SDLSystem(const std::initializer_list& flag_sdl, } ret=IMG_Init(img_flag); - if(ret!=0) + if(ret!=img_flag) /// IMG_Init returns its parameter on success. { ErrorViewer e; e.fetch(); @@ -39,7 +39,7 @@ SDLSystem::SDLSystem(const std::initializer_list& flag_sdl, } ret=Mix_Init(mix_flag); - if(ret!=0) + if(ret!=mix_flag) /// Mix_Init returns its parameter on success. { ErrorViewer e; e.fetch(); From 943cb0def024a21a308e340fc1a0007de15d01a5 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 15:58:34 +0800 Subject: [PATCH 08/22] Event handling are now under MiniEngine namespace --- MiniEngine_Event.cpp | 5 +++++ MiniEngine_Event.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/MiniEngine_Event.cpp b/MiniEngine_Event.cpp index d3e8720..14bd876 100644 --- a/MiniEngine_Event.cpp +++ b/MiniEngine_Event.cpp @@ -1,5 +1,8 @@ #include "MiniEngine_Event.h" +namespace MiniEngine +{ + int PollEvent(Event& refEvent) { return SDL_PollEvent(&refEvent); @@ -279,3 +282,5 @@ void LooperWithTime::run() } } } + +}/// End of namespace MiniEngine diff --git a/MiniEngine_Event.h b/MiniEngine_Event.h index b3c5ed4..8b0c8fb 100644 --- a/MiniEngine_Event.h +++ b/MiniEngine_Event.h @@ -4,6 +4,9 @@ #include #include +namespace MiniEngine +{ + typedef SDL_Event Event; typedef decltype(Event::type) _SDLEventType_; @@ -97,3 +100,5 @@ public: protected: int _timeout_ms; }; + +}/// End of namespace MiniEngine From f500a470f671cd07178111b6b921e4ae42af483c Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 16:29:04 +0800 Subject: [PATCH 09/22] Add Plugin class --- SDLWrapper/__Plugin.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 SDLWrapper/__Plugin.h diff --git a/SDLWrapper/__Plugin.h b/SDLWrapper/__Plugin.h new file mode 100644 index 0000000..dd66522 --- /dev/null +++ b/SDLWrapper/__Plugin.h @@ -0,0 +1,36 @@ +#pragma once +#include "begin_code.h" +namespace _internal +{ + +/// This is just an empty class. +/// Most wrapper class regard this class as a friend class. +/// You can get/set raw pointers through this class. +class Plugin +{ +public: + template + decltype(auto) get(const T& obj) + { + return obj._get(); + } + template + void set(T& obj,U&& value) + { + obj._set(value); + } + template + void clear(T& obj) + { + obj._clear(); + } + + template + void set_no_delete(T& obj,U&& value) + { + obj._set_no_delete(value); + } +}; + +} +#include "end_code.h" From c6f54fa3cb69b3a38fc0195c66474c6d280ea2b8 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 17:11:06 +0800 Subject: [PATCH 10/22] Add Plugin as friend to wrapped class. --- SDLWrapper/Cursor.h | 3 +++ SDLWrapper/Font.h | 3 +++ SDLWrapper/Music.h | 3 +++ SDLWrapper/RWOP.h | 3 +++ SDLWrapper/Renderer.h | 3 +++ SDLWrapper/Sound.h | 2 ++ SDLWrapper/Surface.h | 3 +++ SDLWrapper/Texture.h | 3 +++ SDLWrapper/Window.h | 2 ++ 9 files changed, 25 insertions(+) diff --git a/SDLWrapper/Cursor.h b/SDLWrapper/Cursor.h index b1b381d..6b45469 100644 --- a/SDLWrapper/Cursor.h +++ b/SDLWrapper/Cursor.h @@ -3,6 +3,7 @@ #include "_SystemCursorType.h" #include "Point.h" #include "Surface.h" +#include "__Plugin.h" #include "begin_code.h" class Cursor { @@ -26,5 +27,7 @@ private: void _set_no_delete(SDL_Cursor*); SDL_Cursor* _get(); void _clear(); + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Font.h b/SDLWrapper/Font.h index d2d9a24..1587746 100644 --- a/SDLWrapper/Font.h +++ b/SDLWrapper/Font.h @@ -7,6 +7,7 @@ #include "Texture.h" #include "Renderer.h" #include +#include "__Plugin.h" #include "begin_code.h" class Font { @@ -118,5 +119,7 @@ private: void _set(TTF_Font*); void _clear(); TTF_Font* _get() const; + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Music.h b/SDLWrapper/Music.h index 7966886..aebc972 100644 --- a/SDLWrapper/Music.h +++ b/SDLWrapper/Music.h @@ -5,6 +5,7 @@ #include "ErrorViewer.h" #include "Audio.h" #include "__Noncopyable.h" +#include "__Plugin.h" #include "begin_code.h" /// Forward Declaration class Music @@ -19,7 +20,9 @@ private: void _set(Mix_Music*); void _clear(); Mix_Music* _get() const; + friend class MusicPlayer; + friend class _internal::Plugin; }; class MusicPlayer : public AudioPlayer, public NonCopyable diff --git a/SDLWrapper/RWOP.h b/SDLWrapper/RWOP.h index 0dd8418..6c0530a 100644 --- a/SDLWrapper/RWOP.h +++ b/SDLWrapper/RWOP.h @@ -3,6 +3,7 @@ #include #include #include +#include "__Plugin.h" #include "begin_code.h" class RWOP { @@ -22,5 +23,7 @@ private: void _set(SDL_RWops*); friend class Surface; friend class Renderer; + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Renderer.h b/SDLWrapper/Renderer.h index b26084b..be95dfc 100644 --- a/SDLWrapper/Renderer.h +++ b/SDLWrapper/Renderer.h @@ -5,6 +5,7 @@ #include "Window.h" #include "Surface.h" #include "Texture.h" +#include "__Plugin.h" #include #include "begin_code.h" class Renderer @@ -145,5 +146,7 @@ private: void _set(SDL_Renderer*); void _clear(); SDL_Renderer* _get() const; + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Sound.h b/SDLWrapper/Sound.h index b1f677c..3ab2e48 100644 --- a/SDLWrapper/Sound.h +++ b/SDLWrapper/Sound.h @@ -4,6 +4,7 @@ #include #include "Audio.h" #include "ErrorViewer.h" +#include "__Plugin.h" #include "begin_code.h" class Sound { @@ -19,6 +20,7 @@ private: Mix_Chunk* _get() const; friend class Channel; + friend class _internal::Plugin; }; class Channel diff --git a/SDLWrapper/Surface.h b/SDLWrapper/Surface.h index a83fcf6..3fce1dc 100644 --- a/SDLWrapper/Surface.h +++ b/SDLWrapper/Surface.h @@ -5,6 +5,7 @@ #include "Point.h" #include "RWOP.h" #include "ErrorViewer.h" +#include "__Plugin.h" #include "begin_code.h" class Surface { @@ -81,6 +82,8 @@ private: friend class Renderer; friend class Font; friend class Cursor; + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Texture.h b/SDLWrapper/Texture.h index b023244..3c0dcfc 100644 --- a/SDLWrapper/Texture.h +++ b/SDLWrapper/Texture.h @@ -4,6 +4,7 @@ #include "RGBA.h" #include "ColorMode.h" #include "_BlendMode.h" +#include "__Plugin.h" #include #include "begin_code.h" @@ -40,6 +41,8 @@ private: SDL_Texture* _get() const; Rect _rect; friend class Renderer; + + friend class _internal::Plugin; }; #include "end_code.h" diff --git a/SDLWrapper/Window.h b/SDLWrapper/Window.h index 4e1a9e9..644bd0f 100644 --- a/SDLWrapper/Window.h +++ b/SDLWrapper/Window.h @@ -5,6 +5,7 @@ #include "ErrorViewer.h" #include "MessageBox.h" #include "Surface.h" +#include "__Plugin.h" #include "begin_code.h" class Window { @@ -62,5 +63,6 @@ private: SDL_Window* _get() const; friend class Renderer; + friend class _internal::Plugin; }; #include "end_code.h" From ff862f1dea771feb087f9eade8534efa67f106f9 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 17:21:35 +0800 Subject: [PATCH 11/22] Change Plugin methods to static --- SDLWrapper/__Plugin.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SDLWrapper/__Plugin.h b/SDLWrapper/__Plugin.h index dd66522..c9430ff 100644 --- a/SDLWrapper/__Plugin.h +++ b/SDLWrapper/__Plugin.h @@ -10,23 +10,23 @@ class Plugin { public: template - decltype(auto) get(const T& obj) + static decltype(auto) get(const T& obj) { return obj._get(); } template - void set(T& obj,U&& value) + static void set(T& obj,U&& value) { obj._set(value); } template - void clear(T& obj) + static void clear(T& obj) { obj._clear(); } template - void set_no_delete(T& obj,U&& value) + static void set_no_delete(T& obj,U&& value) { obj._set_no_delete(value); } From 1ca4e2bc3f03a65fc296f17b38ee2e49eb0e0b4e Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 1 Jul 2017 20:34:34 +0800 Subject: [PATCH 12/22] Update Event Loop to do-while style --- MiniEngine_Event.cpp | 107 ++++++++++++++++++++++--------------------- MiniEngine_Event.h | 1 - 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/MiniEngine_Event.cpp b/MiniEngine_Event.cpp index 14bd876..671b02a 100644 --- a/MiniEngine_Event.cpp +++ b/MiniEngine_Event.cpp @@ -67,22 +67,22 @@ Looper::Looper() LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) { _evmap[event_type].push_front(std::make_pair(_loop_cnt,event_callback)); - return _getNextID(event_type); + return _getNextID(event_type); } LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) { _evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback(ev);})); - return _getNextID(event_type); + return _getNextID(event_type); } LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) { _evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback(lp);})); - return _getNextID(event_type); + return _getNextID(event_type); } LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) { _evmap[event_type].push_front(std::make_pair(_loop_cnt,[=](Looper& lp,Event& ev)->int{return event_callback();})); - return _getNextID(event_type); + return _getNextID(event_type); } LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) @@ -99,7 +99,7 @@ LooperID Looper::add(_SDLEventType_ event_type,const std::function& event_callback) { - return add(event_type,std::function([=](Looper& lp,Event& ev)->int{event_callback();return 0;})); + return add(event_type,std::function([=](Looper& lp,Event& ev)->int{event_callback(); return 0;})); } LooperID Looper::operator + (const std::pair<_SDLEventType_,std::function>& event_callback) @@ -140,10 +140,10 @@ LooperID Looper::operator + (const std::pair<_SDLEventType_,std::functionfirst==looperid._looper_cnt) { @@ -169,17 +169,20 @@ void Looper::dispatch() } void Looper::run() { - while(_running) + do { + if(_update) + { + updater(); + _update=false; + } + while(!_update&&WaitEvent(_e)) { dispatch(); } - - updater(); - - _update=false; } + while(_running); } Event Looper::GetLastEvent() { @@ -189,14 +192,10 @@ void Looper::needupdate() { _update=true; } -void Looper::needstop() -{ - _running=false; -} void Looper::stop() { - needstop(); - needupdate(); + _running=false; + _update=true; } void Looper::reset() { @@ -209,30 +208,37 @@ void Looper::reset() LooperID Looper::_getNextID(const _SDLEventType_& event_type) { - LooperID id; - id._looper_cnt = _loop_cnt; - id._type_id = event_type; + LooperID id; + id._looper_cnt = _loop_cnt; + id._type_id = event_type; - ++_loop_cnt; - return id; + ++_loop_cnt; + return id; } Poller::Poller() { - idler=[](){}; + idler=[]() {}; } void Poller::reset() { Looper::reset(); - idler=[](){}; + idler=[]() {}; } void Poller::run() { int pollret=1; - while(_running) + + do { + if(_update) + { + updater(); + _update=false; + } + while(!_update&&(pollret=PollEvent(_e))) { dispatch(); @@ -240,47 +246,46 @@ void Poller::run() /// If pollret is not 0 (new event requests update), or pollret is 0 (No New Event) but Idle function requests update, then call updater. if(!pollret) idler(); - if(_update) - { - updater(); - _update=false; - } + } + while(_running); } LooperWithTime::LooperWithTime(int Timeout_ms) { - _timeout_ms = Timeout_ms; + _timeout_ms = Timeout_ms; } void LooperWithTime::setTimeout(int ms) { - _timeout_ms = ms; + _timeout_ms = ms; } int LooperWithTime::getTimeout() const { - return _timeout_ms; + return _timeout_ms; } void LooperWithTime::run() { - int timeret = 1; - while (_running) - { - while (!_update&&(timeret=WaitEventTimeout(_e, _timeout_ms))) - { - dispatch(); - } + int timeret = 1; + do + { + if (_update) + { + updater(); + _update = false; + } - /// If timeret is not 0 (new event request update), or timeret is 0 (Time out) but Idle function requests update, then call updater. - if (!timeret) idler(); - if (_update) - { - updater(); - _update = false; - } - } + while (!_update&&(timeret=WaitEventTimeout(_e, _timeout_ms))) + { + dispatch(); + } + + /// If timeret is not 0 (new event request update), or timeret is 0 (Time out) but Idle function requests update, then call updater. + if (!timeret) idler(); + } + while (_running); } }/// End of namespace MiniEngine diff --git a/MiniEngine_Event.h b/MiniEngine_Event.h index 8b0c8fb..e329f32 100644 --- a/MiniEngine_Event.h +++ b/MiniEngine_Event.h @@ -66,7 +66,6 @@ public: void run(); Event GetLastEvent(); void needupdate(); - void needstop(); void stop(); void reset(); From e080389709a33681977d2feb35e7cf4221d752a3 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 2 Jul 2017 08:43:25 +0800 Subject: [PATCH 13/22] Fix Compile Error and warning --- SDLWrapper/SharedLibrary.h | 1 + SDLWrapper/_caster.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/SDLWrapper/SharedLibrary.h b/SDLWrapper/SharedLibrary.h index 8b7b620..5438e41 100644 --- a/SDLWrapper/SharedLibrary.h +++ b/SDLWrapper/SharedLibrary.h @@ -2,6 +2,7 @@ #include "include.h" #include #include +#include #include "begin_code.h" class SharedLibrary { diff --git a/SDLWrapper/_caster.cpp b/SDLWrapper/_caster.cpp index dfa1194..7fdbd1b 100644 --- a/SDLWrapper/_caster.cpp +++ b/SDLWrapper/_caster.cpp @@ -236,6 +236,8 @@ Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag) return SDL_INIT_EVENTS; case SDLInitFlag::All: return SDL_INIT_EVERYTHING; + default: + return 0; /// Return 0 by default. (Fix warning) } } @@ -254,6 +256,8 @@ int getIntFromIMGInitFlag(IMGInitFlag flag) return IMG_INIT_WEBP; case IMGInitFlag::ALL: return ( IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF | IMG_INIT_WEBP ); + default: + return 0; /// Return 0 by default. (Fix warning) } } @@ -273,6 +277,8 @@ int getIntFromMixInitFlag(MixInitFlag flag) return MIX_INIT_OGG; case MixInitFlag::FLUIDSYNTH: return MIX_INIT_FLUIDSYNTH; + default: + return 0; /// Return 0 by default. (Fix warning) } } 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 14/22] 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" From 11d45b4bfda99e3e2cfb9209b2219157f4a0fa92 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 2 Jul 2017 10:01:05 +0800 Subject: [PATCH 15/22] Add Makefile Generator for C4droid --- makefile_c4 | 14 -------- makefile_c4gen.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 14 deletions(-) delete mode 100644 makefile_c4 create mode 100644 makefile_c4gen.cpp diff --git a/makefile_c4 b/makefile_c4 deleted file mode 100644 index 507ec04..0000000 --- a/makefile_c4 +++ /dev/null @@ -1,14 +0,0 @@ -CXXFLAGS = -std=c++14 -Wall -O2 -D__C4DROID__ -Iinclude -LDFLAGS = -LDLIBS = -lSDL2_image -lSDL2_net -ltiff -ljpeg -lpng -lz -lSDL2_ttf -lfreetype -lSDL2_mixer -lSDL2_test -lsmpeg2 -lvorbisfile -lvorbis -logg -lstdc++ -lSDL2 -lEGL -lGLESv1_CM -lGLESv2 -landroid -Wl,--no-undefined -shared - -PROG = program_name -OBJS = MiniEngine.o MiniEngine_Android.o MiniEngine_Event.o MiniEngine_Widget.o sqlite/sqlite3.o MiniEngine_SQLite.o - -all: $(PROG) - -$(PROG): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs` - -clean: - rm -f $(PROG) $(OBJS) \ No newline at end of file diff --git a/makefile_c4gen.cpp b/makefile_c4gen.cpp new file mode 100644 index 0000000..8daca92 --- /dev/null +++ b/makefile_c4gen.cpp @@ -0,0 +1,82 @@ +/// makefile_c4gen.cpp +/// Under MIT License. Part of MiniEngine Project. +/// You can run this code to generate a makefile for c4droid. + +#include +#include +#include +#include +#include +using namespace std; + +char buff[1024]; +int main() +{ + printf("#Detecting source files...#\n"); + // Set up environment + sprintf(buff,"PATH=%s:/data/data/com.n0n3m4.droidc/bzbox/",getenv("PATH")); + putenv(buff); + fflush(stdout); + system("find . -name \"*.cpp\" > cpplist.txt "); + system("find . -name \"*.c\" > clist.txt "); + vector dvec; + FILE* fp=fopen("cpplist.txt","r"); + memset(buff,0,1024); + while(fgets(buff,1024,fp)!=nullptr) + { + int len=strlen(buff); + if(buff[len-1]=='\n') buff[len-1]=0; + char* p=strstr(buff,".cpp"); + sprintf(p,".o"); + string d(buff); + dvec.push_back(d); + memset(buff,0,1024); + } + fclose(fp); + vector ccd; + fp=fopen("clist.txt","r"); + memset(buff,0,1024); + while(fgets(buff,1024,fp)!=nullptr) + { + int len=strlen(buff); + if(buff[len-1]=='\n') buff[len-1]=0; + char* p=strstr(buff,".c"); + sprintf(p,".o"); + string d(buff); + dvec.push_back(d); + memset(buff,0,1024); + } + fclose(fp); + + printf("#Excluding files...#\n"); + auto iter=find_if(dvec.begin(),dvec.end(),[](const string& str){ return (str.find("makefile_c4gen")!=string::npos);}); + if(iter!=dvec.end()) dvec.erase(iter); + + printf("#Generating makefile...#\n"); + fp=fopen("makefile","w"); + fprintf(fp, +"CXXFLAGS = -std=c++14 -Wall -O2 -D__C4DROID__ -Iinclude\n" +"LDFLAGS =\n" +"LDLIBS = -lSDL2_image -lSDL2_net -ltiff -ljpeg -lpng -lz -lSDL2_ttf -lfreetype -lSDL2_mixer " +"-lSDL2_test -lsmpeg2 -lvorbisfile -lvorbis -logg -lstdc++ -lSDL2 -lEGL -lGLESv1_CM -lGLESv2 " +"-landroid -Wl,--no-undefined -shared\n" +"PROG = program_name\n" +"OBJS = "); + for(auto& d:dvec) + { + fprintf(fp,"%s ",d.c_str()); + } + fprintf(fp,"\n"); + fprintf(fp, +"all: $(PROG)\n" +"\n" +"$(PROG): $(OBJS)\n" +"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n" +"\n" +"clean:\n" +"\trm -f $(PROG) $(OBJS))\n"); + fclose(fp); + + printf("#End of Generation#\n"); + return 0; +} From 977721b226bcae34fd6afc268a240bd5773639e7 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Mon, 3 Jul 2017 07:45:06 +0800 Subject: [PATCH 16/22] Add Git Attribute trying to fix language displaying problem --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e709388 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.c linguist-language=C++ +*.cpp linguist-language=C++ +*.h linguist-language=C++ +*.hpp linguist-language=C++ From 52918909e9a086674fe26c5b53d57eb37c346feb Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 4 Jul 2017 22:38:33 +0800 Subject: [PATCH 17/22] RWOP can now work with Music and Sound loading --- SDLWrapper/Music.cpp | 6 +++++ SDLWrapper/Music.h | 4 +++ SDLWrapper/RWOP.h | 2 ++ SDLWrapper/Sound.cpp | 5 ++++ SDLWrapper/Sound.h | 2 ++ SDLWrapper/_MusicType.h | 8 ++++++ SDLWrapper/_caster.cpp | 59 +++++++++++++++++++++++++++++++++++++++++ SDLWrapper/_caster.h | 3 +++ 8 files changed, 89 insertions(+) create mode 100644 SDLWrapper/_MusicType.h diff --git a/SDLWrapper/Music.cpp b/SDLWrapper/Music.cpp index 9bdae9b..0fd8a41 100644 --- a/SDLWrapper/Music.cpp +++ b/SDLWrapper/Music.cpp @@ -1,4 +1,5 @@ #include "Music.h" +#include "_caster.h" #include "begin_code.h" //private void Music::_set(Mix_Music* p) @@ -21,6 +22,11 @@ Music::Music(const std::string& Filename) _set(Mix_LoadMUS(Filename.c_str())); } +Music::Music(const RWOP& rwop,MusicType musicType) +{ + _set(Mix_LoadMUSType_RW(rwop._get(),_internal::getMixMusicTypeFromMusicType(musicType),0)); +} + bool Music::isReady() const { return (_get()!=nullptr); diff --git a/SDLWrapper/Music.h b/SDLWrapper/Music.h index aebc972..e5cbc1e 100644 --- a/SDLWrapper/Music.h +++ b/SDLWrapper/Music.h @@ -4,6 +4,8 @@ #include #include "ErrorViewer.h" #include "Audio.h" +#include "RWOP.h" +#include "_MusicType.h" #include "__Noncopyable.h" #include "__Plugin.h" #include "begin_code.h" @@ -13,8 +15,10 @@ class Music public: Music()=default; Music(const std::string& Filename); + Music(const RWOP& rwop,MusicType musicType); bool isReady() const; void release(); + MusicType getType() const; private: std::shared_ptr _music; void _set(Mix_Music*); diff --git a/SDLWrapper/RWOP.h b/SDLWrapper/RWOP.h index 6c0530a..bebefb3 100644 --- a/SDLWrapper/RWOP.h +++ b/SDLWrapper/RWOP.h @@ -23,6 +23,8 @@ private: void _set(SDL_RWops*); friend class Surface; friend class Renderer; + friend class Sound; + friend class Music; friend class _internal::Plugin; }; diff --git a/SDLWrapper/Sound.cpp b/SDLWrapper/Sound.cpp index 5852cd2..768f7bd 100644 --- a/SDLWrapper/Sound.cpp +++ b/SDLWrapper/Sound.cpp @@ -21,6 +21,11 @@ Sound::Sound(const std::string& WAVFilename) _set(Mix_LoadWAV(WAVFilename.c_str())); } +Sound::Sound(const RWOP& rwop) +{ + _set(Mix_LoadWAV_RW(rwop._get(),0)); +} + bool Sound::isReady() const { return (_get()!=nullptr); diff --git a/SDLWrapper/Sound.h b/SDLWrapper/Sound.h index 3ab2e48..9cb9043 100644 --- a/SDLWrapper/Sound.h +++ b/SDLWrapper/Sound.h @@ -4,6 +4,7 @@ #include #include "Audio.h" #include "ErrorViewer.h" +#include "RWOP.h" #include "__Plugin.h" #include "begin_code.h" class Sound @@ -11,6 +12,7 @@ class Sound public: Sound() = default; Sound(const std::string& WAVFilename); + Sound(const RWOP& rwop); bool isReady() const; void release(); private: diff --git a/SDLWrapper/_MusicType.h b/SDLWrapper/_MusicType.h new file mode 100644 index 0000000..7a11c5a --- /dev/null +++ b/SDLWrapper/_MusicType.h @@ -0,0 +1,8 @@ +#pragma once +#include "include.h" +#include "begin_code.h" +enum class MusicType +{ + None,CMD,WAV,MOD,MID,OGG,MP3,MP3MAD,FLAC,MODPLUG +}; +#include "end_code.h" diff --git a/SDLWrapper/_caster.cpp b/SDLWrapper/_caster.cpp index 7fdbd1b..7db951c 100644 --- a/SDLWrapper/_caster.cpp +++ b/SDLWrapper/_caster.cpp @@ -282,5 +282,64 @@ int getIntFromMixInitFlag(MixInitFlag flag) } } +MusicType getMusicTypeFromMixMusicType(Mix_MusicType type) +{ + switch(type) + { + case MUS_NONE: + return MusicType::None; + case MUS_CMD: + return MusicType::CMD; + case MUS_WAV: + return MusicType::WAV; + case MUS_MOD: + return MusicType::MOD; + case MUS_MID: + return MusicType::MID; + case MUS_OGG: + return MusicType::OGG; + case MUS_MP3: + return MusicType::MP3; + case MUS_MP3_MAD: + return MusicType::MP3MAD; + case MUS_FLAC: + return MusicType::FLAC; + case MUS_MODPLUG: + return MusicType::MODPLUG; + default: + return MusicType::None; + } +} + +Mix_MusicType getMixMusicTypeFromMusicType(MusicType type) +{ + switch(type) + { + case MusicType::None: + return MUS_NONE; + case MusicType::CMD: + return MUS_CMD; + case MusicType::WAV: + return MUS_WAV; + case MusicType::MOD: + return MUS_MOD; + case MusicType::MID: + return MUS_MID; + case MusicType::OGG: + return MUS_OGG; + case MusicType::MP3: + return MUS_MP3; + case MusicType::MP3MAD: + return MUS_MP3_MAD; + case MusicType::FLAC: + return MUS_FLAC; + case MusicType::MODPLUG: + return MUS_MODPLUG; + default: + return MUS_NONE; + } +} + + }/// End of namespace _internal #include "end_code.h" diff --git a/SDLWrapper/_caster.h b/SDLWrapper/_caster.h index 171c403..4583215 100644 --- a/SDLWrapper/_caster.h +++ b/SDLWrapper/_caster.h @@ -8,6 +8,7 @@ #include "_SDLInitFlag.h" #include "_IMGInitFlag.h" #include "_MixInitFlag.h" +#include "_MusicType.h" #include #include "begin_code.h" namespace _internal @@ -24,5 +25,7 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode); Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag); int getIntFromIMGInitFlag(IMGInitFlag flag); int getIntFromMixInitFlag(MixInitFlag flag); +MusicType getMusicTypeFromMixMusicType(Mix_MusicType); +Mix_MusicType getMixMusicTypeFromMusicType(MusicType); }/// End of namespace _internal #include "end_code.h" From cdddfc059e07b27b634ebc4487b46a5ac2f101cd Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 4 Jul 2017 22:48:44 +0800 Subject: [PATCH 18/22] Fix bugs in Music, MusicPlayer --- SDLWrapper/Music.cpp | 11 +++++++++++ SDLWrapper/Music.h | 1 + 2 files changed, 12 insertions(+) diff --git a/SDLWrapper/Music.cpp b/SDLWrapper/Music.cpp index 0fd8a41..8e9410b 100644 --- a/SDLWrapper/Music.cpp +++ b/SDLWrapper/Music.cpp @@ -37,6 +37,11 @@ void Music::release() _clear(); } +MusicType Music::getType() const +{ + return _internal::getMusicTypeFromMixMusicType(Mix_GetMusicType(_get())); +} + //static int MusicPlayer::GetDecoderNum() { @@ -75,6 +80,12 @@ int MusicPlayer::stop() return Mix_HaltMusic(); } +int MusicPlayer::fadeIn(Music music, int loops, int ms) +{ + m=music; + return fadeIn(loops,ms); +} + int MusicPlayer::fadeIn(int loops, int ms) { return Mix_FadeInMusic(m._get(), loops, ms); diff --git a/SDLWrapper/Music.h b/SDLWrapper/Music.h index e5cbc1e..1d870a6 100644 --- a/SDLWrapper/Music.h +++ b/SDLWrapper/Music.h @@ -42,6 +42,7 @@ public: void rewind(); int setPosition(double second); int stop(); + int fadeIn(Music music,int loops,int ms); int fadeIn(int loops, int ms); int fadeOut(int ms); From a19874c6daa2b365a056759492728f057fab0947 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 6 Jul 2017 22:55:33 +0800 Subject: [PATCH 19/22] Add Makefile generator for Linux --- makefile_linux | 14 -------- makefile_linuxgen.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 14 deletions(-) delete mode 100644 makefile_linux create mode 100644 makefile_linuxgen.cpp diff --git a/makefile_linux b/makefile_linux deleted file mode 100644 index 85a1c68..0000000 --- a/makefile_linux +++ /dev/null @@ -1,14 +0,0 @@ -CXXFLAGS = -std=c++14 -Wall -O2 -D__LINUX__ -Iinclude -LDFLAGS = -LDLIBS = -lstdc++ -lSDL2_image -lSDL2_net -lSDL2_ttf -lSDL2_mixer -lSDL2_test -lSDL2 -shared - -PROG = program_name -OBJS = MiniEngine.o MiniEngine_Android.o MiniEngine_Event.o MiniEngine_Widget.o sqlite/sqlite3.o MiniEngine_SQLite.o - -all: $(PROG) - -$(PROG): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs` - -clean: - rm -f $(PROG) $(OBJS) diff --git a/makefile_linuxgen.cpp b/makefile_linuxgen.cpp new file mode 100644 index 0000000..55e6447 --- /dev/null +++ b/makefile_linuxgen.cpp @@ -0,0 +1,74 @@ +/// makefile_linuxgen.cpp +/// Under MIT License. Part of MiniEngine Project. +/// You can run this code to generate a makefile for linux. + +#include +#include +#include +#include +#include +using namespace std; + +char buff[1024]; +int main() +{ + printf("#Detecting source files...#\n"); + /// Find files + system("find . -name \"*.cpp\" > cpplist.txt "); + system("find . -name \"*.c\" > clist.txt "); + vector dvec; + FILE* fp=fopen("cpplist.txt","r"); + memset(buff,0,1024); + while(fgets(buff,1024,fp)!=nullptr) + { + int len=strlen(buff); + if(buff[len-1]=='\n') buff[len-1]=0; + char* p=strstr(buff,".cpp"); + sprintf(p,".o"); + string d(buff); + dvec.push_back(d); + memset(buff,0,1024); + } + fclose(fp); + vector ccd; + fp=fopen("clist.txt","r"); + memset(buff,0,1024); + while(fgets(buff,1024,fp)!=nullptr) + { + int len=strlen(buff); + if(buff[len-1]=='\n') buff[len-1]=0; + char* p=strstr(buff,".c"); + sprintf(p,".o"); + string d(buff); + dvec.push_back(d); + memset(buff,0,1024); + } + fclose(fp); + + printf("#Generating makefile...#\n"); + fp=fopen("makefile","w"); + fprintf(fp, +"CXXFLAGS = -std=c++14 -Wall -O2 -D__LINUX__ -Iinclude\n" +"LDFLAGS = \n" +"LDLIBS = -lstdc++ -lSDL2_image -lSDL2_net -lSDL2_ttf -lSDL2_mixer -lSDL2_test -lSDL2 -shared\n" +"\n" +"PROG = your_project\n" +"OBJS = "); + for(auto& d:dvec) + { + fprintf(fp,"%s ",d.c_str()); + } + fprintf(fp,"\n"); + fprintf(fp, +"all: $(PROG)\n" +"\n" +"$(PROG): $(OBJS)\n" +"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n" +"\n" +"clean:\n" +"\trm -f $(PROG) $(OBJS))\n"); + fclose(fp); + + printf("#End of Generation#\n"); + return 0; +} From 813fdfc98551ac700a1b05d58c9d43896883b969 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Fri, 7 Jul 2017 11:28:56 +0800 Subject: [PATCH 20/22] Update C4droid makefile generator. Remove linux makefile generator.(Recommand Codeblocks on Linux) --- makefile_c4gen.cpp | 170 ++++++++++++++++++++++++++++++------------ makefile_linuxgen.cpp | 74 ------------------ 2 files changed, 124 insertions(+), 120 deletions(-) delete mode 100644 makefile_linuxgen.cpp diff --git a/makefile_c4gen.cpp b/makefile_c4gen.cpp index 8daca92..14b2219 100644 --- a/makefile_c4gen.cpp +++ b/makefile_c4gen.cpp @@ -1,70 +1,70 @@ /// makefile_c4gen.cpp /// Under MIT License. Part of MiniEngine Project. -/// You can run this code to generate a makefile for c4droid. +/// You can run this code to generate a makefile for C4droid. + +#include +#include +/// Declaration +void FindFileRev(const std::string& dirname,const std::function& func); #include #include #include #include #include +#include using namespace std; char buff[1024]; int main() { - printf("#Detecting source files...#\n"); - // Set up environment - sprintf(buff,"PATH=%s:/data/data/com.n0n3m4.droidc/bzbox/",getenv("PATH")); - putenv(buff); - fflush(stdout); - system("find . -name \"*.cpp\" > cpplist.txt "); - system("find . -name \"*.c\" > clist.txt "); - vector dvec; - FILE* fp=fopen("cpplist.txt","r"); - memset(buff,0,1024); - while(fgets(buff,1024,fp)!=nullptr) + printf("Generator: Detecting source files...\n"); + /// Find files + vector objvec; + const string toFindCpp=".cpp"; + const string toFindC=".c"; + const string toAppendObj=".o"; + auto replaceEnd=[](const string& source,const string& replaceFrom,const string& replaceTo)->string { - int len=strlen(buff); - if(buff[len-1]=='\n') buff[len-1]=0; - char* p=strstr(buff,".cpp"); - sprintf(p,".o"); - string d(buff); - dvec.push_back(d); - memset(buff,0,1024); - } - fclose(fp); - vector ccd; - fp=fopen("clist.txt","r"); - memset(buff,0,1024); - while(fgets(buff,1024,fp)!=nullptr) + return source.substr(0,source.size()-replaceFrom.size()).append(replaceTo); + }; + auto endWith=[](const string& text,const string& testEndWith)->bool { - int len=strlen(buff); - if(buff[len-1]=='\n') buff[len-1]=0; - char* p=strstr(buff,".c"); - sprintf(p,".o"); - string d(buff); - dvec.push_back(d); - memset(buff,0,1024); - } - fclose(fp); - - printf("#Excluding files...#\n"); - auto iter=find_if(dvec.begin(),dvec.end(),[](const string& str){ return (str.find("makefile_c4gen")!=string::npos);}); - if(iter!=dvec.end()) dvec.erase(iter); - - printf("#Generating makefile...#\n"); - fp=fopen("makefile","w"); + return (text.substr(text.size()-testEndWith.size())==testEndWith); + }; + FindFileRev(".",[&](const std::string& name) + { + if(endWith(name,toFindCpp)) + { + objvec.push_back(replaceEnd(name,toFindCpp,toAppendObj)); + } + else if(endWith(name,toFindC)) + { + objvec.push_back(replaceEnd(name,toFindC,toAppendObj)); + } + }); + printf("Generator: Excluding files...\n"); + objvec.erase(remove_if(objvec.begin(),objvec.end(),[](const string& objname)->bool + { + return ( /// Beginning of excluding list + (objname.find("makefile_")!=string::npos && objname.find("gen.")!=string::npos) || + (objname.find("_Windows.")!=string::npos) + ); + }),objvec.end()); + printf("Generator: Generating makefile...\n"); + FILE* fp=fopen("makefile","w"); fprintf(fp, -"CXXFLAGS = -std=c++14 -Wall -O2 -D__C4DROID__ -Iinclude\n" +"CFLAGS = -Wall -s -O2 -D__LINUX__ -Iinclude -fPIC\n" +"CXXFLAGS = -std=c++14 -Wall -s -O2 -D__C4DROID__ -Iinclude\n" "LDFLAGS =\n" "LDLIBS = -lSDL2_image -lSDL2_net -ltiff -ljpeg -lpng -lz -lSDL2_ttf -lfreetype -lSDL2_mixer " "-lSDL2_test -lsmpeg2 -lvorbisfile -lvorbis -logg -lstdc++ -lSDL2 -lEGL -lGLESv1_CM -lGLESv2 " "-landroid -Wl,--no-undefined -shared\n" "PROG = program_name\n" "OBJS = "); - for(auto& d:dvec) + for(auto& obj:objvec) { - fprintf(fp,"%s ",d.c_str()); + fprintf(fp,"%s ",obj.c_str()); } fprintf(fp,"\n"); fprintf(fp, @@ -74,9 +74,87 @@ int main() "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n" "\n" "clean:\n" -"\trm -f $(PROG) $(OBJS))\n"); +"\trm -f $(PROG) $(OBJS)\n"); fclose(fp); - printf("#End of Generation#\n"); + printf("Generator: Generation Finished.\n"); return 0; } + +/// Implement +#if defined(_MSC_VER) || defined(_WIN32) /// VS or Windows +#include +#include +#include +#include +void FindFileRev(const std::string& dirname,const std::function& func) +{ + std::string patternString; + if(dirname[dirname.size()-1]!='\\') + { + patternString=dirname+"\\*"; + } + else + { + patternString=dirname+"*"; + } + + WIN32_FIND_DATA fnd; + HANDLE hand=FindFirstFile(patternString.c_str(),&fnd); + if(hand!=INVALID_HANDLE_VALUE) + { + do + { + std::string fullname=dirname+fnd.cFileName; + if(fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + fullname.append("\\"); + FindFileRev(fullname,func); + } + else + { + func(fullname); + } + } + while(FindNextFile(hand,&fnd)); + FindClose(hand); + } +} +#else /// Linux-like +#include +#include +#include +#include + +void FindFileRev(const std::string& dirname,const std::function& func) +{ + DIR* Dir = NULL; + struct dirent* file = NULL; + std::string curDir; + if (dirname[dirname.size()-1] != '/') + { + curDir=dirname+"/"; + } + else + { + curDir=dirname; + } + + if ((Dir = opendir(curDir.c_str())) == NULL) + { + return ; + } + while ((file = readdir(Dir)) != nullptr) + { + if (file->d_type == DT_REG) + { + func(curDir + file->d_name); + } + else if (file->d_type == DT_DIR && strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0) + { + FindFileRev(curDir + file->d_name,func); + } + } + closedir(Dir); +} +#endif diff --git a/makefile_linuxgen.cpp b/makefile_linuxgen.cpp deleted file mode 100644 index 55e6447..0000000 --- a/makefile_linuxgen.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/// makefile_linuxgen.cpp -/// Under MIT License. Part of MiniEngine Project. -/// You can run this code to generate a makefile for linux. - -#include -#include -#include -#include -#include -using namespace std; - -char buff[1024]; -int main() -{ - printf("#Detecting source files...#\n"); - /// Find files - system("find . -name \"*.cpp\" > cpplist.txt "); - system("find . -name \"*.c\" > clist.txt "); - vector dvec; - FILE* fp=fopen("cpplist.txt","r"); - memset(buff,0,1024); - while(fgets(buff,1024,fp)!=nullptr) - { - int len=strlen(buff); - if(buff[len-1]=='\n') buff[len-1]=0; - char* p=strstr(buff,".cpp"); - sprintf(p,".o"); - string d(buff); - dvec.push_back(d); - memset(buff,0,1024); - } - fclose(fp); - vector ccd; - fp=fopen("clist.txt","r"); - memset(buff,0,1024); - while(fgets(buff,1024,fp)!=nullptr) - { - int len=strlen(buff); - if(buff[len-1]=='\n') buff[len-1]=0; - char* p=strstr(buff,".c"); - sprintf(p,".o"); - string d(buff); - dvec.push_back(d); - memset(buff,0,1024); - } - fclose(fp); - - printf("#Generating makefile...#\n"); - fp=fopen("makefile","w"); - fprintf(fp, -"CXXFLAGS = -std=c++14 -Wall -O2 -D__LINUX__ -Iinclude\n" -"LDFLAGS = \n" -"LDLIBS = -lstdc++ -lSDL2_image -lSDL2_net -lSDL2_ttf -lSDL2_mixer -lSDL2_test -lSDL2 -shared\n" -"\n" -"PROG = your_project\n" -"OBJS = "); - for(auto& d:dvec) - { - fprintf(fp,"%s ",d.c_str()); - } - fprintf(fp,"\n"); - fprintf(fp, -"all: $(PROG)\n" -"\n" -"$(PROG): $(OBJS)\n" -"\t$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs`\n" -"\n" -"clean:\n" -"\trm -f $(PROG) $(OBJS))\n"); - fclose(fp); - - printf("#End of Generation#\n"); - return 0; -} From 1ac2ea6c313e35b052461c7e2def83ed91dbbb05 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Fri, 7 Jul 2017 11:33:57 +0800 Subject: [PATCH 21/22] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c4457b..03bc527 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,18 @@ C++编写的SDL2引擎. ### 编译说明 -Windows: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作. +Windows/Linux: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作. > 依赖库 > SDL2 (SDL2.lib, SDL2main.lib, SDL2test.lib) > SDL2 Image (SDL2_image.lib) > SDL2 Mixer (SDL2_mixer.lib) > SDL2 TTF (SDL2_ttf.lib) +Linux Codeblocks PPA 参见: [Code::Blocks Release Builds](https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable) + Windows-Visual Studio: 使用VS编译本项目可能会出现某些错误,目前还没有很好的解决办法. -C4droid: 长按编译键选择编译模式为Makefile. 选择编译目标为SDL2 Application. 修改程序名称为program_name(此处与makefile对应即可) +C4droid: 使用Makefile Generator生成makefile文件. 选择编译目标为SDL2 Application. 修改程序名称为program_name(与makefile对应) > 依赖库 > C4droid本体 > GCC Plugin For C4droid From c769c0a3db12664bff5e42f1966e4c340a7bdb71 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Fri, 7 Jul 2017 11:38:57 +0800 Subject: [PATCH 22/22] Fix bugs of ErrorViewer --- SDLWrapper/Font.cpp | 12 +++++++++--- SDLWrapper/Renderer.cpp | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SDLWrapper/Font.cpp b/SDLWrapper/Font.cpp index 75afcd6..55682ac 100644 --- a/SDLWrapper/Font.cpp +++ b/SDLWrapper/Font.cpp @@ -215,7 +215,9 @@ Rect Font::sizeText(const std::string& Text) const throw (ErrorViewer) if(TTF_SizeText(_get(),Text.c_str(),&w,&h)!=0) { /// Something might be wrong - throw ErrorViewer(); + ErrorViewer e; + e.fetch(); + throw e; } return Rect(0,0,w,h); } @@ -226,7 +228,9 @@ Rect Font::sizeUTF8(const std::string& Text) const throw (ErrorViewer) if(TTF_SizeUTF8(_get(),Text.c_str(),&w,&h)!=0) { /// Something might be wrong - throw ErrorViewer(); + ErrorViewer e; + e.fetch(); + throw e; } return Rect(0,0,w,h); } @@ -237,7 +241,9 @@ Rect Font::sizeUnicode(const uint16_t* Text) const throw (ErrorViewer) if(TTF_SizeUNICODE(_get(),Text,&w,&h)!=0) { /// Something might be wrong - throw ErrorViewer(); + ErrorViewer e; + e.fetch(); + throw e; } return Rect(0,0,w,h); } diff --git a/SDLWrapper/Renderer.cpp b/SDLWrapper/Renderer.cpp index 85322ff..00664e0 100644 --- a/SDLWrapper/Renderer.cpp +++ b/SDLWrapper/Renderer.cpp @@ -58,7 +58,9 @@ Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags { if(createRenderer(wnd,RendererFlags)!=0) { - throw ErrorViewer(); + ErrorViewer e; + e.fetch(); + throw e; } } @@ -66,7 +68,9 @@ Renderer::Renderer(Surface& surf) throw (ErrorViewer) { if(createSoftRenderer(surf)!=0) { - throw ErrorViewer(); + ErrorViewer e; + e.fetch(); + throw e; } }