From 7505db992ab32a266ba500c059c7b67232cc8b50 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sun, 18 Jun 2017 16:47:21 +0800 Subject: [PATCH] remove SDLEngine old code. --- SDLEngine/MiniEngine/Event.cpp | 0 SDLEngine/MiniEngine/Event.h | 32 ------ SDLEngine/MiniEngine/Widget.cpp | 47 -------- SDLEngine/MiniEngine/Widget.h | 89 --------------- SDLEngine/MiniEngine/widget_brush.hpp | 69 ----------- SDLEngine/include/App.h | 9 -- SDLEngine/include/InitManager.h | 42 ------- SDLEngine/include/MusicManager.h | 60 ---------- SDLEngine/include/basic_config.h | 38 ------- SDLEngine/include/config.h | 9 -- SDLEngine/include/mini_engine.h | 22 ---- SDLEngine/include/sdl_engine.h | 158 -------------------------- SDLEngine/makefile | 14 --- SDLEngine/src/App.cpp | 44 ------- SDLEngine/src/InitManager.cpp | 119 ------------------- SDLEngine/src/MusicManager.cpp | 86 -------------- SDLEngine/src/basic_config.cpp | 3 - SDLEngine/src/config.cpp | 10 -- SDLEngine/src/main.cpp | 13 --- SDLEngine/src/mini_engine.cpp | 20 ---- SDLEngine/src/sdl_engine.cpp | 144 ----------------------- SDLEngine/src/sdl_engine_font.hpp | 61 ---------- SDLEngine/src/sdl_engine_rect.hpp | 25 ---- SDLEngine/src/sdl_engine_renderer.hpp | 98 ---------------- SDLEngine/src/sdl_engine_rgba.hpp | 24 ---- SDLEngine/src/sdl_engine_surface.hpp | 27 ----- SDLEngine/src/sdl_engine_texture.hpp | 37 ------ SDLEngine/src/sdl_engine_window.hpp | 55 --------- 28 files changed, 1355 deletions(-) delete mode 100644 SDLEngine/MiniEngine/Event.cpp delete mode 100644 SDLEngine/MiniEngine/Event.h delete mode 100644 SDLEngine/MiniEngine/Widget.cpp delete mode 100644 SDLEngine/MiniEngine/Widget.h delete mode 100644 SDLEngine/MiniEngine/widget_brush.hpp delete mode 100644 SDLEngine/include/App.h delete mode 100644 SDLEngine/include/InitManager.h delete mode 100644 SDLEngine/include/MusicManager.h delete mode 100644 SDLEngine/include/basic_config.h delete mode 100644 SDLEngine/include/config.h delete mode 100644 SDLEngine/include/mini_engine.h delete mode 100644 SDLEngine/include/sdl_engine.h delete mode 100644 SDLEngine/makefile delete mode 100644 SDLEngine/src/App.cpp delete mode 100644 SDLEngine/src/InitManager.cpp delete mode 100644 SDLEngine/src/MusicManager.cpp delete mode 100644 SDLEngine/src/basic_config.cpp delete mode 100644 SDLEngine/src/config.cpp delete mode 100644 SDLEngine/src/main.cpp delete mode 100644 SDLEngine/src/mini_engine.cpp delete mode 100644 SDLEngine/src/sdl_engine.cpp delete mode 100644 SDLEngine/src/sdl_engine_font.hpp delete mode 100644 SDLEngine/src/sdl_engine_rect.hpp delete mode 100644 SDLEngine/src/sdl_engine_renderer.hpp delete mode 100644 SDLEngine/src/sdl_engine_rgba.hpp delete mode 100644 SDLEngine/src/sdl_engine_surface.hpp delete mode 100644 SDLEngine/src/sdl_engine_texture.hpp delete mode 100644 SDLEngine/src/sdl_engine_window.hpp diff --git a/SDLEngine/MiniEngine/Event.cpp b/SDLEngine/MiniEngine/Event.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/SDLEngine/MiniEngine/Event.h b/SDLEngine/MiniEngine/Event.h deleted file mode 100644 index f725328..0000000 --- a/SDLEngine/MiniEngine/Event.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "../config.h" -#include - -//#include -namespace MiniEngine -{ - -class MouseEvent -{ -private: - struct EventData - { - int x,y; - } -public: - int type; - EventData data; -}; -class MouseEventListener -{ -public: - MouseEventListener(); - - function onButtonDown; - function onButtonUp; - - function onMotion; - function onWheel; -}; - -}/// End of namespace MiniEngine diff --git a/SDLEngine/MiniEngine/Widget.cpp b/SDLEngine/MiniEngine/Widget.cpp deleted file mode 100644 index eab0250..0000000 --- a/SDLEngine/MiniEngine/Widget.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "Widget.h" - -using namespace Engine; -using namespace std; - -namespace MiniEngine -{ -/// Brush -#include "widget_brush.hpp" - -struct SimpleProgressBar::impl -{ - int percentage; - int w,h; - RGBA ucolor,lcolor; -}; - -SimpleProgressBar::SimpleProgressBar(int incw,int inch,RGBA upper_color,RGBA lower_color) -{ - pimpl=new impl; - pimpl->w=incw; - pimpl->h=inch; - pimpl->ucolor=upper_color; - pimpl->lcolor=lower_color; - pimpl->percentage=0; -} -void SimpleProgressBar::DrawAt(Renderer& rnd,int x,int y) -{ - RGBA prev=rnd.getColor(); - if(pimpl->percentage) - { - rnd.setColor(pimpl->ucolor); - rnd.fillRect(Rect(x,y,pimpl->w*pimpl->percentage/100,pimpl->h)); - } - if(pimpl->percentage-100) - { - rnd.setColor(pimpl->lcolor); - rnd.fillRect(Rect(x+pimpl->w*pimpl->percentage/100,y,pimpl->w*(100-pimpl->percentage)/100,pimpl->h)); - } - rnd.setColor(prev); -} -void SimpleProgressBar::setPercentage(int iPercentage) -{ - pimpl->percentage=min(max(0,iPercentage),100); -} - -}/// End of namespace MiniEngine diff --git a/SDLEngine/MiniEngine/Widget.h b/SDLEngine/MiniEngine/Widget.h deleted file mode 100644 index a5d2e96..0000000 --- a/SDLEngine/MiniEngine/Widget.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once -#include "../config.h" -#include - -#define _MINI_ENGINE_IMPL_COPY_DECL(ClassName) _SDL_ENGINE_IMPL_COPY_DECL(ClassName) -#define _MINI_ENGINE_IMPL _SDL_ENGINE_IMPL -namespace MiniEngine -{ - -class Stage; - -class Brush -{ -public: - ~Brush(); - _MINI_ENGINE_IMPL_COPY_DECL(Brush) - - void copy(Engine::Texture t,Engine::Rect src,Engine::Rect dst,bool autoZoom); - void copyTo(Engine::Texture t,Engine::Rect dst,bool autoZoom); - void copyFill(Engine::Texture t,Engine::Rect src); - void copyFullFill(Engine::Texture t); -public: - Brush(const Engine::Window& rnd,Engine::Rect DrawableArea); -private: - _MINI_ENGINE_IMPL - friend class Stage; -}; - -class Stage -{ -public: - Stage(); - ~Stage(); -}; - -class Drawable -{ -public: - virtual int Draw(const Brush& brush)=0; - virtual Engine::Rect getSize()=0; -}; - -class BaseButton : public Drawable -{ -public: - BaseButton(); - BaseButton(const BaseButton&); - BaseButton& operator = (const BaseButton&); - BaseButton(BaseButton&&); - BaseButton& operator = (BaseButton&&); - - virtual int Draw(const Brush& brush); - virtual Engine::Rect getSize(); - - virtual ~BaseButton(); -private: - struct impl; - impl* pimpl; -}; - -class SimpleButton : public BaseButton -{ -public: - /// Default Style - SimpleButton(); - SimpleButton(std::string word, - Engine::RGBA color_word, - Engine::RGBA color_background, - Engine::RGBA color_highlight); - SimpleButton(const SimpleButton&); - SimpleButton& operator = (const SimpleButton&); - SimpleButton(SimpleButton&&); - SimpleButton& operator = (SimpleButton&&); - ~SimpleButton(); -}; - -class SimpleProgressBar -{ -public: - SimpleProgressBar(int incw,int inch,Engine::RGBA upper_color,Engine::RGBA lower_color); - void DrawAt(Engine::Renderer& rnd,int x,int y); - void setPercentage(int iPercentage); - ~SimpleProgressBar(); -private: - struct impl; - impl* pimpl; -}; - -}/// End of namespace MiniEngine. diff --git a/SDLEngine/MiniEngine/widget_brush.hpp b/SDLEngine/MiniEngine/widget_brush.hpp deleted file mode 100644 index d0a4da7..0000000 --- a/SDLEngine/MiniEngine/widget_brush.hpp +++ /dev/null @@ -1,69 +0,0 @@ -struct Brush::impl -{ - Renderer rnd; - Rect area; - impl(const Renderer& incrnd) : rnd(incrnd) - { - - } -}; -Brush::Brush(const Window& wnd,Rect DrawableArea) /// Protected -{ - pimpl=new impl(wnd.getRenderer()); - pimpl->area=DrawableArea; -} -void Brush::copy(Texture t,Rect src,Rect dst,bool autoZoom) -{ - dst.x+=pimpl->area.x; - dst.y+=pimpl->area.y; - if(dst.w>pimpl->area.w) dst.w=pimpl->area.w; - if(dst.h>pimpl->area.h) dst.h=pimpl->area.h; - if(autoZoom) - { - - } - else - { - if(src.w>pimpl->area.w) src.w=pimpl->area.w; - if(src.h>pimpl->area.h) src.h=pimpl->area.h; - } - pimpl->rnd.copy(t,src,dst); -} -void Brush::copyTo(Texture t,Rect dst,bool autoZoom) -{ - dst.x+=pimpl->area.x; - dst.y+=pimpl->area.y; - - if(dst.w>pimpl->area.w) dst.w=pimpl->area.w; - if(dst.h>pimpl->area.h) dst.h=pimpl->area.h; - - if(autoZoom) - { - pimpl->rnd.copyTo(t,dst); - } - else - { - int w=t.getw(); - int h=t.geth(); - if(w>pimpl->area.w) w=pimpl->area.w; - if(h>pimpl->area.h) h=pimpl->area.h; - Rect src(0,0,w,h); - pimpl->rnd.copy(t,src,dst); - } -} -void Brush::copyFill(Texture t,Rect src) -{ - Rect dst=pimpl->area; - pimpl->rnd.copy(t,src,dst); -} - -void Brush::copyFullFill(Texture t) -{ - Rect dst=pimpl->area; - pimpl->rnd.copyTo(t,dst); -} - -Brush::~Brush() -{ - delete pimpl; -} diff --git a/SDLEngine/include/App.h b/SDLEngine/include/App.h deleted file mode 100644 index bd65162..0000000 --- a/SDLEngine/include/App.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "mini_engine.h" - -namespace App -{ - /** Entrance of Application. - */ - void Main(); -} diff --git a/SDLEngine/include/InitManager.h b/SDLEngine/include/InitManager.h deleted file mode 100644 index 43bed37..0000000 --- a/SDLEngine/include/InitManager.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "config.h" - -class InitManager_SDL -{ -public: - InitManager_SDL(); - ~InitManager_SDL(); -}; - -class InitManager_TTF -{ -public: - InitManager_TTF(); - ~InitManager_TTF(); - int openFont(const char* FileName,int Size); - int closeFont(); - TTF_Font* font(); -private: - TTF_Font* _font; - static int ctm; -}; - -class InitManager_IMG -{ -public: - InitManager_IMG(); - ~InitManager_IMG(); - SDL_Surface* loadimage(const char* FileName); - SDL_Texture* loadtexture(SDL_Renderer* rnd,const char* Filename); -}; -class InitManager_Mix -{ -public: - InitManager_Mix(); - ~InitManager_Mix(); -}; - -extern InitManager_SDL* syssdl; -extern InitManager_IMG* sysimg; -extern InitManager_TTF* systtf; -extern InitManager_Mix* sysmix; diff --git a/SDLEngine/include/MusicManager.h b/SDLEngine/include/MusicManager.h deleted file mode 100644 index 663c344..0000000 --- a/SDLEngine/include/MusicManager.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -#include "config.h" -#include - -#define _MUSIC_MANAGER_IMPL \ - struct impl; \ - std::shared_ptr pimpl; - -/// Fwd Decl -class MusicPlayer; - -class Music -{ -public: - Music(); - Music(const char* MusicFileName); - int load(const char* MusicFileName); - int unload(); - bool ready(); - ~Music(); -private: - _MUSIC_MANAGER_IMPL - - friend class MusicPlayer; -}; - -class SoundEffect -{ -public: - SoundEffect(); - SoundEffect(const char* SoundEffectFileName); - int load(const char* SoundEffectFileName); - ~SoundEffect(); -private: - _MUSIC_MANAGER_IMPL -}; - -class MusicPlayer -{ -public: - MusicPlayer(int freq=MIX_DEFAULT_FREQUENCY,Uint16 format=MIX_DEFAULT_FORMAT,int soundChannel=2,int chunkSize=1024); - ~MusicPlayer(); - int play(); - int stop(); - int add(Music& music,int times); -private: - static MusicPlayer* pInstance; - _MUSIC_MANAGER_IMPL -}; - -class SoundEffectPlayer -{ -public: - SoundEffectPlayer(); - ~SoundEffectPlayer(); - int play(SoundEffect& soundeffect,int times); -private: - _MUSIC_MANAGER_IMPL; -}; - diff --git a/SDLEngine/include/basic_config.h b/SDLEngine/include/basic_config.h deleted file mode 100644 index c279469..0000000 --- a/SDLEngine/include/basic_config.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#ifdef __C4DROID__ -#define _WINDOW_PROGRAM -#endif // __C4DROID__ - -#include -#include -#include - -/// If you have configured SDL2 header files, -/// they will be used first. - -#include "SDL2/SDL.h" -#undef main - -#include "SDL2/SDL_ttf.h" -#include "SDL2/SDL_image.h" -#include "SDL2/SDL_mixer.h" - -class NonCopyable -{ -public: - NonCopyable()=default; - ~NonCopyable()=default; - NonCopyable(const NonCopyable&)=delete; - NonCopyable& operator = (const NonCopyable&)=delete; -}; - -extern FILE* _log_fp; - -#ifdef _WINDOW_PROGRAM -#define mlog_init() _log_fp=fopen("mini_engine_log.txt","w") -#define mlog(fmt,args...) do {if(_log_fp) {fprintf(_log_fp,fmt,##args);fprintf(_log_fp,"\n");fflush(_log_fp);} }while(0) -#else -#define mlog_init() -#define mlog(fmt,args...) printf(fmt,##args);printf("\n") -#endif diff --git a/SDLEngine/include/config.h b/SDLEngine/include/config.h deleted file mode 100644 index 0db9d80..0000000 --- a/SDLEngine/include/config.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "basic_config.h" - -#include "sdl_engine.h" - -namespace Global -{ - void ErrorQuit(const char* ErrorMessage); -} diff --git a/SDLEngine/include/mini_engine.h b/SDLEngine/include/mini_engine.h deleted file mode 100644 index 8dea741..0000000 --- a/SDLEngine/include/mini_engine.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "config.h" - -/******************************************************************************/ -/// InitManager -#include "InitManager.h" - -/******************************************************************************/ -/// MusicManager -#include "MusicManager.h" - -/******************************************************************************/ -/// Widget -#include "MiniEngine/Widget.h" - -/******************************************************************************/ -/// Application -#include "App.h" - -void AllInit(); -void AllQuit(); diff --git a/SDLEngine/include/sdl_engine.h b/SDLEngine/include/sdl_engine.h deleted file mode 100644 index 6a71dfc..0000000 --- a/SDLEngine/include/sdl_engine.h +++ /dev/null @@ -1,158 +0,0 @@ -#pragma once -#include "basic_config.h" - -SDL_Texture* RenderText(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph); -SDL_Texture* RenderUTF8(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph); -void TextureDraw(SDL_Renderer* rnd,SDL_Texture* texture,int dstx,int dsty); -bool isInRect(int x,int y,SDL_Rect rect); -bool isInRect(int x,int y,int LU_x,int LU_y,int RD_x,int RD_y); -void ClearMessageQueue(); - -int MyChangeDir(const char* DirName); - -namespace Engine -{ -class Rect -{ -public: - Rect(); - Rect(int incx,int incy,int incw,int inch); - SDL_Rect toSDLRect(); - ~Rect(); - - int x,y,w,h; -}; -class RGBA -{ -public: - RGBA(); - RGBA(int incr,int incg,int incb,int inca); - ~RGBA(); - - SDL_Color toSDLColor(); - - int r,g,b,a; -}; - -class Renderer; -class Texture; -class Font; - -#define _SDL_ENGINE_IMPL_COPY_DECL(ClassName) \ - ClassName(const ClassName&); \ - ClassName(ClassName&&); \ - ClassName& operator = (const ClassName&); \ - ClassName& operator = (ClassName&&); - -#define _SDL_ENGINE_IMPL \ - struct impl; \ - impl* pimpl; - -#define DEFAULT_WIDTH 1024 -#define DEFAULT_HEIGHT 768 - -class Window -{ -public: - Window(int winw,int winh); - ~Window(); - - _SDL_ENGINE_IMPL_COPY_DECL(Window); - - Renderer getRenderer() const; - void resetRenderer(); - - Rect getSize(); - - void setSize(Rect r); - -private: - _SDL_ENGINE_IMPL -}; - -class Surface -{ -public: - ~Surface(); - _SDL_ENGINE_IMPL_COPY_DECL(Surface); -protected: - Surface(); -private: - _SDL_ENGINE_IMPL - friend class Renderer; - friend class Font; -}; - -class Renderer -{ -public: - virtual ~Renderer(); - _SDL_ENGINE_IMPL_COPY_DECL(Renderer); - - int clear(); - void update(); - int copy(Texture t,Rect src,Rect dst); - int copyTo(Texture t,Rect dst); - int copyFill(Texture t,Rect src); - int copyFullFill(Texture t); - Texture loadImage(const char* FileName); - Texture render(Surface surface); - - int setColor(RGBA pack); - RGBA getColor(int* pStatus=nullptr); - - int fillRect(Rect rect); - int drawRect(Rect rect); - - /// Not Recommended - SDL_Renderer* getDirectRenderer(); -protected: - Renderer(); -private: - _SDL_ENGINE_IMPL - friend class Window; -}; - -class Texture -{ -public: - ~Texture(); - int getw(); - int geth(); - _SDL_ENGINE_IMPL_COPY_DECL(Texture); -protected: - Texture(); -private: - _SDL_ENGINE_IMPL - friend class Renderer; -}; - -class Font -{ -public: - Font(); - Font(const char* FontFileName,int sz); - int use(const char* FontFileName,int sz); - ~Font(); - - _SDL_ENGINE_IMPL_COPY_DECL(Font); - - Texture renderText(Renderer rnd,const char* Word,RGBA fg); - Texture renderTextShaded(Renderer rnd,const char* Word,RGBA fg,RGBA bg); - Texture renderTextSolid(Renderer rnd,const char* Word,RGBA fg); - - Texture renderUTF8(Renderer rnd,const char* Word,RGBA fg); - Texture renderUTF8Shaded(Renderer rnd,const char* Word,RGBA fg,RGBA bg); - Texture renderUTF8Solid(Renderer rnd,const char* Word,RGBA fg); -private: - _SDL_ENGINE_IMPL -}; - -class SDLSystem -{ -public: - static void delay(int ms); -}; - -}/// End of namespace Engine - diff --git a/SDLEngine/makefile b/SDLEngine/makefile deleted file mode 100644 index 0284420..0000000 --- a/SDLEngine/makefile +++ /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 = basic_config.o sdl_engine.o config.o InitManager.o mini_engine.o App.o main.o - -all: $(PROG) - -$(PROG): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $(OBJS) `sdl2-config --cflags --libs` - -clean: - rm -f $(PROG) $(OBJS) diff --git a/SDLEngine/src/App.cpp b/SDLEngine/src/App.cpp deleted file mode 100644 index 4259cf3..0000000 --- a/SDLEngine/src/App.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "App.h" - -using namespace Engine; -using namespace MiniEngine; - -namespace App -{ - /// Application Main Method - void Main() - { - Window wnd(1366,768);///16:9 - Renderer rnd=wnd.getRenderer(); - Font bigf; - if(bigf.use("msyh.ttf",72)<0) - { - mlog("Failed to open Font."); - return; - } - rnd.clear(); - rnd.update(); - - MusicPlayer player; - Music m; - int ret=m.load("res/music.mp3"); - printf("ret=%d\n",ret); - ret=player.add(m,-1); - printf("ret=%d\n",ret); - ret=player.play(); - printf("ret=%d\n",ret); - printf("%s\n",Mix_GetError()); - - while(1) SDL_PollEvent(0); - - /* - /// Sample Code of Brush - Brush b(wnd,Rect(wnd.getSize().w/2-50,wnd.getSize().h/2-50,100,100)); - Texture t=rnd.loadImage("D:\\sample.png"); - Rect dst(0,0,wnd.getSize().w,wnd.getSize().h); - b.copyTo(t,dst,false); - rnd.update(); - SDL_Delay(2000); - */ - } -} diff --git a/SDLEngine/src/InitManager.cpp b/SDLEngine/src/InitManager.cpp deleted file mode 100644 index 2fc1e27..0000000 --- a/SDLEngine/src/InitManager.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "InitManager.h" - -InitManager_SDL::InitManager_SDL() -{ - if(SDL_Init(SDL_INIT_EVERYTHING)<0) - { - #ifndef __C4DROID__ - Global::ErrorQuit("Failed to init SDL2."); - #else - /// C4droid does not fully support SDL2, - /// so initializing everything crashes. - #endif - } -} - -InitManager_SDL::~InitManager_SDL() -{ - SDL_Quit(); -} - -InitManager_IMG::InitManager_IMG() -{ - if(IMG_Init(IMG_INIT_JPG|IMG_INIT_PNG)<0) - { - Global::ErrorQuit("Failed to init SDL2 Image."); - } -} - -SDL_Surface* InitManager_IMG::loadimage(const char* Filename) -{ - return IMG_Load(Filename); -} - -SDL_Texture* InitManager_IMG::loadtexture(SDL_Renderer* rnd,const char* Filename) -{ - return IMG_LoadTexture(rnd,Filename); -} - -InitManager_IMG::~InitManager_IMG() -{ - IMG_Quit(); -} - -int InitManager_TTF::ctm=0; - -InitManager_TTF::InitManager_TTF() -{ - /// ~_~ check ctm and add it anyway - if(ctm++>0) - { - return; - } - - if(TTF_Init()<0) - { - Global::ErrorQuit("Failed to init SDL2 TTF."); - } - _font=NULL; -} - -int InitManager_TTF::openFont(const char* FileName,int Size) -{ - _font=TTF_OpenFont(FileName,Size); - if(_font==NULL) return -1; - else return 0; -} - -TTF_Font* InitManager_TTF::font() -{ - return _font; -} - -int InitManager_TTF::closeFont() -{ - TTF_CloseFont(_font); - _font=NULL; - return 0; -} - -InitManager_TTF::~InitManager_TTF() -{ - /// Close Font anyway. - if(_font) closeFont(); - - /// ~_~ Firstly ctm=ctm-1, if ctm still > 0, then return ( TTF_Quit Not Executed ) - if(--ctm>0) - { - return; - } - - TTF_Quit(); -} - -InitManager_Mix::InitManager_Mix() -{ - if(Mix_Init(MIX_INIT_MP3)<0) - { - Global::ErrorQuit("Failed to Init Mixer."); - } - - /* - if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 1024)<0) - { - Global::ErrorQuit("Failed to OpenAudio"); - } - Mix_AllocateChannels(32); - */ -} - -InitManager_Mix::~InitManager_Mix() -{ - //Mix_CloseAudio(); - Mix_Quit(); -} - -InitManager_SDL* syssdl=NULL; -InitManager_IMG* sysimg=NULL; -InitManager_TTF* systtf=NULL; -InitManager_Mix* sysmix=NULL; diff --git a/SDLEngine/src/MusicManager.cpp b/SDLEngine/src/MusicManager.cpp deleted file mode 100644 index 964c30e..0000000 --- a/SDLEngine/src/MusicManager.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "MusicManager.h" -#include -#include -using namespace std; - -struct Music::impl -{ - friend class Music; - shared_ptr sMusic; -}; -Music::Music() -{ - pimpl.reset(new impl); -} -Music::Music(const char* MusicFileName) : Music() -{ - load(MusicFileName); -} -int Music::load(const char* MusicFileName) -{ - Mix_Music* ptemp=Mix_LoadMUS(MusicFileName); - if(ptemp==nullptr) return -1; - pimpl->sMusic.reset(ptemp,Mix_FreeMusic); - return 0; -} -int Music::unload() -{ - printf("Unloaded.\n"); - if(pimpl->sMusic.get()) - { - printf("Reset to NULL\n"); - pimpl->sMusic.reset(); - return 0; - } - else return -2; -} -bool Music::ready() -{ - return (pimpl->sMusic.get()!=nullptr); -} -Music::~Music() -{ - -} - - -struct MusicPlayer::impl -{ - vector> vec; -}; -MusicPlayer::MusicPlayer(int freq,Uint16 format,int soundChannel,int chunkSize) -{ - pimpl.reset(new impl); - if(pInstance) return; - Mix_OpenAudio(freq,format,soundChannel,chunkSize); - pInstance=this; -} -MusicPlayer::~MusicPlayer() -{ - if(pInstance) Mix_CloseAudio(); - pInstance=nullptr; -} -int MusicPlayer::play() -{ - return Mix_PlayMusic(pimpl->vec.front().first.pimpl->sMusic.get(),pimpl->vec.front().second); -} -int MusicPlayer::add(Music& music,int times) -{ - if(!music.ready()) return -1; - pimpl->vec.push_back(make_pair(music,times)); - return 0; -} -MusicPlayer* MusicPlayer::pInstance=nullptr; - - - -struct SoundEffect::impl -{ - friend class SoundEffect; - shared_ptr sChunk; -}; - -SoundEffect::SoundEffect() -{ - pimpl.reset(new impl); -} diff --git a/SDLEngine/src/basic_config.cpp b/SDLEngine/src/basic_config.cpp deleted file mode 100644 index 7439e16..0000000 --- a/SDLEngine/src/basic_config.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "basic_config.h" - -FILE* _log_fp=NULL; diff --git a/SDLEngine/src/config.cpp b/SDLEngine/src/config.cpp deleted file mode 100644 index e28b8ab..0000000 --- a/SDLEngine/src/config.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "config.h" - -namespace Global -{ - void ErrorQuit(const char* ErrorMessage) - { - mlog(ErrorMessage); - exit(0); - } -} diff --git a/SDLEngine/src/main.cpp b/SDLEngine/src/main.cpp deleted file mode 100644 index ca44d87..0000000 --- a/SDLEngine/src/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "config.h" -#include "App.h" - -int main() -{ - /// Initialize SDL2... - AllInit(); - /// Call Application Main - App::Main(); - /// Clean Up SDL2 - AllQuit(); - return 0; -} diff --git a/SDLEngine/src/mini_engine.cpp b/SDLEngine/src/mini_engine.cpp deleted file mode 100644 index b6937ed..0000000 --- a/SDLEngine/src/mini_engine.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "mini_engine.h" - -void AllInit() -{ - mlog_init(); - - syssdl=new InitManager_SDL; - sysimg=new InitManager_IMG; - systtf=new InitManager_TTF; - sysmix=new InitManager_Mix; - -} - -void AllQuit() -{ - delete sysmix; - delete systtf; - delete sysimg; - delete syssdl; -} diff --git a/SDLEngine/src/sdl_engine.cpp b/SDLEngine/src/sdl_engine.cpp deleted file mode 100644 index 4fcb17f..0000000 --- a/SDLEngine/src/sdl_engine.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include "sdl_engine.h" -#include "unistd.h" -#include -using namespace std; - -SDL_Texture* RenderUTF8(SDL_Renderer* rnd,TTF_Font* font,const char* Text,SDL_Color color,int* pw,int* ph) -{ - SDL_Surface* surf=TTF_RenderUTF8_Blended(font,Text,color); - if(surf==NULL) return NULL; - SDL_Texture* texture=SDL_CreateTextureFromSurface(rnd,surf); - SDL_FreeSurface(surf); - if(pw&&ph) SDL_QueryTexture(texture,NULL,NULL,pw,ph); - return texture; -} - -bool isInRect(int x,int y,SDL_Rect rect) -{ - return ((x>=rect.x&&x<=rect.x+rect.w)&&(y>=rect.y&&y<=rect.y+rect.h)); -} - -bool isInRect(int x,int y,int LU_x,int LU_y,int RD_x,int RD_y) -{ - return ((x>=LU_x&&x<=RD_x)&&(y>=LU_y&&y<=RD_y)); -} - -void ClearMessageQueue() -{ - /// Clear Message Queue - while(SDL_PeepEvents(NULL,1,SDL_GETEVENT,SDL_FIRSTEVENT,SDL_LASTEVENT)); -} - -SDL_Color color_white { 255,255,255 }; -SDL_Color color_black { 0,0,0 }; - -int MyChangeDir(const char* DirName) -{ - mlog("Change Dir to \"%s\"",DirName); - int ret=chdir(DirName); - mlog("Change Dir returns %d",ret); - return ret; -} - - -namespace Engine -{ - -/// Rect -#include "sdl_engine_rect.hpp" - -struct Renderer::impl -{ -private: - friend class Renderer; - shared_ptr sRnd; -public: - void set(SDL_Renderer* rnd) - { - sRnd.reset(rnd,SDL_DestroyRenderer); - } -}; - -struct Window::impl -{ -private: - friend class Window; - shared_ptr sWnd; - Renderer rnd; -public: - void set(SDL_Window* wnd) - { - sWnd.reset(wnd,SDL_DestroyWindow); - rnd.pimpl->set(SDL_CreateRenderer(wnd,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE)); - } - SDL_Window* getRawWindow() - { - return sWnd.get(); - } -}; - -struct Texture::impl -{ -private: - friend class Texture; - shared_ptr sText; - int w,h; -public: - void set(SDL_Texture* text) - { - sText.reset(text,SDL_DestroyTexture); - SDL_QueryTexture(text,NULL,NULL,&w,&h); - } - SDL_Texture* getRawTexture() - { - return sText.get(); - } -}; - -struct Surface::impl -{ -private: - friend class Surface; - shared_ptr sSurf; -public: - void set(SDL_Surface* surf) - { - sSurf.reset(surf,SDL_FreeSurface); - } - SDL_Surface* getRawSurface() - { - return sSurf.get(); - } -}; - -struct Font::impl -{ -private: - friend class Font; - shared_ptr sTTF; -public: - void set(TTF_Font* font) - { - sTTF.reset(font,TTF_CloseFont); - } -}; - -/// Window -#include "sdl_engine_window.hpp" -/// Renderer -#include "sdl_engine_renderer.hpp" -/// Surface -#include "sdl_engine_surface.hpp" -/// Texture -#include "sdl_engine_texture.hpp" -/// RGBA -#include "sdl_engine_rgba.hpp" -/// Font -#include "sdl_engine_font.hpp" - -void SDLSystem::delay(int ms) -{ - SDL_Delay(ms); -} - -}/// End of namespace Engine diff --git a/SDLEngine/src/sdl_engine_font.hpp b/SDLEngine/src/sdl_engine_font.hpp deleted file mode 100644 index c1f6bd0..0000000 --- a/SDLEngine/src/sdl_engine_font.hpp +++ /dev/null @@ -1,61 +0,0 @@ -Font::Font() -{ - pimpl=new impl; -} - -Font::Font(const char* FontFileName,int sz) : Font() -{ - use(FontFileName,sz); -} - -Font::Font(const Font& inc) : Font() -{ - *pimpl=*(inc.pimpl); -} -Font& Font::operator = (const Font& inc) -{ - *pimpl=*(inc.pimpl); - return *this; -} -Font::Font(Font&& inc) -{ - pimpl=inc.pimpl; - inc.pimpl=nullptr; -} -Font& Font::operator = (Font&& inc) -{ - *pimpl=*(inc.pimpl); - inc.pimpl=nullptr; - return *this; -} - -Font::~Font() -{ - delete pimpl; -} - -int Font::use(const char* FontFileName,int sz) -{ - TTF_Font* font=TTF_OpenFont(FontFileName,sz); - if(font==NULL) return -1; - pimpl->sTTF.reset(font,TTF_CloseFont); - return 0; -} - - - -Texture Font::renderText(Renderer rnd,const char* Word,RGBA fg) -{ - Surface surf; - surf.pimpl->set(TTF_RenderText_Blended(pimpl->sTTF.get(),Word,fg.toSDLColor())); - Texture t=rnd.render(surf); - return t; -} - -Texture Font::renderUTF8(Renderer rnd,const char* Word,RGBA fg) -{ - Surface surf; - surf.pimpl->set(TTF_RenderUTF8_Blended(pimpl->sTTF.get(),Word,fg.toSDLColor())); - Texture t=rnd.render(surf); - return t; -} diff --git a/SDLEngine/src/sdl_engine_rect.hpp b/SDLEngine/src/sdl_engine_rect.hpp deleted file mode 100644 index 4c4bec7..0000000 --- a/SDLEngine/src/sdl_engine_rect.hpp +++ /dev/null @@ -1,25 +0,0 @@ -Rect::Rect() -{ - x=y=w=h=0; -} -Rect::Rect(int incx,int incy,int incw,int inch) -{ - x=incx; - y=incy; - w=incw; - h=inch; -} -Rect::~Rect() -{ - -} - -SDL_Rect Rect::toSDLRect() -{ - SDL_Rect rect; - rect.x=x; - rect.y=y; - rect.w=w; - rect.h=h; - return rect; -} diff --git a/SDLEngine/src/sdl_engine_renderer.hpp b/SDLEngine/src/sdl_engine_renderer.hpp deleted file mode 100644 index 74e7882..0000000 --- a/SDLEngine/src/sdl_engine_renderer.hpp +++ /dev/null @@ -1,98 +0,0 @@ -Renderer::Renderer() -{ - pimpl=new impl; -} -Renderer::Renderer(const Renderer& inc) : Renderer() -{ - *pimpl=*(inc.pimpl); -} -Renderer& Renderer::operator = (const Renderer& inc) -{ - *pimpl=*(inc.pimpl); - return *this; -} -Renderer::Renderer(Renderer&& inc) -{ - pimpl=inc.pimpl; - inc.pimpl=nullptr; -} -Renderer& Renderer::operator = (Renderer&& inc) -{ - *pimpl=*(inc.pimpl); - inc.pimpl=nullptr; - return *this; -} - -Renderer::~Renderer() -{ - delete pimpl; -} - -int Renderer::clear() -{ - return SDL_RenderClear(pimpl->sRnd.get()); -} -Texture Renderer::loadImage(const char* FileName) -{ - Texture t; - t.pimpl->set(IMG_LoadTexture(pimpl->sRnd.get(),FileName)); - return t; -} -Texture Renderer::render(Surface surface) -{ - Texture t; - t.pimpl->set(SDL_CreateTextureFromSurface(pimpl->sRnd.get(),surface.pimpl->getRawSurface())); - return t; -} - -void Renderer::update() -{ - SDL_RenderPresent(pimpl->sRnd.get()); -} - -int Renderer::copy(Texture t,Rect src,Rect dst) -{ - SDL_Rect s=src.toSDLRect(); - SDL_Rect d=dst.toSDLRect(); - return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),&s,&d); -} -int Renderer::copyTo(Texture t,Rect dst) -{ - SDL_Rect d=dst.toSDLRect(); - return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),NULL,&d); -} -int Renderer::copyFill(Texture t,Rect src) -{ - SDL_Rect s=src.toSDLRect(); - return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),&s,NULL); -} -int Renderer::copyFullFill(Texture t) -{ - return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),NULL,NULL); -} - -int Renderer::setColor(RGBA pack) -{ - return SDL_SetRenderDrawColor(pimpl->sRnd.get(),pack.r,pack.g,pack.b,pack.a); -} - -RGBA Renderer::getColor(int* pstatus) -{ - Uint8 r,g,b,a; - int ret=SDL_GetRenderDrawColor(pimpl->sRnd.get(),&r,&g,&b,&a); - RGBA pack(r,g,b,a); - if(pstatus) *pstatus=ret; - return pack; -} - -int Renderer::fillRect(Rect rect) -{ - auto inr=rect.toSDLRect(); - return SDL_RenderFillRect(pimpl->sRnd.get(),&inr); -} - -int Renderer::drawRect(Rect rect) -{ - auto inr=rect.toSDLRect(); - return SDL_RenderDrawRect(pimpl->sRnd.get(),&inr); -} diff --git a/SDLEngine/src/sdl_engine_rgba.hpp b/SDLEngine/src/sdl_engine_rgba.hpp deleted file mode 100644 index 6eb0165..0000000 --- a/SDLEngine/src/sdl_engine_rgba.hpp +++ /dev/null @@ -1,24 +0,0 @@ -RGBA::RGBA() -{ - r=g=b=a=0; -} -RGBA::RGBA(int incr,int incg,int incb,int inca) -{ - r=incr; - g=incg; - b=incb; - a=inca; -} -SDL_Color RGBA::toSDLColor() -{ - SDL_Color color; - color.r=r; - color.g=g; - color.b=b; - color.a=a; - return color; -} -RGBA::~RGBA() -{ - -} diff --git a/SDLEngine/src/sdl_engine_surface.hpp b/SDLEngine/src/sdl_engine_surface.hpp deleted file mode 100644 index 6e77f9e..0000000 --- a/SDLEngine/src/sdl_engine_surface.hpp +++ /dev/null @@ -1,27 +0,0 @@ -Surface::Surface() -{ - pimpl=new impl; -} -Surface::Surface(const Surface& inc) : Surface() -{ - *pimpl=*(inc.pimpl); -} -Surface& Surface::operator = (const Surface& inc) -{ - *pimpl=*(inc.pimpl); - return *this; -} -Surface::Surface(Surface&& inc) -{ - pimpl=inc.pimpl; - inc.pimpl=nullptr; -} -Surface& Surface::operator = (Surface&& inc) -{ - *(pimpl)=*(inc.pimpl); - return *this; -} -Surface::~Surface() -{ - delete pimpl; -} diff --git a/SDLEngine/src/sdl_engine_texture.hpp b/SDLEngine/src/sdl_engine_texture.hpp deleted file mode 100644 index 72b7e09..0000000 --- a/SDLEngine/src/sdl_engine_texture.hpp +++ /dev/null @@ -1,37 +0,0 @@ -Texture::Texture() -{ - pimpl=new impl; -} -Texture::Texture(const Texture& inc) : Texture() -{ - *pimpl=*(inc.pimpl); -} -Texture& Texture::operator = (const Texture& inc) -{ - *pimpl=*(inc.pimpl); - return *this; -} -Texture::Texture(Texture&& inc) -{ - pimpl=inc.pimpl; - inc.pimpl=nullptr; -} -Texture& Texture::operator = (Texture&& inc) -{ - *(pimpl)=*(inc.pimpl); - inc.pimpl=nullptr; - return *this; -} - -int Texture::getw() -{ - return pimpl->w; -} -int Texture::geth() -{ - return pimpl->h; -} -Texture::~Texture() -{ - delete pimpl; -} diff --git a/SDLEngine/src/sdl_engine_window.hpp b/SDLEngine/src/sdl_engine_window.hpp deleted file mode 100644 index 3d16a0c..0000000 --- a/SDLEngine/src/sdl_engine_window.hpp +++ /dev/null @@ -1,55 +0,0 @@ -Window::Window(int winw,int winh) -{ - pimpl=new impl; - SDL_Window* wnd=SDL_CreateWindow("Engine",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,winw,winh,SDL_WINDOW_SHOWN); - pimpl->set(wnd); -} - -Window::Window(const Window& inc) -{ - pimpl=new impl; - *pimpl=*(inc.pimpl); -} - -Window& Window::operator = (const Window& inc) -{ - *pimpl=*(inc.pimpl); - return *this; -} - -Window::Window(Window&& inc) -{ - pimpl=inc.pimpl; - inc.pimpl=nullptr; -} - -Window& Window::operator = (Window&& inc) -{ - *pimpl=*(inc.pimpl); - inc.pimpl=nullptr; - return *this; -} - - -Window::~Window() -{ - delete pimpl; -} - -Renderer Window::getRenderer() const -{ - return pimpl->rnd; -} - -Rect Window::getSize() -{ - int w,h; - SDL_GetWindowSize(pimpl->getRawWindow(),&w,&h); - Rect rect(0,0,w,h); - return rect; -} - -void Window::setSize(Rect rect) -{ - SDL_SetWindowSize(pimpl->getRawWindow(),rect.w,rect.h); -}