Some fixes, use datadir for sounds too

This commit is contained in:
Stefan Bühler 2009-08-07 15:18:14 +02:00
parent d2e51f7389
commit 9928297edf
6 changed files with 51 additions and 53 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
*.o *.o
bomber sdlbomber
matcher matcher

View File

@ -4,10 +4,10 @@ WARNFLAGS = -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-al
override CFLAGS += -D_REENTRANT -O2 $(shell sdl-config --cflags) $(DBG) $(WARNFLAGS) override CFLAGS += -D_REENTRANT -O2 $(shell sdl-config --cflags) $(DBG) $(WARNFLAGS)
.PHONY: all clean install .PHONY: all clean install
all: bomber all: sdlbomber
bomber: bomber.o gfx.o sound.o announce.o sdlbomber: 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) gcc -o sdlbomber bomber.o gfx.o sound.o announce.o $(shell sdl-config --libs) -lavahi-common -lavahi-client $(DBG)
matcher: matcher.c matcher: matcher.c
@ -20,10 +20,10 @@ sound.o: sound.c
announce.o: announce.c announce.h announce.o: announce.c announce.h
clean: clean:
rm -f *.o matcher bomber rm -f *.o matcher sdlbomber
install: bomber install: sdlbomber
echo "Installing into $(DESTDIR)" echo "Installing into $(DESTDIR)"
mkdir -p "$(DESTDIR)/usr/bin/" "$(DESTDIR)/usr/share/sdlbomber/" mkdir -p "$(DESTDIR)/usr/bin/" "$(DESTDIR)/usr/share/sdlbomber/"
install -m 0755 bomber "$(DESTDIR)/usr/bin/" install -m 0755 sdlbomber "$(DESTDIR)/usr/bin/"
install -m 0644 data/*.pcx "$(DESTDIR)/usr/share/sdlbomber/" install -m 0644 data/*.pcx data/*.raw "$(DESTDIR)/usr/share/sdlbomber/"

View File

@ -11,18 +11,15 @@
#include <signal.h> #include <signal.h>
#include "bomber.h" #include "bomber.h"
#include "gfx.h" #include "gfx.h"
#include "announce.h"
#include "sound.h"
#include <fcntl.h> #include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
#include "announce.h"
static void domode(void); static void domode(void);
static int iterate(void); static int iterate(void);
static int scaninvite(int size); static int scaninvite(int size);
#ifndef DATADIR
#define DATADIR "."
#endif
#define FRACTION 9 #define FRACTION 9
#define MAXMSG 4096 #define MAXMSG 4096
#define PORT 5521 #define PORT 5521
@ -840,7 +837,7 @@ char tname[256];
if(ihand<0) if(ihand<0)
{ {
char tname2[256]; char tname2[256];
sprintf(tname2,"data/%s.pcx",tname); sprintf(tname2,"%s.pcx",tname);
ihand=open(tname2,O_RDONLY); ihand=open(tname2,O_RDONLY);
if(ihand<0) if(ihand<0)
return 1; return 1;

View File

@ -328,13 +328,4 @@ received will be answered with PKT_QUIT.
*/ */
int soundopen(void);
void soundclose(void);
void playsound(int n);
#endif // BOMBER_H #endif // BOMBER_H

58
sound.c
View File

@ -5,24 +5,26 @@
#include <SDL_audio.h> #include <SDL_audio.h>
#include <SDL_error.h> #include <SDL_error.h>
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 MIXMAX 16
#define SOUND_QUIET -1 #define SOUND_QUIET -1
char *soundnames[] = static const char *soundnames[] = {
{ "bomb1.raw",
"bomb1.raw", "power1.raw",
"power1.raw", "death.raw",
"death.raw", "drop.raw",
"drop.raw", "bomb2.raw",
"bomb2.raw", "power2.raw",
"power2.raw",
}; };
typedef struct sample typedef struct sample
{ {
char *data; char *data;
@ -31,21 +33,21 @@ typedef struct sample
#define SNDFRAGMENT 1024 #define SNDFRAGMENT 1024
sample samples[NUMSOUNDS]; static sample samples[NUMSOUNDS];
int soundworking=0; static int soundworking=0;
int fragment; static int fragment;
int soundwrite,soundread; // static int soundwrite,soundread;
int *soundbuffer; static int *soundbuffer;
int soundbufferlen; static int soundbufferlen;
unsigned char sndclip[8192]; static unsigned char sndclip[8192];
#define MAXSOUNDCOMMANDS 32 #define MAXSOUNDCOMMANDS 32
char soundcommands[MAXSOUNDCOMMANDS]; static char soundcommands[MAXSOUNDCOMMANDS];
int soundtake,soundput; static int soundtake,soundput;
int sndplaying[MIXMAX],sndposition[MIXMAX]; static int sndplaying[MIXMAX],sndposition[MIXMAX];
void fillaudio(void *udata,Uint8 *buffer,int len) static void fillaudio(void *udata,Uint8 *buffer,int len)
{ {
char com,*p; char com,*p;
int i,j,*ip; int i,j,*ip;
@ -91,8 +93,7 @@ int which;
} }
int soundopen(void) int soundopen(void) {
{
SDL_AudioSpec wanted; SDL_AudioSpec wanted;
int i,j; int i,j;
@ -131,8 +132,7 @@ int i,j;
SDL_PauseAudio(0); SDL_PauseAudio(0);
return 0; return 0;
} }
void soundclose(void) void soundclose(void) {
{
if(soundworking) if(soundworking)
{ {
SDL_CloseAudio(); SDL_CloseAudio();
@ -141,8 +141,7 @@ void soundclose(void)
} }
int readsound(int num) int readsound(int num) {
{
char name[256],*p1,*p2,ch; char name[256],*p1,*p2,ch;
int i,file,size,len; int i,file,size,len;
p1=dirlist; p1=dirlist;
@ -177,8 +176,7 @@ int i,file,size,len;
return 0; return 0;
} }
void playsound(int n) void playsound(int n) {
{
soundcommands[soundput]=n; soundcommands[soundput]=n;
soundput=(soundput+1)&(MAXSOUNDCOMMANDS-1); soundput=(soundput+1)&(MAXSOUNDCOMMANDS-1);
} }

12
sound.h Normal file
View File

@ -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