diff options
| author | David Reid <mackron@gmail.com> | 2018-04-21 17:26:40 +1000 |
|---|---|---|
| committer | David Reid <mackron@gmail.com> | 2018-04-21 17:26:40 +1000 |
| commit | f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6 (patch) | |
| tree | 800aeb61be9c2018d1a048da54d1f6ab746f11f1 /src/utils.c | |
| parent | 950f31e620a9239dc91230ad92bb243f149e6f2c (diff) | |
| parent | 847bdaf68287f70fbeb5599361257b6f982e48c5 (diff) | |
| download | raylib-f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6.tar.gz raylib-f5ebbfb6bc80e5d5555e84ee505ff794c2bc64b6.zip | |
Merge branch 'master' of https://github.com/raysan5/raylib into dr/mini_al
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/utils.c b/src/utils.c index 967ed916..9d9d8b55 100644 --- a/src/utils.c +++ b/src/utils.c @@ -16,16 +16,13 @@ * Show TraceLog() output messages * NOTE: By default LOG_DEBUG traces not shown * -* #define SUPPORT_TRACELOG_DEBUG -* Show TraceLog() LOG_DEBUG messages -* * DEPENDENCIES: * stb_image_write - BMP/PNG writting functions * * * LICENSE: zlib/libpng * -* Copyright (c) 2014-2017 Ramon Santamaria (@raysan5) +* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -44,8 +41,7 @@ * **********************************************************************************************/ -#define SUPPORT_TRACELOG // Output tracelog messages -//#define SUPPORT_TRACELOG_DEBUG // Avoid LOG_DEBUG messages tracing +#include "config.h" #include "raylib.h" // WARNING: Required for: LogType enum #include "utils.h" @@ -63,15 +59,16 @@ #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) #define STB_IMAGE_WRITE_IMPLEMENTATION - #include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png() + #include "external/stb_image_write.h" // Required for: stbi_write_bmp(), stbi_write_png() #endif -#define RRES_IMPLEMENTATION -#include "rres.h" - //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- + +// Log types messages supported flags (bit based) +static unsigned char logTypeFlags = LOG_INFO | LOG_WARNING | LOG_ERROR; + #if defined(PLATFORM_ANDROID) AAssetManager *assetManager; #endif @@ -90,16 +87,17 @@ static int android_close(void *cookie); // Module Functions Definition - Utilities //---------------------------------------------------------------------------------- +// Enable trace log message types (bit flags based) +void SetTraceLog(unsigned char types) +{ + logTypeFlags = types; +} + // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG) void TraceLog(int msgType, const char *text, ...) { #if defined(SUPPORT_TRACELOG) static char buffer[128]; - int traceDebugMsgs = 0; - -#if defined(SUPPORT_TRACELOG_DEBUG) - traceDebugMsgs = 1; -#endif switch(msgType) { @@ -119,14 +117,21 @@ void TraceLog(int msgType, const char *text, ...) #if defined(PLATFORM_ANDROID) switch(msgType) { - case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break; - case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break; - case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break; - case LOG_DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break; + case LOG_INFO: if (logTypeFlags & LOG_INFO) __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break; + case LOG_WARNING: if (logTypeFlags & LOG_WARNING) __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break; + case LOG_ERROR: if (logTypeFlags & LOG_ERROR) __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break; + case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break; default: break; } #else - if ((msgType != LOG_DEBUG) || ((msgType == LOG_DEBUG) && (traceDebugMsgs))) vprintf(buffer, args); + switch(msgType) + { + case LOG_INFO: if (logTypeFlags & LOG_INFO) vprintf(buffer, args); break; + case LOG_WARNING: if (logTypeFlags & LOG_WARNING) vprintf(buffer, args); break; + case LOG_ERROR: if (logTypeFlags & LOG_ERROR) vprintf(buffer, args); break; + case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) vprintf(buffer, args); break; + default: break; + } #endif va_end(args); @@ -136,13 +141,14 @@ void TraceLog(int msgType, const char *text, ...) #endif // SUPPORT_TRACELOG } -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) - #if defined(SUPPORT_SAVE_BMP) // Creates a BMP image file from an array of pixel data void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize) { +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) stbi_write_bmp(fileName, width, height, compSize, imgData); + TraceLog(LOG_INFO, "BMP Image saved: %s", fileName); +#endif } #endif @@ -150,9 +156,11 @@ void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height // Creates a PNG image file from an array of pixel data void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize) { +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) stbi_write_png(fileName, width, height, compSize, imgData, width*compSize); -} + TraceLog(LOG_INFO, "PNG Image saved: %s", fileName); #endif +} #endif // Keep track of memory allocated |
