goat3dgfx
diff src/logger.cc @ 5:18879c956eb1
- skycube example
- added fatal_log
- changed the dataset to keep the whole path while searching for data files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 17 Nov 2013 03:22:40 +0200 |
parents | 1873dfd13f2d |
children | 7d6b667821cf |
line diff
1.1 --- a/src/logger.cc Sat Nov 16 21:09:42 2013 +0200 1.2 +++ b/src/logger.cc Sun Nov 17 03:22:40 2013 +0200 1.3 @@ -4,9 +4,11 @@ 1.4 1.5 #if defined(unix) || defined(__unix__) || defined(__APPLE__) 1.6 #include <unistd.h> 1.7 +#elif defined(WIN32) 1.8 +#include <windows.h> 1.9 #endif 1.10 1.11 -enum { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG }; 1.12 +enum { LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL, LOG_DEBUG }; 1.13 1.14 static int typecolor(int type); 1.15 1.16 @@ -25,9 +27,18 @@ 1.17 { 1.18 vfprintf(fp, fmt, ap); 1.19 } 1.20 - if(type == LOG_ERROR || type == LOG_DEBUG) { 1.21 + if(type == LOG_ERROR || type == LOG_FATAL || type == LOG_DEBUG) { 1.22 fflush(fp); 1.23 } 1.24 + 1.25 +#ifdef WIN32 1.26 + if(type == LOG_FATAL) { 1.27 + static char msgbuf[1024]; 1.28 + vsnprintf(msgbuf, sizeof msgbuf - 1, fmt, ap); 1.29 + msgbuf[sizeof msgbuf - 1] = 0; 1.30 + MessageBox(0, msgbuf, "Fatal error", MB_OK | MB_ICONSTOP); 1.31 + } 1.32 +#endif 1.33 } 1.34 1.35 void info_log(const char *fmt, ...) 1.36 @@ -57,6 +68,15 @@ 1.37 va_end(ap); 1.38 } 1.39 1.40 +void fatal_log(const char *fmt, ...) 1.41 +{ 1.42 + va_list ap; 1.43 + 1.44 + va_start(ap, fmt); 1.45 + logmsg(LOG_FATAL, fmt, ap); 1.46 + va_end(ap); 1.47 +} 1.48 + 1.49 void debug_log(const char *fmt, ...) 1.50 { 1.51 va_list ap; 1.52 @@ -85,6 +105,8 @@ 1.53 switch(type) { 1.54 case LOG_ERROR: 1.55 return ANSI_FGCOLOR(RED); 1.56 + case LOG_FATAL: 1.57 + return ANSI_FGCOLOR(RED); // TODO differentiate from LOG_ERROR 1.58 case LOG_WARNING: 1.59 return ANSI_FGCOLOR(YELLOW); 1.60 case LOG_DEBUG: