diff --git a/debug.h b/debug.h index 344d06a..a742aa3 100644 --- a/debug.h +++ b/debug.h @@ -2,11 +2,24 @@ #define _DEBUG_H_ #ifdef DEBUG + #include #include +#include + +using std::fprintf; using std::cerr; using std::endl; -using std::fprintf; -#endif +using std::string; + +#endif + +inline void debug(string msg) +{ +#ifdef DEBUG + cerr << "debug: " << msg << endl; +#endif + return; +} #endif diff --git a/game.cpp b/game.cpp index 4010cec..db9ab83 100644 --- a/game.cpp +++ b/game.cpp @@ -27,9 +27,7 @@ bool Game::init() if (background == NULL) { -#ifdef DEBUG - std::cerr << "debug: Game::init(): error: Couldn't load background image\n"; -#endif + debug("Game::init(): error: Couldn't load background image"); return false; } diff --git a/gamedata.cpp b/gamedata.cpp index d8af9cb..6997690 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -93,8 +93,8 @@ bool GameData::add_vertex(int x, int y, int r, int colour) { Graph::add_vertex(x, y, r, colour, 10); #ifdef DEBUG - fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", - calculate_strength(*(vertices.rbegin()))); + fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", + calculate_strength(*(vertices.rbegin()))); #endif if (player == PLAYER1) player1_played = true; if (player == PLAYER2) player2_played = true; @@ -225,17 +225,13 @@ bool GameData::endgame() if (get_colour(PLAYER1_COLOUR).empty()) { player = WIN2; -#ifdef DEBUG - fprintf(stderr, "debug: Gamedata::endgame(): player 2 wins\n"); -#endif + debug("Gamedata::endgame(): player 2 wins\n"); return true; } if (get_colour(PLAYER2_COLOUR).empty()) { player = WIN1; -#ifdef DEBUG - fprintf(stderr, "debug: Gamedata::endgame(): player 1 wins\n"); -#endif + debug("Gamedata::endgame(): player 1 wins\n"); return true; } diff --git a/graph.cpp b/graph.cpp index fb20e68..8f3d8e3 100644 --- a/graph.cpp +++ b/graph.cpp @@ -101,7 +101,7 @@ bool Graph::add_vertex(int x, int y, int r, int colour, int score, Vertex* src) if (planar && crosses_edge(v, src)) { #ifdef DEBUG - fprintf(stderr, "debug: Graph::add_vertex(): failed to add due to edge collision: x1=%d, y1=%d, x2=%d, y2=%d\n", v->x, v->y, src->x, src->y); + fprintf(stderr, "debug: Graph::add_vertex(): failed to add due to edge collision: x1=%d, y1=%d, x2=%d, y2=%d\n", v->x, v->y, src->x, src->y); #endif delete v; return false; diff --git a/titlescreen.cpp b/titlescreen.cpp index e9a615a..7f4ee86 100644 --- a/titlescreen.cpp +++ b/titlescreen.cpp @@ -25,9 +25,7 @@ bool TitleScreen::init() if (background == NULL) { -#ifdef DEBUG - std::cerr << "debug: TitleScreen::init(): error: Couldn't load background image\n"; -#endif + debug("TitleScreen::init(): error: Couldn't load background image"); return false; } @@ -35,9 +33,7 @@ bool TitleScreen::init() if (title_banner == NULL) { -#ifdef DEBUG - std::cerr << "debug: TitleScreen::init(): error: Couldn't load title banner\n"; -#endif + debug("TitleScreen::init(): error: Couldn't load title banner"); return false; } }