Compare commits

...

108 Commits
v0.3 ... master

Author SHA1 Message Date
2da82e4944 Fix compile warning C4717 2020-02-13 09:54:22 +08:00
4f3bfbbade update json support library and license 2020-02-13 09:53:34 +08:00
4a23114b52 Update document 2018-03-15 12:09:19 +08:00
04d3b12c87 Add toolcenter integration 2018-03-14 20:10:05 +08:00
ca6e30a675 Update to Mixer 2.0.2. Fix compile error in VS2017 2018-03-14 19:53:41 +08:00
a09c723a98 Moving files, make things easy. 2018-03-04 15:10:52 +08:00
7e8c6f7c1e Fix compile error 2017-12-31 16:54:29 +08:00
1f056f4841 Move files 2017-12-18 14:09:20 +08:00
563b2c5bd4 Add License from nlohmann/json repo. 2017-08-03 08:24:00 +08:00
c0bd2803a7 Add License year and copyright holders. 2017-08-03 08:15:53 +08:00
7d9729b530 Merge branch 'mingw-dev'
Fix exception specification compile error in C++17 (with -std=c++17 by
GCC 6.1)
2017-07-21 12:01:41 +08:00
dd88f8b4b1 Fix compile warning
Fix warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
2017-07-19 18:11:45 +08:00
1ae05bab71 Remove exception specification
Exception Specification is deprecated in C++11.
2017-07-15 00:12:48 +08:00
8187d5c9a6 Add Tests 2017-07-11 23:00:04 +08:00
edefaa6b2a Merge pull request #11 from Kiritow/pre-merge
Update to v0.7
2017-07-07 17:49:24 +08:00
c769c0a3db Fix bugs of ErrorViewer 2017-07-07 11:38:57 +08:00
1ac2ea6c31 Update README.md 2017-07-07 11:33:57 +08:00
813fdfc985 Update C4droid makefile generator. Remove linux makefile generator.(Recommand Codeblocks on Linux) 2017-07-07 11:28:56 +08:00
a19874c6da Add Makefile generator for Linux 2017-07-06 22:55:33 +08:00
cdddfc059e Fix bugs in Music, MusicPlayer 2017-07-04 22:48:44 +08:00
52918909e9 RWOP can now work with Music and Sound loading 2017-07-04 22:38:33 +08:00
977721b226 Add Git Attribute trying to fix language displaying problem 2017-07-03 07:45:06 +08:00
11d45b4bfd Add Makefile Generator for C4droid 2017-07-02 10:01:05 +08:00
6b213984c6 Add experimental constructor of SDLSystem 2017-07-02 09:47:37 +08:00
e080389709 Fix Compile Error and warning 2017-07-02 08:46:34 +08:00
1ca4e2bc3f Update Event Loop to do-while style 2017-07-01 20:34:34 +08:00
ff862f1dea Change Plugin methods to static 2017-07-01 17:21:35 +08:00
c6f54fa3cb Add Plugin as friend to wrapped class. 2017-07-01 17:11:15 +08:00
f500a470f6 Add Plugin class 2017-07-01 17:06:13 +08:00
943cb0def0 Event handling are now under MiniEngine namespace 2017-07-01 15:58:34 +08:00
2fdf701703 Fix bugs in SDLSystem. Update MiniEngine 2017-07-01 15:46:42 +08:00
46204ba517 Move clipboard functions to SDLSystem 2017-07-01 15:39:51 +08:00
5eb66f6d0d Move SDL,IMG,Mix,TTF Init to SDLSystem 2017-07-01 15:30:08 +08:00
b6f7e70cdd Remove main function provided in MiniEngine 2017-07-01 14:50:01 +08:00
17f12ecc2f Add Nonmoveable 2017-07-01 14:48:58 +08:00
2d0b1b77a8 Enable software Renderer creating in class Renderer 2017-06-28 15:27:13 +08:00
ad34163fbf Add some functions to Rect 2017-06-28 15:13:55 +08:00
e87f513857 Merge pull request #10 from Kiritow/pre-merge
Update MiniEngine
2017-06-23 22:56:01 +08:00
1b02c209fe Update Sound(Chunk) Wrapper 2017-06-23 14:16:15 +08:00
0ea8797093 Update Music Wrapper 2017-06-23 13:18:00 +08:00
4319ee521b Add optional. Change IncludeAll Header. 2017-06-23 11:50:44 +08:00
0a141bb4a0 Move Audio,SoundPlayer out from Music Part 2017-06-23 11:24:50 +08:00
f4f4327b7a Add Json library (Powered by nlohmann/json) 2017-06-23 10:54:35 +08:00
f9b9e7b859 Change Enum declaration to MiniEngine:: 2017-06-18 20:42:33 +08:00
9ecfeb1962 Move almost all classes out 2017-06-18 20:37:45 +08:00
4c774ca9ec Move Enum out to single files. 2017-06-18 20:37:17 +08:00
c86b52ef19 Move cursor out 2017-06-18 17:43:23 +08:00
681ef2b0c6 Move Window out 2017-06-18 17:40:17 +08:00
dfa628cd14 Move Font,Music,Renderer,Texture,Timer out 2017-06-18 17:36:13 +08:00
62b86cb072 Move Point, ColorMode, RGBA out 2017-06-18 17:03:57 +08:00
0629ceadba Move Rect and Surface out of main file 2017-06-18 17:00:08 +08:00
7505db992a remove SDLEngine old code. 2017-06-18 16:47:21 +08:00
112c1081aa Move Renderer settings out of class Window 2017-06-15 13:53:04 +08:00
a96b48b0c0 Add direct effect add/remove control to SoundPlayer 2017-06-14 20:50:12 +08:00
dd2ccfa55c Add advance MessageBox support 2017-06-12 13:01:28 +08:00
cbb780a9da Add system info querying functions (CPU,RAM) 2017-06-07 20:37:54 +08:00
6df4068539 Extend supercopy function in class Renderer 2017-06-07 20:11:28 +08:00
4608508476 class Renderer supports getting rendering target now. 2017-06-07 19:52:37 +08:00
f0cbeb9702 Enhanced Renderer
Add multi-draw support.
Add Scale, Viewport, LogicalSize, ClipRect support
Querying driver number.
2017-06-07 19:40:21 +08:00
de833ccfc2 Fix Compile and link error 2017-06-07 12:21:48 +08:00
d4aa4cbbaa Add version querying functions 2017-06-06 22:56:07 +08:00
c422bbb57c Merge pull request #9 from Kiritow/pre-merge
Update to v0.5
2017-06-06 21:32:31 +08:00
c4b8e3e34e Merge test branch.
We are about to support some functions from SDL2 Test Library.
2017-06-06 19:07:28 +08:00
c0677b055b Add CRC32 calculating support. 2017-06-06 19:05:52 +08:00
e183a09f34 Add class UniRandom. (Random Number Generator) 2017-06-06 18:38:28 +08:00
3664de7972 Add Music Effect API to class MusicPlayer (Experimental) 2017-06-06 18:19:04 +08:00
f1f86c933d Add Sound Effect API to class SoundPlayer (Experimental) 2017-06-06 16:00:51 +08:00
01c31a4f71 Add decoder query functions in class MusicPlayer and SoundPlayer 2017-06-06 15:50:56 +08:00
bf0f6b8b6d Add more functions to class Font 2017-06-06 13:24:43 +08:00
aacd73d728 Update constant attribute in class Surface, Renderer, Window,
SharedLibrary
2017-06-05 22:01:15 +08:00
4d636586c2 Update constant attribute to function in class Rect, Point, ErrorViewer,
Texture
2017-06-05 20:43:33 +08:00
5581a57e1b Update constant attribute to functions in class Surface 2017-06-05 15:51:29 +08:00
9019971e19 Update C/V attribute functions of class RGBA, class Renderer, class Font 2017-06-05 15:40:16 +08:00
e6624b8238 class Font supports Unicode now. 2017-06-05 14:07:57 +08:00
7cecae5695 Fix Compile error on low level SDL2. 2017-06-01 22:50:17 +08:00
d8e8deb031 Add template-like get method in class SharedLibrary 2017-05-31 22:30:10 +08:00
d450ce8636 Add support for set/get window opacity 2017-05-31 22:17:30 +08:00
7822544701 Add More Functions to class Surface 2017-05-25 18:34:59 +08:00
d8e2bb9e2b Add Surface compare function.
Build Notice!:
I got a link error while compiling the full project. The link error is
"undefined reference to SDL_GetRGBA" and "undefined reference to
SDL_snprintf"...
Currently there is one way to solve it : Link SDL2test.lib first (Before
SDL2 and SDL2main)
2017-05-24 18:17:29 +08:00
1cdf7956f6 Need Surface operating methods.
Merge branch 'mingw-dev' into mingw-dev-test
2017-05-24 18:03:44 +08:00
709e67a40f Fix compile error on C4 2017-05-24 03:09:27 +08:00
337694bd89 Fix compile error 2017-05-24 02:57:23 +08:00
f2d60629a0 Use new UTF8-GBK converter. 2017-05-23 22:31:57 +08:00
79b97736b4 Add more functions to class Surface 2017-05-23 13:05:09 +08:00
1e8a0d6155 Add SDLTest lib support 2017-05-23 12:26:42 +08:00
1b2ba7b2d8 Update class Cursor. Fix compile bug in class Window 2017-05-22 19:17:02 +08:00
52cb15482e More Event Functions 2017-05-22 19:07:26 +08:00
14c31689be Add more support about keyboard.
Now class Window has default constructor.
2017-05-22 18:47:28 +08:00
08a858acf0 Add Clipboard Support 2017-05-22 18:27:56 +08:00
c024cd8467 Merge pull request #8 from Kiritow/pre-merge
Weekly Update
2017-05-22 15:10:19 +08:00
ee8780fe30 Fix Runtime Bug in class Timer
Now callable and vcallable are copied, while args... remains referenced.
2017-05-22 15:02:04 +08:00
a7ab24d8ab Fix bug in class Timer (VoidCallable Constructor) 2017-05-21 21:08:53 +08:00
6c4f1c345d Merge branch 'mingw-dev-xml-parser' into mingw-dev
Provide XML Parsing
2017-05-21 10:20:08 +08:00
54e057b590 Add More Function of Attr and Node 2017-05-20 16:00:19 +08:00
3e995ba610 Add XXX::release() implement. 2017-05-18 18:14:29 +08:00
c46455a2e7 Add Release Interface (For Global Objects Managing) 2017-05-18 17:58:10 +08:00
26beb30f77 Fix bug in StringEngine 2017-05-18 13:04:20 +08:00
547be65c3e Add more functions to Attr and Node 2017-05-18 09:00:27 +08:00
d47a3ed09d Add support functions of XML Node 2017-05-17 23:24:43 +08:00
fc4940c09b Add XML Objects
Document,Node,Attribute...
2017-05-17 21:40:33 +08:00
b6ecc0f856 Enhanced Window Constructor 2017-05-16 22:33:21 +08:00
0d5e8e2893 Set include path of VS to normal in config 2017-05-16 16:50:16 +08:00
65435476b6 Add Configure Header 2017-05-16 16:27:35 +08:00
6901b0054c Add font style single-query methods 2017-05-16 16:23:40 +08:00
00a3000d1d Fix bug in Font::setFontStyle 2017-05-16 15:52:00 +08:00
b40db11955 Query of font size is supported 2017-05-16 15:23:34 +08:00
f9c2e872df Change rapidxml header to avoid compile errors 2017-04-13 20:28:16 +08:00
2b19c80a7e Create header and source 2017-04-13 16:19:35 +08:00
126 changed files with 32049 additions and 7440 deletions

