From 32f91125e9375827ec7fca1990f393a3f756286e Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Fri, 24 Mar 2017 13:50:48 +0800 Subject: [PATCH] Add LogSystem --- MiniEngine.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- MiniEngine.h | 10 ++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index a2b4010..00fcafa 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -573,7 +573,7 @@ namespace MiniEngine font.reset(temp, TTF_CloseFont); return 0; } - + bool Font::isReady() { return (font.get() != nullptr); @@ -635,6 +635,54 @@ namespace MiniEngine return rnd.render(surf); } + void LogSystem::d(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_DEBUG,fmt,ap); + va_end(ap); + } + + void LogSystem::v(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_VERBOSE,fmt,ap); + va_end(ap); + } + + void LogSystem::e(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_ERROR,fmt,ap); + va_end(ap); + } + + void LogSystem::i(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,fmt,ap); + va_end(ap); + } + + void LogSystem::w(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_WARN,fmt,ap); + va_end(ap); + } + + void LogSystem::critical(const char* fmt,...) + { + va_list ap; + va_start(ap,fmt); + SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_CRITICAL,fmt,ap); + va_end(ap); + } + int SDLSystem::SDLInit() { return SDL_Init(SDL_INIT_EVERYTHING); diff --git a/MiniEngine.h b/MiniEngine.h index c296c30..fec9a0c 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -236,6 +236,16 @@ namespace MiniEngine 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 SDLSystem { public: