summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2005-03-24 21:24:31 +0000
committerYohann Ferreira <bertram@cegetel.net>2005-03-24 21:24:31 +0000
commitb5a9e699b9685e2a7d448171e282fd284754caf1 (patch)
tree4c8787fb30d28ec685bbcbb2ddca962b838a256d /src
parentadf5fb5d45c11a0506d199d2cc672535c8418ce1 (diff)
downloadmana-b5a9e699b9685e2a7d448171e282fd284754caf1.tar.gz
mana-b5a9e699b9685e2a7d448171e282fd284754caf1.tar.bz2
mana-b5a9e699b9685e2a7d448171e282fd284754caf1.tar.xz
mana-b5a9e699b9685e2a7d448171e282fd284754caf1.zip
Logger Implemented. (3/3)
Diffstat (limited to 'src')
-rw-r--r--src/gui/char_select.cpp11
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/login.cpp10
-rw-r--r--src/gui/setup.cpp8
-rw-r--r--src/gui/window.cpp4
-rw-r--r--src/log.cpp84
-rw-r--r--src/log.h18
-rw-r--r--src/main.cpp4
-rw-r--r--src/resources/image.cpp7
-rw-r--r--src/resources/mapreader.cpp19
-rw-r--r--src/resources/resourcemanager.cpp17
-rw-r--r--src/sound.cpp17
12 files changed, 52 insertions, 149 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 431297e9..97c35a57 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -21,6 +21,7 @@
* $Id$
*/
+#include "../main.h"
#include "char_select.h"
#include "textfield.h"
#include "button.h"
@@ -195,7 +196,7 @@ void CharSelectDialog::serverCharDelete() {
RFIFOSKIP(3);
}
else {
- new OkDialog(this, "Error", "Unknown error");
+ new OkDialog(this, "Error", "Unknown");
}
}
@@ -210,11 +211,11 @@ void CharSelectDialog::serverCharSelect()
flush();
}
- log("CharSelect: Packet ID: %x, Length: %d, Packet_in_size %d",
+ logger.log("CharSelect: Packet ID: %x, Length: %d, Packet_in_size %d",
RFIFOW(0),
get_length(RFIFOW(0)),
RFIFOW(2));
- log("CharSelect: In_size: %d", in_size);
+ logger.log("CharSelect: In_size: %d", in_size);
if (RFIFOW(0) == 0x0071) {
while (in_size < 28) {
@@ -228,8 +229,8 @@ void CharSelectDialog::serverCharSelect()
map_port = RFIFOW(26);
state = GAME;
- log("CharSelect: Map: %s", map_name);
- log("CharSelect: Server: %s:%d", iptostring(map_address), map_port);
+ logger.log("CharSelect: Map: %s", map_name);
+ logger.log("CharSelect: Server: %s:%d", iptostring(map_address), map_port);
RFIFOSKIP(28);
close_session();
}
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index a4a433a7..e3835df7 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -204,7 +204,7 @@ void server_char_server(int serverIndex) {
}
state = CHAR_SELECT;
- log("CharServer: Player: %s (Packet ID: %x, Length: %d)",
+ logger.log("CharServer: Player: %s (Packet ID: %x, Length: %d)",
char_info->name, RFIFOW(0), RFIFOW(2));
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index f5e51d8d..ab06be75 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -106,7 +106,7 @@ void LoginDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
const std::string user = userField->getText();
- log("Network: Username is %s", user.c_str());
+ logger.log("Network: Username is %s", user.c_str());
// Store config settings
config.setValue("remember", keepCheck->isMarked());
@@ -193,8 +193,8 @@ void server_login(const std::string& user, const std::string& pass) {
while ((in_size < 23) || (out_size > 0)) {
flush();
}
- log("Network: Packet ID: %x", RFIFOW(0));
- log("Network: Packet length: %d", get_packet_length(RFIFOW(0)));
+ logger.log("Network: Packet ID: %x", RFIFOW(0));
+ logger.log("Network: Packet length: %d", get_packet_length(RFIFOW(0)));
if (RFIFOW(0) == 0x0069) {
while (in_size < RFIFOW(2)) {
@@ -213,10 +213,10 @@ void server_login(const std::string& user, const std::string& pass) {
server_info[i].port = RFIFOW(47 + 32 * i + 4);
state = CHAR_SERVER;
}
- log("Network: Server: %s (%s:%d)", server_info[0].name,
+ logger.log("Network: Server: %s (%s:%d)", server_info[0].name,
iptostring(server_info[0].address),
server_info[0].port);
- log("Network: Users: %d", server_info[0].online_users);
+ logger.log("Network: Users: %d", server_info[0].online_users);
RFIFOSKIP(RFIFOW(2));
}
else if (RFIFOW(0) == 0x006a) {
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 6e3197cd..13ba937d 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -50,12 +50,12 @@ ModeListModel::ModeListModel()
// Check if any modes available
if (modes == (SDL_Rect**)0) {
nmode = 0;
- log("No modes");
+ logger.log("No modes");
}
// Check if modes restricted
if (modes == (SDL_Rect**)-1) {
- log("Modes unrestricted");
+ logger.log("Modes unrestricted");
}
for (nmode = 0; modes[nmode]; ++nmode);
@@ -66,7 +66,7 @@ ModeListModel::ModeListModel()
char *temp = (char*)malloc(20 * sizeof(char));
mode[i] = temp;
if (sprintf(mode[i], "%d x %d", modes[i]->w, modes[i]->h) == -1) {
- log("Cannot allocate mode list");
+ logger.log("Cannot allocate mode list");
}
}
}
@@ -229,7 +229,7 @@ void Setup::action(const std::string &eventId)
}
catch (const char *err) {
new OkDialog(this, "Sound Engine", err);
- log("Warning: %s", err);
+ logger.log("Warning: %s", err);
}
} else {
config.setValue("sound", 0);
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 0d8ce5ff..817090ca 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -34,7 +34,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
snapSize(8),
modal(modal)
{
- log("Window::Window(\"%s\")", caption.c_str());
+ logger.log("Window::Window(\"%s\")", caption.c_str());
setBorderSize(0);
setPadding(3);
@@ -73,7 +73,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
Window::~Window()
{
- log("Window::~Window(\"%s\")", getCaption().c_str());
+ logger.log("Window::~Window(\"%s\")", getCaption().c_str());
// Free dialog bitmaps
//release_bitmap(dLeft);
diff --git a/src/log.cpp b/src/log.cpp
index b73b2662..e1db8d4f 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -42,32 +42,6 @@ Logger::~Logger()
logFile.close();
}
-void Logger::log(std::string log_text)
-{
- if ( logFile.is_open() )
- {
- // Time container
- time_t t;
- // Get the current system time
- time(&t);
-
- // Print the log entry
- logFile << "[";
- logFile << ((((t / 60) / 60) % 24 < 10) ? "0" : "");
- logFile << (int)(((t / 60) / 60) % 24);
- logFile << ":";
- logFile << (((t / 60) % 60 < 10) ? "0" : "");
- logFile << (int)((t / 60) % 60);
- logFile << ":";
- logFile << ((t % 60 < 10) ? "0" : "");
- logFile << (int)(t % 60);
- logFile << "] ";
-
- // Print the log entry
- logFile << log_text << std::endl;
- }
-}
-
void Logger::log(const char *log_text, ...)
{
if ( logFile.is_open() )
@@ -105,69 +79,13 @@ void Logger::log(const char *log_text, ...)
void Logger::error(const std::string &error_text)
{
- log(error_text);
#ifdef WIN32
MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
#else
log("Error :");
- log(error_text);
-#endif
- exit(1);
-}
-
-void init_log()
-{
- logfile = fopen("tmw.log", "w");
- if (!logfile) {
- printf("Warning: error while opening log file.\n");
- }
-}
-
-void log(const char *log_text, ...)
-{
- if (logfile)
- {
- char* buf = new char[1024];
- va_list ap;
- time_t t;
-
- // Use a temporary buffer to fill in the variables
- va_start(ap, log_text);
- vsprintf(buf, log_text, ap);
- va_end(ap);
-
- // Get the current system time
- time(&t);
-
- // Print the log entry
- fprintf(logfile,
- "[%s%d:%s%d:%s%d] %s\n",
- (((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),
- buf
- );
-
- // Flush the log file
- fflush(logfile);
-
- // Delete temporary buffer
- delete[] buf;
- }
-}
-
-void error(const std::string &error_text)
-{
log(error_text.c_str());
-
-#ifdef WIN32
- MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
-#else
- fprintf(stderr, "Error: %s\n", error_text.c_str());
#endif
exit(1);
}
+
diff --git a/src/log.h b/src/log.h
index 99c9a0a8..64da662b 100644
--- a/src/log.h
+++ b/src/log.h
@@ -51,7 +51,6 @@ Logger(std::string logFilename);
/**
* Enters a message in the log. The message will be timestamped.
*/
-void log(std::string log_text);
void log(const char *log_text, ...);
/**
@@ -66,21 +65,4 @@ std::ofstream logFile;
};
-
-/**
- * Initializes log file by opening it for writing.
- */
-void init_log();
-
-/**
- * Enters a message in the log. The message will be timestamped.
- */
-void log(const char *log_text, ...);
-
-/**
- * Log an error and quit. The error will pop-up in Windows and will be printed
- * to standard error everywhere else.
- */
-void error(const std::string &error_text);
-
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 9a57555e..347e0d36 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -71,7 +71,7 @@ Sound sound;
// ini file configuration reader
Configuration config;
// Log object
-Logger logger("tmw.log2");
+Logger logger("tmw.log");
/**
* Listener used for responding to map start error dialog.
@@ -111,8 +111,6 @@ void init_engine()
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- init_log();
-
dir = new char[400];
strcpy(dir, "");
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index f976466e..54e0c8b9 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -21,6 +21,7 @@
* $Id$
*/
+#include "../main.h"
#include "../graphics.h"
#include "image.h"
#include "../log.h"
@@ -51,14 +52,14 @@ Image::~Image()
Image* Image::load(const std::string &filePath, int flags)
{
- log("Image::load(%s)", filePath.c_str());
+ logger.log("Image::load(%s)", filePath.c_str());
// Attempt to use SDL_Image to load the file.
SDL_Surface *tmpImage = IMG_Load(filePath.c_str());
// Check if the file was opened and return the appropriate value.
if (!tmpImage) {
- log("Error: Image load failed.");
+ logger.log("Error: Image load failed.");
return NULL;
}
@@ -77,7 +78,7 @@ Image* Image::load(const std::string &filePath, int flags)
// Check if the file was opened and return the appropriate value.
if (!image) {
- log("Error: Image convert failed.");
+ logger.log("Error: Image convert failed.");
return NULL;
}
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 7673bf55..38e15945 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -21,6 +21,7 @@
* $Id$
*/
+#include "../main.h"
#include "mapreader.h"
#include "../log.h"
#include "resourcemanager.h"
@@ -55,25 +56,25 @@ int Tileset::getFirstGid()
Map *MapReader::readMap(const std::string &filename)
{
- log("Attempting to parse XML map data");
+ logger.log("Attempting to parse XML map data");
std::string name = std::string("data/") + filename;
xmlDocPtr doc = xmlParseFile(name.c_str());
if (doc) {
- log("Looking for root node");
+ logger.log("Looking for root node");
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
- log("Warning: No map file (%s)!", filename.c_str());
+ logger.log("Warning: No map file (%s)!", filename.c_str());
return NULL;
}
- log("Loading map from XML tree");
+ logger.log("Loading map from XML tree");
return readMap(node, filename);
xmlFreeDoc(doc);
} else {
- log("Error while parsing map file (%s)!", filename.c_str());
+ logger.log("Error while parsing map file (%s)!", filename.c_str());
}
return NULL;
@@ -108,7 +109,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
}
else if (xmlStrEqual(node->name, BAD_CAST "layer"))
{
- log("- Loading layer %d", layerNr);
+ logger.log("- Loading layer %d", layerNr);
readLayer(node, map, layerNr);
layerNr++;
}
@@ -139,7 +140,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
xmlFree(encoding);
if (compression) {
- log("Warning: no layer compression supported!");
+ logger.log("Warning: no layer compression supported!");
xmlFree(compression);
return;
}
@@ -217,7 +218,7 @@ Tileset* MapReader::readTileset(
xmlNodePtr node, const std::string &path, Map *map)
{
if (xmlHasProp(node, BAD_CAST "source")) {
- log("Warning: External tilesets not supported yet.");
+ logger.log("Warning: External tilesets not supported yet.");
return NULL;
}
@@ -246,7 +247,7 @@ Tileset* MapReader::readTileset(
return set;
}
else {
- log("Warning: Failed to load tileset (%s)\n", source);
+ logger.log("Warning: Failed to load tileset (%s)\n", source);
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index eab6845e..e7b4eef3 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -21,6 +21,7 @@
* $Id$
*/
+#include "../main.h"
#include "resourcemanager.h"
#include "../log.h"
#include <iostream>
@@ -67,7 +68,7 @@ ResourceManager::~ResourceManager()
}
resources.clear();
- log("ResourceManager::~ResourceManager() cleaned up %d references to %d"
+ logger.log("ResourceManager::~ResourceManager() cleaned up %d references to %d"
" resources", danglingReferences, danglingResources);
}
@@ -96,10 +97,10 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
switch (type)
{
case MAP:
- log("Warning: Map resource not supported.");
+ logger.log("Warning: Map resource not supported.");
break;
case MUSIC:
- log("Warning: Music resource not supported.");
+ logger.log("Warning: Music resource not supported.");
break;
case IMAGE:
// Attempt to create and load our image object.
@@ -126,16 +127,16 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
break;
case SCRIPT:
- log("Warning: Script resource not supported.");
+ logger.log("Warning: Script resource not supported.");
break;
case TILESET:
- log("Warning: Tileset resource not supported.");
+ logger.log("Warning: Tileset resource not supported.");
break;
case SOUND_EFFECT:
- log("Warning: Sound FX resource not supported.");
+ logger.log("Warning: Sound FX resource not supported.");
break;
default:
- log("Warning: Unknown resource type");
+ logger.log("Warning: Unknown resource type");
break;
}
@@ -227,7 +228,7 @@ void ResourceManager::searchAndAddZipFiles()
std::string filePath = std::string(programPath) +
std::string("/") + std::string(direntry->d_name);
- log("Adding to PhysicsFS: %s", filePath.c_str());
+ logger.log("Adding to PhysicsFS: %s", filePath.c_str());
// Add the zip file to our PhysicsFS search path
PHYSFS_addToSearchPath(filePath.c_str(), 1);
diff --git a/src/sound.cpp b/src/sound.cpp
index 74222c8c..8de4077e 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -23,6 +23,7 @@
#include "sound.h"
#include "log.h"
+#include "main.h"
void Sound::init(int voices, int mod_voices)
{
@@ -50,7 +51,7 @@ void Sound::init(int voices, int mod_voices)
items = -1;
isOk = 0;
- log("Sound::Init() Initializing Sound");
+ logger.log("Sound::Init() Initializing Sound");
}
void Sound::setVolume(int music)
@@ -81,7 +82,7 @@ void Sound::startBgm(char *in, int loop)
stopBgm();
}
- log("Sound::startBgm() playing \"%s\" %d times", in, loop);
+ logger.log("Sound::startBgm() playing \"%s\" %d times", in, loop);
bgm = Mix_LoadMUS(in);
Mix_PlayMusic(bgm, loop);
@@ -91,7 +92,7 @@ void Sound::stopBgm()
{
if (isOk == -1) return;
- log("Sound::stopBgm()");
+ logger.log("Sound::stopBgm()");
if (bgm != NULL) {
Mix_HaltMusic();
@@ -102,12 +103,12 @@ void Sound::stopBgm()
SOUND_SID Sound::loadItem(char *fpath)
{
- log("Sound::loadItem() precaching \"%s\"", fpath);
+ logger.log("Sound::loadItem() precaching \"%s\"", fpath);
Mix_Chunk *newItem;
if ((newItem = Mix_LoadWAV(fpath))) {
soundpool[++items] = newItem;
- log("Sound::loadItem() success SOUND_SID = %d", items);
+ logger.log("Sound::loadItem() success SOUND_SID = %d", items);
return items;
}
@@ -117,7 +118,7 @@ SOUND_SID Sound::loadItem(char *fpath)
void Sound::startItem(SOUND_SID id, int volume)
{
if (soundpool[id]) {
- log("Sound::startItem() playing SOUND_SID = %d", id);
+ logger.log("Sound::startItem() playing SOUND_SID = %d", id);
Mix_VolumeChunk(soundpool[id], volume);
Mix_PlayChannel(-1, soundpool[id], 0);
}
@@ -131,7 +132,7 @@ void Sound::clearCache()
}
soundpool.clear();
- log("Sound::clearCache() wiped all items off the cache");
+ logger.log("Sound::clearCache() wiped all items off the cache");
}
void Sound::close()
@@ -139,7 +140,7 @@ void Sound::close()
isOk = -1;
clearCache();
Mix_CloseAudio();
- log("Sound::close() shutting down Sound");
+ logger.log("Sound::close() shutting down Sound");
}
bool Sound::isMaxVol(int vol)