diff options
| author | xHire <xhire@tuxportal.cz> | 2008-10-25 14:11:06 +0200 |
|---|---|---|
| committer | xHire <xhire@tuxportal.cz> | 2008-10-25 14:11:06 +0200 |
| commit | c8a9209d77a896bf49227e5aeccd54e91ccf29cc (patch) | |
| tree | 6b7367406ebbc6ce3ea5e0c8668c75f6fb3f6ae9 /src/audio | |
| parent | cb9deba915dd7b114eeb76601eb1c8b07c1ba90f (diff) | |
Changed style of the code to the K&R standard
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/audio.c | 52 | ||||
| -rw-r--r-- | src/audio/audio.h | 4 | ||||
| -rw-r--r-- | src/audio/music.c | 228 | ||||
| -rw-r--r-- | src/audio/music.h | 30 | ||||
| -rw-r--r-- | src/audio/sound.c | 128 | ||||
| -rw-r--r-- | src/audio/sound.h | 30 |
6 files changed, 222 insertions, 250 deletions
diff --git a/src/audio/audio.c b/src/audio/audio.c index 15ad6f7..0d9b0a2 100644 --- a/src/audio/audio.c +++ b/src/audio/audio.c @@ -11,50 +11,46 @@ static bool_t isAudioInit = FALSE; /* * Returns state of audio */ -bool_t -isAudioInicialized() +bool_t isAudioInicialized() { - return isAudioInit; + return isAudioInit; } /* * Inicialize audio */ -void -initAudio() +void initAudio() { - if (isParamFlag("--noaudio")) { - return; - } + if (isParamFlag("--noaudio")) { + return; + } - if (SDL_Init(SDL_INIT_AUDIO) == -1) { - fprintf(stderr, _("Unable to initialize audio: %s\n"), - SDL_GetError()); - return; - } - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == - -1) { - fprintf(stderr, _("Unable to create proper audio settings: %s\n"), - Mix_GetError()); - return; - } - Mix_AllocateChannels(16); - Mix_Volume(-1, MIX_MAX_VOLUME); + if (SDL_Init(SDL_INIT_AUDIO) == -1) { + fprintf(stderr, _("Unable to initialize audio: %s\n"), SDL_GetError()); + return; + } + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == + -1) { + fprintf(stderr, _("Unable to create proper audio settings: %s\n"), + Mix_GetError()); + return; + } + Mix_AllocateChannels(16); + Mix_Volume(-1, MIX_MAX_VOLUME); #ifdef DEBUG - printf(_("Initializing audio system...\n")); + printf(_("Initializing audio system...\n")); #endif - isAudioInit = TRUE; + isAudioInit = TRUE; } /* * Quit audio */ -void -quitAudio() +void quitAudio() { - Mix_CloseAudio(); - isAudioInit = TRUE; + Mix_CloseAudio(); + isAudioInit = TRUE; #ifdef DEBUG - printf(_("Quitting audio...\n")); + printf(_("Quitting audio...\n")); #endif } diff --git a/src/audio/audio.h b/src/audio/audio.h index 61873c3..1f1f95b 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -1,8 +1,8 @@ #ifndef AUDIO_H -#define AUDIO_H +# define AUDIO_H -#include "main.h" +# include "main.h" extern bool_t isAudioInicialized(); extern void initAudio(); diff --git a/src/audio/music.c b/src/audio/music.c index 58be368..04de359 100644 --- a/src/audio/music.c +++ b/src/audio/music.c @@ -18,224 +18,210 @@ static Mix_Music *currentMusic; /* * Return state of music initialization */ -bool_t -isMusicInicialized() +bool_t isMusicInicialized() { - return isMusicInit; + return isMusicInit; } /* * Initialize music */ -void -initMusic() +void initMusic() { - if (isAudioInicialized() == FALSE) { - isMusicInit = FALSE; - return; - } - listStorage = newStorage(); - currentMusic = NULL; - isMusicInit = TRUE; - var_isMusicActive = TRUE; - if (isParamFlag("--nomusic")) - setMusicActive(FALSE); - if (isParamFlag("--music")) - setMusicActive(TRUE); + if (isAudioInicialized() == FALSE) { + isMusicInit = FALSE; + return; + } + listStorage = newStorage(); + currentMusic = NULL; + isMusicInit = TRUE; + var_isMusicActive = TRUE; + if (isParamFlag("--nomusic")) + setMusicActive(FALSE); + if (isParamFlag("--music")) + setMusicActive(TRUE); #ifdef DEBUG - printf(_("Initializing music...\n")); + printf(_("Initializing music...\n")); #endif } /* * Load music file and returns it */ -static Mix_Music * -loadMixMusic(char *file) +static Mix_Music *loadMixMusic(char *file) { - Mix_Music *mixer; - char str[STR_PATH_SIZE]; + Mix_Music *mixer; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading music file: %s\n"), file); + printf(_("Loading music file: %s\n"), file); #endif - if (isFillPath(file)) { - strcpy(str, file); - } - else { - sprintf(str, PATH_MUSIC "%s", file); - } + if (isFillPath(file)) { + strcpy(str, file); + } else { + sprintf(str, PATH_MUSIC "%s", file); + } - accessExistFile(str); + accessExistFile(str); - mixer = Mix_LoadMUS(str); + mixer = Mix_LoadMUS(str); - if (mixer == NULL) { - fprintf(stderr, _("Unable to load music from file: %s\n"), file); - return NULL; - } + if (mixer == NULL) { + fprintf(stderr, _("Unable to load music from file: %s\n"), file); + return NULL; + } - return mixer; + return mixer; } /* * Prepare music mixer */ -static void -playMixMusic() +static void playMixMusic() { - if (currentMusic != NULL) - Mix_PlayMusic(currentMusic, 1000); + if (currentMusic != NULL) + Mix_PlayMusic(currentMusic, 1000); } /* * Free memory of music */ -static void -destroyMusic(void *p) +static void destroyMusic(void *p) { - Mix_FreeMusic((Mix_Music *) p); + Mix_FreeMusic((Mix_Music *) p); } /* * Add file to list with music */ -void -addMusic(char *file, char *name, char *group) +void addMusic(char *file, char *name, char *group) { - Mix_Music *new; - if (isMusicInit == FALSE) - return; + Mix_Music *new; + if (isMusicInit == FALSE) + return; - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); - new = loadMixMusic(file); - addItemToStorage(listStorage, group, name, new); + new = loadMixMusic(file); + addItemToStorage(listStorage, group, name, new); } /* * Disable music and stop playback */ -void -stopMusic() +void stopMusic() { - if (isMusicInit == FALSE || var_isMusicActive == FALSE) - return; + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; - if (currentMusic != NULL) { + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Stopping music...\n")); + printf(_("Stopping music...\n")); #endif - Mix_HaltMusic(); - currentMusic = NULL; - } + Mix_HaltMusic(); + currentMusic = NULL; + } } /* * start music playback */ -void -playMusic(char *name, char *group) +void playMusic(char *name, char *group) { - static char currentMusic_group[STR_SIZE]; - static char currentMusic_name[STR_SIZE]; - static int isStrInit = 0; + static char currentMusic_group[STR_SIZE]; + static char currentMusic_name[STR_SIZE]; + static int isStrInit = 0; - if (isStrInit == 0) { - strcpy(currentMusic_group, "none"); - strcpy(currentMusic_name, "none"); - isStrInit = 1; - } + if (isStrInit == 0) { + strcpy(currentMusic_group, "none"); + strcpy(currentMusic_name, "none"); + isStrInit = 1; + } - if (isMusicInit == FALSE || var_isMusicActive == FALSE) - return; + if (isMusicInit == FALSE || var_isMusicActive == FALSE) + return; - if (currentMusic != NULL && - strcmp(currentMusic_group, group) == 0 && - strcmp(currentMusic_name, name) == 0) { - return; - } + if (currentMusic != NULL && + strcmp(currentMusic_group, group) == 0 && + strcmp(currentMusic_name, name) == 0) { + return; + } - if (currentMusic != NULL) - stopMusic(); + if (currentMusic != NULL) + stopMusic(); - currentMusic = getItemFromStorage(listStorage, group, name); - strcpy(currentMusic_group, group); - strcpy(currentMusic_name, name); + currentMusic = getItemFromStorage(listStorage, group, name); + strcpy(currentMusic_group, group); + strcpy(currentMusic_name, name); - if (currentMusic != NULL) { + if (currentMusic != NULL) { #ifdef DEBUG - printf(_("Playing music file %s\n"), name); + printf(_("Playing music file %s\n"), name); #endif - playMixMusic(); - } + playMixMusic(); + } } /* * Set music active/deactivated */ -void -setMusicActive(bool_t n) +void setMusicActive(bool_t n) { - static Mix_Music *music = NULL; - - if (n == FALSE) { - music = currentMusic; - stopMusic(); - } - if (n == TRUE) { - currentMusic = music; - playMixMusic(); - } - - var_isMusicActive = n; + static Mix_Music *music = NULL; + + if (n == FALSE) { + music = currentMusic; + stopMusic(); + } + if (n == TRUE) { + currentMusic = music; + playMixMusic(); + } + + var_isMusicActive = n; } /* * Return status of music */ -bool_t -isMusicActive() +bool_t isMusicActive() { - return var_isMusicActive; + return var_isMusicActive; } /* * TOCOMMENT */ -char * -getCurrentMusic() +char *getCurrentMusic() { - return "unknown"; + return "unknown"; } /* * TOCOMMENT */ -void -delAllMusicInGroup(char *group) +void delAllMusicInGroup(char *group) { - if (isMusicInit == FALSE) - return; - delAllItemFromStorage(listStorage, group, destroyMusic); + if (isMusicInit == FALSE) + return; + delAllItemFromStorage(listStorage, group, destroyMusic); } /* * Deactivate all what is ment for music */ -void -quitMusic() +void quitMusic() { - if (isMusicInit == FALSE) - return; + if (isMusicInit == FALSE) + return; - stopMusic(); - destroyStorage(listStorage, destroyMusic); - isMusicInit = FALSE; + stopMusic(); + destroyStorage(listStorage, destroyMusic); + isMusicInit = FALSE; #ifdef DEBUG - printf(_("Quitting music...\n")); + printf(_("Quitting music...\n")); #endif } diff --git a/src/audio/music.h b/src/audio/music.h index 2e6cd3f..1b0e1fb 100644 --- a/src/audio/music.h +++ b/src/audio/music.h @@ -1,21 +1,21 @@ #ifndef MUSIC_H -#define MUSIC_H -#ifndef NO_SOUND -#include <SDL_mixer.h> -#include "main.h" +# define MUSIC_H +# ifndef NO_SOUND +# include <SDL_mixer.h> +# include "main.h" -#define MUSIC_GROUP_BASE "base" -#define MUSIC_GROUP_USER "user" +# define MUSIC_GROUP_BASE "base" +# define MUSIC_GROUP_USER "user" - /* - typedef struct music_struct - { - char *name; - int group; - Mix_Music *music; - } music_t; - */ + /* + typedef struct music_struct + { + char *name; + int group; + Mix_Music *music; + } music_t; + */ extern bool_t isMusicInicialized(); extern void initMusic(); @@ -27,5 +27,5 @@ extern bool_t isMusicActive(); extern char *getCurrentMusic(); extern void delAllMusicInGroup(char *group); extern void quitMusic(); -#endif +# endif #endif diff --git a/src/audio/sound.c b/src/audio/sound.c index 50a5aad..c96e3ac 100644 --- a/src/audio/sound.c +++ b/src/audio/sound.c @@ -16,137 +16,127 @@ static bool_t var_isSoundActive = TRUE; /* * Return state of sound */ -bool_t -isSoundInicialized() +bool_t isSoundInicialized() { - return isSoundInit; + return isSoundInit; } /* * Audio initialization */ -void -initSound() +void initSound() { - if (isAudioInicialized() == FALSE) { - isSoundInit = FALSE; - return; - } + if (isAudioInicialized() == FALSE) { + isSoundInit = FALSE; + return; + } - listStorage = newStorage(); - isSoundInit = TRUE; - var_isSoundActive = TRUE; - if (isParamFlag("--nosound")) - setSoundActive(FALSE); - if (isParamFlag("--sound")) - setSoundActive(TRUE); + listStorage = newStorage(); + isSoundInit = TRUE; + var_isSoundActive = TRUE; + if (isParamFlag("--nosound")) + setSoundActive(FALSE); + if (isParamFlag("--sound")) + setSoundActive(TRUE); #ifdef DEBUG - printf(_("Initializing sound...\n")); + printf(_("Initializing sound...\n")); #endif } /* * Load sound file (Null/mixer) */ -static Mix_Chunk * -loadMixSound(char *file) +static Mix_Chunk *loadMixSound(char *file) { - Mix_Chunk *new; - char str[STR_PATH_SIZE]; + Mix_Chunk *new; + char str[STR_PATH_SIZE]; #ifdef DEBUG - printf(_("Loading sound file: %s\n"), file); + printf(_("Loading sound file: %s\n"), file); #endif - sprintf(str, PATH_SOUND "%s", file); - accessExistFile(str); - new = Mix_LoadWAV(str); - if (new == NULL) { - fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), - str, Mix_GetError()); - return NULL; - } - return new; + sprintf(str, PATH_SOUND "%s", file); + accessExistFile(str); + new = Mix_LoadWAV(str); + if (new == NULL) { + fprintf(stderr, _("Unable to load sound file: %s with error: %s\n"), + str, Mix_GetError()); + return NULL; + } + return new; } /* * Play sound with mixer */ -static void -playMixSound(Mix_Chunk * p) +static void playMixSound(Mix_Chunk * p) { - if (Mix_PlayChannel(-1, p, 0) == -1) { - fprintf(stderr, _("Unable to playback sound with error: %s\n"), - Mix_GetError()); - return; - } + if (Mix_PlayChannel(-1, p, 0) == -1) { + fprintf(stderr, _("Unable to playback sound with error: %s\n"), + Mix_GetError()); + return; + } } /* * Destroy mixer chunk */ -static void -destroySound(void *p) +static void destroySound(void *p) { - Mix_FreeChunk((Mix_Chunk *) p); + Mix_FreeChunk((Mix_Chunk *) p); } /* * Add sound to list */ -void -addSound(char *file, char *name, char *group) +void addSound(char *file, char *name, char *group) { - Mix_Chunk *new; + Mix_Chunk *new; - if (isSoundInit == FALSE) - return; - assert(file != NULL); - assert(name != NULL); - assert(group != NULL); - new = loadMixSound(file); - addItemToStorage(listStorage, group, name, new); + if (isSoundInit == FALSE) + return; + assert(file != NULL); + assert(name != NULL); + assert(group != NULL); + new = loadMixSound(file); + addItemToStorage(listStorage, group, name, new); } /* * Start playback file from list */ -void -playSound(char *name, char *group) +void playSound(char *name, char *group) { - if (isSoundInit == FALSE || var_isSoundActive == FALSE) - return; - playMixSound(getItemFromStorage(listStorage, group, name)); + if (isSoundInit == FALSE || var_isSoundActive == FALSE) + return; + playMixSound(getItemFromStorage(listStorage, group, name)); } /* * Set if sound is active True/False */ -void -setSoundActive(bool_t n) +void setSoundActive(bool_t n) { - var_isSoundActive = n; + var_isSoundActive = n; } /* * Return state of sound */ -bool_t -isSoundActive() +bool_t isSoundActive() { - return var_isSoundActive; + return var_isSoundActive; } /* * Quit all sound stuff */ -void -quitSound() +void quitSound() { - if (isSoundInit == FALSE) - return; - destroyStorage(listStorage, destroySound); - isSoundInit = FALSE; + if (isSoundInit == FALSE) + return; + destroyStorage(listStorage, destroySound); + isSoundInit = FALSE; #ifdef DEBUG - printf(_("Quitting sound...\n")); + printf(_("Quitting sound...\n")); #endif } diff --git a/src/audio/sound.h b/src/audio/sound.h index cb85471..f63af13 100644 --- a/src/audio/sound.h +++ b/src/audio/sound.h @@ -1,21 +1,21 @@ #ifndef SOUND_H -#define SOUND_H -#ifndef NO_SOUND -#include <SDL_mixer.h> -#include "main.h" +# define SOUND_H +# ifndef NO_SOUND +# include <SDL_mixer.h> +# include "main.h" -#define SOUND_GROUP_BASE "base" -#define SOUND_GROUP_USER "user" +# define SOUND_GROUP_BASE "base" +# define SOUND_GROUP_USER "user" - /* - typedef struct sound_struct - { - char *name; - int group; - Mix_Chunk *sound; - } sound_t; - */ + /* + typedef struct sound_struct + { + char *name; + int group; + Mix_Chunk *sound; + } sound_t; + */ extern bool_t isSoundInicialized(); extern void initSound(); @@ -24,5 +24,5 @@ extern void playSound(char *name, char *group); extern void setSoundActive(bool_t n); extern bool_t isSoundActive(); extern void quitSound(); -#endif +# endif #endif |