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.
# 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)
#ifndef VOR_CONFIG_H
#define VOR_CONFIG_H
+#define debug(x) if(DEBUG) { x; }
+
#define VERSION "0.1"
#define DATA_PREFIX "/usr/share/vor"
--- /dev/null
+#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");
+}
--- /dev/null
+#ifndef VOR_DEBUG_H
+#define VOR_DEBUG_H
+
+#include <SDL.h>
+
+void printf_surface(SDL_Surface *s, char *name);
+
+#endif // VOR_DEBUG_H
{
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,
* 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"
// 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));
}
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
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);
#include "sound.h"
+#include "config.h"
extern int sound_flag, music_flag;
// 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) {
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++) {
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;
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]);