diff options
| -rw-r--r-- | frontends/gl/audio.c | 26 | ||||
| -rw-r--r-- | frontends/gl/audio.h | 3 | ||||
| -rw-r--r-- | frontends/gl/events.c | 37 | ||||
| -rw-r--r-- | frontends/gl/main.c | 44 | ||||
| -rw-r--r-- | frontends/gl/skin.c | 18 | ||||
| -rw-r--r-- | frontends/gl/skin.h | 4 | ||||
| m--------- | ini | 0 |
7 files changed, 50 insertions, 82 deletions
diff --git a/frontends/gl/audio.c b/frontends/gl/audio.c index 2adbd09..587cb0b 100644 --- a/frontends/gl/audio.c +++ b/frontends/gl/audio.c @@ -9,16 +9,26 @@ #include <stdio.h> #include "audio.h" -void load_multiple_audio(char* name, char* dir_name, int *count, Mix_Chunk** list) { +void load_multiple_audio(char* name, char* dir_name, int *count, Mix_Chunk*** list) { char file[120]; - int index = 0; - for (int i = 0; i < (*count); i++) { - format_str(file, 120, "%s/%s_%i.wav", dir_name, name, i); + *count = 0; + *list = (Mix_Chunk **)malloc(sizeof(Mix_Chunk *) * 2); + + while(1) { + format_str(file, 120, "%s/%s_%i.wav", dir_name, name, *count); - list[index] = Mix_LoadWAV(file); - if (!list[index]) { - (*count)--; - } else index++; + (*list)[*count] = Mix_LoadWAV(file); + + if ((*list)[*count]) { + (*count)++; + *list = (Mix_Chunk **)realloc(*list, sizeof(Mix_Chunk *) * (*count + 1)); + } else break; } } + +void load_audio(char* name, char* dir_name, Mix_Chunk** chunk) { + char file[120]; + format_str(file, 120, "%s/%s.wav", dir_name, name); + *chunk = Mix_LoadWAV(file); +} diff --git a/frontends/gl/audio.h b/frontends/gl/audio.h index 11c6098..ae3570a 100644 --- a/frontends/gl/audio.h +++ b/frontends/gl/audio.h @@ -8,4 +8,5 @@ #include <SDL_mixer.h> -void load_multiple_audio(char* name, char* dir_name, int *count, Mix_Chunk** list); +void load_multiple_audio(char* name, char* dir_name, int *count, Mix_Chunk*** list); +void load_audio(char* name, char* dir_name, Mix_Chunk** chunk); diff --git a/frontends/gl/events.c b/frontends/gl/events.c index a2ed9e1..b62584f 100644 --- a/frontends/gl/events.c +++ b/frontends/gl/events.c @@ -7,33 +7,38 @@ #include <unistd.h> #endif +#include "timer.h" + #include "ui.h" +#include <SDL.h> #include <SDL_mixer.h> void handle_game_event(cetris_ui *ui) { -/* - if (board->game.lock_event > 0) { - Mix_PlayChannel( 1, board->skin.lock_sound, 0 ); - board->game.lock_event--; + if (ui->board.game.waiting) { + SDL_Delay(100); + cetris_start_game(&ui->board.game); + } + + if (ui->board.game.lock_event > 0) { + Mix_PlayChannel( 1, ui->board.skin.lock_sound, 0 ); + ui->board.game.lock_event--; + } + + if (ui->board.game.line_event > 0) { + int index = ui->board.game.line_combo - 1; + Mix_PlayChannel( 1, ui->board.skin.clear_sound[index], 0 ); + ui->board.game.line_event--; } - */ - //if (board->game.line_event > 0) { - - /* if (ui->board.game.tetris_event > 0) { - //int index = rand() % ui->skin.tetris_sound_count; - Mix_PlayChannel( 1, ui->board.skin.tetris_sound[0], 0 ); + int index = rand() % ui->board.skin.tetris_sound_count; + Mix_PlayChannel( 1, ui->board.skin.tetris_sound[index], 0 ); ui->board.game.tetris_event--; } - */ if (ui->board.game.move_event > 0) { - //int index = rand() % ui->skin.tetris_sound_count; - ///Mix_HaltChannel(0); - Mix_PlayChannel( 0, ui->board.skin.move_sound, ui->board.game.move_event - 1); - ui->board.game.move_event = 0; - printf("sound\n"); + Mix_PlayChannel( 0, ui->board.skin.move_sound, 0); + ui->board.game.move_event--; } } diff --git a/frontends/gl/main.c b/frontends/gl/main.c index 1201f82..4880540 100644 --- a/frontends/gl/main.c +++ b/frontends/gl/main.c @@ -97,46 +97,6 @@ void load_config(cetris_ui *ui) { } } - -void handle_game_events(cetris_ui *ui, tetris_board_t *board) { - if (board->game.waiting) { - SDL_Delay(100); - cetris_start_game(&board->game); - } - - if (board->game.lock_event > 0) { - Mix_PlayChannel( 1, board->skin.lock_sound, 0 ); - board->game.lock_event--; - } - - if (board->game.line_event > 0) { - - int index; - //if (ui->skin.random_audio) { - // index = rand() % 4;//ui->skin.clear_sound_count; - //} else { - index = board->game.line_combo - 1; - //} - //if (index >= 4) - //index = ui->skin.clear_sound_count - 1; - - Mix_PlayChannel( 1, board->skin.clear_sound[index], 0 ); - - board->game.line_event--; - } - - if (board->game.tetris_event > 0) { - //int index = rand() % ui->skin.tetris_sound_count; - Mix_PlayChannel( 1, board->skin.tetris_sound[0], 0 ); - board->game.tetris_event--; - } - if (board->game.move_event > 0) { - //int index = rand() % ui->skin.tetris_sound_count; - Mix_PlayChannel( 0, board->skin.move_sound, 0); - board->game.move_event--; - } -} - void handle_key(SDL_Event e, key_bindings_t *keys, tetris_board_t* board) { int sym; switch (e.type) { @@ -249,7 +209,6 @@ int main(void) { start_event_thread(&ui); SDL_Event e; - int delay = 1000/FRAME_RATE; for (;;) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -260,11 +219,8 @@ int main(void) { draw_tetris_board(&ui); draw_held_piece(&ui); - //handle_game_events(&ui, &ui.board); SDL_GL_SwapWindow(window); - - //SDL_Delay(delay); } SDL_GL_DeleteContext(maincontext); diff --git a/frontends/gl/skin.c b/frontends/gl/skin.c index e54b372..4cdb1ac 100644 --- a/frontends/gl/skin.c +++ b/frontends/gl/skin.c @@ -51,21 +51,13 @@ void load_skin(char* name, cetris_skin_t* skin) { char file[125]; - int clear_count = 5; - skin->clear_sound = - (Mix_Chunk **)malloc(sizeof(Mix_Chunk*) * 5); load_multiple_audio("clear", dir_name, - &clear_count, skin->clear_sound); + &skin->clear_sound_count, &skin->clear_sound); - int tetris_count = 5; - skin->tetris_sound = - (Mix_Chunk **)malloc(sizeof(Mix_Chunk*) * 5); load_multiple_audio("four_clear", dir_name, - &tetris_count, skin->tetris_sound); + &skin->tetris_sound_count, &skin->tetris_sound); + + load_audio("lock", dir_name, &skin->lock_sound); + load_audio("move_das", dir_name, &skin->move_sound); - format_str(file, 125, "%s/lock.wav", dir_name); - skin->lock_sound = Mix_LoadWAV(file); - - format_str(file, 125, "%s/move_das.wav", dir_name); - skin->move_sound = Mix_LoadWAV(file); } diff --git a/frontends/gl/skin.h b/frontends/gl/skin.h index f287751..09e0251 100644 --- a/frontends/gl/skin.h +++ b/frontends/gl/skin.h @@ -11,7 +11,11 @@ typedef struct { drawable_t background; Mix_Chunk **clear_sound; + int clear_sound_count; + Mix_Chunk **tetris_sound; + int tetris_sound_count; + Mix_Chunk *lock_sound; Mix_Chunk *move_sound; } cetris_skin_t; diff --git a/ini b/ini -Subproject 3401f2ed3153c6093c2f434e205cf6e7775a02d +Subproject 9b15f721fd53b1beb8364f8763e2207963ac4fd |