From 0bd981145271809b660b73452453c157002cdc35 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Thu, 23 Mar 2017 12:22:02 +0800 Subject: [PATCH 1/3] Visual Studio Special Version We have met a few problems on Visual Studio. We have to change the header and source file to pass the compilation. --- MiniEngine.cpp | 6 ++++-- MiniEngine.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 18fd869..1d3dd3e 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -4,8 +4,6 @@ #include #include -#include - #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_print.hpp" #include "rapidxml/rapidxml_utils.hpp" @@ -1306,6 +1304,9 @@ namespace MiniEngine }/// End of namespace MiniEngine +/// The Following Functions are not avaliable in Visual Studio +#if 0 +#include bool isexist(std::string Path) { @@ -1326,6 +1327,7 @@ bool canexecute(std::string Path) { return access(Path.c_str(),X_OK)==0; } +#endif /// End of if 0 /// Default Setup Code int main(int argc, char* argv[]) diff --git a/MiniEngine.h b/MiniEngine.h index bb02b4f..4bf3fae 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -7,6 +7,7 @@ #include #include +#include #define _DECL_DEPRECATED __declspec(deprecated) #define _DECL_DEPRECATED_MSG(InfoString) __declspec(deprecated(InfoString)) From 0ec40c62700e59af4a7fd8b6761d615c7a0c78d2 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Thu, 23 Mar 2017 13:41:24 +0800 Subject: [PATCH 2/3] Bug Fixed: Font::render... Bug Fixed in class Font::renderText ( and its family functions ) These functions cause exceptions while testing on Visual Studio. And we soon found 'SDL_FreeSurface' was not used in 'reset' method of shared_ptr. Now we have fixed it. --- MiniEngine.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 1d3dd3e..58d0844 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -565,56 +565,56 @@ namespace MiniEngine Texture Font::renderText(Renderer rnd, std::string Text, RGBA fg) { Surface surf; - surf.surf.reset(TTF_RenderText_Blended(font.get(), Text.c_str(), fg.toSDLColor())); + surf.surf.reset(TTF_RenderText_Blended(font.get(), Text.c_str(), fg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength) { Surface surf; - surf.surf.reset(TTF_RenderText_Blended_Wrapped(font.get(), Text.c_str(), fg.toSDLColor(), WrapLength)); + surf.surf.reset(TTF_RenderText_Blended_Wrapped(font.get(), Text.c_str(), fg.toSDLColor(), WrapLength), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg) { Surface surf; - surf.surf.reset(TTF_RenderText_Shaded(font.get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor())); + surf.surf.reset(TTF_RenderText_Shaded(font.get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderTextSolid(Renderer rnd, std::string Text, RGBA fg) { Surface surf; - surf.surf.reset(TTF_RenderText_Solid(font.get(), Text.c_str(), fg.toSDLColor())); + surf.surf.reset(TTF_RenderText_Solid(font.get(), Text.c_str(), fg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderUTF8(Renderer rnd, std::string Text, RGBA fg) { Surface surf; - surf.surf.reset(TTF_RenderUTF8_Blended(font.get(), Text.c_str(), fg.toSDLColor())); + surf.surf.reset(TTF_RenderUTF8_Blended(font.get(), Text.c_str(), fg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderUTF8Wrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength) { Surface surf; - surf.surf.reset(TTF_RenderUTF8_Blended_Wrapped(font.get(), Text.c_str(), fg.toSDLColor(), WrapLength)); + surf.surf.reset(TTF_RenderUTF8_Blended_Wrapped(font.get(), Text.c_str(), fg.toSDLColor(), WrapLength), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderUTF8Shaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg) { Surface surf; - surf.surf.reset(TTF_RenderUTF8_Shaded(font.get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor())); + surf.surf.reset(TTF_RenderUTF8_Shaded(font.get(), Text.c_str(), fg.toSDLColor(), bg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } Texture Font::renderUTF8Solid(Renderer rnd, std::string Text, RGBA fg) { Surface surf; - surf.surf.reset(TTF_RenderUTF8_Solid(font.get(), Text.c_str(), fg.toSDLColor())); + surf.surf.reset(TTF_RenderUTF8_Solid(font.get(), Text.c_str(), fg.toSDLColor()), SDL_FreeSurface); return rnd.render(surf); } From 23553b1330186d7392f19d1abacf5bef2f976241 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Thu, 23 Mar 2017 14:01:06 +0800 Subject: [PATCH 3/3] Set Renderer::Renderer() to public Renderer::isReady() is added to check if the renderer is ready. --- MiniEngine.cpp | 5 +++++ MiniEngine.h | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 58d0844..7069156 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -403,6 +403,11 @@ namespace MiniEngine return t; } + bool Renderer::isReady() + { + return (rnd.get() != nullptr); + } + Window::Window(std::string Title, int Width, int Height, std::initializer_list RendererFlags) throw(ErrorViewer) { SDL_Window* temp = SDL_CreateWindow(Title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_WINDOW_SHOWN); diff --git a/MiniEngine.h b/MiniEngine.h index 4bf3fae..cac60d0 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -163,9 +163,8 @@ namespace MiniEngine Texture loadTexture(std::string FileName) throw(ErrorViewer); Texture createTexture(int Width, int Height) throw(ErrorViewer); - protected: - /// This function is called by class Window ONLY. Renderer() = default; + bool isReady(); private: std::shared_ptr rnd; friend class Window;