From 932b86da42b9e11d941ebfb06073a0bf540b5616 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sun, 22 Jan 2017 00:11:13 -0500 Subject: [PATCH] Added NOSOUND definition option, which disables use of SDL_mixer entirely. --- src/Starfighter.cpp | 2 ++ src/Starfighter.h | 3 +++ src/audio.cpp | 22 ++++++++++++++++++++++ src/engine.cpp | 7 +++++++ 4 files changed, 34 insertions(+) diff --git a/src/Starfighter.cpp b/src/Starfighter.cpp index 9607aa1..6ae33cf 100644 --- a/src/Starfighter.cpp +++ b/src/Starfighter.cpp @@ -127,11 +127,13 @@ int main(int argc, char **argv) srand(time(NULL)); +#ifndef NOSOUND if (engine.useAudio) { Mix_Volume(-1, 100); Mix_VolumeMusic(engine.musicVolume); } +#endif alien_defs_init(); diff --git a/src/Starfighter.h b/src/Starfighter.h index c226333..76d916a 100644 --- a/src/Starfighter.h +++ b/src/Starfighter.h @@ -29,7 +29,10 @@ along with this program. If not, see . #include "SDL.h" #include "SDL_image.h" + +#ifndef NOSOUND #include "SDL_mixer.h" +#endif #include "alien.h" #include "audio.h" diff --git a/src/audio.cpp b/src/audio.cpp index bccdf87..437df41 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -19,7 +19,9 @@ along with this program. If not, see . #include +#ifndef NOSOUND #include "SDL_mixer.h" +#endif #include "defs.h" #include "structs.h" @@ -28,11 +30,14 @@ along with this program. If not, see . #include "engine.h" #include "screen.h" +#ifndef NOSOUND static Mix_Chunk *sound[SFX_MAX]; static Mix_Music *music = NULL; +#endif void audio_loadSounds() { +#ifndef NOSOUND sound[SFX_EXPLOSION] = Mix_LoadWAV("sound/explode.ogg"); sound[SFX_HIT] = Mix_LoadWAV("sound/explode2.ogg"); sound[SFX_DEATH] = Mix_LoadWAV("sound/maledeath.ogg"); @@ -49,10 +54,12 @@ void audio_loadSounds() sound[SFX_LASER] = Mix_LoadWAV("sound/laser.ogg"); sound[SFX_PLASMA2] = Mix_LoadWAV("sound/plasma2.ogg"); sound[SFX_PLASMA3] = Mix_LoadWAV("sound/plasma3.ogg"); +#endif } void audio_playSound(int sid, float x, float y) { +#ifndef NOSOUND int channel = -1; static int freechannel = 4; static int channelVolume[4] = {0, 0, 0, 0}; @@ -119,10 +126,12 @@ void audio_playSound(int sid, float x, float y) Mix_SetPosition(channel, angle, attenuation); Mix_Volume(channel, volume); Mix_PlayChannel(channel, sound[sid], 0); +#endif } void audio_haltMusic() { +#ifndef NOSOUND if (Mix_PlayingMusic()) { Mix_ResumeMusic(); @@ -134,27 +143,35 @@ void audio_haltMusic() Mix_FreeMusic(music); music = NULL; } +#endif } void audio_pauseMusic() { +#ifndef NOSOUND if (Mix_PlayingMusic() && !Mix_PausedMusic()) Mix_PauseMusic(); +#endif } void audio_resumeMusic() { +#ifndef NOSOUND Mix_ResumeMusic(); +#endif } void audio_setMusicVolume(int volume) { +#ifndef NOSOUND if (engine.useMusic && engine.useAudio) Mix_VolumeMusic(volume); +#endif } void audio_playMusic(const char *filename, int loops) { +#ifndef NOSOUND if (engine.useMusic && engine.useAudio) { audio_haltMusic(); @@ -162,10 +179,12 @@ void audio_playMusic(const char *filename, int loops) audio_setMusicVolume(100); Mix_PlayMusic(music, loops); } +#endif } void audio_playRandomTrack() { +#ifndef NOSOUND if ((!engine.useMusic) || (!engine.useAudio)) return; @@ -192,10 +211,12 @@ void audio_playRandomTrack() default: audio_playMusic(track[rand() % tracks], -1); } +#endif } void audio_free() { +#ifndef NOSOUND for (int i = 0 ; i < SFX_MAX ; i++) { if (sound[i] != NULL) @@ -210,4 +231,5 @@ void audio_free() Mix_FreeMusic(music); music = NULL; } +#endif } diff --git a/src/engine.cpp b/src/engine.cpp index fbe2404..3a178f0 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -23,7 +23,10 @@ along with this program. If not, see . #include #include "SDL.h" + +#ifndef NOSOUND #include "SDL_mixer.h" +#endif #include "colors.h" #include "defs.h" @@ -246,6 +249,7 @@ void engine_setMode() exit(1); } +#ifndef NOSOUND if (engine.useAudio) { if (Mix_OpenAudio(44100, AUDIO_S16, engine.useAudio * 2, 1024) < 0) @@ -255,6 +259,7 @@ void engine_setMode() engine.useAudio = 0; } } +#endif SDL_ShowCursor(SDL_DISABLE); SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE); @@ -353,10 +358,12 @@ void engine_cleanup() sprintf(filename, "%smusic.s3m", engine.configDirectory); remove(filename); +#ifndef NOSOUND if (engine.useAudio) { Mix_CloseAudio(); } +#endif // Save the config using current settings FILE *fp;