JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
config.h - Added debug() macro, fixed Makefile and sound.c to use it.
authorJoshua Grams <josh@qualdan.com>
Mon, 10 Jan 2005 22:14:52 +0000 (22:14 +0000)
committerJoshua Grams <josh@qualdan.com>
Mon, 10 Jan 2005 22:14:52 +0000 (22:14 +0000)
   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
config.h
debug.c [new file with mode: 0644]
debug.h [new file with mode: 0644]
file.c
main.c
score.c
sound.c

index 0b8ef80..3f06d1e 100644 (file)
--- a/Makefile
+++ b/Makefile
 #   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)
 
index 3bbb662..0c04fde 100644 (file)
--- 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 (file)
index 0000000..20ee5c2
--- /dev/null
+++ b/debug.c
@@ -0,0 +1,25 @@
+#include "debug.h"
+
+#include <stdio.h>
+
+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 (file)
index 0000000..01d90a8
--- /dev/null
+++ b/debug.h
@@ -0,0 +1,8 @@
+#ifndef VOR_DEBUG_H
+#define VOR_DEBUG_H
+
+#include <SDL.h>
+
+void printf_surface(SDL_Surface *s, char *name);
+
+#endif // VOR_DEBUG_H
diff --git a/file.c b/file.c
index 57cfc56..18193b2 100644 (file)
--- 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 (file)
--- 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<NROCKS; i++) {
-               char a[100];
+               char a[MAX_PATH_LEN];
 
-               sprintf(a,add_path("sprites/rock%d.png"),i);
+               snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%d.png"),i);
                NULLERROR(temp = IMG_Load(a));
                NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
 
-               sprintf(a,add_path("sprites/deadrock%d.png"),i);
+               snprintf(a,MAX_PATH_LEN,add_path("sprites/deadrock%d.png"),i);
                NULLERROR(temp = IMG_Load(a));
                NULLERROR(surf_deadrock[i] = SDL_DisplayFormat(temp));
        }
@@ -725,6 +727,7 @@ draw() {
                case HIGH_SCORE_DISPLAY:
                        // Display de list o high scores mon.
                        display_scores(surf_screen, 150,50);
+                       break;
                case GAMEPLAY:
                case DEAD_PAUSE:
                        ; // no action necessary
diff --git a/score.c b/score.c
index faef94a..f37fc66 100644 (file)
--- a/score.c
+++ b/score.c
@@ -55,8 +55,6 @@ read_high_score_table()
        if(f) {
                // If the file exists, read from it
                for(i = 0; i<N_SCORES; i++) {
-                       g_scores[i].score = 0;
-                       g_scores[i].name[0] = 0;
                        fscanf(f, "%d %31[^\n]", &g_scores[i].score, g_scores[i].name);
                }
                fclose(f);
diff --git a/sound.c b/sound.c
index 3f13e0e..e9008f1 100644 (file)
--- a/sound.c
+++ b/sound.c
@@ -1,4 +1,5 @@
 #include "sound.h"
+#include "config.h"
 
 extern int sound_flag, music_flag;
 
@@ -40,9 +41,7 @@ init_sound() {
     // Return 1 if the sound is ready to roll, and 0 if not.
 
     int i;
-#ifdef DEBUG
-    printf ("Initialise sound\n");
-#endif
+    debug(printf ("Initialise sound\n"));
 
     // Initialise output with SDL_mixer
     if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 4096) < 0) {
@@ -50,14 +49,14 @@ init_sound() {
        return 0;
     }
 
-#ifdef 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");
-#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<NUM_TUNES; i++) {
@@ -77,17 +76,13 @@ init_sound() {
 void
 play_sound(int i)  {
        if(!sound_flag) return;
-#ifdef DEBUG
-    printf ("play sound %d on first free channel\n",i);
-#endif
+    debug(printf ("play sound %d on first free channel\n",i));
     Mix_PlayChannel(-1, wav[i], 0);
 }/*}}}*/
 
 int playing=-1;
 
 
-#undef DEBUG
-
 void
 play_tune(int i) {/*{{{*/
        if(!sound_flag || !music_flag) return;
@@ -95,14 +90,12 @@ play_tune(int i) {/*{{{*/
        return;
     if (playing) {
        Mix_FadeOutMusic(1500);
-#ifdef DEBUG
-       printf("Stop playing %d\n",playing);
-#endif
+       debug(printf("Stop playing %d\n",playing));
     }
-#ifdef DEBUG
-    printf ("Play music %d\n",i);
-    printf ("volume %d\n",music_volume[i]);
-#endif
+       debug(
+                       printf ("Play music %d\n",i);
+                       printf ("volume %d\n",music_volume[i]);
+                       )
     Mix_FadeInMusic(music[i],-1,2000);
     Mix_VolumeMusic(music_volume[i]);