summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp4
-rw-r--r--src/configuration.cpp19
-rw-r--r--src/configuration.h4
-rw-r--r--src/engine.cpp11
-rw-r--r--src/game.cpp22
-rw-r--r--src/graphics.cpp4
-rw-r--r--src/gui/char_select.cpp8
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/chat.cpp6
-rw-r--r--src/gui/chat.h2
-rw-r--r--src/gui/equipment.cpp6
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/itemcontainer.cpp4
-rw-r--r--src/gui/login.cpp8
-rw-r--r--src/gui/setup.cpp10
-rw-r--r--src/gui/window.cpp4
-rw-r--r--src/main.cpp125
-rw-r--r--src/main.h6
-rw-r--r--src/map.cpp6
-rw-r--r--src/net/network.cpp14
-rw-r--r--src/net/protocol.cpp8
-rw-r--r--src/resources/image.cpp8
-rw-r--r--src/resources/itemmanager.cpp18
-rw-r--r--src/resources/mapreader.cpp14
-rw-r--r--src/resources/resourcemanager.cpp26
-rw-r--r--src/sound.cpp34
26 files changed, 192 insertions, 183 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 3ddbeac9..c9b65e60 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -50,11 +50,11 @@ void add_node(Being *being)
else if (being->job >= 1002 && monsterset[being->job - 1002] == NULL) {
std::stringstream filename;
filename << "graphics/sprites/monster" << (being->job - 1002) << ".png";
- logger.log("%s",filename.str().c_str());
+ logger->log("%s",filename.str().c_str());
ResourceManager *resman = ResourceManager::getInstance();
Image *monsterbitmap = resman->getImage(filename.str());
if (!monsterbitmap) {
- logger.error("Unable to load monster.png");
+ logger->error("Unable to load monster.png");
}
else {
monsterset[being->job - 1002] = new Spriteset(monsterbitmap, 60, 60);
diff --git a/src/configuration.cpp b/src/configuration.cpp
index b73e9427..8cacd065 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -43,6 +43,17 @@
void Configuration::init(const std::string &filename)
{
+ configPath = filename;
+
+ // Do not attempt to read config from non-existant file
+ FILE *testFile = fopen(configPath.c_str(), "r");
+ if (!testFile) {
+ return;
+ }
+ else {
+ fclose(testFile);
+ }
+
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
if (!doc) return;
@@ -50,7 +61,7 @@ void Configuration::init(const std::string &filename)
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) {
- logger.log("Warning: No configuration file (%s)", filename.c_str());
+ logger->log("Warning: No configuration file (%s)", filename.c_str());
return;
}
@@ -74,9 +85,9 @@ void Configuration::init(const std::string &filename)
xmlFreeDoc(doc);
}
-bool Configuration::write(const std::string &filename)
+bool Configuration::write()
{
- xmlTextWriterPtr writer = xmlNewTextWriterFilename(filename.c_str(), 0);
+ xmlTextWriterPtr writer = xmlNewTextWriterFilename(configPath.c_str(), 0);
if (writer)
{
@@ -88,7 +99,7 @@ bool Configuration::write(const std::string &filename)
for (iter = options.begin(); iter != options.end(); iter++)
{
- logger.log("Configuration::write(%s, \"%s\")",
+ logger->log("Configuration::write(%s, \"%s\")",
iter->first.c_str(), iter->second.c_str());
xmlTextWriterStartElement(writer, BAD_CAST "option");
diff --git a/src/configuration.h b/src/configuration.h
index 8c5a0470..e6959ee5 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -58,7 +58,7 @@ class Configuration {
* \brief Writes the current settings back to an ini-file.
* \param filename Full path to INI file (~/.manaworld/tmw.ini)
*/
- bool write(const std::string &filename);
+ bool write();
/**
* \brief Sets an option using a string value.
@@ -102,6 +102,8 @@ class Configuration {
private:
std::map<std::string, std::string> options;
std::map<std::string, std::list<ConfigListener*> > listeners;
+
+ std::string configPath; /**< Location of config file */
};
#endif
diff --git a/src/engine.cpp b/src/engine.cpp
index 11a0cd81..6200bd0c 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -145,7 +145,8 @@ Engine::Engine()
guiTop->add(debugInfo);
// Create dialogs
- chatWindow = new ChatWindow("chatlog.txt", 20);
+ chatWindow = new ChatWindow(
+ std::string(homeDir) + std::string("chatlog.txt"));
statusWindow = new StatusWindow();
buyDialog = new BuyDialog();
sellDialog = new SellDialog();
@@ -216,10 +217,10 @@ Engine::Engine()
Image *itembitmap = resman->getImage(
"graphics/sprites/items.png", IMG_ALPHA);
- if (!npcbmp) logger.error("Unable to load npcs.png");
- if (!emotionbmp) logger.error("Unable to load emotions.png");
- if (!weaponbitmap) logger.error("Unable to load weapons.png");
- if (!itembitmap) logger.error("Unable to load items.png");
+ if (!npcbmp) logger->error("Unable to load npcs.png");
+ if (!emotionbmp) logger->error("Unable to load emotions.png");
+ if (!weaponbitmap) logger->error("Unable to load weapons.png");
+ if (!itembitmap) logger->error("Unable to load items.png");
npcset = new Spriteset(npcbmp, 50, 80);
emotionset = new Spriteset(emotionbmp, 19, 19);
diff --git a/src/game.cpp b/src/game.cpp
index 7e538346..95bbf384 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -154,7 +154,7 @@ void do_init()
if (!tiledMap)
{
- logger.error("Could not find map file!");
+ logger->error("Could not find map file!");
}
}
@@ -947,7 +947,7 @@ void do_parse()
memset(map_path, '\0', 480);
strcat(map_path, TMW_DATADIR "data/maps/");
strncat(map_path, RFIFOP(2), 497 - strlen(map_path));
- logger.log("Warping to %s (%d, %d)",
+ logger->log("Warping to %s (%d, %d)",
map_path, RFIFOW(18), RFIFOW(20));
strcpy(strrchr(map_path, '.') + 1, "tmx.gz");
@@ -979,7 +979,7 @@ void do_parse()
while (out_size > 0) flush();
}
else {
- logger.error("Could not find map file");
+ logger->error("Could not find map file");
}
break;
// Skill ...
@@ -1134,7 +1134,7 @@ void do_parse()
break;
// Level up
case 0x019b:
- logger.log("Level up");
+ logger->log("Level up");
if (RFIFOL(2) == player_node->id) {
sound.playSfx("sfx/levelup.ogg");
}
@@ -1350,7 +1350,7 @@ void do_parse()
// Answer to equip item
case 0x00aa:
- logger.log("Equipping: %i %i %i", RFIFOW(2), RFIFOW(4), RFIFOB(6));
+ logger->log("Equipping: %i %i %i", RFIFOW(2), RFIFOW(4), RFIFOB(6));
if (RFIFOB(6) == 0)
chatWindow->chat_log("Unable to equip.", BY_SERVER);
else {
@@ -1361,7 +1361,7 @@ void do_parse()
mask *= 2;
position++;
}
- logger.log("Position %i", position-1);
+ logger->log("Position %i", position-1);
int equippedId = equipmentWindow->equipments[position - 1].id;
if (equippedId > 0)
inventoryWindow->items->setEquipped(
@@ -1393,7 +1393,7 @@ void do_parse()
break;
// Equipment related
case 0x01d7:
- logger.log("1d7 %i %i %i %i", RFIFOL(2), RFIFOB(6), RFIFOW(7), RFIFOW(9));
+ logger->log("1d7 %i %i %i %i", RFIFOL(2), RFIFOB(6), RFIFOW(7), RFIFOW(9));
break;
// Answer to unequip item
case 0x00ac:
@@ -1425,7 +1425,7 @@ void do_parse()
equipmentWindow->removeEquipment(position - 1);
break;
}
- logger.log("Unequipping: %i %i(%i) %i", RFIFOW(2),RFIFOW(4),RFIFOB(6), position -1);
+ logger->log("Unequipping: %i %i(%i) %i", RFIFOW(2),RFIFOW(4),RFIFOB(6), position -1);
}
}
break;
@@ -1437,7 +1437,7 @@ void do_parse()
inventoryWindow->items->getId(RFIFOW(2)));
equipmentWindow->arrowsNumber =
inventoryWindow->items->getQuantity(RFIFOW(2));
- logger.log("Arrows equipped: %i", RFIFOW(2));
+ logger->log("Arrows equipped: %i", RFIFOW(2));
}
break;
// Various messages
@@ -1445,7 +1445,7 @@ void do_parse()
if (RFIFOW(2) == 0)
chatWindow->chat_log("Equip arrows first", BY_SERVER);
else
- logger.log("0x013b: Unhandled message %i", RFIFOW(2));
+ logger->log("0x013b: Unhandled message %i", RFIFOW(2));
break;
// Updates a stat value
case 0x00bc:
@@ -1528,7 +1528,7 @@ void do_parse()
break;
// Manage non implemented packets
default:
- logger.log("Unhandled packet: %x", id);
+ logger->log("Unhandled packet: %x", id);
break;
}
diff --git a/src/graphics.cpp b/src/graphics.cpp
index e0763c29..5ff02aa8 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -38,7 +38,7 @@ Graphics::Graphics():
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
int gotDoubleBuffer;
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
- logger.log("Using OpenGL %s double buffering.",
+ logger->log("Using OpenGL %s double buffering.",
(gotDoubleBuffer ? "with" : "without"));
}
@@ -55,7 +55,7 @@ Graphics::Graphics():
ResourceManager *resman = ResourceManager::getInstance();
mouseCursor = resman->getImage("graphics/gui/mouse.png", IMG_ALPHA);
if (!mouseCursor) {
- logger.error("Unable to load mouse cursor.");
+ logger->error("Unable to load mouse cursor.");
}
// Initialize for drawing
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 31c5298a..008c7e8d 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -215,11 +215,11 @@ void CharSelectDialog::serverCharSelect()
flush();
}
- logger.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));
- logger.log("CharSelect: In_size: %d", in_size);
+ logger->log("CharSelect: In_size: %d", in_size);
if (RFIFOW(0) == 0x0071) {
while (in_size < 28) {
@@ -233,8 +233,8 @@ void CharSelectDialog::serverCharSelect()
map_port = RFIFOW(26);
state = GAME;
- logger.log("CharSelect: Map: %s", map_name);
- logger.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 d7faf0c6..a2bd352f 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -206,7 +206,7 @@ void server_char_server(int serverIndex) {
}
state = CHAR_SELECT;
- logger.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/chat.cpp b/src/gui/chat.cpp
index 40a44b13..cc625358 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -29,12 +29,12 @@
#include "../main.h"
#include <iostream>
-ChatWindow::ChatWindow(const char *logfile, int item_num):
+ChatWindow::ChatWindow(const std::string &logfile):
Window("")
{
- chatlog_file.open(logfile, std::ios::out | std::ios::app);
+ chatlog_file.open(logfile.c_str(), std::ios::out | std::ios::app);
items = 0;
- items_keep = item_num;
+ items_keep = 20;
setContentSize(600, 100);
textOutput = new TextBox();
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 1c3fc007..61fe902a 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -107,7 +107,7 @@ class ChatWindow : public Window, public gcn::ActionListener,
/**
* Constructor.
*/
- ChatWindow(const char *logfile, int item_num);
+ ChatWindow(const std::string &logfile);
/**
* Destructor.
diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp
index 5393459f..8ca23833 100644
--- a/src/gui/equipment.cpp
+++ b/src/gui/equipment.cpp
@@ -34,12 +34,12 @@ EquipmentWindow::EquipmentWindow():
{
setContentSize(134, 60);
setPosition(40, 40);
-
+
ResourceManager *resman = ResourceManager::getInstance();
Image *itemImg = resman->getImage("graphics/sprites/items.png", IMG_ALPHA);
- if (!itemImg) logger.error("Unable to load items.png");
+ if (!itemImg) logger->error("Unable to load items.png");
itemset = new Spriteset(itemImg, 20, 20);
-
+
for (int i = 0; i < 10; i++ ) {
equipments[i].id = 0;
equipments[i].inventoryIndex = -1;
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 97423af6..5b527904 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -73,7 +73,7 @@ Gui::Gui(Graphics *graphics):
}
catch (gcn::Exception e)
{
- logger.error("Unable to load fixedfont.png!");
+ logger->error("Unable to load fixedfont.png!");
}
gcn::Widget::setGlobalFont(guiFont);
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 5bb3eb35..61e9383f 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -30,11 +30,11 @@ ItemContainer::ItemContainer()
{
ResourceManager *resman = ResourceManager::getInstance();
Image *itemImg = resman->getImage("graphics/sprites/items.png", IMG_ALPHA);
- if (!itemImg) logger.error("Unable to load items.png");
+ if (!itemImg) logger->error("Unable to load items.png");
itemset = new Spriteset(itemImg, 20, 20);
selImg = resman->getImage("graphics/gui/selection.png", IMG_ALPHA);
- if (!selImg) logger.error("Unable to load selection.png");
+ if (!selImg) logger->error("Unable to load selection.png");
selectedItem = -1; // No item selected
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 56373011..3b9c3cac 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -113,7 +113,7 @@ void LoginDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
const std::string user = userField->getText();
- logger.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());
@@ -134,7 +134,7 @@ void LoginDialog::action(const std::string& eventId)
state = EXIT;
} else if (eventId == "register") {
const std::string user = userField->getText();
- logger.log("LoginDialog::register Username is %s", user.c_str());
+ logger->log("LoginDialog::register Username is %s", user.c_str());
// Store config settings
config.setValue("remember", keepCheck->isMarked());
@@ -239,13 +239,13 @@ void server_login(const std::string& user, const std::string& pass) {
server_info[i].port = RFIFOW(47 + 32 * i + 4);
state = CHAR_SERVER;
}
- logger.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);
RFIFOSKIP(RFIFOW(2));
}
else if (RFIFOW(0) == 0x006a) {
- logger.log("Login::error code: %i", RFIFOB(2));
+ logger->log("Login::error code: %i", RFIFOB(2));
switch (RFIFOB(2)) {
case 0:
new OkDialog("Error", "Unregistered ID");
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index a0be66cc..e6987766 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -43,18 +43,18 @@ ModeListModel::ModeListModel()
/* Check is there are any modes available */
if (modes == (SDL_Rect **)0) {
- logger.log("No modes available");
+ logger->log("No modes available");
}
/* Check if our resolution is restricted */
if (modes == (SDL_Rect **)-1) {
- logger.log("All resolutions available");
+ logger->log("All resolutions available");
}
else{
/* Print valid modes */
- logger.log("Available Modes");
+ logger->log("Available Modes");
for (int i = 0; modes[i]; ++i) {
- logger.log(" %dx%d", modes[i]->w, modes[i]->h);
+ logger->log(" %dx%d", modes[i]->w, modes[i]->h);
std::stringstream mode;
mode << (int)modes[i]->w << "x" << (int)modes[i]->h;
videoModes.push_back(mode.str());
@@ -228,7 +228,7 @@ void Setup::action(const std::string &eventId)
}
catch (const char *err) {
new OkDialog(this, "Sound Engine", err);
- logger.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 eacb3d6d..c9042ffd 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -39,7 +39,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
maxWinWidth(512),
maxWinHeight(512)
{
- logger.log("Window::Window(\"%s\")", caption.c_str());
+ logger->log("Window::Window(\"%s\")", caption.c_str());
setBorderSize(0);
setPadding(3);
@@ -81,7 +81,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
Window::~Window()
{
- logger.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/main.cpp b/src/main.cpp
index c8d71212..16a97e61 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -65,7 +65,6 @@ short map_port;
char map_name[16];
unsigned char state;
unsigned char screen_mode;
-char *dir = NULL;
char *homeDir = NULL;
int displayFlags, screenW, screenH, bitDepth;
bool useOpenGL = false;
@@ -73,12 +72,9 @@ bool useOpenGL = false;
Sound sound;
Music *bgm;
-// Xml file configuration reader
-Configuration config;
-// Log object
-Logger logger("tmw.log");
-// Item database object
-ItemManager itemDb;
+Configuration config; /**< Xml file configuration reader */
+Logger *logger; /**< Log object */
+ItemManager itemDb; /**< Item database object */
/**
* Listener used for responding to map start error dialog.
@@ -118,19 +114,12 @@ void init_engine()
SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
- dir = new char[400];
- strcpy(dir, "");
-
homeDir = new char[256];
#ifndef __USE_UNIX98
- // WIN32 and others
- strcpy(dir, "config.xml");
-
// In Windows and other systems we currently store data next to executable.
strcpy(homeDir, "");
#else
- // In UNIX we store data in ~/.manaworld/
- char *userHome;
+ // In UNIX we store data in ~/.tmw/
char *name = getlogin();
passwd *pass;
@@ -146,52 +135,55 @@ void init_engine()
exit(1);
}
- userHome = pass->pw_dir;
-
- // Checking if homeuser/.manaworld folder exists.
- sprintf(dir, "%s/.manaworld", userHome);
- if ((mkdir(dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) &&
+ // Checking if homeuser/.tmw folder exists.
+ sprintf(homeDir, "%s/.tmw/", pass->pw_dir);
+ if ((mkdir(homeDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) &&
(errno != EEXIST))
{
- printf("%s can't be made, but it doesn't exist! Exitting.\n", dir);
+ printf("%s can't be made, but it doesn't exist! Exitting.\n", homeDir);
exit(1);
}
- sprintf(dir, "%s/.manaworld/config.xml", userHome);
-
- //strcpy(homeDir, "%s/.manaworld/", userHome);
#endif
+ // Initialize logger
+ logger = new Logger(std::string(homeDir) + std::string("tmw.log"));
+
+ // Fill configuration with defaults
+ config.setValue("host", "animesites.de");
+ config.setValue("port", 6901);
+ config.setValue("hwaccel", 0);
+ config.setValue("opengl", 0);
+ config.setValue("screen", 0);
+ config.setValue("sound", 1);
+ config.setValue("guialpha", 0.8f);
+ config.setValue("remember", 1);
+ config.setValue("sfxVolume", 100);
+ config.setValue("musicVolume", 60);
+
// Checking if the configuration file exists... otherwise creates it with
// default options !
FILE *tmwFile = 0;
- tmwFile = fopen(dir, "r");
+ char configPath[256];
+ sprintf(configPath, "%sconfig.xml", homeDir);
+ tmwFile = fopen(configPath, "r");
// If we can't read it, it doesn't exist !
if (tmwFile == NULL) {
// We reopen the file in write mode and we create it
- printf("No file : %s\n, Creating Default Options...\n", dir);
- tmwFile = fopen(dir, "wt");
+ printf("No file : %s\n, Creating Default Options...\n", configPath);
+ tmwFile = fopen(configPath, "wt");
if (tmwFile == NULL) {
- printf("Can't create %s file. Using Defaults.\n", dir);
+ printf("Can't create %s file. Using Defaults.\n", configPath);
}
else {
fclose(tmwFile);
- // Fill configuration with defaults
- config.setValue("host", "animesites.de");
- config.setValue("port", 6901);
- config.setValue("hwaccel", 0);
- config.setValue("opengl", 0);
- config.setValue("screen", 0);
- config.setValue("sound", 1);
- config.setValue("guialpha", 0.8f);
- config.setValue("remember", 1);
- config.setValue("sfxVolume", 100);
- config.setValue("musicVolume", 60);
- config.write(dir);
+ config.init(configPath);
}
}
-
- config.init(dir);
+ else {
+ fclose(tmwFile);
+ config.init(configPath);
+ }
SDL_WM_SetCaption("The Mana World", NULL);
@@ -213,7 +205,7 @@ void init_engine()
}
else {
if ((int)config.getValue("hwaccel", 0)) {
- logger.log("Attempting to use hardware acceleration.");
+ logger->log("Attempting to use hardware acceleration.");
displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
}
else {
@@ -237,33 +229,33 @@ void init_engine()
char videoDriverName[64];
if (SDL_VideoDriverName(videoDriverName, 64)) {
- logger.log("Using video driver: %s", videoDriverName);
+ logger->log("Using video driver: %s", videoDriverName);
}
else {
- logger.log("Using video driver: unkown");
+ logger->log("Using video driver: unkown");
}
const SDL_VideoInfo *vi = SDL_GetVideoInfo();
- logger.log("Possible to create hardware surfaces: %s",
+ logger->log("Possible to create hardware surfaces: %s",
((vi->hw_available) ? "yes" : "no "));
- logger.log("Window manager available: %s",
+ logger->log("Window manager available: %s",
((vi->wm_available) ? "yes" : "no"));
- logger.log("Accelerated hardware to hardware blits: %s",
+ logger->log("Accelerated hardware to hardware blits: %s",
((vi->blit_hw) ? "yes" : "no"));
- logger.log("Accelerated hardware to hardware colorkey blits: %s",
+ logger->log("Accelerated hardware to hardware colorkey blits: %s",
((vi->blit_hw_CC) ? "yes" : "no"));
- logger.log("Accelerated hardware to hardware alpha blits: %s",
+ logger->log("Accelerated hardware to hardware alpha blits: %s",
((vi->blit_hw_A) ? "yes" : "no"));
- logger.log("Accelerated software to hardware blits: %s",
+ logger->log("Accelerated software to hardware blits: %s",
((vi->blit_sw) ? "yes" : "no"));
- logger.log("Accelerated software to hardware colorkey blits: %s",
+ logger->log("Accelerated software to hardware colorkey blits: %s",
((vi->blit_sw_CC) ? "yes" : "no"));
- logger.log("Accelerated software to hardware alpha blits: %s",
+ logger->log("Accelerated software to hardware alpha blits: %s",
((vi->blit_sw_A) ? "yes" : "no"));
- logger.log("Accelerated color fills: %s",
+ logger->log("Accelerated color fills: %s",
((vi->blit_fill) ? "yes" : "no"));
- logger.log("Available video memory: %d", vi->video_mem);
+ logger->log("Available video memory: %d", vi->video_mem);
//vfmt Pixel format of the video device
@@ -279,9 +271,9 @@ void init_engine()
Image *hairImg = resman->getImage(
"graphics/sprites/player_male_hair.png");
- if (!login_wallpaper) logger.error("Couldn't load login_wallpaper.png");
- if (!playerImg) logger.error("Couldn't load player_male_base.png");
- if (!hairImg) logger.error("Couldn't load player_male_hair.png");
+ if (!login_wallpaper) logger->error("Couldn't load login_wallpaper.png");
+ if (!playerImg) logger->error("Couldn't load player_male_base.png");
+ if (!hairImg) logger->error("Couldn't load player_male_hair.png");
playerset = new Spriteset(playerImg, 64, 120);
hairset = new Spriteset(hairImg, 40, 40);
@@ -300,15 +292,15 @@ void init_engine()
catch (const char *err) {
state = ERROR;
new OkDialog("Sound Engine", err, &initWarningListener);
- logger.log("Warning: %s", err);
+ logger->log("Warning: %s", err);
}
}
/** Clear the engine */
void exit_engine()
{
- config.write(dir);
- delete[] dir;
+ config.write();
+ delete[] homeDir;
delete gui;
delete graphics;
@@ -316,6 +308,7 @@ void exit_engine()
xmlCleanupParser();
ResourceManager::deleteInstance();
+ delete logger;
}
/** Main */
@@ -350,24 +343,24 @@ int main(int argc, char *argv[])
switch (state) {
case LOGIN:
- logger.log("State: LOGIN");
+ logger->log("State: LOGIN");
sound.playMusic(TMW_DATADIR "data/music/Ivano(de)Jeanette.ogg");
/*bgm = resman->getMusic("music/Ivano(de)Jeanette.ogg");
bgm->play(-1);*/
login();
break;
case CHAR_SERVER:
- logger.log("State: CHAR_SERVER");
+ logger->log("State: CHAR_SERVER");
char_server();
break;
case CHAR_SELECT:
- logger.log("State: CHAR_SELECT");
+ logger->log("State: CHAR_SELECT");
charSelect();
break;
case GAME:
sound.fadeOutMusic(1000);
//bgm->stop();
- logger.log("State: GAME");
+ logger->log("State: GAME");
try {
map_start();
game();
@@ -389,7 +382,7 @@ int main(int argc, char *argv[])
break;
}
}
- logger.log("State: EXIT");
+ logger->log("State: EXIT");
exit_engine();
PHYSFS_deinit();
return 0;
diff --git a/src/main.h b/src/main.h
index 95fa99bb..58aa3f7e 100644
--- a/src/main.h
+++ b/src/main.h
@@ -71,7 +71,7 @@ typedef struct {
char name[20];
short online_users;
} SERVER_INFO;
-
+
typedef struct {
int id;
float lastAttackTime; // used to synchronize the charge dialog
@@ -106,8 +106,10 @@ extern unsigned char state;
extern Configuration config;
extern Sound sound;
extern Map *tiledMap;
-extern Logger logger;
+extern Logger *logger;
extern int screenW, screenH, bitDepth, displayFlags;
extern bool useOpenGL;
extern ItemManager itemDb;
+extern char *homeDir;
+
#endif
diff --git a/src/map.cpp b/src/map.cpp
index 17e9fd02..81540e98 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -112,7 +112,7 @@ Map::~Map()
Map *Map::load(const std::string &mapFile)
{
- logger.log("Map::load(%s)", mapFile.c_str());
+ logger->log("Map::load(%s)", mapFile.c_str());
if (mapFile.find(".tmx", 0) != std::string::npos)
{
@@ -123,7 +123,7 @@ Map *Map::load(const std::string &mapFile)
FILE *file = fopen(mapFile.c_str(), "r");
if (!file) {
- logger.log("Warning: %s", mapFile.c_str());
+ logger->log("Warning: %s", mapFile.c_str());
return NULL;
}
@@ -136,7 +136,7 @@ Map *Map::load(const std::string &mapFile)
// Load the default tileset
ResourceManager *resman = ResourceManager::getInstance();
Image *tilesetbmp = resman->getImage("graphics/tiles/desert.png");
- if (!tilesetbmp) logger.error("Unable to load desert.png");
+ if (!tilesetbmp) logger->error("Unable to load desert.png");
Spriteset *tileset = new Spriteset(tilesetbmp, 32, 32);
// Transfer tile data
diff --git a/src/net/network.cpp b/src/net/network.cpp
index 44d07e13..fa009341 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -45,7 +45,7 @@ fd_set write_socket;
void WFIFOSET(int len)
{
if (out_size + len >= buffer_size) {
- logger.log("Warning: Output buffer full");
+ logger->log("Warning: Output buffer full");
}
else {
out_size += len;
@@ -154,16 +154,16 @@ void flush()
}
}
if (ret == SOCKET_ERROR) {
- logger.error("Socket Error");
+ logger->error("Socket Error");
#ifdef WIN32
- logger.log("Error: Socket error: %i ", WSAGetLastError());
+ logger->log("Error: Socket error: %i ", WSAGetLastError());
if (WSAGetLastError() == 10053)
- logger.log("Error: Packet size error");
+ logger->log("Error: Packet size error");
/** Probably the last packet you sent, was defined with
* wrong size: WFIFOSET(size);
*/
#else
- logger.log("Error: Undefined socket error");
+ logger->log("Error: Undefined socket error");
#endif
}
}
@@ -175,9 +175,9 @@ void flush()
ret = recv(sock, in+in_size, RFIFOSPACE, 0);
if (ret == SOCKET_ERROR) {
#ifdef WIN32
- logger.log("Error: Socket error: %i ", WSAGetLastError());
+ logger->log("Error: Socket error: %i ", WSAGetLastError());
#else
- logger.log("Error: Undefined socket error");
+ logger->log("Error: Undefined socket error");
#endif
} else RFIFOSET(ret); // Set size of available data to read
}
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index d2761457..92d1fae5 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -158,7 +158,7 @@ void map_start()
// Connect to map server
if (open_session(iptostring(map_address), map_port) == SOCKET_ERROR)
{
- logger.log("Warning: Unable to connect to map server");
+ logger->log("Warning: Unable to connect to map server");
throw "Unable to connect to map server";
return;
}
@@ -182,13 +182,13 @@ void map_start()
startX = get_x(RFIFOP(6));
startY = get_y(RFIFOP(6));
int direction = get_direction(RFIFOP(6));
- logger.log("Protocol: Player start position: (%d, %d), Direction: %d",
+ logger->log("Protocol: Player start position: (%d, %d), Direction: %d",
startX, startY, direction);
RFIFOSKIP(11);
} else if (0x0081) {
- logger.log("Warning: Map server D/C");
+ logger->log("Warning: Map server D/C");
} else {
- logger.error("Unknown packet: map_start");
+ logger->error("Unknown packet: map_start");
}
// Send "map loaded"
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 5114d1d3..1e186d7b 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -76,7 +76,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, int flags)
// Check if the file was opened and return the appropriate value.
if (!image) {
- logger.log("Error: Image convert failed.");
+ logger->log("Error: Image convert failed.");
return NULL;
}
@@ -101,7 +101,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, int flags)
rmask, gmask, bmask, amask);
if (formatImage == NULL) {
- logger.log("Error", "Image load failed: not enough memory");
+ logger->log("Error", "Image load failed: not enough memory");
}
SDL_Surface *image = SDL_ConvertSurface(
@@ -149,7 +149,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, int flags)
GLuint texture;
glGenTextures(1, &texture);
- logger.log("Binding texture %d (%dx%d)", texture, realWidth, realHeight);
+ logger->log("Binding texture %d (%dx%d)", texture, realWidth, realHeight);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(
GL_TEXTURE_2D, 0, 4,
@@ -189,7 +189,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, int flags)
errmsg = "GL_OUT_OF_MEMORY";
break;
}
- logger.log("Error: Image GL import failed: %s", errmsg.c_str());
+ logger->log("Error: Image GL import failed: %s", errmsg.c_str());
return NULL;
}
diff --git a/src/resources/itemmanager.cpp b/src/resources/itemmanager.cpp
index ecccd20c..a3438241 100644
--- a/src/resources/itemmanager.cpp
+++ b/src/resources/itemmanager.cpp
@@ -42,18 +42,18 @@ ItemManager::ItemManager()
std::fstream dbFile;
dbFile.open(TMW_DATADIR "data/items.xml", std::ios::in);
if (!dbFile.is_open()) {
- logger.log("Cannot find item database!");
+ logger->log("Cannot find item database!");
return;
}
dbFile.close();
-
+
xmlDocPtr doc = xmlParseFile(TMW_DATADIR "data/items.xml");
if (doc) {
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) {
- logger.log("Warning: Not a valid database file!");
+ logger->log("Warning: Not a valid database file!");
} else {
for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
@@ -84,7 +84,7 @@ ItemManager::ItemManager()
prop = xmlGetProp(node, BAD_CAST "slot");
int slot = atoi((const char*)prop);
xmlFree(prop);
-
+
ItemInfo *itemInfo = new ItemInfo();
itemInfo->setImage(image);
itemInfo->setArt(art);
@@ -94,20 +94,20 @@ ItemManager::ItemManager()
itemInfo->setWeight(weight);
itemInfo->setSlot(slot);
db[id] = itemInfo;
-
- /*logger.log("Item: %i %i %i %s %s %i %i %i", id,
+
+ /*logger->log("Item: %i %i %i %s %s %i %i %i", id,
getImage(id), getArt(id), getName(id).c_str(),
getDescription(id).c_str(), getType(id), getWeight(id),
getSlot(id));*/
}
}
}
-
+
xmlFreeDoc(doc);
} else {
- logger.log("Error while parsing item database!");
+ logger->log("Error while parsing item database!");
}
-
+
unknown = new ItemInfo();
unknown->setName("Unknown item");
}
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 11deacbf..d5d30e79 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -62,7 +62,7 @@ Map *MapReader::readMap(const std::string &filename)
std::fstream fin;
fin.open(name.c_str(), std::ios::in);
if (!fin.is_open()) {
- logger.log("No such file!");
+ logger->log("No such file!");
return NULL;
}
fin.close();
@@ -73,14 +73,14 @@ Map *MapReader::readMap(const std::string &filename)
xmlNodePtr node = xmlDocGetRootElement(doc);
if (!node || !xmlStrEqual(node->name, BAD_CAST "map")) {
- logger.log("Warning: Not a map file (%s)!", filename.c_str());
+ logger->log("Warning: Not a map file (%s)!", filename.c_str());
return NULL;
}
return readMap(node, filename);
xmlFreeDoc(doc);
} else {
- logger.log("Error while parsing map file (%s)!", filename.c_str());
+ logger->log("Error while parsing map file (%s)!", filename.c_str());
}
return NULL;
@@ -115,7 +115,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path)
}
else if (xmlStrEqual(node->name, BAD_CAST "layer"))
{
- logger.log("- Loading layer %d", layerNr);
+ logger->log("- Loading layer %d", layerNr);
readLayer(node, map, layerNr);
layerNr++;
}
@@ -150,7 +150,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
xmlFree(encoding);
if (compression) {
- logger.log("Warning: no layer compression supported!");
+ logger->log("Warning: no layer compression supported!");
xmlFree(compression);
return;
}
@@ -228,7 +228,7 @@ Tileset* MapReader::readTileset(
xmlNodePtr node, const std::string &path, Map *map)
{
if (xmlHasProp(node, BAD_CAST "source")) {
- logger.log("Warning: External tilesets not supported yet.");
+ logger->log("Warning: External tilesets not supported yet.");
return NULL;
}
@@ -259,7 +259,7 @@ Tileset* MapReader::readTileset(
return set;
}
else {
- logger.log("Warning: Failed to load tileset (%s)", source);
+ logger->log("Warning: Failed to load tileset (%s)", source);
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index ba990734..d4a3a037 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -68,7 +68,7 @@ ResourceManager::~ResourceManager()
}
resources.clear();
- logger.log("ResourceManager::~ResourceManager() cleaned up %d references "
+ logger->log("ResourceManager::~ResourceManager() cleaned up %d references "
"to %d resources", danglingReferences, danglingResources);
}
@@ -84,7 +84,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
return resIter->second.resource;
}
- logger.log("ResourceManager::get(%s)", idPath.c_str());
+ logger->log("ResourceManager::get(%s)", idPath.c_str());
Resource *resource = NULL;
@@ -92,7 +92,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
switch (type)
{
case MAP:
- logger.log("Warning: Map resource not supported.");
+ logger->log("Warning: Map resource not supported.");
break;
case MUSIC:
{
@@ -109,7 +109,7 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
free(buffer);
}
else {
- logger.log("Warning: resource doesn't exist!");
+ logger->log("Warning: resource doesn't exist!");
}
}
break;
@@ -128,15 +128,15 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
free(buffer);
}
else {
- logger.log("Warning: resource doesn't exist!");
+ logger->log("Warning: resource doesn't exist!");
}
}
break;
case SCRIPT:
- logger.log("Warning: Script resource not supported.");
+ logger->log("Warning: Script resource not supported.");
break;
case TILESET:
- logger.log("Warning: Tileset resource not supported.");
+ logger->log("Warning: Tileset resource not supported.");
break;
case SOUND_EFFECT:
{
@@ -153,12 +153,12 @@ Resource* ResourceManager::get(const E_RESOURCE_TYPE &type,
free(buffer);
}
else {
- logger.log("Warning: resource doesn't exist!");
+ logger->log("Warning: resource doesn't exist!");
}
}
break;
default:
- logger.log("Warning: Unknown resource type");
+ logger->log("Warning: Unknown resource type");
break;
}
@@ -231,7 +231,7 @@ void ResourceManager::searchAndAddZipFiles()
std::string filePath = std::string("data/") +
std::string(findFileInfo.name);
- logger.log("Adding to PhysicsFS: %s", findFileInfo.name);
+ logger->log("Adding to PhysicsFS: %s", findFileInfo.name);
// Add the zip file to our PhysicsFS search path
PHYSFS_addToSearchPath(filePath.c_str(), 1);
@@ -264,7 +264,7 @@ void ResourceManager::searchAndAddZipFiles()
std::string filePath = std::string(programPath) +
std::string("/") + std::string(direntry->d_name);
- logger.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);
@@ -279,7 +279,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
{
// If the file doesn't exist indicate failure
if (!PHYSFS_exists(fileName.c_str())) {
- logger.log("Warning: %s not found!", fileName.c_str());
+ logger->log("Warning: %s not found!", fileName.c_str());
return NULL;
}
@@ -288,7 +288,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
// If the handler is an invalid pointer indicate failure
if (file == NULL) {
- logger.log("Warning: %s failed to load!", fileName.c_str());
+ logger->log("Warning: %s failed to load!", fileName.c_str());
return NULL;
}
diff --git a/src/sound.cpp b/src/sound.cpp
index 332fc3a2..78e949cb 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -43,10 +43,10 @@ void Sound::init()
// Don't initialize sound engine twice
if (installed) return;
- logger.log("Sound::init() Initializing sound...");
+ logger->log("Sound::init() Initializing sound...");
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
- logger.log("Sound::init() Failed to initialize audio subsystem");
+ logger->log("Sound::init() Failed to initialize audio subsystem");
return;
}
@@ -57,7 +57,7 @@ void Sound::init()
if (res >= 0) {
Mix_AllocateChannels(16);
} else {
- logger.log("Sound::init Could not initialize audio: %s",
+ logger->log("Sound::init Could not initialize audio: %s",
Mix_GetError());
return;
}
@@ -93,18 +93,18 @@ void Sound::info() {
case AUDIO_S16MSB: format = "S16MSB"; break;
}
- logger.log("Sound::info() SDL_mixer: %i.%i.%i (compiled)",
+ logger->log("Sound::info() SDL_mixer: %i.%i.%i (compiled)",
compiledVersion.major,
compiledVersion.minor,
compiledVersion.patch);
- logger.log("Sound::info() SDL_mixer: %i.%i.%i (linked)",
+ logger->log("Sound::info() SDL_mixer: %i.%i.%i (linked)",
linkedVersion->major,
linkedVersion->minor,
linkedVersion->patch);
- logger.log("Sound::info() Driver: %s", driver);
- logger.log("Sound::init() Format: %s", format);
- logger.log("Sound::init() Rate: %i", rate);
- logger.log("Sound::init() Channels: %i", channels);
+ logger->log("Sound::info() Driver: %s", driver);
+ logger->log("Sound::init() Format: %s", format);
+ logger->log("Sound::init() Rate: %i", rate);
+ logger->log("Sound::init() Channels: %i", channels);
}
void Sound::setMusicVolume(int volume)
@@ -131,14 +131,14 @@ void Sound::playMusic(const char *path, int loop)
stopMusic();
}
- logger.log("Sound::startMusic() Playing \"%s\" %i times", path, loop);
+ logger->log("Sound::startMusic() Playing \"%s\" %i times", path, loop);
music = Mix_LoadMUS(path);
if (music) {
Mix_PlayMusic(music, loop);
}
else {
- logger.log("Sound::startMusic() Warning: error loading file.");
+ logger->log("Sound::startMusic() Warning: error loading file.");
}
}
@@ -146,7 +146,7 @@ void Sound::stopMusic()
{
if (!installed) return;
- logger.log("Sound::stopMusic()");
+ logger->log("Sound::stopMusic()");
if (music != NULL) {
Mix_HaltMusic();
@@ -163,7 +163,7 @@ void Sound::fadeInMusic(const char *path, int loop, int ms)
stopMusic();
}
- logger.log("Sound::fadeInMusic() Fading \"%s\" %i times (%i ms)", path,
+ logger->log("Sound::fadeInMusic() Fading \"%s\" %i times (%i ms)", path,
loop, ms);
music = Mix_LoadMUS(path);
@@ -171,7 +171,7 @@ void Sound::fadeInMusic(const char *path, int loop, int ms)
Mix_FadeInMusic(music, loop, ms);
}
else {
- logger.log("Sound::fadeInMusic() Warning: error loading file.");
+ logger->log("Sound::fadeInMusic() Warning: error loading file.");
}
}
@@ -179,7 +179,7 @@ void Sound::fadeOutMusic(int ms)
{
if (!installed) return;
- logger.log("Sound::fadeOutMusic() Fading-out (%i ms)", ms);
+ logger->log("Sound::fadeOutMusic() Fading-out (%i ms)", ms);
if (music != NULL) {
Mix_FadeOutMusic(ms);
@@ -196,7 +196,7 @@ void Sound::playSfx(const char *path)
SoundEffect *sample = resman->getSoundEffect(path);
if (sample) {
sample->play(0, 120);
- logger.log("Sound::playSfx() Playing: %s", path);
+ logger->log("Sound::playSfx() Playing: %s", path);
}
}
@@ -204,5 +204,5 @@ void Sound::close()
{
installed = false;
Mix_CloseAudio();
- logger.log("Sound::close() Shutting down sound...");
+ logger->log("Sound::close() Shutting down sound...");
}