From e788c9b6a44d9f2dea7aa048b48a11b14761229e Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 19 May 2002 21:52:57 +0200 Subject: [PATCH] rnd-20020519-2-src --- src/game.c | 48 ++++++------- src/init.c | 5 +- src/libgame/misc.c | 2 +- src/libgame/sound.c | 169 ++++++++++++++++++++++++++------------------ src/libgame/sound.h | 96 +++++++++++-------------- src/main.h | 8 --- src/timestamp.h | 2 +- src/tools.c | 8 +-- 8 files changed, 168 insertions(+), 170 deletions(-) diff --git a/src/game.c b/src/game.c index 89d556d3..fc53f256 100644 --- a/src/game.c +++ b/src/game.c @@ -865,7 +865,7 @@ void InitGame() OpenDoor(DOOR_OPEN_ALL); - PlaySoundStereo(SND_GAME_STARTING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_GAME_STARTING, SOUND_MAX_RIGHT); if (setup.sound_music) PlayMusic(level_nr); @@ -1018,18 +1018,18 @@ void GameWon() local_player->LevelSolved = FALSE; - PlaySoundStereo(SND_GAME_WINNING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_GAME_WINNING, SOUND_MAX_RIGHT); if (TimeLeft) { if (!tape.playing && setup.sound_loops) - PlaySoundExt(SND_GAME_LEVELTIME_BONUS, PSND_MAX_VOLUME, PSND_MAX_RIGHT, + PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT, SND_CTRL_PLAY_LOOP); while (TimeLeft > 0) { if (!tape.playing && !setup.sound_loops) - PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, PSND_MAX_RIGHT); + PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_RIGHT); if (TimeLeft > 0 && !(TimeLeft % 10)) RaiseScore(level.score[SC_ZEITBONUS]); if (TimeLeft > 100 && !(TimeLeft % 10)) @@ -1049,13 +1049,13 @@ void GameWon() else if (level.time == 0) /* level without time limit */ { if (!tape.playing && setup.sound_loops) - PlaySoundExt(SND_GAME_LEVELTIME_BONUS, PSND_MAX_VOLUME, PSND_MAX_RIGHT, + PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MAX_RIGHT, SND_CTRL_PLAY_LOOP); while (TimePlayed < 999) { if (!tape.playing && !setup.sound_loops) - PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, PSND_MAX_RIGHT); + PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_RIGHT); if (TimePlayed < 999 && !(TimePlayed % 10)) RaiseScore(level.score[SC_ZEITBONUS]); if (TimePlayed < 900 && !(TimePlayed % 10)) @@ -4941,7 +4941,7 @@ void GameActions() TimeLeft--; if (TimeLeft <= 10 && setup.time_limit) - PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, PSND_MAX_RIGHT); + PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MAX_RIGHT); DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); @@ -5807,7 +5807,7 @@ int DigField(struct PlayerInfo *player, TimeLeft += 10; DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); } - PlaySoundStereo(SND_EXTRA_TIME_COLLECTING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_EXTRA_TIME_COLLECTING, SOUND_MAX_RIGHT); break; case EL_SHIELD_PASSIVE: @@ -5999,7 +5999,7 @@ int DigField(struct PlayerInfo *player, return MF_NO_ACTION; player->LevelSolved = player->GameOver = TRUE; - PlaySoundStereo(SND_SP_EXIT_ENTERING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_SP_EXIT_ENTERING, SOUND_MAX_RIGHT); break; case EL_FELSBROCKEN: @@ -6246,7 +6246,7 @@ int DigField(struct PlayerInfo *player, TimeLeft += 10; DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); DrawLevelField(x, y); - PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MAX_RIGHT); return MF_ACTION; break; @@ -6449,7 +6449,7 @@ void PlaySoundLevel(int x, int y, int nr) { int sx = SCREENX(x), sy = SCREENY(y); int volume, stereo_position; - int silence_distance = 8; + int max_distance = 8; int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND); if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) || @@ -6457,30 +6457,24 @@ void PlaySoundLevel(int x, int y, int nr) return; if (!IN_LEV_FIELD(x, y) || - sx < -silence_distance || sx >= SCR_FIELDX + silence_distance || - sy < -silence_distance || sy >= SCR_FIELDY + silence_distance) + sx < -max_distance || sx >= SCR_FIELDX + max_distance || + sy < -max_distance || sy >= SCR_FIELDY + max_distance) return; - volume = PSND_MAX_VOLUME; - -#if !defined(PLATFORM_MSDOS) - stereo_position = (sx - SCR_FIELDX / 2) * 12; -#else - stereo_position = PSND_MIDDLE + (2 * sx - (SCR_FIELDX - 1)) * 5; - if (stereo_position > PSND_MAX_RIGHT) - stereo_position = PSND_MAX_RIGHT; - if (stereo_position < PSND_MAX_LEFT) - stereo_position = PSND_MAX_LEFT; -#endif + volume = SOUND_MAX_VOLUME; if (!IN_SCR_FIELD(sx, sy)) { - int dx = ABS(sx - SCR_FIELDX/2) - SCR_FIELDX/2; - int dy = ABS(sy - SCR_FIELDY/2) - SCR_FIELDY/2; + int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2; + int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2; - volume -= volume * (dx > dy ? dx : dy) / silence_distance; + volume -= volume * (dx > dy ? dx : dy) / max_distance; } + stereo_position = (SOUND_MAX_LEFT + + (sx + max_distance) * SOUND_MAX_LEFT2RIGHT / + (SCR_FIELDX + 2 * max_distance)); + PlaySoundExt(nr, volume, stereo_position, type); } diff --git a/src/init.c b/src/init.c index 08069f4a..8393c629 100644 --- a/src/init.c +++ b/src/init.c @@ -361,10 +361,7 @@ void InitGfx() DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); -#if defined(PLATFORM_MSDOS) - DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE); - rest(200); -#endif + DrawInitText("Loading graphics:", 120, FC_GREEN); for(i=0; i> PSND_MAX_VOLUME_BITS; + mixer[i].volume * (long)premix_first_buffer[j] / SOUND_MAX_VOLUME; /* fill the last mixing buffer with stereo or mono sound */ if (stereo) { - int middle_pos = PSND_MAX_LEFT2RIGHT / 2; - int left_volume = stereo_volume[middle_pos + mixer[i].stereo_position]; - int right_volume= stereo_volume[middle_pos - mixer[i].stereo_position]; + int left_volume = SOUND_VOLUME_LEFT(mixer[i].stereo_position); + int right_volume = SOUND_VOLUME_RIGHT(mixer[i].stereo_position); for(j=0; j> PSND_MAX_LEFT2RIGHT_BITS; + left_volume * premix_first_buffer[j] / SOUND_MAX_LEFT2RIGHT; premix_right_buffer[j] = - (right_volume * premix_first_buffer[j]) - >> PSND_MAX_LEFT2RIGHT_BITS; + right_volume * premix_first_buffer[j] / SOUND_MAX_LEFT2RIGHT; premix_last_buffer[2 * j + 0] += premix_left_buffer[j]; premix_last_buffer[2 * j + 1] += premix_right_buffer[j]; @@ -1233,11 +1265,10 @@ static int Mixer_Main_SimpleAudio(SoundControl snd_ctrl) premix_first_buffer); /* adjust volume of actual sound sample */ - if (mixer[i].volume != PSND_MAX_VOLUME) + if (mixer[i].volume != SOUND_MAX_VOLUME) for(j=0; j> PSND_MAX_VOLUME_BITS; + mixer[i].volume * (long)premix_first_buffer[j] / SOUND_MAX_VOLUME; /* might be needed for u-law /dev/audio */ #if 0 @@ -1455,7 +1486,7 @@ static int ulaw_to_linear(unsigned char ulawbyte) static SoundInfo *Load_WAV(char *filename) { SoundInfo *snd_info; -#if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS) +#if defined(AUDIO_UNIX_NATIVE) byte sound_header_buffer[WAV_HEADER_SIZE]; char chunk_name[CHUNK_ID_LEN + 1]; int chunk_size; @@ -1780,22 +1811,22 @@ void PlayMusic(int nr) void PlaySound(int nr) { - PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, SND_CTRL_PLAY_SOUND); + PlaySoundExt(nr, SOUND_MAX_VOLUME, SOUND_MIDDLE, SND_CTRL_PLAY_SOUND); } void PlaySoundStereo(int nr, int stereo_position) { - PlaySoundExt(nr, PSND_MAX_VOLUME, stereo_position, SND_CTRL_PLAY_SOUND); + PlaySoundExt(nr, SOUND_MAX_VOLUME, stereo_position, SND_CTRL_PLAY_SOUND); } void PlaySoundLoop(int nr) { - PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, SND_CTRL_PLAY_LOOP); + PlaySoundExt(nr, SOUND_MAX_VOLUME, SOUND_MIDDLE, SND_CTRL_PLAY_LOOP); } void PlaySoundMusic(int nr) { - PlaySoundExt(nr, PSND_MAX_VOLUME, PSND_MIDDLE, SND_CTRL_PLAY_MUSIC); + PlaySoundExt(nr, SOUND_MAX_VOLUME, SOUND_MIDDLE, SND_CTRL_PLAY_MUSIC); } void PlaySoundExt(int nr, int volume, int stereo_position, int state) @@ -1807,15 +1838,15 @@ void PlaySoundExt(int nr, int volume, int stereo_position, int state) audio.sound_deactivated) return; - if (volume < PSND_MIN_VOLUME) - volume = PSND_MIN_VOLUME; - else if (volume > PSND_MAX_VOLUME) - volume = PSND_MAX_VOLUME; + if (volume < SOUND_MIN_VOLUME) + volume = SOUND_MIN_VOLUME; + else if (volume > SOUND_MAX_VOLUME) + volume = SOUND_MAX_VOLUME; - if (stereo_position < PSND_MAX_LEFT) - stereo_position = PSND_MAX_LEFT; - else if (stereo_position > PSND_MAX_RIGHT) - stereo_position = PSND_MAX_RIGHT; + if (stereo_position < SOUND_MAX_LEFT) + stereo_position = SOUND_MAX_LEFT; + else if (stereo_position > SOUND_MAX_RIGHT) + stereo_position = SOUND_MAX_RIGHT; snd_ctrl.active = TRUE; snd_ctrl.nr = nr; @@ -2047,10 +2078,10 @@ void InitReloadSounds(char *set_name) if (!audio.sound_available) return; -#if defined(TARGET_SDL) || defined(TARGET_ALLEGRO) - ReloadCustomSounds(); -#elif defined(AUDIO_UNIX_NATIVE) +#if defined(AUDIO_UNIX_NATIVE) WriteReloadInfoToPipe(set_name, SND_CTRL_RELOAD_SOUNDS); +#else + ReloadCustomSounds(); #endif } @@ -2059,10 +2090,10 @@ void InitReloadMusic(char *set_name) if (!audio.music_available) return; -#if defined(TARGET_SDL) || defined(TARGET_ALLEGRO) - ReloadCustomMusic(); -#elif defined(AUDIO_UNIX_NATIVE) +#if defined(AUDIO_UNIX_NATIVE) WriteReloadInfoToPipe(set_name, SND_CTRL_RELOAD_MUSIC); +#else + ReloadCustomMusic(); #endif } diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 5d27f20a..9997e664 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -70,63 +70,51 @@ /* values for PlaySound(), StopSound() and friends */ -#define SND_CTRL_NONE (0) -#define SND_CTRL_MUSIC (1 << 0) -#define SND_CTRL_LOOP (1 << 1) -#define SND_CTRL_FADE (1 << 2) -#define SND_CTRL_STOP (1 << 3) -#define SND_CTRL_ALL_SOUNDS (1 << 4) -#define SND_CTRL_RELOAD_SOUNDS (1 << 5) -#define SND_CTRL_RELOAD_MUSIC (1 << 6) - -#define SND_CTRL_PLAY_SOUND (SND_CTRL_NONE) -#define SND_CTRL_PLAY_LOOP (SND_CTRL_LOOP) -#define SND_CTRL_PLAY_MUSIC (SND_CTRL_LOOP | SND_CTRL_MUSIC) - -#define SND_CTRL_FADE_SOUND (SND_CTRL_FADE) -#define SND_CTRL_FADE_MUSIC (SND_CTRL_FADE | SND_CTRL_MUSIC) -#define SND_CTRL_FADE_ALL (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS) - -#define SND_CTRL_STOP_SOUND (SND_CTRL_STOP) -#define SND_CTRL_STOP_MUSIC (SND_CTRL_STOP | SND_CTRL_MUSIC) -#define SND_CTRL_STOP_ALL (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS) - -#define IS_MUSIC(x) ((x).state & SND_CTRL_MUSIC) -#define IS_LOOP(x) ((x).state & SND_CTRL_LOOP) -#define IS_FADING(x) ((x).state & SND_CTRL_FADE) -#define IS_STOPPING(x) ((x).state & SND_CTRL_STOP) -#define IS_RELOADING(x) ((x).state & (SND_CTRL_RELOAD_SOUNDS | \ - SND_CTRL_RELOAD_MUSIC)) -#define ALL_SOUNDS(x) ((x).state & SND_CTRL_ALL_SOUNDS) - - -#if !defined(TARGET_ALLEGRO) - -#define PSND_SILENCE 0 -#define PSND_MAX_VOLUME_BITS 15 -#define PSND_MIN_VOLUME 0 -#define PSND_MAX_VOLUME (1 << PSND_MAX_VOLUME_BITS) -#define PSND_MIDDLE 0 -#define PSND_MAX_STEREO_BITS 7 -#define PSND_MAX_STEREO (1 << PSND_MAX_STEREO_BITS) -#define PSND_MAX_LEFT (-PSND_MAX_STEREO) -#define PSND_MAX_RIGHT (+PSND_MAX_STEREO) -#define PSND_MAX_LEFT2RIGHT_BITS (PSND_MAX_STEREO_BITS+1) -#define PSND_MAX_LEFT2RIGHT (1 << PSND_MAX_LEFT2RIGHT_BITS) - -#else /* TARGET_ALLEGRO */ - -#define PSND_SILENCE 0 -#define PSND_MIN_VOLUME 0 -#define PSND_MAX_VOLUME 255 -#define PSND_MAX_LEFT 0 -#define PSND_MAX_RIGHT 255 -#define PSND_MIDDLE 128 - +#define SND_CTRL_NONE (0) +#define SND_CTRL_MUSIC (1 << 0) +#define SND_CTRL_LOOP (1 << 1) +#define SND_CTRL_FADE (1 << 2) +#define SND_CTRL_STOP (1 << 3) +#define SND_CTRL_ALL_SOUNDS (1 << 4) +#define SND_CTRL_RELOAD_SOUNDS (1 << 5) +#define SND_CTRL_RELOAD_MUSIC (1 << 6) + +#define SND_CTRL_PLAY_SOUND (SND_CTRL_NONE) +#define SND_CTRL_PLAY_LOOP (SND_CTRL_LOOP) +#define SND_CTRL_PLAY_MUSIC (SND_CTRL_LOOP | SND_CTRL_MUSIC) + +#define SND_CTRL_FADE_SOUND (SND_CTRL_FADE) +#define SND_CTRL_FADE_MUSIC (SND_CTRL_FADE | SND_CTRL_MUSIC) +#define SND_CTRL_FADE_ALL (SND_CTRL_FADE | SND_CTRL_ALL_SOUNDS) + +#define SND_CTRL_STOP_SOUND (SND_CTRL_STOP) +#define SND_CTRL_STOP_MUSIC (SND_CTRL_STOP | SND_CTRL_MUSIC) +#define SND_CTRL_STOP_ALL (SND_CTRL_STOP | SND_CTRL_ALL_SOUNDS) + +#define IS_MUSIC(x) ((x).state & SND_CTRL_MUSIC) +#define IS_LOOP(x) ((x).state & SND_CTRL_LOOP) +#define IS_FADING(x) ((x).state & SND_CTRL_FADE) +#define IS_STOPPING(x) ((x).state & SND_CTRL_STOP) +#define IS_RELOADING(x) ((x).state & (SND_CTRL_RELOAD_SOUNDS |\ + SND_CTRL_RELOAD_MUSIC)) +#define ALL_SOUNDS(x) ((x).state & SND_CTRL_ALL_SOUNDS) + +#define SOUND_MIN_VOLUME 0 +#if defined(TARGET_SDL) +#define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME +#elif defined(TARGET_ALLEGRO) +#define SOUND_MAX_VOLUME 255 +#else +#define SOUND_MAX_VOLUME 128 #endif +#define SOUND_MAX_LEFT 0 +#define SOUND_MAX_RIGHT 255 +#define SOUND_MAX_LEFT2RIGHT 255 +#define SOUND_MIDDLE (SOUND_MAX_LEFT2RIGHT / 2) + /* value for undefined sound effect filename */ -#define SND_FILE_UNDEFINED "NONE" +#define SND_FILE_UNDEFINED "NONE" struct SoundEffectInfo diff --git a/src/main.h b/src/main.h index 28495aea..06939a39 100644 --- a/src/main.h +++ b/src/main.h @@ -30,14 +30,6 @@ #define WIN_XSIZE 672 #define WIN_YSIZE 560 -#if !defined(PLATFORM_MSDOS) -#define WIN_XPOS 0 -#define WIN_YPOS 0 -#else -#define WIN_XPOS ((XRES - WIN_XSIZE) / 2) -#define WIN_YPOS ((YRES - WIN_YSIZE) / 2) -#endif - #define SCR_FIELDX 17 #define SCR_FIELDY 17 #define MAX_BUF_XSIZE (SCR_FIELDX + 2) diff --git a/src/timestamp.h b/src/timestamp.h index 1e92361f..18c401c9 100644 --- a/src/timestamp.h +++ b/src/timestamp.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-05-19 14:04]" +#define COMPILE_DATE_STRING "[2002-05-19 20:35]" diff --git a/src/tools.c b/src/tools.c index a300c84f..801eb6b5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -20,10 +20,6 @@ #include "network.h" #include "tape.h" -#if defined(PLATFORM_MSDOS) -extern boolean wait_for_vsync; -#endif - /* tool button identifiers */ #define TOOL_CTRL_ID_YES 0 #define TOOL_CTRL_ID_NO 1 @@ -2105,9 +2101,9 @@ unsigned int MoveDoor(unsigned int door_state) if (!(door_state & DOOR_NO_DELAY)) { if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2)) - PlaySoundStereo(SND_MENU_DOOR_OPENING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_MENU_DOOR_OPENING, SOUND_MAX_RIGHT); if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2)) - PlaySoundStereo(SND_MENU_DOOR_CLOSING, PSND_MAX_RIGHT); + PlaySoundStereo(SND_MENU_DOOR_CLOSING, SOUND_MAX_RIGHT); } start = ((door_state & DOOR_NO_DELAY) ? DXSIZE : 0); -- 2.34.1