4
.gitattributes vendored Normal file
View File

@ -0,0 +1,4 @@
*.c linguist-language=C++
*.cpp linguist-language=C++
*.h linguist-language=C++
*.hpp linguist-language=C++

View File

@ -1,5 +1,4 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2017, Kiritow. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

File diff suppressed because it is too large Load Diff

View File

@ -1,647 +0,0 @@
#pragma once
#ifdef _MSC_VER
/// Visual Studio (VC++ Compiler)
#include <SDL.h>
#undef main
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL_mixer.h>
/// VC++ does not implied C++ exception. Use this to ignore compile warning on this.
#pragma warning (disable:4290)
#else
/// CodeBlocks (MinGW Compiler)
#include <SDL2/SDL.h>
#undef main
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#endif
#include <string>
#include <memory>
#include <functional>
#define _DECL_DEPRECATED [[deprecated]]
namespace MiniEngine
{
class Rect
{
public:
int x, y, w, h;
Rect(int X, int Y, int W, int H);
Rect(const SDL_Rect&);
Rect();
SDL_Rect toSDLRect() const;
bool isEmpty();
bool operator == (const Rect&) const;
bool hasIntersection(const Rect&);
Rect getIntersection(const Rect&);
Rect getUnion(const Rect&);
};
class Point
{
public:
int x, y;
Point(int X, int Y);
Point();
SDL_Point toSDLPoint();
bool inRect(Rect rect);
};
class ColorMode
{
public:
int r, g, b;
ColorMode(int R, int G, int B);
ColorMode();
};
class RGBA
{
public:
int r, g, b, a;
RGBA(int R, int G, int B, int A);
RGBA(ColorMode mode, int A);
RGBA();
SDL_Color toSDLColor();
ColorMode toColorMode();
};
class NonCopyable
{
protected:
NonCopyable() = default;
~NonCopyable() = default;
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator = (const NonCopyable&) = delete;
};
class ErrorViewer : public std::exception
{
public:
void fetch();
std::string getError();
const char* what() const throw() override;
private:
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<SDL_RWops> _op;
SDL_RWops* _get();
void _clear();
void _set(SDL_RWops*);
friend class Renderer;
};
enum class BlendMode { None,Blend,Add,Mod };
class Surface
{
public:
~Surface() = default;
int savePNG(const std::string& filename);
int getw();
int geth();
BlendMode getBlendMode();
int setBlendMode(BlendMode mode);
int blit(Surface s,Rect src,Rect dst);
int blitTo(Surface t, Rect dst);
int blitTo(Surface t, Point lupoint);
int blitFill(Surface t, Rect src);
int blitFullFill(Surface t);
int blitScaled(Surface s,Rect src,Rect dst);
int blitScaledTo(Surface t, Rect dst);
int blitScaledTo(Surface t, Point lupoint);
int blitScaledFill(Surface t, Rect src);
int blitScaledFullFill(Surface t);
int setAlphaMode(int alpha);
int getAlphaMode();
ColorMode getColorMode();
int setColorMode(ColorMode mode);
RGBA getRGBA();
void setRGBA(RGBA pack);
bool mustlock();
int lock();
void unlock();
static Surface createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
protected:
Surface() = default;
private:
std::shared_ptr<SDL_Surface> _surf;
void _set(SDL_Surface*);
void _clear();
SDL_Surface* _get();
std::shared_ptr<SDL_Surface>& _getex();
friend class Window;
friend class Renderer;
friend class Font;
friend class Cursor;
};
class Texture
{
public:
Texture();
~Texture() = default;
Rect getSize();
int getw();
int geth();
bool isReady();
int setBlendMode(BlendMode mode);
BlendMode getBlendMode();
/// Alpha: 0: Transparent 255: opaque
int setAlphaMode(int alpha);
int getAlphaMode();
ColorMode getColorMode();
int setColorMode(ColorMode mode);
RGBA getRGBA();
void setRGBA(RGBA pack);
protected:
/// updateInfo() must be called after Texture is changed.
void updateInfo();
private:
std::shared_ptr<SDL_Texture> _text;
void _set(SDL_Texture*);
void _clear();
SDL_Texture* _get();
Rect rect;
friend class Renderer;
};
enum class RendererType { Software, Accelerated, PresentSync, TargetTexture };
enum class FlipMode { None, Horizontal, Vertical };
class Renderer
{
public:
Renderer() = default;
int setColor(RGBA pack);
RGBA getColor();
int setBlendMode(BlendMode mode);
BlendMode getBlendMode();
int setTarget(Texture& t);
int setTarget();
int fillRect(Rect rect);
int drawRect(Rect rect);
int drawPoint(Point p);
int clear();
void update();
int copy(Texture t, Rect src, Rect dst);
int copyTo(Texture t, Rect dst);
int copyTo(Texture t, Point lupoint);
int copyFill(Texture t, Rect src);
int copyFullFill(Texture t);
int supercopy(Texture t,bool srcfull,Rect src,bool dstfull,Rect dst,double angle,bool haspoint,Point center,FlipMode mode);
Surface loadSurface(std::string FileName) throw(ErrorViewer);
Surface loadSurfaceRW(RWOP rwop) throw(ErrorViewer);
Texture render(Surface surf) throw (ErrorViewer);
Texture loadTexture(std::string FileName) throw(ErrorViewer);
Texture loadTextureRW(RWOP rwop) throw(ErrorViewer);
Texture createTexture(int Width, int Height) throw(ErrorViewer);
bool isReady();
private:
std::shared_ptr<SDL_Renderer> _rnd;
void _set(SDL_Renderer*);
void _clear();
SDL_Renderer* _get();
friend class Window;
};
enum class SystemCursorType
{
Arrow, Ibeam, CrossHair,
Wait, WaitArrow,
SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll,
No, Hand
};
class Cursor
{
public:
static Cursor CreateSystemCursor(SystemCursorType);
static Cursor CreateCursor(Surface surf,Point hotspot={0,0});
static Cursor GetActiveCursor();
static Cursor GetDefaultCursor();
static void show(bool);
static bool isShow();
void activate();
private:
std::shared_ptr<SDL_Cursor> _cur;
void _set(SDL_Cursor*);
void _set_no_delete(SDL_Cursor*);
SDL_Cursor* _get();
void _clear();
};
enum class MessageBoxType { Error, Warning, Information };
class Window
{
public:
Window(std::string Title, int Width, int Height, std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw(ErrorViewer);
Renderer getRenderer() const;
void setRenderer(RendererType Type)
{
_internal_rndflagcalc=0;
_setRenderer(Type);
}
template<typename... Args>
void setRenderer(RendererType Type,Args&&... args)
{
_internal_rndflagcalc=0;
_setRenderer(Type,std::forward<RendererType>(args...));
}
void setRenderer(std::initializer_list<RendererType>);
Rect getSize();
void setSize(Rect sizeRect);
void setSize(int w, int h);
Rect getPosition();
void setPosition(int x, int y);
/// FIXME: Use class Point or class Rect ?
void setPosition(Point point);
void setTitle(std::string Title);
std::string getTitle();
void setGrab(bool);
bool getGrab();
void setResizable(bool resizable);
/// Use UTF8 in Title and Message please.
int showSimpleMessageBox(MessageBoxType type,std::string Title,std::string Message);
void show();
void hide();
void raise();
void minimize();
void maximize();
void restore();
_DECL_DEPRECATED Surface getSurface();
protected:
template<typename... Args>
void _setRenderer(RendererType Type,Args&&... args)
{
_internal_rndflagcalc|=_render_caster(Type);
_setRenderer(args...);
}
void _setRenderer(RendererType Type)
{
_internal_rndflagcalc|=_render_caster(Type);
_setRenderer_Real(_internal_rndflagcalc);
}
private:
void _setRenderer_Real(Uint32 flags);
Uint32 _internal_rndflagcalc;
Uint32 _render_caster(RendererType);
std::shared_ptr<SDL_Window> _wnd;
void _set(SDL_Window*);
void _clear();
SDL_Window* _get();
Renderer winrnd;
};
class Font
{
public:
enum class Style { Normal, Bold, Italic, UnderLine, StrikeThrough };
Font() = default;
Font(std::string FontFileName, int size) throw(ErrorViewer);
int use(std::string FontFileName, int size);
bool isReady();
template<typename... Args>
void setFontStyle(Style style,Args&&... args)
{
_internal_fontcalc=0;
_setFontStyle(style,std::forward(args...));
}
void setFontStyle(Style style)
{
_real_setFontStyle(_style_caster(style));
}
std::tuple<Style> getFontStyles();
Surface renderText(std::string Text, RGBA fg);
Surface renderTextWrapped(std::string Text, RGBA fg, int WrapLength);
Surface renderTextShaded(std::string Text, RGBA fg, RGBA bg);
Surface renderTextSolid(std::string Text, RGBA fg);
Surface renderUTF8(std::string Text, RGBA fg);
Surface renderUTF8Wrapped(std::string Text, RGBA fg, int WrapLength);
Surface renderUTF8Shaded(std::string Text, RGBA fg, RGBA bg);
Surface renderUTF8Solid(std::string Text, RGBA fg);
Texture renderText(Renderer rnd, std::string Text, RGBA fg);
Texture renderTextWrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
Texture renderTextShaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
Texture renderTextSolid(Renderer rnd, std::string Text, RGBA fg);
Texture renderUTF8(Renderer rnd, std::string Text, RGBA fg);
Texture renderUTF8Wrapped(Renderer rnd, std::string Text, RGBA fg, int WrapLength);
Texture renderUTF8Shaded(Renderer rnd, std::string Text, RGBA fg, RGBA bg);
Texture renderUTF8Solid(Renderer rnd, std::string Text, RGBA fg);
protected:
template<typename... Args>
void _setFontStyle(Style style,Args&&... args)
{
_internal_fontcalc|=_style_caster(style);
_setFontStyle(args...);
}
void _setFontStyle(Style style)
{
_internal_fontcalc|=_style_caster(style);
_real_setFontStyle(_internal_fontcalc);
}
private:
void _real_setFontStyle(int);
int _style_caster(Style);
int _internal_fontcalc;
std::shared_ptr<TTF_Font> _font;
void _set(TTF_Font*);
void _clear();
TTF_Font* _get();
};
enum class Platform { Unknown,Windows,MacOS,Linux,iOS,Android };
enum class PowerState { Unknown,OnBattery,NoBattery,Charging,Charged };
class LogSystem
{
static void v(const char* fmt,...);/// Verbose
static void d(const char* fmt,...);/// Debug
static void i(const char* fmt,...);/// Information
static void w(const char* fmt,...);/// Warning
static void e(const char* fmt,...);/// Error
static void critical(const char* fmt,...);/// Critical
};
class SharedLibrary
{
public:
SharedLibrary();
SharedLibrary(const std::string& Filename);
~SharedLibrary();
int load(const std::string& Filename);
int unload();
void* get(const std::string& FunctionName);
private:
void* _obj;
};
class SDLSystem
{
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();
static void Delay(int ms);
static PowerState GetPowerState();
static int GetPowerLifeLeft();
static int GetPowerPrecentageLeft();
static Platform GetPlatform();
static void StartTextInput();
static void StopTextInput();
class Android
{
public:
static std::string GetInternal();
static bool ExternalAvaliable();
static bool CanReadExternal();
static bool CanWriteExternal();
static std::string GetExternal();
static void* GetJNIEnv();
};
};
Uint32 _global_timer_executor(Uint32 interval,void* param);
class Timer
{
public:
Timer();
/// void func(Uint32,...)
template<typename VoidCallable,typename... Args>
Timer(Uint32 interval,VoidCallable&& vcallable,Args&&... args) : Timer()
{
auto realCall=[&](Uint32 ims)->Uint32{vcallable(ims,args...);return interval;};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc);
}
/// Uint32 func(Uint32,...)
template<typename Callable,typename... Args>
Timer(Callable&& callable,Uint32 interval,Args&&... args) : Timer()
{
auto realCall=[&](Uint32 ims)->Uint32{return callable(ims,args...);};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc);
}
/// Restore For Capability
Timer(SDL_TimerCallback callback,Uint32 interval,void* param);
int enable();
int disable();
bool isenable();
void detach();
~Timer();
static void _delete_delegator(std::function<Uint32(Uint32)>* Delegator);
private:
void _real_timer_call(SDL_TimerCallback callback,Uint32 interval,void* param);
SDL_TimerCallback _callback;
Uint32 _interval;
void* _param;
SDL_TimerID id;
bool _enabled;
bool _detached;
/// Reserved Variable For Template variable Parameter
bool _delete_on_disable;
};
class AudioPlayer
{
public:
AudioPlayer();
~AudioPlayer();
private:
class _Audio
{
public:
_Audio();
~_Audio();
};
static _Audio* _sysAudio;
static int _sysAudioCounter;
};
/// Forward Declaration
class Music
{
public:
protected:
Music() = default;
private:
std::shared_ptr<Mix_Music> _music;
void _set(Mix_Music*);
void _clear();
Mix_Music* _get();
friend class MusicPlayer;
};
class MusicPlayer : public AudioPlayer
{
public:
Music loadMusic(std::string Filename) throw (ErrorViewer);
int play(Music music, int loops);
void pause();
void resume();
void rewind();
int stop();
int fadeIn(int loops, int ms);
int fadeOut(int ms);
bool isPlaying();
bool isPaused();
int isFading();
private:
Music m;
};
class Sound
{
public:
protected:
Sound() = default;
private:
std::shared_ptr<Mix_Chunk> _sound;
void _set(Mix_Chunk*);
void _clear();
Mix_Chunk* _get();
friend class SoundPlayer;
};
typedef int ChannelID;
class SoundPlayer : public AudioPlayer
{
public:
SoundPlayer(int Channels = 16);
Sound loadSound(std::string Filename) throw (ErrorViewer);
ChannelID playSound(Sound sound, int loops) throw (ErrorViewer);
ChannelID fadein(Sound sound, int loops, int ms) throw (ErrorViewer);
int fadeout(ChannelID id, int ms);
void pause(ChannelID id);
void resume(ChannelID id);
int stop(ChannelID id);
};
class StringEngine
{
public:
StringEngine(std::string StringFile,std::string LanguageTag);
StringEngine(StringEngine& )=delete;
StringEngine& operator = (StringEngine& )=delete;
int useLanaguage(std::string LanguageTag);
bool ready();
std::string getString(std::string Tag);
~StringEngine();
private:
struct impl;
impl* pimpl;
};
}/// End of namespace MiniEngine
std::string UTF8ToGBK(std::string UTF8String);
std::string GBKToUTF8(std::string GBKString);
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();

