diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-02 20:17:46 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-06-02 20:17:46 +0000 |
| commit | f18096a5c43d5cc52670c24d73d3efeebb120307 (patch) | |
| tree | bab91bcdeaccc207f5eacd16ac6e5941c65b5eae /src/sound.c | |
| parent | 6f8cef248e1467595a932707eb9a9c53af2e8839 (diff) | |
- data ako obrazky, zvuky hudba sa uklada do mojho storage API ( storage.c/.h )
a image.c sound.c music.c je iba skupina funkcii ktora vola storage API,
teraz tam ma podstatne mensiu dupicitu kodu v hore vymenovanych zdrojakoch
git-svn-id: http://opensvn.csie.org/tuxanci_ng@58 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/sound.c')
| -rw-r--r-- | src/sound.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/src/sound.c b/src/sound.c index 3dc5552..a35d996 100644 --- a/src/sound.c +++ b/src/sound.c @@ -10,8 +10,9 @@ #include "string_length.h" #include "audio.h" #include "sound.h" +#include "storage.h" -static list_t *listSound; +static list_t *listStorage; static bool_t isSoundInit = FALSE; static bool_t var_isSoundActive = TRUE; @@ -29,7 +30,7 @@ void initSound() return; } - listSound = newList(); + listStorage = newStorage(); isSoundInit = TRUE; var_isSoundActive = TRUE; @@ -68,65 +69,48 @@ static Mix_Chunk* loadMixSound(char *file) return new; } -static sound_t *newSound(char *file, char *name, int group) -{ - sound_t *new; - - new = malloc( sizeof(sound_t) ); - new->name = strdup(name); - new->group = group; - new->sound = loadMixSound(file); - return new; -} - -static void playMixSound(sound_t *p) +static void playMixSound(Mix_Chunk *p) { - if( Mix_PlayChannel(-1, p->sound, 0) == -1 ) + if( Mix_PlayChannel(-1, p, 0) == -1 ) { fprintf(stderr, "Nelze prehrat zvuk : %s\n", Mix_GetError()); return; } } -static void destroySound(sound_t *p) +static void destroySound(void *p) { - free(p->name); - Mix_FreeChunk(p->sound); - free(p); + Mix_FreeChunk((Mix_Chunk *)p); } -void addSound(char *file, char *name, int group) +void addSound(char *file, char *name, char *group) { + Mix_Chunk *new; + if( isSoundInit == FALSE ) { return; } - addList( listSound, newSound(file, name, group) ); + assert( file != NULL ); + assert( name != NULL ); + assert( group != NULL ); + + new = loadMixSound(file); + + addItemToStorage(listStorage, group, name, new ); } -void playSound(char *name, int group) +void playSound(char *name, char *group) { - int i; - sound_t *this; - if( isSoundInit == FALSE || var_isSoundActive == FALSE ) { return; } - for( i = 0 ; i < listSound->count ; i++ ) - { - this = (sound_t *)listSound->list[i]; - - if( this->group == group && strcmp(this->name, name) == 0 ) - { - playMixSound(this); - return; - } - } + playMixSound( getItemFromStorage(listStorage, group, name) ); } void setSoundActive(bool_t n) @@ -146,7 +130,7 @@ void quitSound() return; } - destroyListItem(listSound, destroySound); + destroyStorage(listStorage, destroySound); isSoundInit = FALSE; printf("quit sound..\n"); } |