From 232d1b5f32a2d72f4d3fe7326f942bb7887a7f40 Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Mon, 10 Jan 2005 22:14:52 +0000 Subject: [PATCH] config.h - Added debug() macro, fixed Makefile and sound.c to use it. Added debug.c debug.h to go along with this. file.c - fixed bug in find_score_file (added strdup). score.c (read_high_score_table) - removed initializers so we use values which are assigned to the global g_score. --- Makefile | 5 +++-- config.h | 2 ++ debug.c | 25 +++++++++++++++++++++++++ debug.h | 8 ++++++++ file.c | 5 ++++- main.c | 11 +++++++---- score.c | 2 -- sound.c | 39 ++++++++++++++++----------------------- 8 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 debug.c create mode 100644 debug.h diff --git a/Makefile b/Makefile index 0b8ef80..3f06d1e 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +debug := $(if $(DEBUG),1,0) ldflags := $(shell sdl-config --libs) -lSDL_image -lSDL_mixer -cflags := $(shell sdl-config --cflags) -Wall +cflags := $(shell sdl-config --cflags) -Wall -DDEBUG=$(debug) -my_objects := file.o score.o sound.o main.o +my_objects := file.o score.o sound.o main.o $(if $(DEBUG),debug.o) libs := SFont.o objects := $(libs) $(my_objects) diff --git a/config.h b/config.h index 3bbb662..0c04fde 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,8 @@ #ifndef VOR_CONFIG_H #define VOR_CONFIG_H +#define debug(x) if(DEBUG) { x; } + #define VERSION "0.1" #define DATA_PREFIX "/usr/share/vor" diff --git a/debug.c b/debug.c new file mode 100644 index 0000000..20ee5c2 --- /dev/null +++ b/debug.c @@ -0,0 +1,25 @@ +#include "debug.h" + +#include + +void +printf_surface(SDL_Surface *s, char *name) +{ + printf("SDL_Surface *%s = {\n", name); + printf("\tflags = 0x%x;\n", s->flags); + printf("\tformat = {\n"); + printf("\t\tBitsPerPixel = %d;\n", s->format->BitsPerPixel); + printf("\t\tBytesPerPixel = %d;\n", s->format->BytesPerPixel); + printf("\t\tmasks = 0x%x, 0x%x, 0x%x, 0x%x;\n", s->format->Rmask, s->format->Gmask, + s->format->Bmask, s->format->Amask); + printf("\t\tshifts = %d, %d, %d, %d;\n", s->format->Rshift, s->format->Gshift, + s->format->Bshift, s->format->Ashift); + printf("\t\tlosses = %d, %d, %d, %d;\n", s->format->Rloss, s->format->Gloss, + s->format->Bloss, s->format->Aloss); + printf("\t\tcolorkey = %d;\n", s->format->colorkey); + printf("\t\talpha = %d;\n", s->format->alpha); + printf("\t};\n"); + printf("\tw, h = %d, %d;\n", s->w, s->h); + printf("\tpitch = %d;\n", s->pitch); + printf("};\n"); +} diff --git a/debug.h b/debug.h new file mode 100644 index 0000000..01d90a8 --- /dev/null +++ b/debug.h @@ -0,0 +1,8 @@ +#ifndef VOR_DEBUG_H +#define VOR_DEBUG_H + +#include + +void printf_surface(SDL_Surface *s, char *name); + +#endif // VOR_DEBUG_H diff --git a/file.c b/file.c index 57cfc56..18193b2 100644 --- a/file.c +++ b/file.c @@ -82,7 +82,10 @@ find_score_file(void) { g_score_file = add_path("scores"); g_score_mode = 0111; - if(is_file(g_score_file)) return true; + if(is_file(g_score_file)) { + g_score_file = strdup(g_score_file); + return true; + } g_score_file = malloc(MAX_PATH_LEN); snprintf(g_score_file, MAX_PATH_LEN, diff --git a/main.c b/main.c index 4801df7..825d85d 100644 --- a/main.c +++ b/main.c @@ -19,7 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#undef DEBUG +#ifdef DEBUG +#include "debug.h" +#endif #include "config.h" #include "file.h" @@ -562,13 +564,13 @@ init(int fullscreen) { // Load all our lovely rocks for(i = 0; i 1) ? "stereo" : "mono"); -#endif + debug( + // What kind of sound did we get? Ah who cares. As long as it can play + // some basic bangs and simple music. + Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); + printf("Opened audio at %d Hz %d bit %s\n", audio_rate, + (audio_format&0xFF), + (audio_channels > 1) ? "stereo" : "mono"); + ) // Preload all the tunes into memory for (i=0; i