[Moeng-cvs] BBRpg/src/shared console.cpp, 1.6, 1.7 console.h, 1.5, 1.6 inflate.cpp, 1.1, 1.2 map_re
Status: Alpha
Brought to you by:
b_lindeijer
From: Bjørn L. <b_l...@us...> - 2007-02-13 23:46:50
|
Update of /cvsroot/moeng/BBRpg/src/shared In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13203/src/shared Modified Files: console.cpp console.h inflate.cpp map_reader.cpp Log Message: Flush the log file instead of opening and closing and log map loading errors. Index: map_reader.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/map_reader.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- map_reader.cpp 13 Feb 2007 01:49:22 -0000 1.1 +++ map_reader.cpp 13 Feb 2007 23:46:46 -0000 1.2 @@ -372,9 +372,9 @@ } xmlFree(source); } else { - printf("Warning: Failed to load tileset %s (%s) for map " - "%s\n", nameOnly, (char*)name, - path.c_str()); + console.log(CON_QUIT, CON_ALWAYS, + "Failed to load tileset %s (%s) for map %s\n", + nameOnly, (char*)name, path.c_str()); } } Index: console.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- console.h 13 Feb 2007 01:49:22 -0000 1.5 +++ console.h 13 Feb 2007 23:46:46 -0000 1.6 @@ -17,14 +17,14 @@ #include <allegro.h> -#define CON_CONSOLE 1 -#define CON_LOG 2 -#define CON_QUIT 4 -#define CON_POPUP 8 +#define CON_CONSOLE 1 /**< Log to in-game console (not functional) */ +#define CON_LOG 2 /**< Log to log file */ +#define CON_QUIT 4 /**< Write to log file and terminal and quit */ +#define CON_POPUP 8 /**< Show the message in a popup */ -#define CON_ALWAYS 1 -#define CON_DEBUG 2 -#define CON_VDEBUG 4 +#define CON_ALWAYS 1 /**< Always log this */ +#define CON_DEBUG 2 /**< Only log when debug mode is enabled */ +#define CON_VDEBUG 4 /**< Only log when verbose debugging is enabled */ /** * The console. This class handles logging as well as displaying a console with @@ -33,7 +33,7 @@ class Console { public: - Console(const char* filename); + Console(const char *filename); ~Console(); void update(); @@ -45,7 +45,6 @@ private: FILE* logFile; - char* logFilename; std::list<char*> logMessages; bool active; int progress; Index: console.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- console.cpp 13 Feb 2007 01:49:22 -0000 1.6 +++ console.cpp 13 Feb 2007 23:46:46 -0000 1.7 @@ -18,23 +18,18 @@ #include <math.h> #ifndef M_PI -#define M_PI 3.14159 +#define M_PI 3.1415926 #endif -Console::Console(const char* filename) +Console::Console(const char *filename): + enableLogfile(true), + active(false), + progress(0) { - logFilename = new char[strlen(filename) + 1]; - strcpy(logFilename, filename); - logFilename[strlen(filename)] = '\0'; + logFile = fopen(filename, "w"); - logFile = fopen(logFilename, "w"); - fclose(logFile); log(CON_LOG, CON_ALWAYS, "----- Start of RPG log file -----"); - - progress = 0; - active = false; - enableLogfile = true; } @@ -45,13 +40,13 @@ while (!logMessages.empty()) { i = logMessages.begin(); - delete (*i); + free(*i); logMessages.erase(i); } log(CON_LOG, CON_ALWAYS, "----- End of RPG log file -----"); - delete logFilename; + fclose(logFile); } void Console::update() @@ -115,7 +110,6 @@ time(&t); if (enableLogfile) { - logFile = fopen(logFilename, "a"); fprintf( logFile, "[%s%d:%s%d:%s%d] ", @@ -126,16 +120,14 @@ (t % 60 < 10) ? "0" : "", (int)(t % 60) ); - fprintf(logFile, buf); - fprintf(logFile, "\n"); - fclose(logFile); + fprintf(logFile, "%s\n", buf); + fflush(logFile); } if (where & CON_QUIT) { - logFile = fopen(logFilename, "a"); fprintf(logFile, "FATAL ERROR!\n"); - fclose(logFile); + fflush(logFile); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(buf); printf("\n"); @@ -162,7 +154,7 @@ else { // Clean up the allocated string space - delete buf; + free(buf); } } } Index: inflate.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/inflate.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- inflate.cpp 13 Feb 2007 01:49:22 -0000 1.1 +++ inflate.cpp 13 Feb 2007 23:46:46 -0000 1.2 @@ -23,6 +23,7 @@ #include "inflate.h" +#include "../common.h" #include "console.h" #include <zlib.h> @@ -47,9 +48,7 @@ errorString = "Unknown error while decompressing data!"; } - // TODO: Well, make it actually log the error - printf("%s\n", errorString); - exit(1); + console.log(CON_QUIT, CON_ALWAYS, errorString); } bool |