View File

@ -1,142 +0,0 @@
#include "MiniEngine.h"
using namespace std;
#include <windows.h>
//GBK编码转换到UTF8编码
int _GBKToUTF8(unsigned char * lpGBKStr,unsigned char * lpUTF8Str,int nUTF8StrLen)
{
wchar_t * lpUnicodeStr = NULL;
int nRetLen = 0;
if(!lpGBKStr) //如果GBK字符串为NULL则出错退出
return 0;
nRetLen = MultiByteToWideChar(CP_ACP,0,(char *)lpGBKStr,-1,NULL,0); //获取转换到Unicode编码后所需要的字符空间长度
lpUnicodeStr = new WCHAR[nRetLen + 1]; //为Unicode字符串空间
nRetLen = ::MultiByteToWideChar(CP_ACP,0,(char *)lpGBKStr,-1,lpUnicodeStr,nRetLen); //转换到Unicode编码
if(!nRetLen) //转换失败则出错退出
return 0;
nRetLen = ::WideCharToMultiByte(CP_UTF8,0,lpUnicodeStr,-1,NULL,0,NULL,0); //获取转换到UTF8编码后所需要的字符空间长度
if(!lpUTF8Str) //输出缓冲区为空则返回转换后需要的空间大小
{
if(lpUnicodeStr)
delete []lpUnicodeStr;
return nRetLen;
}
if(nUTF8StrLen < nRetLen) //如果输出缓冲区长度不够则退出
{
if(lpUnicodeStr)
delete []lpUnicodeStr;
return 0;
}
nRetLen = ::WideCharToMultiByte(CP_UTF8,0,lpUnicodeStr,-1,(char *)lpUTF8Str,nUTF8StrLen,NULL,NULL); //转换到UTF8编码
if(lpUnicodeStr)
delete []lpUnicodeStr;
return nRetLen;
}
// UTF8编码转换到GBK编码
int _UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen)
{
wchar_t * lpUnicodeStr = NULL;
int nRetLen = 0;
if(!lpUTF8Str) //如果UTF8字符串为NULL则出错退出
return 0;
nRetLen = ::MultiByteToWideChar(CP_UTF8,0,(char *)lpUTF8Str,-1,NULL,0); //获取转换到Unicode编码后所需要的字符空间长度
lpUnicodeStr = new WCHAR[nRetLen + 1]; //为Unicode字符串空间
nRetLen = ::MultiByteToWideChar(CP_UTF8,0,(char *)lpUTF8Str,-1,lpUnicodeStr,nRetLen); //转换到Unicode编码
if(!nRetLen) //转换失败则出错退出
return 0;
nRetLen = ::WideCharToMultiByte(CP_ACP,0,lpUnicodeStr,-1,NULL,0,NULL,NULL); //获取转换到GBK编码后所需要的字符空间长度
if(!lpGBKStr) //输出缓冲区为空则返回转换后需要的空间大小
{
if(lpUnicodeStr)
delete []lpUnicodeStr;
return nRetLen;
}
if(nGBKStrLen < nRetLen) //如果输出缓冲区长度不够则退出
{
if(lpUnicodeStr)
delete []lpUnicodeStr;
return 0;
}
nRetLen = ::WideCharToMultiByte(CP_ACP,0,lpUnicodeStr,-1,(char *)lpGBKStr,nRetLen,NULL,NULL); //转换到GBK编码
if(lpUnicodeStr)
delete []lpUnicodeStr;
return nRetLen;
}
string UTF8ToGBK(string UTF8String)
{
int sz=UTF8String.size()*2/3+256;
auto utf8str=new unsigned char[sz];
memset(utf8str,0,sz);
memcpy(utf8str,UTF8String.c_str(),UTF8String.size());
auto gbkstr=new unsigned char[sz];
memset(gbkstr,0,sz);
_UTF8ToGBK(utf8str,gbkstr,sz);
string s((char*)gbkstr);
delete[] gbkstr;
delete[] utf8str;
return s;
}
string GBKToUTF8(string GBKString)
{
int sz=GBKString.size()*3/2+32;
auto gbkstr=new unsigned char[sz];
memset(gbkstr,0,sz);
memcpy(gbkstr,GBKString.c_str(),GBKString.size());
auto utf8str=new unsigned char[sz];
memset(utf8str,0,sz);
_GBKToUTF8(gbkstr,utf8str,sz);
string s((char*)utf8str);
delete[] gbkstr;
delete[] utf8str;
return s;
}
#ifdef _MSC_VER
bool isexist(std::string Path)
{
return false;
}
bool canread(std::string Path)
{
return false;
}
bool canwrite(std::string Path)
{
return false;
}
bool canexecute(std::string Path)
{
return false;
}
#endif /// End of _MSC_VER

View File

