From 01735059fc71e1fc9a2bddb0f1c22dc0e3c172f4 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Mon, 10 Apr 2017 15:27:24 +0800 Subject: [PATCH] Add Support for SDL_RWops --- MiniEngine.cpp | 21 +++++++++++++++++++++ MiniEngine.h | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 2025cff..783067f 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -129,6 +129,27 @@ namespace MiniEngine return str.c_str(); } + RWOP::RWOP(FILE* fp,bool autoclose) + { + SDL_bool b=autoclose?SDL_TRUE:SDL_FALSE; + op.reset(SDL_RWFromFP(fp,b),[](SDL_RWops* p){SDL_RWclose(p);}); + } + + RWOP::RWOP(const std::string& filename,const std::string& openmode) + { + op.reset(SDL_RWFromFile(filename.c_str(),openmode.c_str()),[](SDL_RWops* p){SDL_RWclose(p);}); + } + + RWOP::RWOP(const void* mem,int size) + { + op.reset(SDL_RWFromConstMem(mem,size),[](SDL_RWops* p){SDL_RWclose(p);}); + } + + RWOP::RWOP(void* mem,int size) + { + op.reset(SDL_RWFromMem(mem,size),[](SDL_RWops* p){SDL_RWclose(p);}); + } + Texture::Texture() { updateInfo(); diff --git a/MiniEngine.h b/MiniEngine.h index e01195d..6cb3d2e 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -72,6 +72,20 @@ namespace MiniEngine std::string str; }; + class RWOP + { + public: + RWOP(FILE* fp,bool autoclose); + RWOP(const std::string& filename,const std::string& openmode); + RWOP(const void* mem,int size); + RWOP(void* mem,int size); + RWOP()=default; + ~RWOP()=default; + private: + std::shared_ptr op; + }; + + enum class BlendMode { None = SDL_BLENDMODE_NONE,