From: Holger Schemel Date: Tue, 28 Nov 2000 21:03:59 +0000 (+0100) Subject: rnd-20001128-1-src X-Git-Tag: 2.0.0^2~28 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=1150bdce04915bf329bd816307fb2507eba80e15;p=rocksndiamonds.git rnd-20001128-1-src --- diff --git a/Makefile b/Makefile index 82094534..cf775274 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,6 @@ X11_PATH = /usr/X11 # uncomment this if your system has no joystick include file # JOYSTICK = -DNO_JOYSTICK -# uncomment this if your system has no sound -# SOUNDS = -DNO_SOUNDS - # choose if you want to allow many global score file entries for one player # default is 'MANY_PER_NAME' # when installing the game in a multi user environment, choose this diff --git a/src/Makefile b/src/Makefile index 4dc15309..cc8e1df0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -84,7 +84,7 @@ endif CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR) -CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(SOUNDS) $(JOYSTICK) +CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(JOYSTICK) DEBUG = -DDEBUG -g OPTIONS = $(DEBUG) -Wall # only for debugging purposes @@ -93,6 +93,7 @@ OPTIONS = $(DEBUG) -Wall # only for debugging purposes # OPTIONS = -O3 -Wall -ansi -pedantic # OPTIONS = -O3 -Wall # OPTIONS = -O3 +# OPTIONS = -DSYSV -Ae # may be needed for HP-UX CFLAGS = $(OPTIONS) $(SYS_CFLAGS) $(CONFIG) LDFLAGS = $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm diff --git a/src/game.c b/src/game.c index 70802137..1f3aca00 100644 --- a/src/game.c +++ b/src/game.c @@ -167,10 +167,10 @@ static unsigned int getStateCheckSum(int counter) void GetPlayerConfig() { - if (sound_status == SOUND_OFF) + if (!sysinfo.audio_available) setup.sound = FALSE; - if (!sound_loops_allowed) + if (!sysinfo.audio_loops_available) { setup.sound_loops = FALSE; setup.sound_music = FALSE; @@ -6233,7 +6233,7 @@ static void HandleGameButtons(struct GadgetInfo *gi) setup.sound_music = FALSE; FadeSound(background_loop[level_nr % num_bg_loops]); } - else if (sound_loops_allowed) + else if (sysinfo.audio_loops_available) { setup.sound = setup.sound_music = TRUE; PlaySoundLoop(background_loop[level_nr % num_bg_loops]); @@ -6243,14 +6243,14 @@ static void HandleGameButtons(struct GadgetInfo *gi) case SOUND_CTRL_ID_LOOPS: if (setup.sound_loops) setup.sound_loops = FALSE; - else if (sound_loops_allowed) + else if (sysinfo.audio_loops_available) setup.sound = setup.sound_loops = TRUE; break; case SOUND_CTRL_ID_SIMPLE: if (setup.sound_simple) setup.sound_simple = FALSE; - else if (sound_status==SOUND_AVAILABLE) + else if (sysinfo.audio_available) setup.sound = setup.sound_simple = TRUE; break; diff --git a/src/init.c b/src/init.c index b95b99c2..60e0bcd3 100644 --- a/src/init.c +++ b/src/init.c @@ -35,10 +35,6 @@ struct PictureFileInfo boolean picture_with_mask; }; -#ifndef TARGET_SDL -static int sound_process_id = 0; -#endif - static void InitPlayerInfo(void); static void InitLevelInfo(void); static void InitNetworkServer(void); @@ -146,31 +142,32 @@ void InitSound() { int i; - if (sound_status == SOUND_OFF) + /* REMOVE THIS! (gone to system.c:InitAudio) */ + if (!sysinfo.audio_available) return; #if defined(TARGET_SDL) if (InitAudio()) { - sound_status = SOUND_AVAILABLE; - sound_loops_allowed = TRUE; + sysinfo.audio_available = TRUE; + sysinfo.audio_loops_available = TRUE; } else { - sound_status = SOUND_OFF; + sysinfo.audio_available = FALSE; } #else /* !TARGET_SDL */ #if defined(PLATFORM_UNIX) - if ((sound_status = CheckAudio(sound_device_name)) == SOUND_OFF) + if (!(sysinfo.audio_available = CheckAudio(sound_device_name))) return; #ifdef VOXWARE - sound_loops_allowed = TRUE; + sysinfo.audio_loops_available = TRUE; #endif #else /* !PLATFORM_UNIX */ - sound_loops_allowed = TRUE; + sysinfo.audio_loops_available = TRUE; #endif /* !PLATFORM_UNIX */ #endif /* !TARGET_SDL */ @@ -181,8 +178,8 @@ void InitSound() if (!LoadSound(&Sound[i])) { - sound_status = SOUND_OFF; - sound_loops_allowed = FALSE; + sysinfo.audio_available = FALSE; + sysinfo.audio_loops_available = FALSE; return; } } @@ -190,35 +187,35 @@ void InitSound() void InitSoundServer() { - if (sound_status == SOUND_OFF) + if (!sysinfo.audio_available) return; #if !defined(TARGET_SDL) #if defined(PLATFORM_UNIX) - if (pipe(sound_pipe)<0) + if (pipe(sysinfo.audio_process_pipe) < 0) { Error(ERR_WARN, "cannot create pipe - no sounds"); - sound_status = SOUND_OFF; + sysinfo.audio_available = FALSE; return; } - if ((sound_process_id = fork()) < 0) + if ((sysinfo.audio_process_id = fork()) < 0) { Error(ERR_WARN, "cannot create sound server process - no sounds"); - sound_status = SOUND_OFF; + sysinfo.audio_available = FALSE; return; } - if (!sound_process_id) /* we are child */ + if (!sysinfo.audio_process_id) /* we are child */ { SoundServer(); /* never reached */ exit(0); } - else /* we are parent */ - close(sound_pipe[0]); /* no reading from pipe needed */ + else /* we are parent */ + close(sysinfo.audio_process_pipe[0]); /* no reading from pipe needed */ #else /* !PLATFORM_UNIX */ @@ -1809,10 +1806,10 @@ void CloseAllAndExit(int exit_value) StopSounds(); FreeSounds(NUM_SOUNDS); #else - if (sound_process_id) + if (sysinfo.audio_process_id) { StopSounds(); - kill(sound_process_id, SIGTERM); + kill(sysinfo.audio_process_id, SIGTERM); FreeSounds(NUM_SOUNDS); } #endif diff --git a/src/main.c b/src/main.c index b980ea24..49fde3e9 100644 --- a/src/main.c +++ b/src/main.c @@ -35,9 +35,8 @@ Pixmap clipmask[NUM_BITMAPS], tile_clipmask[NUM_TILES]; DrawBuffer drawto, drawto_field, backbuffer, fieldbuffer; Colormap cmap; -int sound_pipe[2]; -int sound_device; char *sound_device_name = SOUND_DEVICE; + int joystick_device = 0; char *joystick_device_name[MAX_PLAYERS] = { @@ -57,8 +56,6 @@ boolean motion_status = FALSE; int key_joystick_mapping = 0; int global_joystick_status = JOYSTICK_STATUS; int joystick_status = JOYSTICK_STATUS; -int sound_status = SOUND_STATUS; -boolean sound_loops_allowed = FALSE; boolean fullscreen_available = FULLSCREEN_STATUS; boolean fullscreen_enabled = FALSE; @@ -105,11 +102,12 @@ struct LevelDirInfo *leveldir_first = NULL, *leveldir_current = NULL; struct LevelInfo level; struct PlayerInfo stored_player[MAX_PLAYERS], *local_player = NULL; struct HiScore highscore[MAX_SCORE_ENTRIES]; -struct SoundInfo Sound[NUM_SOUNDS]; +struct SampleInfo Sound[NUM_SOUNDS]; struct TapeInfo tape; struct OptionInfo options; struct SetupInfo setup; struct GameInfo game; +struct SystemInfo sysinfo; struct GlobalInfo global; /* data needed for playing sounds */ diff --git a/src/main.h b/src/main.h index 016433e1..705582ab 100644 --- a/src/main.h +++ b/src/main.h @@ -463,9 +463,8 @@ extern Pixmap clipmask[], tile_clipmask[]; extern DrawBuffer drawto, drawto_field, backbuffer, fieldbuffer; extern Colormap cmap; -extern int sound_pipe[2]; -extern int sound_device; extern char *sound_device_name; + extern int joystick_device; extern char *joystick_device_name[]; @@ -478,8 +477,6 @@ extern int button_status; extern boolean motion_status; extern int key_joystick_mapping; extern int global_joystick_status, joystick_status; -extern int sound_status; -extern boolean sound_loops_allowed; extern boolean fullscreen_available; extern boolean fullscreen_enabled; @@ -528,11 +525,12 @@ extern struct LevelInfo level; extern struct PlayerInfo stored_player[], *local_player; extern struct HiScore highscore[]; extern struct TapeInfo tape; -extern struct SoundInfo Sound[]; +extern struct SampleInfo Sound[]; extern struct JoystickInfo joystick[]; extern struct OptionInfo options; extern struct SetupInfo setup; extern struct GameInfo game; +extern struct SystemInfo sysinfo; extern struct GlobalInfo global; extern char *sound_name[]; diff --git a/src/msdos.c b/src/msdos.c index 089d1a9d..181a9f1a 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -90,10 +90,11 @@ static void allegro_drivers() last_joystick_state = 0; joystick_event = FALSE; + sysinfo.audio_available = TRUE; reserve_voices(MAX_SOUNDS_PLAYING, 0); if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1) if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1) - sound_status = SOUND_OFF; + sysinfo.audio_available = FALSE; } static boolean hide_mouse(Display *display, int x, int y, diff --git a/src/platform.h b/src/platform.h index 903f1165..6c40c695 100644 --- a/src/platform.h +++ b/src/platform.h @@ -22,4 +22,20 @@ #define PLATFORM_UNIX #endif +/* define additional keywords for several Unix platforms */ + +#if defined(__FreeBSD__) +#define PLATFORM_FREEBSD +#endif + +/* detecting HP-UX by the following compiler keyword definitions: + - in K&R mode (the default), the HP C compiler defines "hpux" + - in ANSI mode (-Aa or -Ae), the HP C compiler defines "__hpux" + - the gcc (Gnu) C compiler defines "__hpux__" + Thanks to Jarkko Hietaniemi for this note. */ + +#if defined(__hpux__) || defined(__hpux) || defined(hpux) +#define PLATFORM_HPUX +#endif + #endif /* PLATFORM_H */ diff --git a/src/screens.c b/src/screens.c index 1723c602..b97c44a1 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1409,7 +1409,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) { int yy = y-1; - if (y==3 && sound_status==SOUND_AVAILABLE) + if (y == 3 && sysinfo.audio_available) { if (setup.sound) { @@ -1423,7 +1423,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.sound = !setup.sound; } - else if (y==4 && sound_loops_allowed) + else if (y == 4 && sysinfo.audio_loops_available) { if (setup.sound_loops) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1435,7 +1435,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) } setup.sound_loops = !setup.sound_loops; } - else if (y==5 && sound_loops_allowed) + else if (y == 5 && sysinfo.audio_loops_available) { if (setup.sound_music) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1449,7 +1449,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) } #if 0 - else if (y==6) + else if (y == 6) { if (setup.toons) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1457,7 +1457,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.toons = !setup.toons; } - else if (y==7) + else if (y == 7) { #if 0 if (setup.double_buffering) @@ -1474,7 +1474,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) } #endif - else if (y==6) + else if (y == 6) { if (setup.scroll_delay) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1482,7 +1482,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.scroll_delay = !setup.scroll_delay; } - else if (y==7) + else if (y == 7) { if (setup.soft_scrolling) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1491,7 +1491,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) setup.soft_scrolling = !setup.soft_scrolling; } #if 0 - else if (y==8) + else if (y == 8) { if (setup.fading) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1500,7 +1500,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) setup.fading = !setup.fading; } #endif - else if (y==8 && fullscreen_available) + else if (y == 8 && fullscreen_available) { if (setup.fullscreen) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1508,7 +1508,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.fullscreen = !setup.fullscreen; } - else if (y==9) + else if (y == 9) { if (setup.quick_doors) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1516,7 +1516,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.quick_doors = !setup.quick_doors; } - else if (y==10) + else if (y == 10) { if (setup.autorecord) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1524,7 +1524,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.autorecord = !setup.autorecord; } - else if (y==11) + else if (y == 11) { if (setup.team_mode) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1532,7 +1532,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.team_mode = !setup.team_mode; } - else if (y==12) + else if (y == 12) { if (setup.handicap) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1540,7 +1540,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.handicap = !setup.handicap; } - else if (y==13) + else if (y == 13) { if (setup.time_limit) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); @@ -1548,7 +1548,7 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); setup.time_limit = !setup.time_limit; } - else if (y==14) + else if (y == 14) { game_status = SETUPINPUT; DrawSetupInputScreen(); diff --git a/src/sound.c b/src/sound.c index 51b0f126..185b1822 100644 --- a/src/sound.c +++ b/src/sound.c @@ -104,7 +104,7 @@ void SoundServer() struct SoundControl snd_ctrl; fd_set sound_fdset; - close(sound_pipe[1]); /* no writing into pipe needed */ + close(sysinfo.audio_process_pipe[1]); /* no writing into pipe needed */ #endif for(i=0;i= 0) + (sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { @@ -196,12 +197,13 @@ void SoundServer() /* (with stereo the effective buffer size will shrink to 256) */ fragment_size = 0x00020009; - if (ioctl(sound_device, SNDCTL_DSP_SETFRAGMENT, &fragment_size) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_size) + < 0) Error(ERR_EXIT_SOUND_SERVER, "cannot set fragment size of /dev/dsp - no sounds"); /* try if we can use stereo sound */ - if (ioctl(sound_device, SNDCTL_DSP_STEREO, &stereo) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_STEREO, &stereo) < 0) { #ifdef DEBUG static boolean reported = FALSE; @@ -215,12 +217,13 @@ void SoundServer() stereo = FALSE; } - if (ioctl(sound_device, SNDCTL_DSP_SPEED, &sample_rate) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_SPEED, &sample_rate) < 0) Error(ERR_EXIT_SOUND_SERVER, "cannot set sample rate of /dev/dsp - no sounds"); /* get the real fragmentation size; this should return 512 */ - if (ioctl(sound_device, SNDCTL_DSP_GETBLKSIZE, &fragment_size) < 0) + if (ioctl(sysinfo.audio_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size) + < 0) Error(ERR_EXIT_SOUND_SERVER, "cannot get fragment size of /dev/dsp - no sounds"); @@ -231,9 +234,10 @@ void SoundServer() SoundServer_InsertNewSound(snd_ctrl); while(playing_sounds && - select(sound_pipe[0]+1,&sound_fdset,NULL,NULL,&delay)<1) + select(sysinfo.audio_process_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { - FD_SET(sound_pipe[0], &sound_fdset); + FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset); /* first clear the last premixing buffer */ memset(premix_last_buffer,0,fragment_size*sizeof(int)); @@ -330,12 +334,12 @@ void SoundServer() } /* finally play the sound fragment */ - write(sound_device,playing_buffer,fragment_size); + write(sysinfo.audio_fd, playing_buffer,fragment_size); } /* if no sounds playing, free device for other sound programs */ if (!playing_sounds) - close(sound_device); + close(sysinfo.audio_fd); } } @@ -350,14 +354,15 @@ void SoundServer() int wait_percent = 90; /* wait 90% of the real playing time */ int i; - if ((sound_device = OpenAudio(sound_device_name)) >= 0) + if ((sysinfo.audio_fd = OpenAudio(sound_device_name)) >= 0) { playing_sounds = 1; while(playing_sounds && - select(sound_pipe[0]+1,&sound_fdset,NULL,NULL,&delay)<1) + select(sysinfo.audio_process_pipe[0] + 1, + &sound_fdset, NULL, NULL, &delay) < 1) { - FD_SET(sound_pipe[0], &sound_fdset); + FD_SET(sysinfo.audio_process_pipe[0], &sound_fdset); /* get pointer and size of the actual sound sample */ sample_ptr = snd_ctrl.data_ptr + snd_ctrl.playingpos; @@ -384,12 +389,12 @@ void SoundServer() playing_sounds = 0; /* finally play the sound fragment */ - write(sound_device,playing_buffer,sample_size); + write(sysinfo.audio_fd,playing_buffer,sample_size); delay.tv_sec = 0; delay.tv_usec = ((sample_size*10*wait_percent)/(sample_rate))*1000; } - close(sound_device); + close(sysinfo.audio_fd); } } @@ -603,7 +608,7 @@ static void SoundServer_StopSound(int nr) #if !defined(PLATFORM_MSDOS) if (!playing_sounds) - close(sound_device); + close(sysinfo.audio_fd); #endif } @@ -622,7 +627,7 @@ static void SoundServer_StopAllSounds() playing_sounds = 0; #if !defined(PLATFORM_MSDOS) - close(sound_device); + close(sysinfo.audio_fd); #endif } #endif /* PLATFORM_MSDOS */ @@ -767,7 +772,7 @@ static int ulaw_to_linear(unsigned char ulawbyte) #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define WAV_HEADER_SIZE 20 /* size of WAV file header */ -boolean LoadSound(struct SoundInfo *snd_info) +boolean LoadSound(struct SampleInfo *snd_info) { char filename[256]; char *sound_ext = "wav"; @@ -886,7 +891,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) { struct SoundControl snd_ctrl = emptySoundControl; - if (sound_status==SOUND_OFF || !setup.sound) + if (!sysinfo.audio_available || !setup.sound) return; if (volume