@ -2,32 +2,43 @@
A C++ Mini Engine. Based on SDL2.
C++编写的SDL2引擎.
[English Version](README_en_US.md)
**可能存在的错误**: 由于Event和Widget体系尚未构建完全使用时可能出现问题(包括未解决的编译错误)。若只使用MiniEngine主体则不会出现问题。
**重要提示**: master分支为稳定分支,dev分支为开发分支.
C++编写的SDL2引擎.
### 编译说明
Windows: 请使用Codeblocks 16.01(推荐)载入所有.cpp文件.接下来Codeblocks会完成其余的工作.
> 依赖库
Windows: 推荐使用VS2017. 将项目克隆后加入解决方案, 注意删除`makefile_c4gen.cpp`以及`test`文件夹.
Linux: 请使用Codeblocks 17.12(推荐)载入所有文件.接下来Codeblocks会完成其余的工作.需要手动删除`makefile_c4gen.cpp`并排除`test`文件夹.
C4droid: 编译并运行`makefile_c4gen.cpp`,将生成一份makefile. 修改编译目标为SDL2 Application. 修改程序名称为program_name(也可以修改makefile为其他名称)
Windows,Linux需要以下依赖库:
> SDL2 (SDL2.lib, SDL2main.lib, SDL2test.lib)
> SDL2 Image (SDL2_image.lib)
> SDL2 Mixer (SDL2_mixer.lib)
> SDL2 TTF (SDL2_ttf.lib)
Windows-Visual Studio: 使用VS编译本项目可能会出现某些错误,目前还没有很好的解决办法.
C4droid需要保证已经安装以下应用:
C4droid: 长按编译键选择编译模式为Makefile. 选择编译目标为SDL2 Application. 修改程序名称为program_name(此处与makefile对应即可)
> 依赖库
> C4droid本体
> GCC Plugin For C4droid
> SDL2 Plugin For C4droid
[前往SDL2官网下载最新版本](http://www.libsdl.org/download-2.0.php)
[C4droid on GooglePlay](https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en)
Linux Codeblocks PPA 参见: [Code::Blocks Release Builds](https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable)
### 下载链接
[SDL2官网下载](http://www.libsdl.org/download-2.0.php)
##### 依赖库下载地址
[SDL2_image下载地址](https://www.libsdl.org/projects/SDL_image/)
[SDL2_mixer下载地址](https://www.libsdl.org/projects/SDL_mixer/)
[SDL2_ttf下载地址](https://www.libsdl.org/projects/SDL_ttf/)
[在GooglePlay上下载C4droid](https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en "付费+需要科学上网")
[C4droid百度贴吧](http://tieba.baidu.com/f?kw=c4droid "虽然自从吧主换届之后大不如前...")

39
README_en_US.md Normal file
View File

@ -0,0 +1,39 @@
# MiniEngine
A C++ Mini Engine. Based on SDL2
### How to compile
Windows: Visual Studio 2017 is recommended. Import all files except `makefile_c4gen.cpp` and `test` directory.
Linux: Codeblocks 17.12 is recommended. Import all files except `makefile_c4gen.cpp` and `test` directory.
C4droid: Compile and run `makefile_c4gen.cpp`. Makefile will be generated. Then change make target to `SDL2 Application` and set the program name with `program_name`.
For Windows and Linux, the following libraries are required:
> SDL2 (SDL2.lib, SDL2main.lib, SDL2test.lib)
> SDL2 Image (SDL2_image.lib)
> SDL2 Mixer (SDL2_mixer.lib)
> SDL2 TTF (SDL2_ttf.lib)
For C4droid, the following packages are required:
> C4droid APP
> GCC Plugin For C4droid
> SDL2 Plugin For C4droid
This PPA is recommended for installing Code::Blocks in Linux: [Code::Blocks Release Builds](https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable)
### Download Links
[SDL2 Official Download Website](https://www.libsdl.org/download-2.0.php)
[SDL2 Image Download](https://www.libsdl.org/projects/SDL_image/)
[SDL2 Mixer Download](https://www.libsdl.org/projects/SDL_mixer/)
[SDL2 TTF Download](https://www.libsdl.org/projects/SDL_ttf/)
[C4droid on GooglePlay](https://play.google.com/store/apps/details?id=com.n0n3m4.droidc&hl=en)

View File

@ -1,32 +0,0 @@
#pragma once
#include "../config.h"
#include <functional>
//#include <SDL2/SDL_events.h>
namespace MiniEngine
{
class MouseEvent
{
private:
struct EventData
{
int x,y;
}
public:
int type;
EventData data;
};
class MouseEventListener
{
public:
MouseEventListener();
function<void(const MouseEvent&)> onButtonDown;
function<void(const MouseEvent&)> onButtonUp;
function<void(const MouseEvent&)> onMotion;
function<void(const MouseEvent&)> onWheel;
};
}/// End of namespace MiniEngine

View File

@ -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

View File

@ -1,89 +0,0 @@
#pragma once
#include "../config.h"
#include <string>
#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.

View File

@ -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;
}

View File

@ -1,9 +0,0 @@
#pragma once
#include "mini_engine.h"
namespace App
{
/** Entrance of Application.
*/
void Main();
}

View File

@ -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;

View File

@ -1,60 +0,0 @@
#pragma once
#include "config.h"
#include <memory>
#define _MUSIC_MANAGER_IMPL \
struct impl; \
std::shared_ptr<impl> 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;
};

View File

@ -1,38 +0,0 @@
#pragma once
#ifdef __C4DROID__
#define _WINDOW_PROGRAM
#endif // __C4DROID__
#include <cstdio>
#include <cstdlib>
#include <cstring>
/// 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

View File

@ -1,9 +0,0 @@
#pragma once
#include "basic_config.h"
#include "sdl_engine.h"
namespace Global
{
void ErrorQuit(const char* ErrorMessage);
}

View File

@ -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();

View File

@ -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

View File

@ -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)

View File

@ -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);
*/
}
}

View File

@ -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;

View File

@ -1,86 +0,0 @@
#include "MusicManager.h"
#include <memory>
#include <vector>
using namespace std;
struct Music::impl
{
friend class Music;
shared_ptr<Mix_Music> 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<pair<Music,int>> 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<Mix_Chunk> sChunk;
};
SoundEffect::SoundEffect()
{
pimpl.reset(new impl);
}

View File

@ -1,3 +0,0 @@
#include "basic_config.h"
FILE* _log_fp=NULL;

View File

@ -1,10 +0,0 @@
#include "config.h"
namespace Global
{
void ErrorQuit(const char* ErrorMessage)
{
mlog(ErrorMessage);
exit(0);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,144 +0,0 @@
#include "sdl_engine.h"
#include "unistd.h"
#include <memory>
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<SDL_Renderer> sRnd;
public:
void set(SDL_Renderer* rnd)
{
sRnd.reset(rnd,SDL_DestroyRenderer);
}
};
struct Window::impl
{
private:
friend class Window;
shared_ptr<SDL_Window> 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<SDL_Texture> 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<SDL_Surface> 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<TTF_Font> 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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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()
{
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

36
include/MiniEngine.h Normal file
View File

@ -0,0 +1,36 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include "SDLWrapper/IncludeAll.h"
namespace MiniEngine
{
class StringEngine
{
public:
StringEngine(std::string StringFile,std::string LanguageTag);
StringEngine(StringEngine& )=delete;
StringEngine& operator = (StringEngine& )=delete;
int useLanaguage(std::string LanguageTag);
bool ready();
std::string getString(std::string Tag);
~StringEngine();
private:
struct impl;
impl* pimpl;
};
/// Experimental - For Experts: Use SDL ScanCode
bool GetScanKeyState(SDL_Scancode);
}/// End of namespace MiniEngine
std::string UTF8ToGBK(std::string UTF8String);
std::string GBKToUTF8(std::string GBKString);
bool canread(std::string Path);
bool canwrite(std::string Path);
bool isexist(std::string Path);
bool canexecute(std::string Path);

View File

@ -0,0 +1,19 @@
#pragma once
#ifdef _MSC_VER
/// Visual Studio (VC++ Compiler)
/// VC++ does not implied C++ exception. Use this to ignore compile warning on this.
#pragma warning (disable:4290)
#define _COMPILER_LABLE 1
#else
/// CodeBlocks (MinGW Compiler)
#define _COMPILER_LABLE 2
#endif /// End of #ifdef _MSC_VER
#include <SDL2/SDL.h>
#undef main
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#define _DECL_DEPRECATED [[deprecated]]

View File

@ -1,7 +1,11 @@
#pragma once
#include "MiniEngine.h"
#include "MiniEngine_Config.h"
#include <map>
#include <list>
#include <functional>
namespace MiniEngine
{
typedef SDL_Event Event;
typedef decltype(Event::type) _SDLEventType_;
@ -16,6 +20,8 @@ bool HasEvent(_SDLEventType_ EventTypeMin,_SDLEventType_ EventTypeMax);
bool EnableEvent(_SDLEventType_ EventType);
bool DisableEvent(_SDLEventType_ EventType);
bool IsEventEnabled(_SDLEventType_ EventType);
_SDLEventType_ RegisterEvent(int howMuch);
bool IsValidEventType(_SDLEventType_ EventType);
typedef struct
{
@ -60,7 +66,6 @@ public:
void run();
Event GetLastEvent();
void needupdate();
void needstop();
void stop();
void reset();
@ -94,3 +99,5 @@ public:
protected:
int _timeout_ms;
};
}/// End of namespace MiniEngine

View File

@ -2,6 +2,7 @@
#include "sqlite/sqlite3.h"
#include <string>
#include <memory>
#include <functional>
namespace MiniEngine
{

37
include/MiniEngine_Test.h Normal file
View File

@ -0,0 +1,37 @@
#pragma once
#include "MiniEngine.h"
#include <string>
namespace MiniEngine
{
namespace Test
{
std::string GetMD5(unsigned char* buffer,unsigned int bufferLen);
void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff);
int GetCRC32(unsigned char* buffer,unsigned int bufferLen,uint32_t& out_CRCResult);
/// Compare two surfaces. Currently, Surface::getRawPointer() does not has constant attribute.
int CompareSurface(Surface& surface1,Surface& surface2,int allowableError);
class UniRandom
{
public:
/// Default Constructor is based on system current time.
UniRandom();
UniRandom(unsigned int A,unsigned int B);
uint32_t get();
private:
struct _impl;
std::shared_ptr<_impl> _sp;
};
/// Not Implied : SDLTest_RandomAsciiString,SDLTest_RandomAsciiStringOfSize cause link error.
std::string GetRandomString();
std::string GetRandomString(size_t length);
}/// End of namespace MiniEngine::Test
}/// End of namespace MiniEngine

129
include/MiniEngine_Xml.h Normal file
View File

@ -0,0 +1,129 @@
#pragma once
#include "rapidxml/rapidxml.hpp"
#include <string>
namespace MiniEngine
{
namespace XML
{
typedef rapidxml::xml_node<> XNode;
typedef rapidxml::xml_attribute<> XAttr;
typedef rapidxml::xml_document<> XDoc;
/// Fwd Decl
class Document;
class Attribute
{
public:
void _set(XAttr*);
XAttr* _get() const;
void _clear();
void _setdoc(Document*);
Attribute();
Attribute(XAttr*);
std::string getName() const;
std::string getValue() const;
char* getNameRaw() const;
char* getValueRaw() const;
bool hasPrevAttr() const;
bool hasNextAttr() const;
Attribute getPrevAttr() const;
Attribute getNextAttr() const;
Attribute getPrevAttr(const std::string& name) const;
Attribute getNextAttr(const std::string& name) const;
private:
XAttr* _pattr;
Document* _pdoc;
};
class Node
{
public:
void _set(XNode*);
XNode* _get() const;
void _clear();
void _setdoc(Document*);
Node();
Node(XNode*);
std::string getName() const;
std::string getValue() const;
char* getNameRaw() const;
char* getValueRaw() const;
Node& push_front(const Node&);
Node& push_back(const Node&);
Node& insert(const Node& where,const Node& val);
Node& remove_first_node();
Node& remove_last_node();
Node& remove_node(const Node& todelete);
Node& remove_all_node();
Node& push_front(const Attribute&);
Node& push_back(const Attribute&);
Node& insert(const Attribute& where,const Attribute& val);
Node& remove_first_attr();
Node& remove_last_attr();
Node& remove_attr(const Attribute& todelete);
Node& remove_all_attr();
bool operator == (const Node& node);
bool hasPrevNode() const;
bool hasNextNode() const;
bool hasParentNode() const;
Node getPrevNode() const;
Node getNextNode() const;
Node getParentNode() const;
Node getPrevNode(const std::string& name) const;
Node getNextNode(const std::string& name) const;
Node getChild() const;
Node getChild(const std::string& nodename) const;
bool valid();
private:
XNode* _pnode;
Document* _pdoc;
};
class Document
{
public:
Document();
Document(const std::string& filename);
int loadFrom(const std::string& filename,bool clearCurrent=true);
int saveTo(const std::string& filename);
bool ready();
Node newNode(const std::string& name,const std::string& value);
Attribute newAttr(const std::string& name,const std::string& value);
Node cloneNode(const Node&);
void clear();
protected:
char* _allocate_string(const std::string& str);
char* _allocate_string(const char* pstr,int sz);
private:
XDoc _doc;
bool _is_ready;
};
}/// End of namespace MiniEngine::XML
}/// End of namespace MiniEngine

View File

@ -0,0 +1,20 @@
#pragma once
#include "include.h"
namespace MiniEngine {
class AudioPlayer
{
public:
AudioPlayer();
~AudioPlayer();
private:
class _Audio
{
public:
_Audio();
~_Audio();
};
static _Audio* _sysAudio;
static int _sysAudioCounter;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class BlendMode
{
None,
Blend,
Add,
Mod
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,14 @@
#pragma once
#include "include.h"
namespace MiniEngine {
class ColorMode
{
public:
int r, g, b;
ColorMode(int R, int G, int B);
ColorMode();
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,36 @@
#pragma once
#include "include.h"
#include "SystemCursorType.h"
#include "Point.h"
#include "Surface.h"
#include "__Plugin.h"
namespace MiniEngine {
class Cursor
{
public:
Cursor()=default;
Cursor(SystemCursorType);
Cursor(Surface surf,Point hotspot= {0,0});
static Cursor GetActiveCursor();
static Cursor GetDefaultCursor();
static void setShow(bool);
static bool isShow();
void activate();
void release();
private:
std::shared_ptr<SDL_Cursor> _cur;
void _set(SDL_Cursor*);
void _set_no_delete(SDL_Cursor*);
SDL_Cursor* _get();
void _clear();
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,17 @@
#pragma once
#include <exception>
#include <string>
namespace MiniEngine {
class ErrorViewer : public std::exception
{
public:
void fetch();
std::string getError() const;
const char* what() const noexcept override;
private:
std::string str;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class FlipMode
{
None,
Horizontal,
Vertical
};
} /// End of namespace MiniEngine

125
include/SDLWrapper/Font.h Normal file
View File

@ -0,0 +1,125 @@
#pragma once
#include "include.h"
#include "FontStyle.h"
#include "FontHint.h"
#include "Rect.h"
#include "Surface.h"
#include "Texture.h"
#include "Renderer.h"
#include <vector>
#include "__Plugin.h"
namespace MiniEngine {
class Font
{
public:
Font() = default;
Font(const std::string& FontFileName, size_t size);
int use(const std::string& FontFileName, size_t size);
bool isReady() const;
bool isNormal() const;
bool isBold() const;
bool isItalic() const;
bool isUnderLine() const;
bool isStrikeThrough() const;
void setNormal();
void setBold(bool);
void setItalic(bool);
void setUnderLine(bool);
void setStrikeThrough(bool);
template<typename... Args>
void setFontStyle(FontStyle style,Args&&... args)
{
int fontcalc=0;
_setFontStyle(fontcalc,style,args...);
}
void setFontStyle(FontStyle style)
{
int fontcalc=0;
_setFontStyle(fontcalc,style);
}
std::vector<FontStyle> getFontStyles() const;
int getFontHeight() const;
int getFontAscent() const;
int getFontDescent() const;
int getFontLineSkip() const;
bool isFontKerning() const;
void setFontKerning(bool enableKerning);
long getFontFaceNum() const;
int getFontFaceIsFixedWidth() const;
std::string getFontFaceFamilyName() const;
std::string getFontFaceStyleName() const;
FontHint getFontHint() const;
void setFontHint(FontHint hint);
Rect sizeText(const std::string& Text) const;
Rect sizeUTF8(const std::string& Text) const;
Rect sizeUnicode(const uint16_t* Text) const;
/// Surface Rendering Functions.
Surface renderText(const std::string& Text, const RGBA& fg) const;
Surface renderTextWrapped(const std::string& Text, const RGBA& fg, size_t WrapLength) const;
Surface renderTextShaded(const std::string& Text, const RGBA& fg, const RGBA& bg) const;
Surface renderTextSolid(const std::string& Text, const RGBA& fg) const;
Surface renderUTF8(const std::string& Text, const RGBA& fg) const;
Surface renderUTF8Wrapped(const std::string& Text, const RGBA& fg, size_t WrapLength) const;
Surface renderUTF8Shaded(const std::string& Text, const RGBA& fg, const RGBA& bg) const;
Surface renderUTF8Solid(const std::string& Text, const RGBA& fg) const;
Surface renderUnicode(const uint16_t* Text,const RGBA& fg) const;
Surface renderUnicodeWrapped(const uint16_t* Text,const RGBA& fg,size_t WrapLength) const;
Surface renderUnicodeShaded(const uint16_t* Text,const RGBA& fg,const RGBA& bg) const;
Surface renderUnicodeSolid(const uint16_t* Text,const RGBA& fg) const;
/// Texture Rendering Functions.
Texture renderText(const Renderer& rnd, const std::string& Text, const RGBA& fg) const;
Texture renderTextWrapped(const Renderer& rnd, const std::string& Text, const RGBA& fg, size_t WrapLength) const;
Texture renderTextShaded(const Renderer& rnd, const std::string& Text, const RGBA& fg, const RGBA& bg) const;
Texture renderTextSolid(const Renderer& rnd, const std::string& Text, const RGBA& fg) const;
Texture renderUTF8(const Renderer& rnd, const std::string& Text, const RGBA& fg) const;
Texture renderUTF8Wrapped(const Renderer& rnd, const std::string& Text, const RGBA& fg, size_t WrapLength) const;
Texture renderUTF8Shaded(const Renderer& rnd, const std::string& Text, const RGBA& fg, const RGBA& bg) const;
Texture renderUTF8Solid(const Renderer& rnd, const std::string& Text, const RGBA& fg) const;
Texture renderUnicode(const Renderer& rnd,const uint16_t* Text,const RGBA& fg) const;
Texture renderUnicodeWrapped(const Renderer& rnd,const uint16_t* Text,const RGBA& fg,size_t WrapLength) const;
Texture renderUnicodeShaded(const Renderer& rnd,const uint16_t* Text,const RGBA& fg,const RGBA& bg) const;
Texture renderUnicodeSolid(const Renderer& rnd,const uint16_t* Text,const RGBA& fg) const;
void release();
protected:
template<typename... Args>
void _setFontStyle(int& fontcalc,FontStyle style,Args&&... args)
{
fontcalc|=_style_caster(style);
_setFontStyle(fontcalc,args...);
}
void _setFontStyle(int& fontcalc,FontStyle style)
{
fontcalc|=_style_caster(style);
_real_setFontStyle(fontcalc);
}
private:
void _real_setFontStyle(int);
int _style_caster(FontStyle);
std::shared_ptr<TTF_Font> _font;
void _set(TTF_Font*);
void _clear();
TTF_Font* _get() const;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,13 @@
#pragma once
namespace MiniEngine {
enum class FontHint
{
Normal,
Light,
Mono,
None,
Error
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,13 @@
#pragma once
namespace MiniEngine {
enum class FontStyle
{
Normal,
Bold,
Italic,
UnderLine,
StrikeThrough
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,11 @@
#pragma once
namespace MiniEngine {
enum class IMGInitFlag
{
JPG,
PNG,
TIF,
WEBP,
ALL
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,21 @@
#pragma once
/// Sorted by alphabet sequence. Some files are ignored.
#include "ColorMode.h"
#include "Cursor.h"
#include "ErrorViewer.h"
#include "Font.h"
#include "Log.h"
#include "MessageBox.h"
#include "Music.h"
#include "Point.h"
#include "Rect.h"
#include "Renderer.h"
#include "RGBA.h"
#include "RWOP.h"
#include "SDLSystem.h"
#include "SharedLibrary.h"
#include "Sound.h"
#include "Surface.h"
#include "Texture.h"
#include "Timer.h"
#include "Window.h"

13
include/SDLWrapper/Log.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "include.h"
namespace MiniEngine {
class LogSystem
{
static void v(const char* fmt,...);/// Verbose
static void d(const char* fmt,...);/// Debug
static void i(const char* fmt,...);/// Information
static void w(const char* fmt,...);/// Warning
static void e(const char* fmt,...);/// Error
static void critical(const char* fmt,...);/// Critical
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,45 @@
#pragma once
#include "include.h"
#include "MessageBoxType.h"
#include <string>
#include <functional>
#include <vector>
namespace MiniEngine {
class WindowMessageBoxButton
{
public:
WindowMessageBoxButton();
WindowMessageBoxButton(const std::string& ButtonText,const std::function<void()>& CallbackFunc=[]() {});
std::string text;
std::function<void()> callback;
/// Default: no hit option set.
void setHitAsReturn(bool);
void setHitAsEscape(bool);
bool isHitAsReturn() const;
bool isHitAsEscape() const;
private:
int _hitoption;
};
class WindowMessageBox
{
public:
WindowMessageBox();
WindowMessageBox(const std::string& Title,const std::string& Text,MessageBoxType BoxType=MessageBoxType::Information,const std::function<void()>& DefaultCallback=[]() {});
MessageBoxType boxtype;
std::string title;
std::string text;
std::function<void()> defaultcallback;
void addButton(const WindowMessageBoxButton& button);
int getButtonNum() const;
WindowMessageBoxButton& getButton(int index);
const WindowMessageBoxButton& getButtonConst(int index) const;
private:
std::vector<WindowMessageBoxButton> _vec;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,9 @@
#pragma once
namespace MiniEngine {
enum class MessageBoxType
{
Error,
Warning,
Information
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class MixInitFlag
{
FLAC,
MOD,
MODPLUG,
MP3,
OGG,
FLUIDSYNTH
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,57 @@
#pragma once
#include "include.h"
#include <memory>
#include <string>
#include "ErrorViewer.h"
#include "Audio.h"
#include "RWOP.h"
#include "MusicType.h"
#include "__Noncopyable.h"
#include "__Plugin.h"
namespace MiniEngine {
/// Forward Declaration
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<Mix_Music> _music;
void _set(Mix_Music*);
void _clear();
Mix_Music* _get() const;
friend class MusicPlayer;
friend class _internal::Plugin;
};
class MusicPlayer : public AudioPlayer, public NonCopyable
{
public:
static int GetDecoderNum();
static std::string GetDecoderName(int index);
/// Play Music. Loop: -1:Infinite, >0:Exact that time.
int play(Music music, int loops);
void pause();
void resume();
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);
bool isPlaying() const;
bool isPaused() const;
int isFading() const;
private:
Music m;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,8 @@
#pragma once
#include "include.h"
namespace MiniEngine {
enum class MusicType
{
None,CMD,WAV,MOD,MID,OGG,MP3,MP3MAD,FLAC,MODPLUG
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class Platform
{
Unknown,
Windows,
MacOS,
Linux,
iOS,
Android
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,16 @@
#pragma once
#include "include.h"
#include "Rect.h"
namespace MiniEngine {
class Point
{
public:
int x, y;
Point(int X, int Y);
Point();
SDL_Point toSDLPoint() const;
bool inRect(const Rect& rect) const;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,11 @@
#pragma once
namespace MiniEngine {
enum class PowerState
{
Unknown,
OnBattery,
NoBattery,
Charging,
Charged
};
} /// End of namespace MiniEngine

18
include/SDLWrapper/RGBA.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "include.h"
#include "ColorMode.h"
namespace MiniEngine {
class RGBA
{
public:
int r, g, b, a;
RGBA(int R, int G, int B, int A);
RGBA(ColorMode mode, int A);
RGBA();
SDL_Color toSDLColor() const;
ColorMode toColorMode() const;
};
} /// End of namespace MiniEngine

34
include/SDLWrapper/RWOP.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include "include.h"
#include <cstdio>
#include <string>
#include <memory>
#include "__Plugin.h"
namespace MiniEngine {
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;
void release();
private:
std::shared_ptr<SDL_RWops> _op;
SDL_RWops* _get() const;
void _clear();
void _set(SDL_RWops*);
friend class Surface;
friend class Renderer;
friend class Sound;
friend class Music;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

21
include/SDLWrapper/Rect.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include "include.h"
namespace MiniEngine {
class Rect
{
public:
int x, y, w, h;
Rect(int X, int Y, int W, int H);
explicit Rect(const SDL_Rect&);
Rect();
SDL_Rect toSDLRect() const;
bool isEmpty() const;
bool operator == (const Rect&) const;
bool hasIntersection(const Rect&) const;
Rect getIntersection(const Rect&) const;
Rect getUnion(const Rect&) const;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,152 @@
#pragma once
#include "include.h"
#include "RendererType.h"
#include "FlipMode.h"
#include "Window.h"
#include "Surface.h"
#include "Texture.h"
#include "__Plugin.h"
#include <initializer_list>
namespace MiniEngine {
class Renderer
{
public:
Renderer() = default;
/// Create a Renderer associated with Window
Renderer(Window& wnd,std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture });
/// Create a software Renderer
Renderer(Surface& surf);
~Renderer() = default;
/// If Renderer is current not ready, setRenderer will create Renderer.
/// Otherwise, setRenderer will fail.
int createRenderer(Window& wnd,RendererType Type)
{
int flagcalc=0;
return _createRenderer(wnd,flagcalc,Type);
}
template<typename... Args>
int createRenderer(Window& wnd,RendererType Type,Args&&... args)
{
int flagcalc=0;
return _createRenderer(wnd,flagcalc,Type,std::forward<RendererType>(args...));
}
int createRenderer(Window& wnd,std::initializer_list<RendererType>);
int createSoftRenderer(Surface& surf);
int setColor(const RGBA& pack);
RGBA getColor() const;
int setBlendMode(BlendMode mode);
BlendMode getBlendMode() const;
int setTarget(Texture& t);
int setTarget();
Texture getTarget();
int fillRect(const Rect& rect);
int drawRect(const Rect& rect);
int drawPoint(const Point& p);
int drawLine(const Point& A,const Point& B);
/// Experimental
int fillRects(const SDL_Rect* pRectArray,int n);
int drawRects(const SDL_Rect* pRectArray,int n);
int drawPoints(const SDL_Point* pPointArray,int n);
int drawLines(const SDL_Point* pPointArray,int n);
/// Experimental
int fillRects(const std::vector<SDL_Rect>& rectvec);
int drawRects(const std::vector<SDL_Rect>& rectvec);
int drawPoints(const std::vector<SDL_Point>& pointvec);
int drawLines(const std::vector<SDL_Point>& pointvec);
/// Slower Functions (Need Convert First, then call Experimental Functions.)
int fillRects(const std::vector<Rect>& rectvec);
int drawRects(const std::vector<Rect>& rectvec);
int drawPoints(const std::vector<Point>& pointvec);
int drawLines(const std::vector<Point>& pointvec);
int setScale(float scaleX,float scaleY);
std::tuple<float,float> getScale() const;
int setViewport(const Rect& viewport);
Rect getViewport() const;
int setLogicalSize(int w,int h);
Rect getLogicalSize() const;
int setClipRect(const Rect& cliprect);
Rect getClipRect() const;
bool isClipEnabled() const;
Rect getOutputSize() const;
int clear();
void update();
int copy(const Texture& t, const Rect& src, const Rect& dst);
int copyTo(const Texture& t, const Rect& dst);
int copyTo(const Texture& t, const Point& lupoint);
int copyFill(const Texture& t, const Rect& src);
int copyFullFill(const Texture& t);
/// Super copy without center point.
int copy(const Texture& t, const Rect& src, const Rect& dst,double angle,FlipMode mode);
int copyTo(const Texture& t, const Rect& dst,double angle,FlipMode mode);
int copyTo(const Texture& t, const Point& lupoint,double angle,FlipMode mode);
int copyFill(const Texture& t, const Rect& src,double angle,FlipMode mode);
int copyFullFill(const Texture& t,double angle,FlipMode mode);
/// Super copy with center point
int copy(const Texture& t, const Rect& src, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
int copyTo(const Texture& t, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
int copyTo(const Texture& t, const Point& lupoint,const Point& centerPoint,double angle,FlipMode mode);
int copyFill(const Texture& t, const Rect& src,const Point& centerPoint,double angle,FlipMode mode);
int copyFullFill(const Texture& t,const Point& centerPoint,double angle,FlipMode mode);
/// Reserved for compatibility
int supercopy(const Texture& t,
bool srcfull,const Rect& src,bool dstfull,const Rect& dst,
double angle,
bool haspoint,const Point& center,FlipMode mode);
Texture render(const Surface& surf) const;
Texture loadTexture(const std::string& FileName) const;
Texture loadTextureRW(const RWOP& rwop) const;
Texture createTexture(int Width, int Height) const;
bool isRenderTargetSupported() const;
bool isReady() const;
void release();
/// Experimental
static int GetDriversNum();
protected:
template<typename... Args>
int _createRenderer(Window& wnd,int& refcalc,RendererType Type,Args&&... args)
{
refcalc|=_rendertype_caster(Type);
return _createRenderer(wnd,refcalc,args...);
}
// template<>
int _createRenderer(Window& wnd,int& refcalc,RendererType Type)
{
refcalc|=_rendertype_caster(Type);
return _createRenderer_Real(wnd,refcalc);
}
private:
std::shared_ptr<SDL_Renderer> _rnd;
int _createRenderer_Real(Window& wnd,Uint32 flags);
Uint32 _rendertype_caster(RendererType);
void _set(SDL_Renderer*);
void _clear();
SDL_Renderer* _get() const;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class RendererType
{
Software,
Accelerated,
PresentSync,
TargetTexture
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,14 @@
#pragma once
namespace MiniEngine {
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
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,76 @@
#pragma once
#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 <tuple>
#include <string>
namespace MiniEngine {
class SDLSystem : public NonCopyable, public NonMoveable
{
public:
SDLSystem(const std::initializer_list<SDLInitFlag>& flag_sdl = {SDLInitFlag::All} ,
const std::initializer_list<IMGInitFlag>& flag_img = {IMGInitFlag::JPG,IMGInitFlag::PNG} ,
const std::initializer_list<MixInitFlag>& flag_mix = {MixInitFlag::MP3} ,
bool init_ttf = true );
/// Experimental Constructor
SDLSystem(Uint32 sdl_flag, Uint32 img_flag, Uint32 mix_flag, bool init_ttf);
~SDLSystem();
static void Delay(int ms);
static PowerState GetPowerState();
static int GetPowerLifeLeft();
static int GetPowerPrecentageLeft();
static Platform GetPlatform();
static void StartTextInput();
static bool IsTextInputActive();
static void StopTextInput();
static bool HasScreenKeyboardSupport();
static std::tuple<int,int,int> GetSDLCompileVersion();
static std::tuple<int,int,int> GetSDLLinkedVersion();
static std::tuple<int,int,int> GetIMGCompileVersion();
static std::tuple<int,int,int> GetIMGLinkedVersion();
static std::tuple<int,int,int> GetMixCompileVersion();
static std::tuple<int,int,int> GetMixLinkedVersion();
static std::tuple<int,int,int> GetTTFCompileVersion();
static std::tuple<int,int,int> GetTTFLinkedVersion();
static int GetCPUCount();
static int GetCPUCacheLineSize();
/// 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:
static std::string GetInternal();
static bool ExternalAvaliable();
static bool CanReadExternal();
static bool CanWriteExternal();
static std::string GetExternal();
static void* GetJNIEnv();
};
private:
void _init(Uint32,Uint32,Uint32,bool);
void _quit();
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,30 @@
#pragma once
#include "include.h"
#include <string>
#include <memory>
#include <functional>
namespace MiniEngine {
class SharedLibrary
{
public:
SharedLibrary();
SharedLibrary(const std::string& Filename);
~SharedLibrary()=default;
int load(const std::string& Filename);
int unload();
template<typename ReturnType,typename... Arguments>
std::function<ReturnType(Arguments...)> get(const std::string& FunctionName)
{
return std::function<ReturnType(Arguments...)>(reinterpret_cast<ReturnType(*)(Arguments...)>(get(FunctionName)));
}
void* get(const std::string& FunctionName) const;
void release();
private:
void* _get() const;
void _set(void*);
void _clear();
std::shared_ptr<void> _obj;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,70 @@
#pragma once
#include "include.h"
#include <memory>
#include <string>
#include "Audio.h"
#include "ErrorViewer.h"
#include "RWOP.h"
#include "__Plugin.h"
namespace MiniEngine {
class Sound
{
public:
Sound() = default;
Sound(const std::string& WAVFilename);
Sound(const RWOP& rwop);
bool isReady() const;
void release();
private:
std::shared_ptr<Mix_Chunk> _sound;
void _set(Mix_Chunk*);
void _clear();
Mix_Chunk* _get() const;
friend class Channel;
friend class _internal::Plugin;
};
class Channel
{
public:
Channel& playSound(Sound sound,int loops);
Channel& fadeIn(Sound sound,int loops,int ms);
int fadeOut(int ms);
void pause();
void resume();
int stop();
/// Experimental
int setPanning(uint8_t left,uint8_t right);
int setPosition(int16_t angle,uint8_t distance);
int setDistance(uint8_t distance);
int setReverseStereo(int flip);
/// Experimental: Direct Add/Remove Effect
int addEffect(Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg);
int removeEffect(Mix_EffectFunc_t f);
int removeAllEffect();
protected:
Channel();
private:
void _set(int ChannelID);
int _get() const;
void _clear();
int _id;
friend class SoundPlayer;
};
class SoundPlayer : public AudioPlayer
{
public:
static int GetDecoderNum();
static std::string GetDecoderName(int index);
SoundPlayer(int NumChannels = 16);
Channel playSound(Sound sound, int loops);
Channel fadeIn(Sound sound, int loops, int ms);
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,91 @@
#pragma once
#include "include.h"
#include "BlendMode.h"
#include "RGBA.h"
#include "Point.h"
#include "RWOP.h"
#include "ErrorViewer.h"
#include "__Plugin.h"
namespace MiniEngine {
class Surface
{
public:
Surface()=default;
Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
Surface(int width,int height,int depth,RGBA colorPack);
Surface(int width,int height,int depth,Uint32 surfaceFormat);
Surface(const std::string& filename);
Surface(const RWOP& rwop);
~Surface() = default;
/// static functions
static Surface load(const std::string& filename);
static Surface load(const RWOP& rwop);
static Surface create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
static Surface create(int width,int height,int depth,Uint32 surfaceFormat);
/// xxxAs will clear the current surface if loaded or created successfully.
int loadAs(const std::string& filename);
int loadAs(const RWOP& rwop);
int createAs(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
int createAs(int width,int height,int depth,Uint32 surfaceFormat);
int savePNG(const std::string& filename) const;
int getw() const;
int geth() const;
BlendMode getBlendMode() const;
int setBlendMode(BlendMode mode);
/// Rendering functions. Copy an external surface to this surface. So it has no constant attribute.
int blit(const Surface& s,const Rect& src,const Rect& dst);
int blitTo(const Surface& t, const Rect& dst);
int blitTo(const Surface& t, const Point& lupoint);
int blitFill(const Surface& t, const Rect& src);
int blitFullFill(const Surface& t);
int blitScaled(const Surface& s,const Rect& src,const Rect& dst);
int blitScaledTo(const Surface& t, const Rect& dst);
int blitScaledTo(const Surface& t, const Point& lupoint);
int blitScaledFill(const Surface& t, const Rect& src);
int blitScaledFullFill(const Surface& t);
int setClipRect(const Rect& clipRect);
Rect getClipRect() const;
void disableClipping();
int setAlphaMode(int alpha);
int getAlphaMode() const;
ColorMode getColorMode() const;
int setColorMode(ColorMode mode);
RGBA getRGBA() const;
void setRGBA(const RGBA& pack);
bool mustlock() const;
int lock();
void unlock();
bool isReady() const;
void release();
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
/// In case you can do anything with this pointer, this function should not has constant attribute.
SDL_Surface* getRawPointer();
private:
std::shared_ptr<SDL_Surface> _surf;
void _set(SDL_Surface*);
void _set_no_delete(SDL_Surface*);
void _clear();
SDL_Surface* _get() const;
friend class Window;
friend class Renderer;
friend class Font;
friend class Cursor;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class SystemCursorType
{
Arrow, Ibeam, CrossHair,
Wait, WaitArrow,
SizeNWSE, SizeNESW, SizeWE, SizeNS, SizeAll,
No, Hand
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,49 @@
#pragma once
#include "include.h"
#include "Rect.h"
#include "RGBA.h"
#include "ColorMode.h"
#include "BlendMode.h"
#include "__Plugin.h"
#include <memory>
namespace MiniEngine {
class Texture
{
public:
Texture();
~Texture() = default;
Rect getSize();
int getw() const;
int geth() const;
bool isReady() const;
int setBlendMode(BlendMode mode);
BlendMode getBlendMode() const;
/// Alpha: 0: Transparent 255: opaque
int setAlphaMode(int alpha);
int getAlphaMode() const;
ColorMode getColorMode() const;
int setColorMode(ColorMode mode);
RGBA getRGBA() const;
void setRGBA(const RGBA& pack);
void release();
protected:
/// updateInfo() must be called after Texture is changed.
void updateInfo();
private:
std::shared_ptr<SDL_Texture> _text;
void _set(SDL_Texture*);
/// Just used for "SDL_GetRenderTarget"
void _set_no_delete(SDL_Texture*);
void _clear();
SDL_Texture* _get() const;
Rect _rect;
friend class Renderer;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,51 @@
#pragma once
#include "include.h"
#include <functional>
namespace MiniEngine {
Uint32 _global_timer_executor(Uint32 interval,void* param);
class Timer
{
public:
Timer();
/// void func(Uint32,...)
template<typename VoidCallable,typename... Args>
Timer(Uint32 interval,VoidCallable&& vcallable,Args&&... args) : Timer()
{
auto realCall=[&,vcallable](Uint32 ims)->Uint32{vcallable(ims,args...); return ims;};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc);
}
/// Uint32 func(Uint32,...)
template<typename Callable,typename... Args>
Timer(Callable&& callable,Uint32 interval,Args&&... args) : Timer()
{
auto realCall=[&,callable](Uint32 ims)->Uint32{return callable(ims,args...);};
auto pfunc=new std::function<Uint32(Uint32 interval)>(realCall);
_real_timer_call(_global_timer_executor,interval,pfunc);
}
/// Restore For Capability
Timer(SDL_TimerCallback callback,Uint32 interval,void* param);
int enable();
int disable();
bool isenable() const;
void detach();
~Timer();
static void _delete_delegator(std::function<Uint32(Uint32)>* Delegator);
private:
void _real_timer_call(SDL_TimerCallback callback,Uint32 interval,void* param);
SDL_TimerCallback _callback;
Uint32 _interval;
void* _param;
SDL_TimerID id;
bool _enabled;
bool _detached;
/// Reserved Variable For Template variable Parameter
bool _delete_on_disable;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,68 @@
#pragma once
#include "include.h"
#include "WindowType.h"
#include "MessageBoxType.h"
#include "ErrorViewer.h"
#include "MessageBox.h"
#include "Surface.h"
#include "__Plugin.h"
namespace MiniEngine {
class Window
{
public:
Window()=default;
Window(std::string Title, int Width, int Height,
std::initializer_list<WindowType> WindowFlags = {WindowType::Shown},
int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED);
Rect getSize() const;
void setSize(const Rect& sizeRect);
void setSize(int w, int h);
Point getPosition() const;
void setPosition(int x, int y);
void setPosition(const Point& point);
void setTitle(const std::string& Title);
std::string getTitle() const;
void setGrab(bool isGrab);
bool getGrab() const;
#if _MINIENGINE_SDL_VERSION_ATLEAST(2,0,5)
/// SDL2.0.5 Required.
int setOpacity(float opacity);
float getOpacity() const;
#endif
/// FIXME: Not Implemented.
void setResizable(bool resizable);
/// Use UTF8 in Title and Message please.
int showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const;
int showMessageBox(const WindowMessageBox& box) const;
void show();
void hide();
void raise();
void minimize();
void maximize();
void restore();
_DECL_DEPRECATED Surface getSurface();
bool isScreenKeyboardShown();
void release();
private:
std::shared_ptr<SDL_Window> _wnd;
void _set(SDL_Window*);
void _clear();
SDL_Window* _get() const;
friend class Renderer;
friend class _internal::Plugin;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,12 @@
#pragma once
namespace MiniEngine {
enum class WindowType
{
FullScreen, OpenGL, Shown, Hidden,
Borderless, Resizable, Minimized, Maximized,
InputGrabbed, InputFocus, MouseFocus,
FullScreenDesktop, Foreign, AllowHighDPI,
MouseCapture, AlwaysOnTop, SkipTaskBar,
Utility, ToolTip, PopUpMenu
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,11 @@
#pragma once
namespace MiniEngine {
class NonCopyable
{
protected:
NonCopyable() = default;
~NonCopyable() = default;
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator = (const NonCopyable&) = delete;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,11 @@
#pragma once
namespace MiniEngine {
class NonMoveable
{
public:
NonMoveable()=default;
~NonMoveable()=default;
NonMoveable(NonMoveable&&) =delete;
NonMoveable& operator = (NonMoveable&&)=delete;
};
} /// End of namespace MiniEngine

View File

@ -0,0 +1,39 @@
#pragma once
namespace MiniEngine {
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<typename T>
static decltype(auto) get(const T& obj)
{
return obj._get();
}
template<typename T,typename U>
static void set(T& obj,U&& value)
{
obj._set(value);
}
template<typename T>
static void clear(T& obj)
{
obj._clear();
}
template<typename T,typename U>
static void set_no_delete(T& obj,U&& value)
{
obj._set_no_delete(value);
}
};
}
} /// End of namespace MiniEngine

View File

@ -0,0 +1,14 @@
#pragma once
/// Include SDL Library Headers.
#include "SDL2/SDL.h"
#undef main
#include "SDL2/SDL_image.h"
#include "SDL2/SDL_ttf.h"
#include "SDL2/SDL_mixer.h"
/// Version Requiring Definition
#define _MINIENGINE_SDL_VERSION_ATLEAST(X,Y,Z) SDL_VERSION_ATLEAST(X,Y,Z)
/// Deprecated Definition
#define _DECL_DEPRECATED [[deprecated]]

21
include/json/LICENSE.MIT Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2013-2019 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22875
include/json/json.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -102,6 +102,40 @@ namespace rapidxml
///////////////////////////////////////////////////////////////////////////
// Internal printing operations
/// Forward Declaration : Fix Compile Bug in MinGW
template<class OutIt, class Ch>
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch> *node, int flags);
template<class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
template<class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
// Print node
template<class OutIt, class Ch>
inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)

View File

@ -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)

160
makefile_c4gen.cpp Normal file
View File

@ -0,0 +1,160 @@
/// makefile_c4gen.cpp
/// Under MIT License. Part of MiniEngine Project.
/// You can run this code to generate a makefile for C4droid.
#include <string>
#include <functional>
/// Declaration
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& func);
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
char buff[1024];
int main()
{
printf("Generator: Detecting source files...\n");
/// Find files
vector<string> 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
{
return source.substr(0,source.size()-replaceFrom.size()).append(replaceTo);
};
auto endWith=[](const string& text,const string& testEndWith)->bool
{
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,
"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& obj:objvec)
{
fprintf(fp,"%s ",obj.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("Generator: Generation Finished.\n");
return 0;
}
/// Implement
#if defined(_MSC_VER) || defined(_WIN32) /// VS or Windows
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& 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 <dirent.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
void FindFileRev(const std::string& dirname,const std::function<void(const std::string&)>& 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

View File

@ -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)

36
setup_toolcenter.sh Normal file
View File

@ -0,0 +1,36 @@
echo "MiniEngine-ToolCenter Integration Script"
echo "TC_ROOT is "
echo $TC_ROOT
if [ 0"$TC_ROOT" = "0" ]; then
echo "ToolCenter not detected. Please set TC_ROOT"
exit
fi
mkdir include
cp -r $TC_ROOT/SDL2/include/* include/
cp -r $TC_ROOT/SDL2_image/include/* include/
cp -r $TC_ROOT/SDL2_mixer/include/* include/
cp -r $TC_ROOT/SDL2_ttf/include/* include/
mkdir lib
cp -r $TC_ROOT/SDL2/lib/* lib/
cp -r $TC_ROOT/SDL2_image/lib/* lib/
cp -r $TC_ROOT/SDL2_mixer/lib/* lib/
cp -r $TC_ROOT/SDL2_ttf/lib/* lib/
cp -r $TC_ROOT/SDL2/dll/x86/* .
cp -r $TC_ROOT/SDL2_image/dll/x86/* .
cp -r $TC_ROOT/SDL2_mixer/dll/x86/* .
cp -r $TC_ROOT/SDL2_ttf/dll/x86/* .
echo "Paste in Visual Studio:"
echo "======================"
echo "SDL2test.lib"
echo "SDL2main.lib"
echo "SDL2.lib"
echo "SDL2_image.lib"
echo "SDL2_mixer.lib"
echo "SDL2_ttf.lib"
echo "======================"
echo "Finish."

107
src/MiniEngine.cpp Normal file
View File

@ -0,0 +1,107 @@
#include "MiniEngine.h"
#include <algorithm>
#include <map>
#include <mutex>
#include <fstream>
#ifdef _MSC_VER /// Visual Studio
#define _MINIENGINE_HAS_UNISTD 0
#else
#define _MINIENGINE_HAS_UNISTD 1
#include <unistd.h>
#endif
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_print.hpp"
#include "rapidxml/rapidxml_utils.hpp"
namespace MiniEngine
{
struct StringEngine::impl
{
rapidxml::xml_document<> doc;
rapidxml::xml_node<>* root;
bool status;
};
StringEngine::StringEngine(std::string StringFile,std::string LanguageTag)
{
pimpl=new impl;
pimpl->status=false;
std::ifstream ifs(StringFile);
if(!ifs) return;
rapidxml::file<> strFile(ifs);
pimpl->doc.parse<0>(strFile.data());
pimpl->root=pimpl->doc.first_node(LanguageTag.c_str());
if(pimpl->root==nullptr) return;
pimpl->status=true;
}
bool StringEngine::ready()
{
return pimpl->status;
}
int StringEngine::useLanaguage(std::string LanguageTag)
{
pimpl->root=pimpl->doc.first_node(LanguageTag.c_str());
if(pimpl->root==nullptr)
{
pimpl->status=false;
return -1;
}
else
{
pimpl->status=true;
return 0;
}
}
std::string StringEngine::getString(std::string Tag)
{
if(!ready()) return "(StringEngine::STRING_NOT_FOUND)";
rapidxml::xml_node<>* pnode=pimpl->root->first_node(Tag.c_str());
if(pnode==nullptr) return "(StringEngine::STRING_NOT_FOUND)";
char* context=pnode->value();
if(context==nullptr) return "";/// Empty String.
else return std::string(context);
}
StringEngine::~StringEngine()
{
delete pimpl;
}
bool GetScanKeyState(SDL_Scancode code)
{
return SDL_GetKeyboardState(NULL)[code];
}
}/// End of namespace MiniEngine
/// The Following Functions are not avaliable in Visual Studio
#if (_MINIENGINE_HAS_UNISTD == 1)
bool isexist(std::string Path)
{
return access(Path.c_str(),F_OK)==0;
}
bool canread(std::string Path)
{
return access(Path.c_str(),R_OK)==0;
}
bool canwrite(std::string Path)
{
return access(Path.c_str(),W_OK)==0;
}
bool canexecute(std::string Path)
{
return access(Path.c_str(),X_OK)==0;
}
#else /// _MINIENGINE_HAS_UNISTD == 0
/// File Functions will be implied in platform specific source file.
#endif

View File

@ -7,12 +7,12 @@ namespace MiniEngine
#if defined(__ANDROID__) && __ANDROID__
std::string SDLSystem::Android::GetInternal()
{
return string(SDL_AndroidGetInternalStoragePath());
return std::string(SDL_AndroidGetInternalStoragePath());
}
std::string SDLSystem::Android::GetExternal()
{
return string(SDL_AndroidGetExternalStoragePath());
return std::string(SDL_AndroidGetExternalStoragePath());
}
bool SDLSystem::Android::CanReadExternal()

View File

@ -1,5 +1,8 @@
#include "MiniEngine_Event.h"
namespace MiniEngine
{
int PollEvent(Event& refEvent)
{
return SDL_PollEvent(&refEvent);
@ -35,6 +38,16 @@ bool HasEvent(_SDLEventType_ EventTypeMin,_SDLEventType_ EventTypeMax)
return ( SDL_HasEvents(EventTypeMin,EventTypeMax)==SDL_TRUE );
}
_SDLEventType_ RegisterEvent(int howMuch)
{
return SDL_RegisterEvents(howMuch);
}
bool IsValidEventType(_SDLEventType_ EventType)
{
return (EventType > SDL_FIRSTEVENT) && (EventType < SDL_LASTEVENT);
}
bool operator == (const LooperID& a,const LooperID& b)
{
return a._type_id==b._type_id && a._looper_cnt==b._looper_cnt ;
@ -156,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()
{
@ -176,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()
{
@ -218,8 +230,15 @@ void Poller::reset()
void Poller::run()
{
int pollret=1;
while(_running)
do
{
if(_update)
{
updater();
_update=false;
}
while(!_update&&(pollret=PollEvent(_e)))
{
dispatch();
@ -227,12 +246,9 @@ 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)
@ -253,8 +269,14 @@ int LooperWithTime::getTimeout() const
void LooperWithTime::run()
{
int timeret = 1;
while (_running)
do
{
if (_update)
{
updater();
_update = false;
}
while (!_update&&(timeret=WaitEventTimeout(_e, _timeout_ms)))
{
dispatch();
@ -262,10 +284,8 @@ void LooperWithTime::run()
/// 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 (_running);
}
}/// End of namespace MiniEngine

100
src/MiniEngine_Test.cpp Normal file
View File

@ -0,0 +1,100 @@
#include "MiniEngine_Test.h"
#include <SDL2/SDL_test.h>
#include <cstring>
namespace MiniEngine
{
namespace Test
{
void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff)
{
SDLTest_Md5Context ct;
SDLTest_Md5Init(&ct);
SDLTest_Md5Update(&ct,buffer,bufferLen);
SDLTest_Md5Final(&ct);
memcpy(outbuff,ct.digest,16);
}
std::string GetMD5(unsigned char* buffer,unsigned int bufferLen)
{
unsigned char buff[16];
char tmp[8];
GetMD5Raw(buffer,bufferLen,buff);
std::string str;
for(int i=0;i<16;i++)
{
sprintf(tmp,"%02x",buff[i]);
str.append(tmp);
}
return str;
}
/// Notice: SDLTest_crc32Calc is an undefined symbol. So we must use these 3 functions.
int GetCRC32(unsigned char* buffer,unsigned int bufferLen,uint32_t& out_CRCResult)
{
uint32_t result;
SDLTest_Crc32Context ct;
SDLTest_Crc32Init(&ct);
int ret=-2;
do
{
if (SDLTest_Crc32CalcStart(&ct,&result))
{
ret=-1;
break;
}
if (SDLTest_Crc32CalcBuffer(&ct, buffer, bufferLen, &result))
{
ret=-1;
break;
}
if (SDLTest_Crc32CalcEnd(&ct, &result))
{
ret=-1;
break;
}
ret=0;
out_CRCResult=result;
break;
}while(0);
SDLTest_Crc32Done(&ct);
return ret;
}
/// Compare two surfaces. Currently, Surface::getRawPointer() does not has constant attribute.
int CompareSurface(Surface& surface1, Surface& surface2, int allowableError)
{
return SDLTest_CompareSurfaces(surface1.getRawPointer(),surface2.getRawPointer(),allowableError);
}
//private
struct UniRandom::_impl
{
SDLTest_RandomContext context;
};
UniRandom::UniRandom()
{
_sp.reset(new _impl);
SDLTest_RandomInitTime(&(_sp.get()->context));
}
UniRandom::UniRandom(unsigned int A, unsigned int B)
{
_sp.reset(new _impl);
SDLTest_RandomInit(&(_sp.get()->context),A,B);
}
uint32_t UniRandom::get()
{
return SDLTest_Random(&(_sp.get()->context));
}
}/// End of namespace MiniEngine::Test
}/// End of namespace MiniEngine

Some files were not shown because too many files have changed in this diff Show More