From 0f0e6a3689e5d810ec55b68ff455210b1081a021 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 25 Mar 2006 17:29:08 +0000 Subject: [PATCH] Unified Messaging Subsystem SVN-Revision: 3118 --- src/audio/sound_file.cpp | 3 +- src/audio/sound_manager.cpp | 17 ++++++----- src/audio/stream_sound_source.cpp | 3 +- src/badguy/badguy.cpp | 3 +- src/badguy/flame.cpp | 3 +- src/collision_grid.cpp | 15 +++++----- src/collision_grid_iterator.hpp | 3 +- src/control/joystickkeyboardcontroller.cpp | 29 ++++++++---------- src/file_system.cpp | 5 ++-- src/game_session.cpp | 16 +++++----- src/level.cpp | 5 ++-- src/level_subset.cpp | 5 ++-- src/lisp/writer.cpp | 11 +++---- src/main.cpp | 29 ++++++++---------- src/msg.hpp | 44 +++++++++++++++++++++++++++ src/object/ambient_sound.cpp | 5 ++-- src/object/anchor_point.cpp | 9 +++--- src/object/background.cpp | 5 ++-- src/object/block.cpp | 7 +++-- src/object/camera.cpp | 3 +- src/object/infoblock.cpp | 3 +- src/object/level_time.cpp | 5 ++-- src/object/path.cpp | 3 +- src/object/platform.cpp | 7 +++-- src/object/player.cpp | 5 ++-- src/object/powerup.cpp | 5 ++-- src/object/text_object.cpp | 3 +- src/object/tilemap.cpp | 11 ++++--- src/physfs/physfs_sdl.cpp | 3 +- src/player_status.cpp | 5 ++-- src/scripting/functions.cpp | 9 +++--- src/scripting/script_interpreter.cpp | 3 +- src/sector.cpp | 15 +++++----- src/spawn_point.cpp | 5 ++-- src/sprite/sprite.cpp | 13 ++++---- src/sprite/sprite_data.cpp | 3 +- src/sprite/sprite_manager.cpp | 11 +++---- src/textscroller.cpp | 12 ++++---- src/tile.cpp | 4 ++- src/tile_manager.cpp | 7 +++-- src/tile_manager.hpp | 3 +- src/tinygettext/tinygettext.cpp | 48 ++++++++++++++++-------------- src/title.cpp | 11 +++---- src/video/color.hpp | 4 +-- src/video/font.cpp | 9 ++---- src/video/texture_manager.cpp | 5 ++-- src/worldmap.cpp | 33 ++++++++++---------- 47 files changed, 264 insertions(+), 201 deletions(-) create mode 100644 src/msg.hpp diff --git a/src/audio/sound_file.cpp b/src/audio/sound_file.cpp index 0012661cf..9a0506bad 100644 --- a/src/audio/sound_file.cpp +++ b/src/audio/sound_file.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "msg.hpp" class WavSoundFile : public SoundFile { @@ -54,7 +55,7 @@ WavSoundFile::WavSoundFile(PHYSFS_file* file) if(PHYSFS_read(file, magic, sizeof(magic), 1) != 1) throw std::runtime_error("Couldn't read file magic (not a wave file)"); if(strncmp(magic, "RIFF", 4) != 0) { - printf("MAGIC: %4s.\n", magic); + msg_debug("MAGIC: " << magic); throw std::runtime_error("file is not a RIFF wav file"); } diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index a671c8c3e..1078ff760 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -8,6 +8,7 @@ #include "sound_file.hpp" #include "sound_source.hpp" #include "stream_sound_source.hpp" +#include "msg.hpp" SoundManager* sound_manager = 0; @@ -33,7 +34,7 @@ SoundManager::SoundManager() } catch(std::exception& e) { device = 0; context = 0; - std::cerr << "Couldn't initialize audio device:" << e.what() << "\n"; + msg_warning("Couldn't initialize audio device:" << e.what()); print_openal_version(); } } @@ -128,7 +129,7 @@ SoundManager::play(const std::string& filename, const Vector& pos) source->play(); sources.push_back(source); } catch(std::exception& e) { - std::cout << "Couldn't play sound " << filename << ": " << e.what() << "\n"; + msg_warning("Couldn't play sound " << filename << ": " << e.what()); } } @@ -197,8 +198,8 @@ SoundManager::play_music(const std::string& filename, bool fade) delete music_source; music_source = newmusic.release(); } catch(std::exception& e) { - std::cerr << "Couldn't play music file '" << filename << "': " - << e.what() << "\n"; + msg_warning("Couldn't play music file '" << filename << "': " + << e.what()); } } @@ -280,10 +281,10 @@ SoundManager::get_sample_format(SoundFile* file) void SoundManager::print_openal_version() { - std::cout << "OpenAL Vendor: " << alGetString(AL_VENDOR) << "\n" - << "OpenAL Version: " << alGetString(AL_VERSION) << "\n" - << "OpenAL Renderer: " << alGetString(AL_RENDERER) << "\n" - << "OpenAl Extensions: " << alGetString(AL_EXTENSIONS) << "\n"; + msg_info("OpenAL Vendor: " << alGetString(AL_VENDOR)); + msg_info("OpenAL Version: " << alGetString(AL_VERSION)); + msg_info("OpenAL Renderer: " << alGetString(AL_RENDERER)); + msg_info("OpenAl Extensions: " << alGetString(AL_EXTENSIONS)); } void diff --git a/src/audio/stream_sound_source.cpp b/src/audio/stream_sound_source.cpp index 3a10e6c59..6918a165b 100644 --- a/src/audio/stream_sound_source.cpp +++ b/src/audio/stream_sound_source.cpp @@ -6,6 +6,7 @@ #include "stream_sound_source.hpp" #include "sound_manager.hpp" #include "sound_file.hpp" +#include "msg.hpp" StreamSoundSource::StreamSoundSource() : file(0), fade_state(NoFading), looping(false) @@ -54,7 +55,7 @@ StreamSoundSource::update() return; // we might have to restart the source if we had a buffer underrun - std::cerr << "Restarting audio source because of buffer underrun.\n"; + msg_info("Restarting audio source because of buffer underrun"); play(); } diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index c364556a2..85d28953f 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -25,6 +25,7 @@ #include "tile.hpp" #include "statistics.hpp" #include "game_session.hpp" +#include "msg.hpp" static const float SQUISH_TIME = 2; static const float X_OFFSCREEN_DISTANCE = 1600; @@ -104,7 +105,7 @@ BadGuy::deactivate() void BadGuy::save(lisp::Writer& ) { - std::cout << "Warning: tried to write out a generic badguy." << std::endl; + msg_warning("tried to write out a generic badguy"); } void diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index d9b0759f9..da6c0264b 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -20,6 +20,7 @@ #include #include "flame.hpp" +#include "msg.hpp" Flame::Flame(const lisp::Lisp& reader) : angle(0), radius(100), speed(2), source(0) @@ -74,7 +75,7 @@ Flame::activate() delete source; source = sound_manager->create_sound_source("sounds/flame.wav"); if(!source) { - std::cerr << "Couldn't start flame sound.\n"; + msg_warning("Couldn't start flame sound"); return; } source->set_position(get_pos()); diff --git a/src/collision_grid.cpp b/src/collision_grid.cpp index e7241cc09..fd3ad33d5 100644 --- a/src/collision_grid.cpp +++ b/src/collision_grid.cpp @@ -21,6 +21,7 @@ #include #include "collision_grid.hpp" +#include "msg.hpp" #include "collision.hpp" #include "sector.hpp" #include "collision_grid_iterator.hpp" @@ -75,7 +76,7 @@ CollisionGrid::add_object(MovingObject* object) int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + msg_warning("Object out of range: " << gridx << ", " << gridy); continue; } GridEntry* entry = new GridEntry; @@ -101,7 +102,7 @@ CollisionGrid::remove_object(MovingObject* object) assert(wrapper != 0); #else if(wrapper == 0) { - std::cerr << "Tried to remove nonexistant object!\n"; + msg_warning("Tried to remove nonexistant object"); return; } #endif @@ -113,7 +114,7 @@ CollisionGrid::remove_object(MovingObject* object) int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + msg_warning("Object out of range: " << gridx << ", " << gridy); continue; } remove_object_from_gridcell(gridy*cells_x + gridx, wrapper); @@ -135,7 +136,7 @@ CollisionGrid::move_object(ObjectWrapper* wrapper) int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + msg_warning("Object out of range: " << gridx << ", " << gridy); continue; } remove_object_from_gridcell(gridy*cells_x + gridx, wrapper); @@ -149,7 +150,7 @@ CollisionGrid::move_object(ObjectWrapper* wrapper) int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + msg_warning("Object out of range: " << gridx << ", " << gridy); continue; } @@ -212,7 +213,7 @@ CollisionGrid::collide_object(ObjectWrapper* wrapper) int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - //std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + //msg_warning("Object out of range: " << gridx << ", " << gridy); continue; } @@ -290,6 +291,6 @@ CollisionGrid::remove_object_from_gridcell(int gridcell, ObjectWrapper* wrapper) entry = entry->next; }; - std::cerr << "Couldn't find object in cell.\n"; + msg_warning("Couldn't find object in cell"); } diff --git a/src/collision_grid_iterator.hpp b/src/collision_grid_iterator.hpp index 79acb00a9..6c2506be1 100644 --- a/src/collision_grid_iterator.hpp +++ b/src/collision_grid_iterator.hpp @@ -21,6 +21,7 @@ #define __COLLISION_GRID_ITERATOR_H__ #include "math/rect.hpp" +#include "msg.hpp" class CollisionGrid; @@ -51,7 +52,7 @@ public: entry = 0; if(start_x >= end_x) { - printf("bad region.\n"); + msg_debug("bad region"); y = 0; end_y = 0; return; diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index c840019a4..a68d09c7d 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -21,6 +21,7 @@ #include #include "joystickkeyboardcontroller.hpp" +#include "msg.hpp" #include "gui/menu.hpp" #include "gettext.hpp" #include "lisp/lisp.hpp" @@ -78,12 +79,12 @@ JoystickKeyboardController::JoystickKeyboardController() SDL_Joystick* joystick = SDL_JoystickOpen(i); bool good = true; if(SDL_JoystickNumButtons(joystick) < 2) { - std::cerr << "Joystick " << i << " has less than 2 buttons.\n"; + msg_warning("Joystick " << i << " has less than 2 buttons"); good = false; } if(SDL_JoystickNumAxes(joystick) < 2 && SDL_JoystickNumHats(joystick) == 0) { - std::cerr << "Joystick " << i << " has less than 2 axes and no hat.\n"; + msg_warning("Joystick " << i << " has less than 2 axes and no hat"); good = false; } if(!good) { @@ -152,7 +153,7 @@ JoystickKeyboardController::read(const lisp::Lisp& lisp) map->get("key", key); map->get("control", control); if(key < SDLK_FIRST || key >= SDLK_LAST) { - std::cerr << "Invalid key '" << key << "' in keymap.\n"; + msg_warning("Invalid key '" << key << "' in keymap"); continue; } @@ -162,12 +163,12 @@ JoystickKeyboardController::read(const lisp::Lisp& lisp) break; } if(controlNames[i] == 0) { - std::cerr << "Invalid control '" << control << "' in keymap.\n"; + msg_warning("Invalid control '" << control << "' in keymap"); continue; } keymap.insert(std::make_pair((SDLKey) key, (Control) i)); } else { - std::cerr << "Invalid lisp element '" << iter.item() << "' in keymap.\n"; + msg_warning("Invalid lisp element '" << iter.item() << "' in keymap"); } } } @@ -188,7 +189,7 @@ JoystickKeyboardController::read(const lisp::Lisp& lisp) map->get("button", button); map->get("control", control); if(button < 0 || button >= max_joybuttons) { - std::cerr << "Invalid button '" << button << "' in buttonmap.\n"; + msg_warning("Invalid button '" << button << "' in buttonmap"); continue; } @@ -198,7 +199,7 @@ JoystickKeyboardController::read(const lisp::Lisp& lisp) break; } if(controlNames[i] == 0) { - std::cerr << "Invalid control '" << control << "' in buttonmap.\n"; + msg_warning("Invalid control '" << control << "' in buttonmap"); continue; } reset_joybutton(button, (Control) i); @@ -265,9 +266,7 @@ JoystickKeyboardController::process_event(const SDL_Event& event) // normal mode, find key in keymap KeyMap::iterator i = keymap.find(event.key.keysym.sym); if(i == keymap.end()) { -#ifdef DEBUG - std::cerr << "Pressed key without mapping.\n"; -#endif + msg_debug("Pressed key without mapping"); return; } Control control = i->second; @@ -346,10 +345,8 @@ JoystickKeyboardController::process_event(const SDL_Event& event) ButtonMap::iterator i = joy_button_map.find(event.jbutton.button); if(i == joy_button_map.end()) { -#ifdef DEBUG - std::cerr << "Unmapped joybutton " << (int) event.jbutton.button - << " pressed.\n"; -#endif + msg_debug("Unmapped joybutton " << (int) event.jbutton.button + << " pressed"); return; } @@ -523,9 +520,7 @@ bool JoystickKeyboardController::check_cheatcode(const std::string& cheatcode) { if(cheatcode.size() > sizeof(last_keys)) { -#ifdef DEBUG - std::cerr << "Cheat Code too long.\n"; -#endif + msg_debug("Cheat Code too long"); return false; } diff --git a/src/file_system.cpp b/src/file_system.cpp index 826d4b753..b60565663 100644 --- a/src/file_system.cpp +++ b/src/file_system.cpp @@ -1,10 +1,10 @@ #include +#include "msg.hpp" #include "file_system.hpp" #include #include -#include #include namespace FileSystem @@ -55,7 +55,8 @@ std::string normalize(const std::string& filename) if(pathelem == "..") { if(path_stack.empty()) { - std::cout << "Invalid '..' in path '" << filename << "'.\n"; + + msg_warning("Invalid '..' in path '" << filename << "'"); // push it into the result path so that the users sees his error... path_stack.push_back(pathelem); } else { diff --git a/src/game_session.cpp b/src/game_session.cpp index b0e61b20e..f495becf0 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -20,7 +20,6 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include "game_session.hpp" +#include "msg.hpp" #include "video/screen.hpp" #include "audio/sound_manager.hpp" #include "gui/menu.hpp" @@ -369,7 +369,7 @@ GameSession::try_cheats() tux.kill(tux.KILL); } if(main_controller->check_cheatcode("whereami")) { - std::cout << "You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y << "." << std::endl; + msg_info("You are at x " << tux.get_pos().x << ", y " << tux.get_pos().y); } #if 0 if(main_controller->check_cheatcode("grid")) { @@ -394,9 +394,9 @@ GameSession::try_cheats() // don't add points to stats though... } if(main_controller->check_cheatcode("camera")) { - std::cout << "Camera is at " + msg_info("Camera is at " << Sector::current()->camera->get_translation().x << "," - << Sector::current()->camera->get_translation().y << "\n"; + << Sector::current()->camera->get_translation().y); } } @@ -459,7 +459,7 @@ GameSession::update(float elapsed_time) if(newsector != "" && newspawnpoint != "") { Sector* sector = level->get_sector(newsector); if(sector == 0) { - std::cerr << "Sector '" << newsector << "' not found.\n"; + msg_warning("Sector '" << newsector << "' not found"); } sector->activate(newspawnpoint); sector->play_music(LEVEL_MUSIC); @@ -744,13 +744,13 @@ GameSession::start_sequence(const std::string& sequencename) } } else if(sequencename == "stoptux") { if(!end_sequence) { - std::cout << "WARNING: Final target reached without " - << "an active end sequence." << std::endl; + msg_warning("Final target reached without " + << "an active end sequence"); this->start_sequence("endsequence"); } end_sequence = ENDSEQUENCE_WAITING; } else { - std::cout << "Unknown sequence '" << sequencename << "'.\n"; + msg_warning("Unknown sequence '" << sequencename << "'"); } } diff --git a/src/level.cpp b/src/level.cpp index 6c87b816e..f589380d4 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -30,6 +30,7 @@ #include #include "video/screen.hpp" +#include "msg.hpp" #include "lisp/parser.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" @@ -79,7 +80,7 @@ Level::load(const std::string& filepath) if(token == "version") { iter.value()->get(version); if(version > 2) { - std::cerr << "Warning: level format newer than application.\n"; + msg_warning("level format newer than application"); } } else if(token == "name") { iter.value()->get(name); @@ -101,7 +102,7 @@ Level::load(const std::string& filepath) sector->parse(*(iter.lisp())); add_sector(sector); } else { - std::cerr << "Unknown token '" << token << "' in level file.\n"; + msg_warning("Unknown token '" << token << "' in level file"); continue; } } diff --git a/src/level_subset.cpp b/src/level_subset.cpp index b7d590e30..e7c4ac7a9 100644 --- a/src/level_subset.cpp +++ b/src/level_subset.cpp @@ -25,6 +25,7 @@ #include #include #include "level.hpp" +#include "msg.hpp" #include "resources.hpp" #include "file_system.hpp" #include "video/surface.hpp" @@ -105,8 +106,8 @@ void LevelSubset::load(const std::string& subset) std::string path = subset + "/"; char** files = PHYSFS_enumerateFiles(path.c_str()); if(!files) { - std::cerr << "Warning: Couldn't read subset dir '" - << path << "'.\n"; + msg_warning("Couldn't read subset dir '" + << path << "'"); return; } diff --git a/src/lisp/writer.cpp b/src/lisp/writer.cpp index 396978966..ee0633c6b 100644 --- a/src/lisp/writer.cpp +++ b/src/lisp/writer.cpp @@ -23,6 +23,7 @@ #include "writer.hpp" #include "physfs/physfs_stream.hpp" +#include "msg.hpp" namespace lisp { @@ -44,7 +45,7 @@ Writer::Writer(std::ostream* newout) Writer::~Writer() { if(lists.size() > 0) { - std::cerr << "Warning: Not all sections closed in lispwriter!\n"; + msg_warning("Not all sections closed in lispwriter"); } if(out_owned) delete out; @@ -70,13 +71,13 @@ void Writer::end_list(const std::string& listname) { if(lists.size() == 0) { - std::cerr << "Trying to close list '" << listname - << "', which is not open.\n"; + msg_warning("Trying to close list '" << listname + << "', which is not open"); return; } if(lists.back() != listname) { - std::cerr << "Warning: trying to close list '" << listname - << "' while list '" << lists.back() << "' is open.\n"; + msg_warning("trying to close list '" << listname + << "' while list '" << lists.back() << "' is open"); return; } lists.pop_back(); diff --git a/src/main.cpp b/src/main.cpp index 0adba3236..47af8c47f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,10 +20,10 @@ #include #include +#include "msg.hpp" #include "main.hpp" #include -#include #include #include #include @@ -61,8 +61,7 @@ static void init_config() try { config->load(); } catch(std::exception& e) { - std::cerr << "Couldn't load config file: " << e.what() << "\n"; - std::cerr << "Using default settings.\n"; + msg_info("Couldn't load config file: " << e.what() << ", using default settings"); } } @@ -145,8 +144,8 @@ static void init_physfs(const char* argv0) if(f) { fclose(f); if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) { - std::cout << "Warning: Couldn't add '" << dir - << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n"; + msg_warning("Couldn't add '" << dir + << "' to physfs searchpath: " << PHYSFS_getLastError()); } else { sourcedir = true; } @@ -163,8 +162,8 @@ static void init_physfs(const char* argv0) datadir = APPDATADIR; #endif if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) { - std::cout << "Couldn't add '" << datadir - << "' to physfs searchpath: " << PHYSFS_getLastError() << "\n"; + msg_warning("Couldn't add '" << datadir + << "' to physfs searchpath: " << PHYSFS_getLastError()); } #endif } @@ -174,7 +173,7 @@ static void init_physfs(const char* argv0) //show search Path for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++) - printf("[%s] is in the search path.\n", *i); + msg_info("[" << *i << "] is in the search path"); } static void print_usage(const char* argv0) @@ -236,13 +235,12 @@ static void parse_commandline(int argc, char** argv) print_usage(argv[0]); throw graceful_shutdown(); } else if(arg == "--version") { - std::cerr << PACKAGE_NAME << " " << PACKAGE_VERSION << "\n"; + msg_info(PACKAGE_NAME << " " << PACKAGE_VERSION); throw graceful_shutdown(); } else if(arg[0] != '-') { config->start_level = arg; } else { - std::cerr << "Unknown option '" << arg << "'.\n"; - std::cerr << "Use --help to see a list of options.\n"; + msg_warning("Unknown option '" << arg << "'. Use --help to see a list of options"); } } @@ -341,7 +339,7 @@ void init_video() } #ifdef DEBUG else { - std::cerr << "Warning: Couldn't find icon 'images/engine/icons/supertux.xpm'.\n"; + msg_warning("Couldn't find icon 'images/engine/icons/supertux.xpm'"); } #endif @@ -433,8 +431,7 @@ static inline void timelog(const char* component) Uint32 current_ticks = SDL_GetTicks(); if(last_timelog_component != 0) { - printf("Component '%s' finished after %f seconds\n", - last_timelog_component, (current_ticks - last_timelog_ticks) / 1000.0); + msg_info("Component '" << last_timelog_component << "' finished after " << (current_ticks - last_timelog_ticks) / 1000.0 << " seconds"); } last_timelog_ticks = current_ticks; @@ -488,10 +485,10 @@ int main(int argc, char** argv) } } catch(graceful_shutdown& e) { } catch(std::exception& e) { - std::cerr << "Unexpected exception: " << e.what() << std::endl; + msg_fatal("Unexpected exception: " << e.what()); return 1; } catch(...) { - std::cerr << "Unexpected exception." << std::endl; + msg_fatal("Unexpected exception"); return 1; } diff --git a/src/msg.hpp b/src/msg.hpp new file mode 100644 index 000000000..7f7113dd2 --- /dev/null +++ b/src/msg.hpp @@ -0,0 +1,44 @@ +// $Id: debug.cpp 2650 2005-06-28 12:42:08Z sommer $ +// +// SuperTux Debug Helper Functions +// Copyright (C) 2006 Christoph Sommer +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#ifndef __SUPERTUX_DEBUG_H__ +#define __SUPERTUX_DEBUG_H__ + +#include +#include + +#ifdef DEBUG + +#define msg_debug(message) std::cerr << "[DEBUG] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl +#define msg_info(message) std::cout << "[INFO] " << message << std::endl +#define msg_warning(message) std::cerr << "[WARNING] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl +#define msg_fatal(message) std::cerr << "[FATAL] " << __FILE__ << " l." << __LINE__ << ": " << message << std::endl + +#else + +#define msg_debug(message) +#define msg_info(message) std::cout << message << std::endl +#define msg_warning(message) std::cerr << "Warning: " << message << std::endl +#define msg_fatal(message) std::cerr << "Fatal: " << message << std::endl + +#endif + +#endif + diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 3b8093e61..397409484 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -28,6 +28,7 @@ #include "sector.hpp" #include "audio/sound_manager.hpp" #include "audio/sound_source.hpp" +#include "msg.hpp" AmbientSound::AmbientSound(const lisp::Lisp& lisp) { @@ -43,7 +44,7 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) sample=""; if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) { - std::cerr << "No Position in ambient_sound" << std::endl; + msg_warning("No Position in ambient_sound"); } lisp.get("width" , dimension.x); @@ -131,7 +132,7 @@ AmbientSound::start_playing() currentvolume=targetvolume=1e-20; sound_source->play(); } catch(std::exception& e) { - std::cerr << "Couldn't play '" << sample << "': " << e.what() << "\n"; + msg_warning("Couldn't play '" << sample << "': " << e.what() << ""); delete sound_source; sound_source = 0; } diff --git a/src/object/anchor_point.cpp b/src/object/anchor_point.cpp index 10cdcdefa..c7f82ac9d 100644 --- a/src/object/anchor_point.cpp +++ b/src/object/anchor_point.cpp @@ -4,6 +4,7 @@ #include #include "anchor_point.hpp" #include "math/rect.hpp" +#include "msg.hpp" std::string anchor_point_to_string(AnchorPoint point) { @@ -75,7 +76,7 @@ Vector get_anchor_pos(const Rect& rect, AnchorPoint point) #ifdef DEBUG throw new std::runtime_error("Invalid anchor point found"); #endif - printf("Invalid anchor point found"); + msg_warning("Invalid anchor point found"); result.x = rect.get_left(); break; } @@ -94,7 +95,7 @@ Vector get_anchor_pos(const Rect& rect, AnchorPoint point) #ifdef DEBUG throw new std::runtime_error("Invalid anchor point found"); #endif - printf("Invalid anchor point found"); + msg_warning("Invalid anchor point found"); result.y = rect.get_top(); break; } @@ -121,7 +122,7 @@ Vector get_anchor_pos(const Rect& destrect, float width, float height, #ifdef DEBUG throw new std::runtime_error("Invalid anchor point found"); #endif - printf("Invalid anchor point found"); + msg_warning("Invalid anchor point found"); result.x = destrect.get_left(); break; } @@ -140,7 +141,7 @@ Vector get_anchor_pos(const Rect& destrect, float width, float height, #ifdef DEBUG throw new std::runtime_error("Invalid anchor point found"); #endif - printf("Invalid anchor point found"); + msg_warning("Invalid anchor point found"); result.y = destrect.get_top(); break; } diff --git a/src/object/background.cpp b/src/object/background.cpp index 2b7efb45f..223961556 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -26,6 +26,7 @@ #include "object_factory.hpp" #include "resources.hpp" #include "main.hpp" +#include "msg.hpp" Background::Background() : type(INVALID), layer(LAYER_BACKGROUND0), image(0) @@ -105,10 +106,10 @@ Background::set_gradient(Color top, Color bottom) if (gradient_top.red > 1.0 || gradient_top.green > 1.0 || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0) - std::cerr << "Warning: top gradient color has values above 1.0." << std::endl; + msg_warning("top gradient color has values above 1.0"); if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0 || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0) - std::cerr << "Warning: bottom gradient color has values above 1.0." << std::endl; + msg_warning("bottom gradient color has values above 1.0"); delete image; image = NULL; diff --git a/src/object/block.cpp b/src/object/block.cpp index 63b02d9c7..417cbdafd 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -20,6 +20,7 @@ #include #include "block.hpp" +#include "msg.hpp" #include @@ -133,7 +134,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) case 4: contents = CONTENT_1UP; break; case 5: contents = CONTENT_ICEGROW; break; default: - std::cerr << "Invalid box contents!\n"; + msg_warning("Invalid box contents"); contents = CONTENT_COIN; break; } @@ -168,7 +169,7 @@ BonusBlock::BonusBlock(const lisp::Lisp& lisp) } else if(contentstring == "custom") { contents = CONTENT_CUSTOM; } else { - std::cerr << "Invalid box contents '" << contentstring << "'.\n"; + msg_warning("Invalid box contents '" << contentstring << "'"); } } else { if(contents == CONTENT_CUSTOM) { @@ -178,7 +179,7 @@ BonusBlock::BonusBlock(const lisp::Lisp& lisp) throw std::runtime_error( "Only MovingObjects are allowed inside BonusBlocks"); } else { - std::cerr << "Invalid element '" << token << "' in bonusblock.\n"; + msg_warning("Invalid element '" << token << "' in bonusblock"); } } } diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 99e5a6e33..8f7b6c5f7 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -32,6 +32,7 @@ #include "sector.hpp" #include "main.hpp" #include "object_factory.hpp" +#include "msg.hpp" Camera::Camera(Sector* newsector) : sector(newsector), do_backscrolling(true), scrollchange(NONE) @@ -68,7 +69,7 @@ Camera::parse(const lisp::Lisp& reader) autoscrollPath = Path::GetByName(use_path); if (autoscrollPath == NULL) { - std::cerr << "Warning: Path for autoscroll camera not found! Make sure that the name is spelled correctly and that the path is initialized before the platform in the level file!" << std::endl; + msg_warning("Path for autoscroll camera not found! Make sure that the name is spelled correctly and that the path is initialized before the platform in the level file!"); } } else if(modename == "manual") { diff --git a/src/object/infoblock.cpp b/src/object/infoblock.cpp index f6703ec59..93566c7e9 100644 --- a/src/object/infoblock.cpp +++ b/src/object/infoblock.cpp @@ -27,6 +27,7 @@ #include "object_factory.hpp" #include "lisp/lisp.hpp" #include "sector.hpp" +#include "msg.hpp" InfoBlock::InfoBlock(const lisp::Lisp& lisp) : Block(sprite_manager->create("images/objects/bonus_block/infoblock.sprite")) @@ -37,7 +38,7 @@ InfoBlock::InfoBlock(const lisp::Lisp& lisp) bbox.set_pos(pos); if(!lisp.get("message", message)) { - std::cerr << "No message in InfoBlock!\n"; + msg_warning("No message in InfoBlock"); } stopped = false; ringing = new AmbientSound(get_pos(), 0.5, 300, 1, "phone"); diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index c1ad71f4b..57616dae4 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -12,6 +12,7 @@ #include "object/player.hpp" #include "video/drawing_context.hpp" #include "lisp/list_iterator.hpp" +#include "msg.hpp" /** When to alert player they're low on time! */ static const float TIME_WARNING = 20; @@ -26,8 +27,8 @@ LevelTime::LevelTime(const lisp::Lisp& reader) iter.value()->get(time); break; } else { - std::cerr << "Unknown token '" << iter.item() - << "' in LevelTime object.\n"; + msg_warning("Unknown token '" << iter.item() + << "' in LevelTime object"); } } if(time < 0) diff --git a/src/object/path.cpp b/src/object/path.cpp index e98264775..c16f1deea 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -24,6 +24,7 @@ #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" #include "object_factory.hpp" +#include "msg.hpp" #include #include @@ -51,7 +52,7 @@ Path::Path(const lisp::Lisp& reader) while(iter.next()) { if(iter.item() != "node") { - std::cerr << "Warning: unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl; + msg_warning("unknown token '" << iter.item() << "' in Path nodes list. Ignored."); continue; } const lisp::Lisp* node_lisp = iter.lisp(); diff --git a/src/object/platform.cpp b/src/object/platform.cpp index bc872b01a..a28ec87a5 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -21,7 +21,7 @@ #include "platform.hpp" -#include +#include "msg.hpp" #include "video/drawing_context.hpp" #include "resources.hpp" #include "player.hpp" @@ -45,8 +45,9 @@ Platform::Platform(const lisp::Lisp& reader) flags |= FLAG_SOLID; path = Path::GetByName(use_path); - if (path == NULL) { - std::cerr << "Warning: Path for moving platform not found! Make sure that the name is spelled correctly,\nand that the path is initialized before the platform in the level file!\n"; + + if (path == NULL) { + msg_warning("Path \"" << use_path << "\" for moving platform not found! Make sure that the name is spelled correctly and that the path is initialized before the platform in the level file!"); } path_offset = bbox.p1; diff --git a/src/object/player.cpp b/src/object/player.cpp index d7458647e..628752e35 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -44,6 +44,7 @@ #include "main.hpp" #include "badguy/badguy.hpp" #include "player_status.hpp" +#include "msg.hpp" static const int TILES_FOR_BUTTJUMP = 3; static const float SHOOTING_TIME = .150; @@ -181,9 +182,7 @@ Player::update(float elapsed_time) if(moving_object) { moving_object->set_pos(pos); } else { -#ifdef DEBUG - std::cout << "Non MovingObjetc grabbed?!?\n"; -#endif + msg_debug("Non MovingObjetc grabbed?!?"); } grabbed_object->ungrab(*this, dir); grabbed_object = 0; diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index 8b000d50a..3fce45b49 100644 --- a/src/object/powerup.cpp +++ b/src/object/powerup.cpp @@ -28,6 +28,7 @@ #include "object_factory.hpp" #include "sector.hpp" #include "scripting/script_interpreter.hpp" +#include "msg.hpp" PowerUp::PowerUp(const lisp::Lisp& lisp) { @@ -56,8 +57,8 @@ PowerUp::collision(GameObject& other, const CollisionHit& hit) if(fabsf(hit.normal.y) > .5) { // roof or ground physic.set_velocity_y(0); } else { // bumped left or right - printf("Normal: %f %f\n", hit.normal.x, hit.normal.y); - printf("LRbounce, new speed. %f\n", physic.get_velocity_x()); + msg_debug("Normal: " << hit.normal.x << "," << hit.normal.y); + msg_debug("LRbounce, new speed: " << physic.get_velocity_x()); physic.set_velocity_x(-physic.get_velocity_x()); } diff --git a/src/object/text_object.cpp b/src/object/text_object.cpp index 348d9341b..8081e852b 100644 --- a/src/object/text_object.cpp +++ b/src/object/text_object.cpp @@ -5,6 +5,7 @@ #include #include "resources.hpp" #include "video/drawing_context.hpp" +#include "msg.hpp" TextObject::TextObject() : fading(0), fadetime(0), visible(false) @@ -33,7 +34,7 @@ TextObject::set_font(const std::string& name) } else if(name == "small") { font = white_small_text; } else { - std::cerr << "Unknown font '" << name << "'.\n"; + msg_warning("Unknown font '" << name << "'."); } } diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index a6765ee67..88c5c08f3 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -34,6 +34,7 @@ #include "lisp/writer.hpp" #include "object_factory.hpp" #include "main.hpp" +#include "msg.hpp" TileMap::TileMap() : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), @@ -62,14 +63,14 @@ TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager) else if(layer_str == "foreground") layer = LAYER_FOREGROUNDTILES; else - std::cerr << "Unknown layer '" << layer_str << "' in tilemap.\n"; + msg_warning("Unknown layer '" << layer_str << "' in tilemap"); } reader.get("solid", solid); reader.get("speed", speed); if(solid && speed != 1) { - std::cout << "Speed of solid tilemap is not 1. fixing.\n"; + msg_warning("Speed of solid tilemap is not 1. fixing"); speed = 1; } if(solid) @@ -121,7 +122,7 @@ TileMap::write(lisp::Writer& writer) writer.write_string("layer", "foreground"); else { writer.write_string("layer", "unknown"); - std::cerr << "Warning unknown layer in tilemap.\n"; + msg_warning("unknown layer in tilemap"); } writer.write_bool("solid", solid); @@ -253,9 +254,7 @@ const Tile* TileMap::get_tile(int x, int y) const { if(x < 0 || x >= width || y < 0 || y >= height) { -#ifdef DEBUG - //std::cout << "Warning: tile outside tilemap requested!\n"; -#endif + //msg_warning("tile outside tilemap requested"); return tilemanager->get(0); } diff --git a/src/physfs/physfs_sdl.cpp b/src/physfs/physfs_sdl.cpp index 6317e6ef2..17ceacbe8 100644 --- a/src/physfs/physfs_sdl.cpp +++ b/src/physfs/physfs_sdl.cpp @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include +#include "msg.hpp" static int funcSeek(struct SDL_RWops* context, int offset, int whence) { @@ -47,7 +48,7 @@ static int funcSeek(struct SDL_RWops* context, int offset, int whence) break; } if(res == 0) { - std::cerr << "Error seeking in file: " << PHYSFS_getLastError() << "\n"; + msg_warning("Error seeking in file: " << PHYSFS_getLastError()); return -1; } diff --git a/src/player_status.cpp b/src/player_status.cpp index bc51aee0f..8241b9bb4 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -28,6 +28,7 @@ #include "sprite/sprite_manager.hpp" #include "math/vector.hpp" #include "main.hpp" +#include "msg.hpp" static const int START_LIVES = 4; static const int MAX_LIVES = 99; @@ -120,7 +121,7 @@ PlayerStatus::write(lisp::Writer& writer) writer.write_string("bonus", "iceflower"); break; default: - std::cerr << "Unknown bonus type.\n"; + msg_warning("Unknown bonus type."); writer.write_string("bonus", "none"); } writer.write_bool("key-brass", keys & KEY_BRASS); @@ -150,7 +151,7 @@ PlayerStatus::read(const lisp::Lisp& lisp) } else if(bonusname == "iceflower") { bonus = ICE_BONUS; } else { - std::cerr << "Unknown bonus '" << bonusname << "' in savefile.\n"; + msg_warning("Unknown bonus '" << bonusname << "' in savefile"); bonus = NO_BONUS; } } diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index f62ef9227..6bff401d7 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -8,6 +8,7 @@ #include "tinygettext/tinygettext.hpp" #include "resources.hpp" #include "gettext.hpp" +#include "msg.hpp" namespace Scripting { @@ -34,15 +35,15 @@ void import(HSQUIRRELVM v, const std::string& filename) std::string file = ScriptInterpreter::current()->get_working_directory() + filename; if(sqstd_loadfile(v, file.c_str(), true) < 0) { - std::cerr << "Warning couldn't load script '" << filename << "' (" - << file << ").\n"; + msg_warning("couldn't load script '" << filename << "' (" + << file << ")"); return; } sq_push(v, -2); if(sq_call(v, 1, false) < 0) { - std::cerr << "Couldn't execute script '" << filename << "' (" - << file << ").\n"; + msg_warning("Couldn't execute script '" << filename << "' (" + << file << ")"); return; } } diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index 6c3fce570..25f88e11b 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -13,6 +13,7 @@ #include #include +#include "msg.hpp" #include "wrapper.hpp" #include "wrapper_util.hpp" #include "sector.hpp" @@ -204,7 +205,7 @@ ScriptInterpreter::add_script_object(Sector* sector, const std::string& name, interpreter->run_script(in, name); sector->add_object(interpreter.release()); } catch(std::exception& e) { - std::cerr << "Couldn't start '" << name << "' script: " << e.what() << "\n"; + msg_warning("Couldn't start '" << name << "' script: " << e.what()); } } diff --git a/src/sector.cpp b/src/sector.cpp index 9c83a7683..7ea513a1c 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -63,6 +63,7 @@ #include "scripting/sound.hpp" #include "scripting/scripted_object.hpp" #include "scripting/text.hpp" +#include "msg.hpp" Sector* Sector::_current = 0; @@ -134,7 +135,7 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader) try { return create_object(name, reader); } catch(std::exception& e) { - std::cerr << e.what() << "\n"; + msg_warning(e.what() << ""); } return 0; @@ -174,7 +175,7 @@ Sector::parse(const lisp::Lisp& sector) fix_old_tiles(); if(!camera) { - std::cerr << "sector '" << name << "' does not contain a camera.\n"; + msg_warning("sector '" << name << "' does not contain a camera."); update_game_objects(); add_object(new Camera(this)); } @@ -284,7 +285,7 @@ Sector::parse_old_format(const lisp::Lisp& reader) spawnpoints.push_back(sp); } } else { - std::cerr << "Unknown token '" << iter.item() << "' in reset-points.\n"; + msg_warning("Unknown token '" << iter.item() << "' in reset-points."); } } } @@ -298,7 +299,7 @@ Sector::parse_old_format(const lisp::Lisp& reader) if(object) { add_object(object); } else { - std::cerr << "Unknown object '" << iter.item() << "' in level.\n"; + msg_warning("Unknown object '" << iter.item() << "' in level."); } } } @@ -407,7 +408,7 @@ Sector::activate(const std::string& spawnpoint) } } if(!sp) { - std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n"; + msg_warning("Spawnpoint '" << spawnpoint << "' not found."); if(spawnpoint != "main") { activate("main"); } else { @@ -535,14 +536,14 @@ Sector::update_game_objects() if(solids == 0) { solids = tilemap; } else { - std::cerr << "Another solid tilemaps added. Ignoring."; + msg_warning("Another solid tilemaps added. Ignoring"); } } Camera* camera = dynamic_cast (object); if(camera) { if(this->camera != 0) { - std::cerr << "Warning: Multiple cameras added. Ignoring."; + msg_warning("Multiple cameras added. Ignoring"); continue; } this->camera = camera; diff --git a/src/spawn_point.cpp b/src/spawn_point.cpp index c0647fb49..b0c9b6487 100644 --- a/src/spawn_point.cpp +++ b/src/spawn_point.cpp @@ -5,6 +5,7 @@ #include "spawn_point.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" +#include "msg.hpp" SpawnPoint::SpawnPoint() {} @@ -27,8 +28,8 @@ SpawnPoint::SpawnPoint(const lisp::Lisp* slisp) } else if(token == "y") { iter.value()->get(pos.y); } else { - std::cerr << "Warning: unknown token '" << token - << "' in SpawnPoint\n"; + msg_warning("unknown token '" << token + << "' in SpawnPoint"); } } diff --git a/src/sprite/sprite.cpp b/src/sprite/sprite.cpp index 9fe4765db..1c8d0bf80 100644 --- a/src/sprite/sprite.cpp +++ b/src/sprite/sprite.cpp @@ -25,6 +25,7 @@ #include "sprite.hpp" #include "video/drawing_context.hpp" +#include "msg.hpp" Sprite::Sprite(SpriteData& newdata) : data(newdata), frame(0), animation_loops(-1) @@ -55,9 +56,7 @@ Sprite::set_action(const std::string& name, int loops) SpriteData::Action* newaction = data.get_action(name); if(!newaction) { -#ifdef DEBUG - std::cerr << "Action '" << name << "' not found.\n"; -#endif + msg_debug("Action '" << name << "' not found."); return; } @@ -100,9 +99,9 @@ Sprite::draw(DrawingContext& context, const Vector& pos, int layer) update(); if((int)frame >= get_frames() || (int)frame < 0) - std::cerr << "Warning: frame out of range: " << (int)frame + msg_warning("frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() - << "/" << get_action_name() << std::endl; + << "/" << get_action_name()); else context.draw_surface(action->surfaces[(int)frame], pos - Vector(action->x_offset, action->y_offset), @@ -117,9 +116,9 @@ Sprite::draw_part(DrawingContext& context, const Vector& source, update(); if((int)frame >= get_frames() || (int)frame < 0) - std::cerr << "Warning: frame out of range: " << (int)frame + msg_warning("frame out of range: " << (int)frame << "/" << get_frames() << " at sprite: " << get_name() - << "/" << get_action_name() << std::endl; + << "/" << get_action_name()); else context.draw_surface_part(action->surfaces[(int)frame], source, size, pos - Vector(action->x_offset, action->y_offset), diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index ca971246f..90a9e4e52 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -27,6 +27,7 @@ #include "resources.hpp" #include "video/drawing_context.hpp" #include "lisp/list_iterator.hpp" +#include "msg.hpp" SpriteData::Action::Action() { @@ -52,7 +53,7 @@ SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir) } else if(iter.item() == "action") { parse_action(iter.lisp(), basedir); } else { - std::cerr << "Unknown sprite field: " << iter.item() << "\n"; + msg_warning("Unknown sprite field: " << iter.item()); } } if(actions.empty()) diff --git a/src/sprite/sprite_manager.cpp b/src/sprite/sprite_manager.cpp index e0c6b5edb..e6ab67f90 100644 --- a/src/sprite/sprite_manager.cpp +++ b/src/sprite/sprite_manager.cpp @@ -29,6 +29,7 @@ #include "lisp/parser.hpp" #include "lisp/list_iterator.hpp" #include "file_system.hpp" +#include "msg.hpp" SpriteManager::SpriteManager(const std::string& filename) { @@ -37,7 +38,7 @@ SpriteManager::SpriteManager(const std::string& filename) #endif load_resfile(filename); #ifdef DEBUG - printf("Loaded sprites in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0f); + msg_debug("Loaded sprites in " << (SDL_GetTicks() - ticks) / 1000.0f << " seconds"); #endif } @@ -70,12 +71,12 @@ SpriteManager::load_resfile(const std::string& filename) } else { delete i->second; i->second = spritedata; - std::cout << "Warning: dulpicate entry: '" << spritedata->get_name() - << "' in spritefile." << std::endl; + msg_warning("dulpicate entry: '" << spritedata->get_name() + << "' in spritefile."); } } else { - std::cout << "SpriteManager: Unknown tag '" << iter.item() - << "' in spritefile.\n"; + msg_warning("Unknown tag '" << iter.item() + << "' in spritefile."); } } } catch(std::exception& e) { diff --git a/src/textscroller.cpp b/src/textscroller.cpp index e6577bb7d..d1cd0ce09 100644 --- a/src/textscroller.cpp +++ b/src/textscroller.cpp @@ -22,6 +22,7 @@ #include "textscroller.hpp" #include +#include "msg.hpp" #include "resources.hpp" #include "video/font.hpp" #include "video/drawing_context.hpp" @@ -85,8 +86,7 @@ void display_text_file(const std::string& filename) if(text_lisp->get("speed", defaultspeed)) defaultspeed /= 50; } catch(std::exception& e) { - std::cerr << "Couldn't load file '" << filename << "': " << e.what() << - "\n"; + msg_warning("Couldn't load file '" << filename << "': " << e.what()); return; } @@ -99,7 +99,7 @@ void display_text_file(const std::string& filename) continue; if(line[0] == '!') { std::string imagename = line.substr(1, line.size()-1); - std::cout << "Imagename: " << imagename << "\n"; + msg_debug("Imagename: " << imagename); images.insert(std::make_pair(imagename, new Surface(imagename))); } } @@ -166,7 +166,7 @@ void display_text_file(const std::string& filename) break; } default: - std::cerr << "Warning: text contains an unformated line.\n"; + msg_warning("text contains an unformated line"); font = normal_font; center = false; break; @@ -239,7 +239,7 @@ InfoBox::InfoBox(const std::string& text) } catch (std::exception& e) { - std::cout << "Could not load scrolling images: " << e.what() << std::endl; + msg_warning("Could not load scrolling images: " << e.what()); arrow_scrollup = 0; arrow_scrolldown = 0; } @@ -297,7 +297,7 @@ InfoBox::draw(DrawingContext& context) break; } default: - std::cerr << "Warning: text contains an unformatted line.\n"; + msg_warning("text contains an unformatted line"); font = normal_font; center = false; break; diff --git a/src/tile.cpp b/src/tile.cpp index 0712dcd61..4e6080b54 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -30,6 +30,8 @@ #include "timer.hpp" #include "math/vector.hpp" #include "video/drawing_context.hpp" +#include "msg.hpp" + Tile::Tile() : id(0), editor_image(0), attributes(0), data(0), anim_fps(1) @@ -125,7 +127,7 @@ Tile::parse_images(const lisp::Lisp& images_lisp) ptr->get_car()->get(h); imagespecs.push_back(ImageSpec(file, Rect(x, y, x+w, y+h))); } else { - std::cerr << "Expected string or list in images tag.\n"; + msg_warning("Expected string or list in images tag"); continue; } diff --git a/src/tile_manager.cpp b/src/tile_manager.cpp index c9db17fc1..474b8f271 100644 --- a/src/tile_manager.cpp +++ b/src/tile_manager.cpp @@ -26,6 +26,7 @@ #include #include #include "video/drawing_context.hpp" +#include "msg.hpp" #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "lisp/list_iterator.hpp" @@ -40,7 +41,7 @@ TileManager::TileManager(const std::string& filename) #endif load_tileset(filename); #ifdef DEBUG - printf("Tiles loaded in %f seconds\n", (SDL_GetTicks() - ticks) / 1000.0); + msg_debug("Tiles loaded in " << (SDL_GetTicks() - ticks) / 1000.0 << "seconds"); #endif } @@ -80,7 +81,7 @@ void TileManager::load_tileset(std::string filename) tiles.push_back(0); } if(tiles[tile->id] != 0) { - std::cout << "Warning: Tile with ID " << tile->id << " redefined\n"; + msg_warning("Tile with ID " << tile->id << " redefined"); } tiles[tile->id] = tile; } else if(iter.item() == "tilegroup") { @@ -137,7 +138,7 @@ void TileManager::load_tileset(std::string filename) } else if(iter.item() == "properties") { // deprecated } else { - std::cerr << "Unknown symbol '" << iter.item() << "' tile defintion file.\n"; + msg_warning("Unknown symbol '" << iter.item() << "' tile defintion file"); } } } diff --git a/src/tile_manager.hpp b/src/tile_manager.hpp index b8ef087f5..66568ba57 100644 --- a/src/tile_manager.hpp +++ b/src/tile_manager.hpp @@ -28,6 +28,7 @@ #include #include #include +#include "msg.hpp" #include "tile.hpp" struct TileGroup @@ -69,7 +70,7 @@ public: assert(id < tiles.size()); Tile* tile = tiles[id]; if(!tile) { - std::cout << "TileManager: Invalid tile: " << id << std::endl; + msg_warning("Invalid tile: " << id); return tiles[0]; } diff --git a/src/tinygettext/tinygettext.cpp b/src/tinygettext/tinygettext.cpp index b31cf2f4b..5ea2c9483 100644 --- a/src/tinygettext/tinygettext.cpp +++ b/src/tinygettext/tinygettext.cpp @@ -26,7 +26,9 @@ #include #include "tinygettext.hpp" +#include "msg.hpp" #include "physfs/physfs_stream.hpp" +#include "msg.hpp" //#define TRANSLATION_DEBUG @@ -58,9 +60,9 @@ std::string convert(const std::string& text, out_len -= out_len_temp; // see above if (retval == (size_t) -1) { - std::cerr << strerror(errno) << std::endl; - std::cerr << "Error: conversion from " << from_charset - << " to " << to_charset << " went wrong: " << retval << std::endl; + msg_warning(strerror(errno)); + msg_warning("Error: conversion from " << from_charset + << " to " << to_charset << " went wrong: " << retval); return ""; } iconv_close(cd); @@ -236,7 +238,7 @@ DictionaryManager::get_dictionary(const std::string& spec) } else // Dictionary for languages lang isn't loaded, so we load it { - //std::cout << "get_dictionary: " << lang << std::endl; + //msg_debug("get_dictionary: " << lang); Dictionary& dict = dictionaries[lang]; dict.set_language(get_language_def(lang)); @@ -248,7 +250,7 @@ DictionaryManager::get_dictionary(const std::string& spec) char** files = PHYSFS_enumerateFiles(p->c_str()); if(!files) { - std::cerr << "Error: enumerateFiles() failed on " << *p << std::endl; + msg_warning("Error: enumerateFiles() failed on " << *p); } else { @@ -260,8 +262,8 @@ DictionaryManager::get_dictionary(const std::string& spec) IFileStream in(pofile); read_po_file(dict, in); } catch(std::exception& e) { - std::cerr << "Error: Failure file opening: " << pofile << std::endl; - std::cerr << e.what() << "\n"; + msg_warning("Error: Failure file opening: " << pofile); + msg_warning(e.what() << ""); } } } @@ -283,7 +285,7 @@ DictionaryManager::get_languages() char** files = PHYSFS_enumerateFiles(p->c_str()); if (!files) { - std::cerr << "Error: opendir() failed on " << *p << std::endl; + msg_warning("Error: opendir() failed on " << *p); } else { @@ -404,10 +406,10 @@ Dictionary::translate(const std::string& msgid, const std::string& msgid2, int n else { #ifdef TRANSLATION_DEBUG - std::cerr << "Warning: Couldn't translate: " << msgid << std::endl; - std::cerr << "Candidates: " << std::endl; + msg_warning("Couldn't translate: " << msgid); + msg_warning("Candidates: "); for (PluralEntries::iterator i = plural_entries.begin(); i != plural_entries.end(); ++i) - std::cout << "'" << i->first << "'" << std::endl; + msg_debug("'" << i->first << "'"); #endif if (plural2_1(num)) // default to english rules @@ -428,7 +430,7 @@ Dictionary::translate(const char* msgid) else { #ifdef TRANSLATION_DBEUG - std::cout << "Error: Couldn't translate: " << msgid << std::endl; + msg_warning("Couldn't translate: " << msgid); #endif return msgid; } @@ -445,7 +447,7 @@ Dictionary::translate(const std::string& msgid) else { #ifdef TRANSLATION_DBEUG - std::cout << "Error: Couldn't translate: " << msgid << std::endl; + msg_warning("Couldn't translate: " << msgid); #endif return msgid; } @@ -529,7 +531,7 @@ public: if (from_charset.empty() || from_charset == "CHARSET") { - std::cerr << "Error: Charset not specified for .po, fallback to ISO-8859-1" << std::endl; + msg_warning("Error: Charset not specified for .po, fallback to ISO-8859-1"); from_charset = "ISO-8859-1"; } @@ -553,12 +555,12 @@ public: } else if (token.keyword.empty()) { - //std::cerr << "Got EOF, everything looks ok." << std::endl; + //msg_warning("Got EOF, everything looks ok."); } else { - std::cerr << "tinygettext: expected 'msgid' keyword, got " << token.keyword - << " at line " << line_num << std::endl; + msg_warning("tinygettext: expected 'msgid' keyword, got " << token.keyword + << " at line " << line_num); } break; @@ -590,8 +592,8 @@ public: } else { - std::cerr << "tinygettext: expected 'msgstr' keyword, got " << token.keyword - << " at line " << line_num << std::endl; + msg_warning("tinygettext: expected 'msgstr' keyword, got " << token.keyword + << " at line " << line_num); } break; @@ -601,7 +603,7 @@ public: int num; if (sscanf(token.keyword.c_str(), "msgstr[%d]", &num) != 1) { - std::cerr << "Error: Couldn't parse: " << token.keyword << std::endl; + msg_warning("Error: Couldn't parse: " << token.keyword); } else { @@ -640,7 +642,7 @@ public: while((c = getchar(in)) != EOF) { - //std::cout << "Lexing char: " << char(c) << " " << state << std::endl; + //msg_debug("Lexing char: " << char(c) << " " << state); switch(state) { case READ_KEYWORD: @@ -691,12 +693,12 @@ public: else if (c == '"') token.content += '"'; else { - std::cout << "Unhandled escape character: " << char(c) << std::endl; + msg_warning("Unhandled escape character: " << char(c)); } } else { - std::cout << "Unterminated string" << std::endl; + msg_warning("Unterminated string"); } } else if (c == '"') { // Content string is terminated state = READ_CONTENT; diff --git a/src/title.cpp b/src/title.cpp index 94ccc5a0a..c23186478 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -60,6 +60,7 @@ #include "control/codecontroller.hpp" #include "main.hpp" #include "exceptions.hpp" +#include "msg.hpp" static Surface* bkg_title; static Surface* logo; @@ -92,7 +93,7 @@ void resume_demo() void update_load_save_game_menu(Menu* menu) { - printf("update loadsavemenu.\n"); + msg_debug("update loadsavemenu"); for(int i = 1; i < 6; ++i) { MenuItem& item = menu->get_item_by_id(i); item.kind = MN_ACTION; @@ -142,8 +143,8 @@ void generate_contrib_menu() contrib_subsets.push_back(subset.release()); } catch(std::exception& e) { #ifdef DEBUG - std::cerr << "Couldn't parse levelset info for '" - << *it << "': " << e.what() << "\n"; + msg_warning("Couldn't parse levelset info for '" + << *it << "': " << e.what() << ""); #endif } } @@ -166,7 +167,7 @@ std::string get_level_name(const std::string& filename) level->get("name", name); return name; } catch(std::exception& e) { - std::cerr << "Problem getting name of '" << filename << "'.\n"; + msg_warning("Problem getting name of '" << filename << "'."); return ""; } } @@ -408,7 +409,7 @@ void title() if(confirm_dialog(bkg_title, str.c_str())) { str = "save/slot" + stream.str() + ".stsg"; - printf("Removing: %s\n",str.c_str()); + msg_debug("Removing: " << str); PHYSFS_delete(str.c_str()); } diff --git a/src/video/color.hpp b/src/video/color.hpp index d48aa8b74..6bce2055f 100644 --- a/src/video/color.hpp +++ b/src/video/color.hpp @@ -2,6 +2,7 @@ #define __COLOR_HPP__ #include +#include "msg.hpp" class Color { @@ -35,8 +36,7 @@ public: if(red < 0 || red > 1.0 || green < 0 || green > 1.0 || blue < 0 || blue > 1.0 || alpha < 0 || alpha > 1.0) - printf("Warning: color value out of range: %f %f %f %f\n", - red, green, blue, alpha); + msg_warning("color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha); } float red, green, blue, alpha; diff --git a/src/video/font.cpp b/src/video/font.cpp index bc46d9bba..972ba40e3 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -28,6 +28,7 @@ #include "screen.hpp" #include "font.hpp" #include "drawing_context.hpp" +#include "msg.hpp" Font::Font(const std::string& file, const std::string& shadowfile, int w, int h, int shadowsize) @@ -210,17 +211,13 @@ Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, if(c >= 0x80) { font_index -= 32; if(c <= 0xa0) { -#ifdef DEBUG - std::cout << "Unsupported utf-8 character '" << c << "' found\n"; -#endif + msg_debug("Unsupported utf-8 character '" << c << "' found"); font_index = 0; } } if(font_index < 0 || font_index >= (ssize_t) char_count) { -#ifdef DEBUG - std::cout << "Unsupported utf-8 character found\n"; -#endif + msg_debug("Unsupported utf-8 character found"); font_index = 0; } diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index 237aff3ef..56ec74b87 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -14,6 +14,7 @@ #include "image_texture.hpp" #include "glutil.hpp" #include "file_system.hpp" +#include "msg.hpp" TextureManager* texture_manager = NULL; @@ -27,9 +28,7 @@ TextureManager::~TextureManager() i != image_textures.end(); ++i) { if(i->second == NULL) continue; -#ifdef DEBUG - std::cerr << "Warning: Texture '" << i->first << "' not freed\n"; -#endif + msg_warning("Texture '" << i->first << "' not freed"); delete i->second; } } diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 2896d6414..816c92d38 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -28,6 +28,7 @@ #include #include "gettext.hpp" +#include "msg.hpp" #include "video/surface.hpp" #include "video/screen.hpp" #include "video/drawing_context.hpp" @@ -145,9 +146,7 @@ Tux::draw(DrawingContext& context) tux_sprite->set_action(moving ? "small-walking" : "small-stop"); break; default: -#ifdef DEBUG - std::cerr << "Bonus type not handled in worldmap.\n"; -#endif + msg_debug("Bonus type not handled in worldmap."); tux_sprite->set_action("large-stop"); break; } @@ -440,7 +439,7 @@ WorldMap::load_map() } else if(iter.item() == "special-tile") { parse_special_tile(iter.lisp()); } else { - std::cerr << "Unknown token '" << iter.item() << "' in worldmap.\n"; + msg_warning("Unknown token '" << iter.item() << "' in worldmap"); } } if(solids == 0) @@ -535,8 +534,8 @@ WorldMap::parse_level_tile(const lisp::Lisp* level_lisp) // Do we want to bail out instead...? We might get messages from modders // who can't make their levels run because they're too dumb to watch // their terminals... - std::cerr << "Error: level file '" << level.name - << "' does not exist and will not be added to the worldmap." << std::endl; + msg_warning("level file '" << level.name + << "' does not exist and will not be added to the worldmap"); return; } @@ -568,7 +567,7 @@ WorldMap::get_level_title(Level& level) level_lisp->get("name", level.title); } catch(std::exception& e) { - std::cerr << "Problem when reading leveltitle: " << e.what() << "\n"; + msg_warning("Problem when reading leveltitle: " << e.what()); return; } } @@ -742,9 +741,8 @@ WorldMap::update(float delta) Level* level = at_level(); if (!level) { - std::cout << "No level to enter at: " - << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y - << std::endl; + msg_warning("No level to enter at: " + << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y); return; } @@ -864,7 +862,7 @@ WorldMap::update(float delta) interpreter->run_script(in, "level-extro-script"); add_object(interpreter.release()); } catch(std::exception& e) { - std::cerr << "Couldn't run level-extro-script:" << e.what() << "\n"; + msg_warning("Couldn't run level-extro-script:" << e.what()); } } @@ -1011,8 +1009,8 @@ WorldMap::display() interpreter->run_script(in, "worldmap-intro-script"); add_object(interpreter.release()); } catch(std::exception& e) { - std::cerr << "Couldn't execute worldmap-intro-script: " - << e.what() << "\n"; + msg_warning("Couldn't execute worldmap-intro-script: " + << e.what()); } intro_displayed = true; @@ -1135,7 +1133,7 @@ WorldMap::savegame(const std::string& filename) void WorldMap::loadgame(const std::string& filename) { - std::cout << "loadgame: " << filename << std::endl; + msg_debug("loadgame: " << filename); savegame_file = filename; if (PHYSFS_exists(filename.c_str())) // savegame exists @@ -1199,14 +1197,13 @@ WorldMap::loadgame(const std::string& filename) } } } else { - std::cerr << "Unknown token '" << iter.item() - << "' in levels block in worldmap.\n"; + msg_warning("Unknown token '" << iter.item() + << "' in levels block in worldmap"); } } } } catch(std::exception& e) { - std::cerr << "Problem loading game '" << filename << "': " << e.what() - << "\n"; + msg_warning("Problem loading game '" << filename << "': " << e.what()); load_map(); player_status->reset(); } -- 2.11.0