From 9928297edf913038ef22a5acac7ee1e98c1f719d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Fri, 7 Aug 2009 15:18:14 +0200 Subject: [PATCH] Some fixes, use datadir for sounds too --- .gitignore | 2 +- Makefile | 14 ++++++------- bomber.c | 9 +++------ bomber.h | 9 --------- sound.c | 58 ++++++++++++++++++++++++++---------------------------- sound.h | 12 +++++++++++ 6 files changed, 51 insertions(+), 53 deletions(-) create mode 100644 sound.h diff --git a/.gitignore b/.gitignore index 7dca63a..236a2b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.o -bomber +sdlbomber matcher diff --git a/Makefile b/Makefile index ca49fa1..3759586 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ WARNFLAGS = -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-al override CFLAGS += -D_REENTRANT -O2 $(shell sdl-config --cflags) $(DBG) $(WARNFLAGS) .PHONY: all clean install -all: bomber +all: sdlbomber -bomber: bomber.o gfx.o sound.o announce.o - gcc -o bomber bomber.o gfx.o sound.o announce.o $(shell sdl-config --libs) -lavahi-common -lavahi-client $(DBG) +sdlbomber: bomber.o gfx.o sound.o announce.o + gcc -o sdlbomber bomber.o gfx.o sound.o announce.o $(shell sdl-config --libs) -lavahi-common -lavahi-client $(DBG) matcher: matcher.c @@ -20,10 +20,10 @@ sound.o: sound.c announce.o: announce.c announce.h clean: - rm -f *.o matcher bomber + rm -f *.o matcher sdlbomber -install: bomber +install: sdlbomber echo "Installing into $(DESTDIR)" mkdir -p "$(DESTDIR)/usr/bin/" "$(DESTDIR)/usr/share/sdlbomber/" - install -m 0755 bomber "$(DESTDIR)/usr/bin/" - install -m 0644 data/*.pcx "$(DESTDIR)/usr/share/sdlbomber/" + install -m 0755 sdlbomber "$(DESTDIR)/usr/bin/" + install -m 0644 data/*.pcx data/*.raw "$(DESTDIR)/usr/share/sdlbomber/" diff --git a/bomber.c b/bomber.c index ae991ec..88d45de 100644 --- a/bomber.c +++ b/bomber.c @@ -11,18 +11,15 @@ #include #include "bomber.h" #include "gfx.h" +#include "announce.h" +#include "sound.h" #include #include -#include "announce.h" static void domode(void); static int iterate(void); static int scaninvite(int size); -#ifndef DATADIR -#define DATADIR "." -#endif - #define FRACTION 9 #define MAXMSG 4096 #define PORT 5521 @@ -840,7 +837,7 @@ char tname[256]; if(ihand<0) { char tname2[256]; - sprintf(tname2,"data/%s.pcx",tname); + sprintf(tname2,"%s.pcx",tname); ihand=open(tname2,O_RDONLY); if(ihand<0) return 1; diff --git a/bomber.h b/bomber.h index 72cabff..f3e806b 100644 --- a/bomber.h +++ b/bomber.h @@ -328,13 +328,4 @@ received will be answered with PKT_QUIT. */ -int soundopen(void); -void soundclose(void); -void playsound(int n); - - - - #endif // BOMBER_H - - diff --git a/sound.c b/sound.c index 151d3c3..50ce9db 100644 --- a/sound.c +++ b/sound.c @@ -5,24 +5,26 @@ #include #include -char dirlist[]="data"; +#include "sound.h" -int readsound(int num); +static char dirlist[]=DATADIR; -#define NUMSOUNDS (sizeof(soundnames)/sizeof(char*)) +static int readsound(int num); + +#define NUMSOUNDS ((int)(sizeof(soundnames)/sizeof(char*))) #define MIXMAX 16 #define SOUND_QUIET -1 -char *soundnames[] = -{ -"bomb1.raw", -"power1.raw", -"death.raw", -"drop.raw", -"bomb2.raw", -"power2.raw", +static const char *soundnames[] = { + "bomb1.raw", + "power1.raw", + "death.raw", + "drop.raw", + "bomb2.raw", + "power2.raw", }; + typedef struct sample { char *data; @@ -31,21 +33,21 @@ typedef struct sample #define SNDFRAGMENT 1024 -sample samples[NUMSOUNDS]; +static sample samples[NUMSOUNDS]; -int soundworking=0; -int fragment; -int soundwrite,soundread; -int *soundbuffer; -int soundbufferlen; -unsigned char sndclip[8192]; +static int soundworking=0; +static int fragment; +// static int soundwrite,soundread; +static int *soundbuffer; +static int soundbufferlen; +static unsigned char sndclip[8192]; #define MAXSOUNDCOMMANDS 32 -char soundcommands[MAXSOUNDCOMMANDS]; -int soundtake,soundput; +static char soundcommands[MAXSOUNDCOMMANDS]; +static int soundtake,soundput; -int sndplaying[MIXMAX],sndposition[MIXMAX]; -void fillaudio(void *udata,Uint8 *buffer,int len) +static int sndplaying[MIXMAX],sndposition[MIXMAX]; +static void fillaudio(void *udata,Uint8 *buffer,int len) { char com,*p; int i,j,*ip; @@ -91,8 +93,7 @@ int which; } -int soundopen(void) -{ +int soundopen(void) { SDL_AudioSpec wanted; int i,j; @@ -131,8 +132,7 @@ int i,j; SDL_PauseAudio(0); return 0; } -void soundclose(void) -{ +void soundclose(void) { if(soundworking) { SDL_CloseAudio(); @@ -141,8 +141,7 @@ void soundclose(void) } -int readsound(int num) -{ +int readsound(int num) { char name[256],*p1,*p2,ch; int i,file,size,len; p1=dirlist; @@ -177,8 +176,7 @@ int i,file,size,len; return 0; } -void playsound(int n) -{ +void playsound(int n) { soundcommands[soundput]=n; soundput=(soundput+1)&(MAXSOUNDCOMMANDS-1); } diff --git a/sound.h b/sound.h new file mode 100644 index 0000000..d3ae16c --- /dev/null +++ b/sound.h @@ -0,0 +1,12 @@ +#ifndef SOUND_H +#define SOUND_H + +#ifndef DATADIR +#define DATADIR "data" +#endif + +int soundopen(void); +void soundclose(void); +void playsound(int n); + +#endif