From a8a90f2df98e13971566af63567e31da4666b1c9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 26 Nov 2006 21:51:01 +0000 Subject: Higher precision log timestamps, some more logging and support for TGA images. --- src/graphics.cpp | 3 ++ src/gui/gui.cpp | 1 + src/log.cpp | 20 ++++++++----- src/main.cpp | 24 ++++++++------- src/openglgraphics.cpp | 3 ++ src/resources/equipmentdb.cpp | 1 + src/resources/image.cpp | 10 ++++++- src/resources/itemdb.cpp | 63 +++++++++++++++++---------------------- src/resources/resourcemanager.cpp | 1 + 9 files changed, 70 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/graphics.cpp b/src/graphics.cpp index 2757214a..b70fdeea 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -41,6 +41,9 @@ Graphics::~Graphics() bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { + logger->log("Setting video mode %dx%d %s", + w, h, fs ? "fullscreen" : "windowed"); + int displayFlags = SDL_ANYFORMAT; mFullscreen = fs; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index df2bbaf0..f148ef38 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -93,6 +93,7 @@ Gui::Gui(Graphics *graphics): mPlayerFollowMouse(false), mWalkTime(0) { + logger->log("Initializing GUI..."); // Set graphics setGraphics(graphics); diff --git a/src/log.cpp b/src/log.cpp index 3d101d29..347fd416 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -30,6 +30,7 @@ #include #include #include +#include Logger::~Logger() @@ -60,7 +61,6 @@ void Logger::log(const char *log_text, ...) 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); @@ -68,19 +68,23 @@ void Logger::log(const char *log_text, ...) va_end(ap); // Get the current system time - time(&t); + timeval tv; + gettimeofday(&tv, NULL); // Print the log entry std::stringstream timeStr; timeStr << "[" - << ((((t / 60) / 60) % 24 < 10) ? "0" : "") - << (int)(((t / 60) / 60) % 24) + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") + << (int)(((tv.tv_sec / 60) / 60) % 24) << ":" - << (((t / 60) % 60 < 10) ? "0" : "") - << (int)((t / 60) % 60) + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") + << (int)((tv.tv_sec / 60) % 60) << ":" - << ((t % 60 < 10) ? "0" : "") - << (int)(t % 60) + << ((tv.tv_sec % 60 < 10) ? "0" : "") + << (int)(tv.tv_sec % 60) + << "." + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") + << (int)((tv.tv_usec / 10000) % 100) << "] "; mLogFile << timeStr.str() << buf << std::endl; diff --git a/src/main.cpp b/src/main.cpp index 0faf5c12..f1a4ed88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -137,17 +137,6 @@ struct Options */ void init_engine(const Options &options) { - // Initialize SDL - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { - std::cerr << "Could not initialize SDL: " << - SDL_GetError() << std::endl; - exit(1); - } - atexit(SDL_Quit); - - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - std::string homeDir = ""; #if !(defined __USE_UNIX98 || defined __FreeBSD__) // In Windows and other systems we currently store data next to executable. @@ -169,6 +158,18 @@ void init_engine(const Options &options) // Set log file logger->setLogFile(homeDir + std::string("/tmw.log")); + // Initialize SDL + logger->log("Initializing SDL..."); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { + std::cerr << "Could not initialize SDL: " << + SDL_GetError() << std::endl; + exit(1); + } + atexit(SDL_Quit); + + SDL_EnableUNICODE(1); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + ResourceManager *resman = ResourceManager::getInstance(); if (!resman->setWriteDir(homeDir)) { @@ -195,6 +196,7 @@ void init_engine(const Options &options) resman->addToSearchPath(TMW_DATADIR "data", true); // Fill configuration with defaults + logger->log("Initializing configuration..."); config.setValue("host", "animesites.de"); config.setValue("port", 6901); config.setValue("hwaccel", 0); diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2a6c931d..acc0fbb9 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -50,6 +50,9 @@ OpenGLGraphics::~OpenGLGraphics() bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { + logger->log("Setting video mode %dx%d %s", + w, h, fs ? "fullscreen" : "windowed"); + int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; mFullscreen = fs; diff --git a/src/resources/equipmentdb.cpp b/src/resources/equipmentdb.cpp index 8bbfc177..78ae3b6a 100644 --- a/src/resources/equipmentdb.cpp +++ b/src/resources/equipmentdb.cpp @@ -40,6 +40,7 @@ namespace void EquipmentDB::load() { + logger->log("Initializing equipment database..."); mUnknown.setSprite("error.xml", 0); mUnknown.setSprite("error.xml", 1); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index eb3a2409..48818f6f 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -68,9 +68,17 @@ Image* Image::load(void *buffer, unsigned int bufferSize, { // Load the raw file data from the buffer in an RWops structure SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize); + SDL_Surface *tmpImage; // Use SDL_Image to load the raw image data and have it free the data - SDL_Surface *tmpImage = IMG_Load_RW(rw, 1); + if (!idPath.compare(idPath.length() - 4, 4, ".tga")) + { + tmpImage = IMG_LoadTyped_RW(rw, 1, const_cast("TGA")); + } + else + { + tmpImage = IMG_Load_RW(rw, 1); + } if (tmpImage == NULL) { logger->log("Error, image load failed: %s", IMG_GetError()); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index d57a3780..b91e34cc 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -31,13 +31,8 @@ #include "../log.h" #include "../utils/dtor.h" +#include "../utils/xml.h" -#define READ_PROP(node, prop, name, target, cast) \ - prop = xmlGetProp(node, BAD_CAST name); \ - if (prop) { \ - target = cast((const char*)prop); \ - xmlFree(prop); \ - } namespace { ItemDB::ItemInfos mItemInfos; @@ -47,6 +42,7 @@ namespace void ItemDB::load() { + logger->log("Initializing item database..."); mUnknown.setName("Unknown item"); ResourceManager *resman = ResourceManager::getInstance(); @@ -54,7 +50,7 @@ void ItemDB::load() char *data = (char*)resman->loadFile("items.xml", size); if (!data) { - logger->error("Item Manager: Could not find items.xml!"); + logger->error("ItemDB: Could not find items.xml!"); } xmlDocPtr doc = xmlParseMemory(data, size); @@ -62,35 +58,31 @@ void ItemDB::load() if (!doc) { - logger->error("Item Manager: Error while parsing item database (items.xml)!"); + logger->error("ItemDB: Error while parsing item database (items.xml)!"); } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "items")) { - logger->error("Item Manager: items.xml is not a valid database file!"); + logger->error("ItemDB: items.xml is not a valid database file!"); } for (node = node->xmlChildrenNode; node != NULL; node = node->next) { - int id = 0, art = 0, type = 0, weight = 0, slot = 0; - std::string name = "", description = "", effect = "", image = ""; - if (!xmlStrEqual(node->name, BAD_CAST "item")) { continue; } - xmlChar *prop = NULL; - READ_PROP(node, prop, "id", id, atoi); - READ_PROP(node, prop, "image", image, ); - READ_PROP(node, prop, "art", art, atoi); - READ_PROP(node, prop, "name", name, ); - READ_PROP(node, prop, "description", description, ); - READ_PROP(node, prop, "effect", effect, ); - READ_PROP(node, prop, "type", type, atoi); - READ_PROP(node, prop, "weight", weight, atoi); - READ_PROP(node, prop, "slot", slot, atoi); + int id = XML::getProperty(node, "id", 0); + int art = XML::getProperty(node, "art", 0); + int type = XML::getProperty(node, "type", 0); + int weight = XML::getProperty(node, "weight", 0); + int slot = XML::getProperty(node, "slot", 0); + std::string name = XML::getProperty(node, "name", ""); + std::string image = XML::getProperty(node, "image", ""); + std::string description = XML::getProperty(node, "description", ""); + std::string effect = XML::getProperty(node, "effect", ""); if (id && name != "") { @@ -109,53 +101,52 @@ void ItemDB::load() if (id == 0) { - logger->log("Item Manager: An item has no ID in items.xml!"); + logger->log("ItemDB: An item has no ID in items.xml!"); } if (name == "") { - logger->log("Item Manager: An item has no name in items.xml!"); + logger->log("ItemDB: Missing name for item %d!", id); } if (image == "") { - logger->log("Item Manager: Missing image parameter for item: %i. %s", + logger->log("ItemDB: Missing image parameter for item: %i. %s", id, name.c_str()); } - /*if (art == 0) + /* + if (art == 0) { logger->log("Item Manager: Missing art parameter for item: %i. %s", id, name.c_str()); - }*/ + } if (description == "") { - logger->log("Item Manager: Missing description parameter for item: %i. %s", + logger->log("ItemDB: Missing description parameter for item: %i. %s", id, name.c_str()); } if (effect == "") { - logger->log("Item Manager: Missing effect parameter for item: %i. %s", + logger->log("ItemDB: Missing effect parameter for item: %i. %s", id, name.c_str()); } - /*if (type == 0) + if (type == 0) { logger->log("Item Manager: Missing type parameter for item: %i. %s", id, name.c_str()); - }*/ + } + */ if (weight == 0) { logger->log("Item Manager: Missing weight parameter for item: %i. %s", id, name.c_str()); } + /* if (slot == 0) { logger->log("Item Manager: Missing slot parameter for item: %i. %s", id, name.c_str()); } - - /*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); diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index aabd1ccc..9ad18db3 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -41,6 +41,7 @@ ResourceManager *ResourceManager::instance = NULL; ResourceManager::ResourceManager() { + logger->log("Initializing resource manager..."); } ResourceManager::~ResourceManager() -- cgit v1.2.3-70-g09d2