[Moeng-cvs] BBRpg/src/shared console.cpp, 1.4, 1.5 console.h, 1.3, 1.4
Status: Alpha
Brought to you by:
b_lindeijer
From: Bjørn L. <b_l...@us...> - 2007-02-07 17:50:50
|
Update of /cvsroot/moeng/BBRpg/src/shared In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv9875/src/shared Modified Files: console.cpp console.h Log Message: Converted files to use UNIX newlines and added Code::Blocks project file. Index: console.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** console.h 23 Oct 2004 11:54:19 -0000 1.3 --- console.h 7 Feb 2007 17:50:31 -0000 1.4 *************** *** 1,53 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_CONSOLE_H_ ! #define _INCLUDED_CONSOLE_H_ ! #include <stdio.h> ! #include <list> ! ! using namespace std; ! ! ! #define CON_CONSOLE 1 ! #define CON_LOG 2 ! #define CON_QUIT 4 ! #define CON_POPUP 8 ! ! #define CON_ALWAYS 1 ! #define CON_DEBUG 2 ! #define CON_VDEBUG 4 ! ! ! class Console ! { ! public: ! Console(const char* filename); ! ~Console(); ! ! void update(); ! void draw(BITMAP *dest); ! bool handleInput(int key); ! void log(int where, int when, const char* what, ...); ! ! bool enableLogfile; ! ! private: ! FILE* logFile; ! char* logFilename; ! list<char*> logMessages; ! bool active; ! int progress; ! }; ! ! ! #endif ! --- 1,53 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #ifndef _INCLUDED_CONSOLE_H_ ! #define _INCLUDED_CONSOLE_H_ ! #include <stdio.h> ! #include <list> ! ! using namespace std; ! ! ! #define CON_CONSOLE 1 ! #define CON_LOG 2 ! #define CON_QUIT 4 ! #define CON_POPUP 8 ! ! #define CON_ALWAYS 1 ! #define CON_DEBUG 2 ! #define CON_VDEBUG 4 ! ! ! class Console ! { ! public: ! Console(const char* filename); ! ~Console(); ! ! void update(); ! void draw(BITMAP *dest); ! bool handleInput(int key); ! void log(int where, int when, const char* what, ...); ! ! bool enableLogfile; ! ! private: ! FILE* logFile; ! char* logFilename; ! list<char*> logMessages; ! bool active; ! int progress; ! }; ! ! ! #endif ! Index: console.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** console.cpp 23 Oct 2004 11:54:19 -0000 1.4 --- console.cpp 7 Feb 2007 17:50:31 -0000 1.5 *************** *** 1,169 **** ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #include <stdio.h> ! #include <stdarg.h> ! #include <allegro.h> ! #include <list> ! #include "console.h" ! #include "../common.h" ! #include <math.h> ! ! #ifndef M_PI ! #define M_PI 3.14159 ! #endif ! ! ! Console::Console(const char* filename) ! { ! logFilename = new char[strlen(filename) + 1]; ! strcpy(logFilename, filename); ! logFilename[strlen(filename)] = '\0'; ! ! logFile = fopen(logFilename, "w"); ! fclose(logFile); ! log(CON_LOG, CON_ALWAYS, "----- Start of RPG log file -----"); ! ! progress = 0; ! active = false; ! enableLogfile = true; ! } ! ! ! Console::~Console() ! { ! // Deallocate console string messages ! list<char*>::iterator i; ! while (!logMessages.empty()) ! { ! i = logMessages.begin(); ! delete (*i); ! logMessages.erase(i); ! } ! ! log(CON_LOG, CON_ALWAYS, "----- End of RPG log file -----"); ! ! delete logFilename; ! } ! ! void Console::update() ! { ! if (active && progress < 100) progress = MIN(100, progress + 2); ! if (!active && progress > 0) progress = MAX(0, progress - 2); ! } ! ! void Console::draw(BITMAP *dest) ! { ! if (progress > 0) { ! int posY = (int)((double)(dest->h / 4) * ! sin(((0.5 * M_PI) / (double)100) * ! (double)progress) - text_height(font)); ! ! line(dest, 0, posY + text_height(font) + 1, dest->w - 1, ! posY + text_height(font) + 1, makecol(0,0,0)); ! set_trans_blender(0,0,0,100); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! rectfill(dest, 0, 0, dest->w - 1, posY + text_height(font), ! makecol(0,0,0)); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! ! font = engine_font; ! ! list<char*>::iterator i = logMessages.begin(); ! while (i != logMessages.end() && posY > - text_height(font)) ! { ! textprintf_ex(dest, font, 2, posY, makecol(200,200,200), -1, (*i)); ! posY -= text_height(font) + 1; ! i++; ! } ! } ! } ! ! bool Console::handleInput(int key) ! { ! if ((progress == 0 || progress == 100) && ! (key == KEY_TILDE || key == KEY_C)) { ! active = !active; ! return true; ! } ! return false; ! } ! ! void Console::log(int where, int when, const char *what, ...) ! { ! if ((when & CON_ALWAYS) || ((when & CON_DEBUG) && debug_mode) || ! ((when & CON_VDEBUG) && debug_mode == 2)) ! { ! char* buf = (char*)malloc(1024 * sizeof(char)); ! ! va_list ap; ! va_start(ap, what); ! uvsprintf(buf, what, ap); ! va_end(ap); ! ! if (where & (CON_LOG | CON_QUIT)) ! { ! time_t t; ! time(&t); ! ! if (enableLogfile) { ! logFile = fopen(logFilename, "a"); ! fprintf( ! logFile, ! "[%s%d:%s%d:%s%d] ", ! (((t / 60) / 60) % 24 < 10) ? "0" : "", ! (int)(((t / 60) / 60) % 24), ! ((t / 60) % 60 < 10) ? "0" : "", ! (int)((t / 60) % 60), ! (t % 60 < 10) ? "0" : "", ! (int)(t % 60) ! ); ! fprintf(logFile, buf); ! fprintf(logFile, "\n"); ! fclose(logFile); ! } ! ! if (where & CON_QUIT) ! { ! logFile = fopen(logFilename, "a"); ! fprintf(logFile, "FATAL ERROR!\n"); ! fclose(logFile); ! set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); ! allegro_message(buf); ! printf("\n"); ! exit(1); ! } ! } ! ! if (where & CON_POPUP) ! { ! allegro_message(buf); ! } ! ! if (where & CON_CONSOLE) ! { ! // Add the message to the console ! logMessages.push_front(buf); ! ! // Clean up the log memory (only keep the last 20 messages) ! if (logMessages.size() > 20) { ! free(logMessages.back()); ! logMessages.pop_back(); ! } ! } ! else ! { ! // Clean up the allocated string space ! delete buf; ! } ! } ! } ! --- 1,168 ---- ! /* ! The Moonlight Engine - An extendable, portable, RPG-focused game engine. ! Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer ! ! This program is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! */ ! ! #include <stdio.h> ! #include <stdarg.h> ! #include <allegro.h> ! #include <list> ! #include "console.h" ! #include "../common.h" ! #include <math.h> ! ! #ifndef M_PI ! #define M_PI 3.14159 ! #endif ! ! ! Console::Console(const char* filename) ! { ! logFilename = new char[strlen(filename) + 1]; ! strcpy(logFilename, filename); ! logFilename[strlen(filename)] = '\0'; ! ! logFile = fopen(logFilename, "w"); ! fclose(logFile); ! log(CON_LOG, CON_ALWAYS, "----- Start of RPG log file -----"); ! ! progress = 0; ! active = false; ! enableLogfile = true; ! } ! ! ! Console::~Console() ! { ! // Deallocate console string messages ! list<char*>::iterator i; ! while (!logMessages.empty()) ! { ! i = logMessages.begin(); ! delete (*i); ! logMessages.erase(i); ! } ! ! log(CON_LOG, CON_ALWAYS, "----- End of RPG log file -----"); ! ! delete logFilename; ! } ! ! void Console::update() ! { ! if (active && progress < 100) progress = MIN(100, progress + 2); ! if (!active && progress > 0) progress = MAX(0, progress - 2); ! } ! ! void Console::draw(BITMAP *dest) ! { ! if (progress > 0) { ! int posY = (int)((double)(dest->h / 4) * ! sin(((0.5 * M_PI) / (double)100) * ! (double)progress) - text_height(font)); ! ! line(dest, 0, posY + text_height(font) + 1, dest->w - 1, ! posY + text_height(font) + 1, makecol(0,0,0)); ! set_trans_blender(0,0,0,100); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! rectfill(dest, 0, 0, dest->w - 1, posY + text_height(font), ! makecol(0,0,0)); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! ! font = engine_font; ! ! list<char*>::iterator i = logMessages.begin(); ! while (i != logMessages.end() && posY > - text_height(font)) ! { ! textprintf_ex(dest, font, 2, posY, makecol(200,200,200), -1, (*i)); ! posY -= text_height(font) + 1; ! i++; ! } ! } ! } ! ! bool Console::handleInput(int key) ! { ! if ((progress == 0 || progress == 100) && ! (key == KEY_TILDE || key == KEY_C)) { ! active = !active; ! return true; ! } ! return false; ! } ! ! void Console::log(int where, int when, const char *what, ...) ! { ! if ((when & CON_ALWAYS) || ((when & CON_DEBUG) && debug_mode) || ! ((when & CON_VDEBUG) && debug_mode == 2)) ! { ! char* buf = (char*)malloc(1024 * sizeof(char)); ! ! va_list ap; ! va_start(ap, what); ! uvsprintf(buf, what, ap); ! va_end(ap); ! ! if (where & (CON_LOG | CON_QUIT)) ! { ! time_t t; ! time(&t); ! ! if (enableLogfile) { ! logFile = fopen(logFilename, "a"); ! fprintf( ! logFile, ! "[%s%d:%s%d:%s%d] ", ! (((t / 60) / 60) % 24 < 10) ? "0" : "", ! (int)(((t / 60) / 60) % 24), ! ((t / 60) % 60 < 10) ? "0" : "", ! (int)((t / 60) % 60), ! (t % 60 < 10) ? "0" : "", ! (int)(t % 60) ! ); ! fprintf(logFile, buf); ! fprintf(logFile, "\n"); ! fclose(logFile); ! } ! ! if (where & CON_QUIT) ! { ! logFile = fopen(logFilename, "a"); ! fprintf(logFile, "FATAL ERROR!\n"); ! fclose(logFile); ! set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); ! allegro_message(buf); ! printf("\n"); ! exit(1); ! } ! } ! ! if (where & CON_POPUP) ! { ! allegro_message(buf); ! } ! ! if (where & CON_CONSOLE) ! { ! // Add the message to the console ! logMessages.push_front(buf); ! ! // Clean up the log memory (only keep the last 20 messages) ! if (logMessages.size() > 20) { ! free(logMessages.back()); ! logMessages.pop_back(); ! } ! } ! else ! { ! // Clean up the allocated string space ! delete buf; ! } ! } ! } |