Cleaned up some debugging code

This commit is contained in:
Anna Rose 2011-06-28 22:14:55 -04:00
parent 7e17865c2a
commit 8550b0f8f1
5 changed files with 23 additions and 20 deletions

17
debug.h
View File

@ -2,11 +2,24 @@
#define _DEBUG_H_ #define _DEBUG_H_
#ifdef DEBUG #ifdef DEBUG
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#include <string>
using std::fprintf;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
using std::fprintf; using std::string;
#endif
#endif
inline void debug(string msg)
{
#ifdef DEBUG
cerr << "debug: " << msg << endl;
#endif
return;
}
#endif #endif

View File

@ -27,9 +27,7 @@ bool Game::init()
if (background == NULL) if (background == NULL)
{ {
#ifdef DEBUG debug("Game::init(): error: Couldn't load background image");
std::cerr << "debug: Game::init(): error: Couldn't load background image\n";
#endif
return false; return false;
} }

View File

@ -93,8 +93,8 @@ bool GameData::add_vertex(int x, int y, int r, int colour)
{ {
Graph::add_vertex(x, y, r, colour, 10); Graph::add_vertex(x, y, r, colour, 10);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n",
calculate_strength(*(vertices.rbegin()))); calculate_strength(*(vertices.rbegin())));
#endif #endif
if (player == PLAYER1) player1_played = true; if (player == PLAYER1) player1_played = true;
if (player == PLAYER2) player2_played = true; if (player == PLAYER2) player2_played = true;
@ -225,17 +225,13 @@ bool GameData::endgame()
if (get_colour(PLAYER1_COLOUR).empty()) if (get_colour(PLAYER1_COLOUR).empty())
{ {
player = WIN2; player = WIN2;
#ifdef DEBUG debug("Gamedata::endgame(): player 2 wins\n");
fprintf(stderr, "debug: Gamedata::endgame(): player 2 wins\n");
#endif
return true; return true;
} }
if (get_colour(PLAYER2_COLOUR).empty()) if (get_colour(PLAYER2_COLOUR).empty())
{ {
player = WIN1; player = WIN1;
#ifdef DEBUG debug("Gamedata::endgame(): player 1 wins\n");
fprintf(stderr, "debug: Gamedata::endgame(): player 1 wins\n");
#endif
return true; return true;
} }

View File

@ -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)) if (planar && crosses_edge(v, src))
{ {
#ifdef DEBUG #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 #endif
delete v; delete v;
return false; return false;

View File

@ -25,9 +25,7 @@ bool TitleScreen::init()
if (background == NULL) if (background == NULL)
{ {
#ifdef DEBUG debug("TitleScreen::init(): error: Couldn't load background image");
std::cerr << "debug: TitleScreen::init(): error: Couldn't load background image\n";
#endif
return false; return false;
} }
@ -35,9 +33,7 @@ bool TitleScreen::init()
if (title_banner == NULL) if (title_banner == NULL)
{ {
#ifdef DEBUG debug("TitleScreen::init(): error: Couldn't load title banner");
std::cerr << "debug: TitleScreen::init(): error: Couldn't load title banner\n";
#endif
return false; return false;
} }
} }