diff options
Diffstat (limited to 'frontends/sdl')
| -rw-r--r-- | frontends/sdl/cetris_sdl.c | 701 | ||||
| -rw-r--r-- | frontends/sdl/cetris_sdl.h | 113 | ||||
| -rw-r--r-- | frontends/sdl/config.ini | 16 | ||||
| -rw-r--r-- | frontends/sdl/data/LICENSE.txt | 202 | ||||
| -rw-r--r-- | frontends/sdl/data/OpenSans-Regular.ttf | bin | 96932 -> 0 bytes | |||
| -rw-r--r-- | frontends/sdl/data/lock.wav | bin | 8864 -> 0 bytes | |||
| -rw-r--r-- | frontends/sdl/data/move_das.wav | bin | 1928 -> 0 bytes | |||
| -rw-r--r-- | frontends/sdl/meson.build | 29 |
8 files changed, 0 insertions, 1061 deletions
diff --git a/frontends/sdl/cetris_sdl.c b/frontends/sdl/cetris_sdl.c deleted file mode 100644 index 89c1f47..0000000 --- a/frontends/sdl/cetris_sdl.c +++ /dev/null @@ -1,701 +0,0 @@ -#define SDL_MAIN_HANDLED -#ifdef _WIN32 -#include <SDL.h> -#include <SDL_ttf.h> -#include <SDL_image.h> -#define format_str sprintf_s -#else -#include <SDL2/SDL.h> -#include <SDL2/SDL_ttf.h> -#include <SDL2/SDL_image.h> -#define format_str snprintf -#endif -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <sys/stat.h> - - -#include <time.h> - -#include <cetris.h> -#include <timer.h> -#include <rules.h> -#include <ini.h> - -#include "cetris_sdl.h" - -#define W 900 -#define H 720 -#define FRAME_RATE 60 - -void setup_sdl(cetris_ui *ui) { - SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); - ui->window = SDL_CreateWindow("cetris", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, W, H, SDL_WINDOW_SHOWN); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - SDL_SetHint(SDL_HINT_RENDER_DRIVER,"opengl"); - ui->render = SDL_CreateRenderer(ui->window, -1, SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED); - SDL_SetRenderDrawBlendMode(ui->render, SDL_BLENDMODE_BLEND); - SDL_RenderSetLogicalSize(ui->render, W, H); - if (!ui->render) exit(fprintf(stderr, "err: could not create SDL renderer\n")); - - TTF_Init(); - ui->font_count = 0; - - IMG_Init(IMG_INIT_PNG); - - SDL_AudioSpec spec; - - SDL_memset(&spec, 0, sizeof(spec)); - spec.freq = 44100; - spec.format = AUDIO_S16; - spec.channels = 2; - spec.samples = 4096; - spec.callback = NULL; - - ui->audio_device = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0); - if (ui->audio_device == 0) printf("failed to open audio device\n"); -} - -TTF_Font* get_font(cetris_ui *ui, int size) { - for (int i = 0; i < ui->font_count; i++) { - if (ui->fonts[i].size == size) { - return ui->fonts[i].font; - } - } - ui->fonts[ui->font_count].font = TTF_OpenFont("data/OpenSans-Regular.ttf", size); - TTF_SetFontHinting(ui->fonts[ui->font_count].font, TTF_HINTING_MONO); - ui->fonts[ui->font_count].size = size; - return ui->fonts[ui->font_count++].font; -} - -SDL_Texture* load_png(cetris_ui* ui, char* file) { - SDL_Surface* loaded_surface = IMG_Load(file); - if (loaded_surface == NULL) return NULL; - return SDL_CreateTextureFromSurface(ui->render, loaded_surface); -} - -void load_multiple_audio(char* name, char* dir_name, int *count, audio_clip_t* 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); - - if (SDL_LoadWAV(file, &list[index].wav_spec, - &list[index].wav_buffer, &list[index].wav_length) == NULL) { - (*count)--; - } else index++; - } -} - -void load_skin(cetris_ui *ui) { - char *dir_name = malloc(100); - format_str(dir_name, 100, "skins/%s", ui->config.skin_name); - - struct stat sb; - -#ifdef _WIN32 - if (!(stat(dir_name, &sb) == 0 && (sb.st_mode & S_IFDIR))) { -#else - if (!(stat(dir_name, &sb) == 0 && S_ISDIR(sb.st_mode))) { -#endif - dir_name = "skins/default"; - } - - ini_parser p; - - char ini_path[100]; - format_str(ini_path, 100, "%s/skin.ini", dir_name); - - char name[120]; - if (load_ini_file(&p, ini_path)) { - char* random_clear = get_ini_value(&p, "sounds", "random_clear_sound"); - if (random_clear && !strcmp(random_clear, "true")) { - ui->skin.random_audio = true; - } else ui->skin.random_audio = false; - - format_str(name, 120, "%s/playboard.png", dir_name); - ui->skin.game_background = load_png(ui, name); - if (ui->skin.game_background != NULL) { - SDL_SetTextureAlphaMod(ui->skin.game_background, 120); - SDL_SetTextureBlendMode(ui->skin.game_background, SDL_BLENDMODE_BLEND); - } - - format_str(name, 120, "%s/overlay_middle.png", dir_name); - ui->skin.overlay_middle = load_png(ui, name); - if (ui->skin.overlay_middle != NULL) { - SDL_SetTextureBlendMode(ui->skin.overlay_middle, SDL_BLENDMODE_BLEND); - } - - format_str(name, 120, "%s/border.png", dir_name); - ui->skin.border = load_png(ui, name); - if (ui->skin.border != NULL) { - SDL_SetTextureBlendMode(ui->skin.border, SDL_BLENDMODE_BLEND); - } - - format_str(name, 120, "%s/background.png", dir_name); - ui->skin.background = load_png(ui, name); - if (ui->skin.border != NULL) { - SDL_SetTextureBlendMode(ui->skin.background, SDL_BLENDMODE_BLEND); - } - - format_str(name, 120, "%s/blocks.png", dir_name); - ui->skin.blocks = load_png(ui, name); - if (ui->skin.blocks != NULL) { - SDL_SetTextureBlendMode(ui->skin.blocks, SDL_BLENDMODE_BLEND); - } - - char* clear_count = get_ini_value(&p, "sounds", "clear_sound_count"); - if (clear_count) { - ui->skin.clear_sound_count = atoi(clear_count); - free(clear_count); - } - - if (ui->skin.clear_sound_count > 0) { - ui->skin.clear_sound = - (audio_clip_t *)malloc(sizeof(audio_clip_t) * ui->skin.clear_sound_count); - load_multiple_audio("clear", dir_name, - &ui->skin.clear_sound_count, ui->skin.clear_sound); - } - - char* tetris_count = get_ini_value(&p, "sounds", "four_clear_sound_count"); - if (tetris_count) { - ui->skin.tetris_sound_count = atoi(tetris_count); - free(tetris_count); - } - - if (ui->skin.tetris_sound_count > 0) { - ui->skin.tetris_sound = - (audio_clip_t *)malloc(sizeof(audio_clip_t) * ui->skin.tetris_sound_count); - load_multiple_audio("four_clear", dir_name, - &ui->skin.tetris_sound_count, ui->skin.tetris_sound); - } - } - - format_str(name, 120, "%s/lock.wav", dir_name); - SDL_LoadWAV(name, &ui->skin.lock_sound.wav_spec, - &ui->skin.lock_sound.wav_buffer, &ui->skin.lock_sound.wav_length); - - //free(dir_name); -} - -void draw_text(cetris_ui *ui, char* string, int x, int y, TTF_Font* font, SDL_Color color) { - SDL_Surface *surface; - surface = TTF_RenderText_Solid(font, string, color); - - SDL_Rect message; - message.x = x; - message.y = y; - message.w = surface->w; - message.h = surface->h; - SDL_Texture* tex = SDL_CreateTextureFromSurface(ui->render, surface); - - SDL_RenderCopy(ui->render, tex, NULL, &message); - SDL_DestroyTexture(tex); - SDL_FreeSurface(surface); -} - -void draw_image(cetris_ui *ui, SDL_Texture *i, int x, int y, int width, int height) { - SDL_Rect dest = {x, y, width, height}; - SDL_RenderCopy(ui->render, i, NULL, &dest); -} - -void draw_block(cetris_ui *ui, int x, int y, int width, int height, int mino, int alpha, SDL_Color off) { - if (ui->skin.blocks) { - SDL_Rect b = {x, y, width, height}; - SDL_Rect block = {(mino + 2) * 32, 0, 32, 32}; - SDL_SetTextureAlphaMod(ui->skin.blocks, alpha); - SDL_RenderCopy(ui->render, ui->skin.blocks, &block, &b); - } else { - SDL_Rect b = {x + 1, y + 1, width - 1, height - 1}; - SDL_Color c = mino_colors[mino]; - SDL_SetRenderDrawColor(ui->render, c.r, c.g, c.b, alpha); - SDL_RenderFillRect(ui->render, &b); - SDL_RenderDrawRect(ui->render, &b); - SDL_SetRenderDrawColor(ui->render, off.r, off.g, off.b, off.a); - b.y--; b.x--; b.w+=2; b.h+=2; - SDL_RenderDrawRect(ui->render, &b); - } -} - -void draw_board(cetris_ui *ui, SDL_Texture *m, game_board_t* board, int x, int y, int w, int h) { - SDL_SetRenderTarget(ui->render, m); - SDL_RenderClear(ui->render); - - int y_offset = 10; - - SDL_Rect background = {0, 0, w, h + y_offset}; - - if (ui->skin.game_background) { - SDL_RenderCopy(ui->render, ui->skin.game_background, NULL, &background); - } else { - SDL_SetRenderDrawColor(ui->render, - board->scheme.off.r - (int)(fmod((double)board->count_down, (double)1.0) * 50), - board->scheme.off.g, board->scheme.off.b, board->scheme.off.a); - - SDL_RenderFillRect(ui->render, &background); - SDL_RenderDrawRect(ui->render, &background); - } - - SDL_SetRenderDrawColor(ui->render, board->scheme.main.r, - board->scheme.main.g, board->scheme.main.b, board->scheme.main.a); - - - int board_x = board->game.config.board_x; - int board_y = board->game.config.board_y; - int board_visible = board_y - board->game.config.board_visible; - - int block_width = w / board->game.config.board_x; - int block_height = h / board->game.config.board_visible; - - if (ui->skin.overlay_middle) { - for (int j = 0; j < board->game.config.board_visible + 1; j++) { - if (j == 0) { - SDL_Rect overlay = {0, y_offset - block_height, (block_width * 10), block_height}; - //SDL_Rect cutoff = {0, block_height - y_offset, (block_width * 10), block_height}; - SDL_RenderCopy(ui->render, ui->skin.overlay_middle, NULL, &overlay); - } else { - SDL_Rect overlay = {0, y_offset + ((j - 1) * block_height), (block_width * 10), block_height}; - SDL_RenderCopy(ui->render, ui->skin.overlay_middle, NULL, &overlay); - } - } - } else { - for (int s = 0; s < board_x + 1; s++) { - int rx = (s * block_width); - SDL_RenderDrawLine(ui->render, rx, 1, rx, h + y_offset); - } - - for (int j = 0; j < board->game.config.board_visible + 1; j++) { - int ry = y_offset + (j * block_height); - SDL_RenderDrawLine(ui->render, 0, ry, w, ry); - } - } - - for (int s = board->game.highest_line; s < board_y; s++) { - for (int j = 0; j < board_x; j++) { - if (board->game.board[j][s] & SLOT_OCCUPIED) { - if (board->game.line_remove_tick[s]) { - if (board->game.tick % 2 == 0) { - continue; - } - } - - int block_x = (j * block_width); - int block_y = (y_offset + ((s - board_visible) * block_height)); - - draw_block(ui, block_x, block_y, block_width, block_height, - (board->game.board[j][s] >> 5), 255, board->scheme.off); - } - } - } - - if (!board->game.game_over) { - for (int s = 0; s < 4; s++) { - for (int j = 0; j < 4; j++) { - if ((board->game.current.m[s]>>(3 - j))&1) { - int block_x = ((j + board->game.current.pos.x) * block_width); - int block_y = y_offset + ((s + board->game.current.pos.y) - board_visible) * block_height; - - draw_block(ui, block_x, block_y, block_width, block_height, - board->game.current.t, 255, board->scheme.off); - - int ghost_y = y_offset + ((s + board->game.current.ghost_y) - board_visible) * block_height; - if (ghost_y != block_y) { - draw_block(ui, block_x, ghost_y, block_width, block_height, - board->game.current.t, 120, board->scheme.off); - } - } - } - } - } - - if (board->count_down > 0) - board->count_down-=(1.0f/FRAME_RATE); - - SDL_SetRenderTarget(ui->render, NULL); - - SDL_Rect dest = {x, y, w, h + y_offset}; - SDL_RenderCopy(ui->render, m, NULL, &dest); - - if (ui->skin.border) { - SDL_Rect border = {x - 110, y - 35, 380, 600}; - SDL_RenderCopy(ui->render, ui->skin.border, NULL, &border); - } -} - -void draw_held_piece(cetris_ui *ui, SDL_Texture *m, game_board_t* board, int x, int y, int w, int h) { - if (w < 8) return; - if (h < 8) return; - - //SDL_SetRenderTarget(ui->render, m); - //SDL_RenderClear(ui->render); - - int block_width = (w - 4) / 5; - int block_height = (h - 4) / 5; - - // make sure blocks are square - if (block_width > block_height) { - block_width = block_height; - } else { - block_height = block_width; - } - - SDL_Rect hold = {0, 0, w, h}; - - SDL_SetRenderDrawColor(ui->render, board->scheme.off.r, - board->scheme.off.g, board->scheme.off.b, board->scheme.off.a); - - //SDL_RenderFillRect(ui->render, &hold); - //SDL_RenderDrawRect(ui->render, &hold); - - if (board->game.piece_held) { - for (int s = 0; s < 4; s++) { - for (int j = 0; j < 4; j++) { - if ((board->game.held.m[s]>>(3 - j))&1) { - int block_x = 2 + ((j) * block_width); - int block_y = (s * block_height); - if (board->game.held.t == MINO_I) { - block_x += (int)(block_width / 1.5f); - block_y += block_height; - } else { - block_x += block_width; - block_y += (int)(block_height); - } - if (board->game.held.t == MINO_O) { - block_x -= block_width / 2; - } - - draw_block(ui, x + block_x, y + block_y, block_width, block_height, - board->game.held.t, 255, board->scheme.off); - - } - } - } - } - - //SDL_SetRenderTarget(ui->render, NULL); - - //SDL_Rect dest = {x, y, w, h}; - //SDL_RenderCopy(ui->render, m, NULL, &dest); -} - -void draw_piece_queue(cetris_ui* ui, SDL_Texture *m, game_board_t* board, int x, int y, int w, int h) { - if (w < 8) return; - if (h < 32) return; - - //SDL_SetRenderTarget(ui->render, m); - - //SDL_RenderClear(ui->render); - - int block_width = ((w - 4) / 4); - int block_height = ((h - 5) / 5) / 3; - - // make sure blocks are square - if (block_width > block_height) { - block_width = block_height; - } else { - block_height = block_width; - } - - //SDL_SetRenderDrawColor(ui->render, board->scheme.off.r, - // board->scheme.off.g, board->scheme.off.b, board->scheme.off.a); - - //SDL_Rect queue = {0, 0, w, h}; - //SDL_RenderFillRect(ui->render, &queue); - //SDL_RenderDrawRect(ui->render, &queue); - - for (int i = 0; i < 5; i++) { - int index = (board->game.current_index + i); - - uint8_t mino; - if (index <= 6) { - mino = board->game.piece_queue[index]; - } else { - index = index % 7; - mino = board->game.next_queue[index]; - } - - for (int s = 0; s < 4; s++) { - for (int j = 0; j < 4; j++) { - if ((default_matrices[mino][s]>>(3 - j))&1) { - int block_x = 2 + ((j) * block_width); - int block_y = (int)(h * (i/5.0)) + (s * block_height); - if (mino == MINO_I) { - block_y += block_height / 2; - } else if (mino != MINO_O) { - block_x += block_width / 2; - } - - draw_block(ui, x + block_x, y + block_y, block_width, block_height, - mino, 255, board->scheme.off); - - } - } - } - } - - //SDL_SetRenderTarget(ui->render, NULL); - - //SDL_Rect dest = {x, y, w, h}; - //SDL_RenderCopy(ui->render, m, NULL, &dest); - -} - -void draw_timer(cetris_ui *ui, game_board_t *board, int x, int y) { - char *buf = malloc(50); - long double second = board->game.timer / 1000000.0f; - if (second > 60.0f) { - int minute = (int)(second / 60.0f); - second -= (minute * 60.0f); - format_str(buf, 50, "%02d:%09.6Lf", minute, second); - } else { - format_str(buf, 50, "%.6Lf", second); - } - draw_text(ui, buf, x, y, get_font(ui, 25), board->scheme.text); - - //format_str(buf, 50, "lines remaining: %i", 20 - g.lines); - //draw_text(buf, 20, H - 60, false); - - free(buf); -} - -void draw(cetris_ui* ui) { - SDL_SetRenderDrawColor(ui->render, ui->colors.main.r, - ui->colors.main.g, ui->colors.main.b, ui->colors.main.a); - - SDL_RenderClear(ui->render); - - if (ui->skin.background) { - - int w, h; - SDL_QueryTexture(ui->skin.background, NULL, NULL, &w, &h); - - int ratio = w / W; - SDL_Rect back = {0, 0, ratio * W, ratio * H}; - SDL_RenderCopy(ui->render, ui->skin.background, &back, NULL); - } - - switch (ui->current_game) { - case SOLO: - //draw_image(ui, ui->solo.background, 0, 0, W, H); - draw_board(ui, ui->solo.main, &ui->solo.game_board, (W / 2) - 125, (H / 2) - 250, 250, 500); - draw_held_piece(ui, ui->solo.hold, &ui->solo.game_board, (W / 2) - 230, (H / 2) - 250, 100, 100); - draw_piece_queue(ui, ui->solo.queue, &ui->solo.game_board, (W / 2) + 150, (H / 2) - 250, 100, 450); - draw_timer(ui, &ui->solo.game_board, 20, 20); - break; - } - - SDL_RenderPresent(ui->render); -} - -void load_config(cetris_ui *ui, game_board_t *board) { - - ui->config.keys = (key_bindings_t){ - .key_down = SDLK_DOWN, - .key_right = SDLK_RIGHT, - .key_left = SDLK_LEFT, - .key_rotate_cw = SDLK_UP, - .key_rotate_ccw = 'x', - .key_drop = SDLK_SPACE, - .key_hold = 'c', - .key_restart = 'r' - }; - - board->conf = tetris_ds_config; - board->conf.levels = &tetris_worlds_levels[0]; - board->conf.win_condition = twenty_line_sprint; - board->conf.wait_on_clear = 0; - - ini_parser p; - if (load_ini_file(&p, "config.ini")) { - int das = atoi(get_ini_value(&p, "das", "das")); - board->conf.das_das = das; - - int arr = atoi(get_ini_value(&p, "das", "arr")); - board->conf.das_arr = arr; - - char* drop_delay = get_ini_value(&p, "game", "drop_delay"); - if (drop_delay) { - board->conf.drop_period = atoi(drop_delay); - //free(drop_delay); - } - - char* next_piece_delay = get_ini_value(&p, "game", "next_piece_delay"); - if (next_piece_delay) { - board->conf.next_piece_delay = atoi(next_piece_delay); - //free(next_piece_delay); - } - - char* lock_delay = get_ini_value(&p, "game", "lock_delay"); - if (lock_delay) { - board->conf.lock_delay = atoi(lock_delay); - //free(lock_delay); - } - - char* force_lock = get_ini_value(&p, "game", "force_lock"); - if (force_lock) { - board->conf.force_lock = atoi(force_lock); - //free(force_lock); - } - - char* wait_on_clear = get_ini_value(&p, "game", "wait_on_clear"); - if (wait_on_clear && !strcmp(wait_on_clear, "true")) { - board->conf.wait_on_clear = true; - } else board->conf.wait_on_clear = false; - - char* line_delay_clear = get_ini_value(&p, "game", "line_clear_delay"); - if (line_delay_clear) { - board->conf.line_delay_clear = atoi(line_delay_clear); - //free(line_delay_clear); - } - - char *dark = get_ini_value(&p, "ui", "dark_mode"); - if (dark) { - if (!strcmp(dark, "true")) { - ui->colors = dark_mode; - } - } else { - ui->colors = light_mode; - } - - char *skin = get_ini_value(&p, "ui", "skin"); - if (skin) { - ui->config.skin_name = skin; - } else ui->config.skin_name = "default"; - } -} - -void load_solo(cetris_ui *ui) { - load_config(ui, &ui->solo.game_board); - ui->solo.game_board.scheme = ui->colors; - - ui->solo.main = SDL_CreateTexture(ui->render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 251, 513); - ui->solo.queue = SDL_CreateTexture(ui->render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 100, 450); - ui->solo.hold = SDL_CreateTexture(ui->render, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 100, 100); - SDL_SetTextureBlendMode(ui->solo.hold, SDL_BLENDMODE_BLEND); - ui->solo.game_board.count_down = 3; - - init_game(&ui->solo.game_board.game, &ui->solo.game_board.conf); -} - -void handle_key(SDL_Event e, cetris_ui *ui, game_board_t* board) { - int sym; - switch (e.type) { - case SDL_QUIT: exit(0); - case SDL_KEYDOWN: - sym = e.key.keysym.sym; - if (sym == ui->config.keys.key_left) { - move_piece(&board->game, LEFT); - } else if (sym == ui->config.keys.key_right) { - move_piece(&board->game, RIGHT); - } else if (sym == ui->config.keys.key_down) { - move_piece(&board->game, DOWN); - } else if (sym == ui->config.keys.key_drop) { - move_piece(&board->game, HARD_DROP); - } else if (sym == ui->config.keys.key_hold) { - hold_piece(&board->game); - } else if (sym == ui->config.keys.key_rotate_cw) { - move_piece(&board->game, ROTATE_CW); - } else if (sym == ui->config.keys.key_rotate_ccw) { - move_piece(&board->game, ROTATE_CCW); - } else if (sym == ui->config.keys.key_restart) { - cetris_stop_game(&board->game); - board->count_down = 3; - } - break; - case SDL_KEYUP: - sym = e.key.keysym.sym; - if (sym == ui->config.keys.key_left) { - unhold_move(&board->game, LEFT); - } else if (sym == ui->config.keys.key_right) { - unhold_move(&board->game, RIGHT); - } else if (sym == ui->config.keys.key_down) { - unhold_move(&board->game, DOWN); - } else if (sym == ui->config.keys.key_drop) { - unhold_move(&board->game, HARD_DROP); - } else if (sym == ui->config.keys.key_rotate_cw) { - unhold_move(&board->game, ROTATE_CW); - } else if (sym == ui->config.keys.key_rotate_ccw) { - unhold_move(&board->game, ROTATE_CCW); - } - break; - } -} - -void handle_game_events(cetris_ui *ui, game_board_t *board) { - if (board->count_down < 0 && board->game.waiting) { - cetris_start_game(&board->game); - } - - if (board->game.line_event > 0) { - int index; - if (ui->skin.random_audio) { - index = rand() % ui->skin.clear_sound_count; - } else { - index = board->game.line_combo - 1; - } - if (index >= ui->skin.clear_sound_count) - index = ui->skin.clear_sound_count - 1; - - SDL_QueueAudio(ui->audio_device, ui->skin.clear_sound[index].wav_buffer, - ui->skin.clear_sound[index].wav_length); - - SDL_PauseAudioDevice(ui->audio_device, 0); - - board->game.line_event--; - if (board->game.lock_event) - board->game.lock_event = 0; - } - - if (board->game.tetris_event > 0) { - int index = rand() % ui->skin.tetris_sound_count; - SDL_QueueAudio(ui->audio_device, ui->skin.tetris_sound[index].wav_buffer, - ui->skin.tetris_sound[index].wav_length); - - SDL_PauseAudioDevice(ui->audio_device, 0); - board->game.tetris_event--; - } - - if (board->game.lock_event > 0) { - SDL_QueueAudio(ui->audio_device, ui->skin.lock_sound.wav_buffer, - ui->skin.lock_sound.wav_length); - - SDL_PauseAudioDevice(ui->audio_device, 0); - board->game.lock_event--; - } -} - -int main(void) { - cetris_ui ui; - memset(&ui, 0, sizeof(cetris_ui)); - - setup_sdl(&ui); - load_solo(&ui); - load_skin(&ui); - ui.current_game = SOLO; - - SDL_Event e; - for(;;) { - while(SDL_PollEvent(&e)) { - switch (ui.current_game) { - case SOLO: - handle_key(e, &ui, &ui.solo.game_board); - break; - } - } - - switch (ui.current_game) { - case SOLO: - handle_game_events(&ui, &ui.solo.game_board); - break; - } - - draw(&ui); - - SDL_Delay(1000 / FRAME_RATE); - } - - return 0; -} diff --git a/frontends/sdl/cetris_sdl.h b/frontends/sdl/cetris_sdl.h deleted file mode 100644 index 0f63d19..0000000 --- a/frontends/sdl/cetris_sdl.h +++ /dev/null @@ -1,113 +0,0 @@ -typedef struct { - SDL_Color main; - SDL_Color off; - SDL_Color text; -} color_scheme_t; - -color_scheme_t dark_mode = { - .main = {40, 40, 40, 255}, - .off = {90, 90, 90, 255}, - .text = {240, 240, 240, 255} -}; - -color_scheme_t light_mode = { - .main = {255, 255, 255, 255}, - .off = {235, 235, 235, 255}, - .text = {10, 10, 10, 255} -}; - -SDL_Color mino_colors[7] = { - {253,253,150,255}, // Yellow - {174,198,207,255}, // Aqua - {255,105,97,255}, // Red - {170,221,119,255}, // Olive - {255,179,71,255}, // Orange - {119,158,203,255}, // Navy - {177,156,217,255} // Purple -}; - -typedef struct { - SDL_AudioSpec wav_spec; - uint32_t wav_length; - uint8_t *wav_buffer; -} audio_clip_t; - -typedef struct { - TTF_Font *font; - int size; -} font_t; - -typedef struct { - bool random_audio; - - int clear_sound_count; - audio_clip_t *clear_sound; - - int tetris_sound_count; - audio_clip_t *tetris_sound; - audio_clip_t lock_sound; - - SDL_Texture *blocks; - SDL_Texture *game_background; - SDL_Texture *overlay_top; - SDL_Texture *overlay_middle; - SDL_Texture *overlay_bottom; - - SDL_Texture *border; - SDL_Texture *background; - -} cetris_skin_t; - -typedef struct { - cetris_game game; - color_scheme_t scheme; - cetris_config conf; - float count_down; -} game_board_t; - -typedef struct { - SDL_Texture *main; - SDL_Texture *queue; - SDL_Texture *hold; - - game_board_t game_board; -} solo_game_t; - -typedef struct { - int key_down; - int key_right; - int key_left; - int key_rotate_cw; - int key_rotate_ccw; - int key_drop; - int key_hold; - int key_restart; -} key_bindings_t; - -typedef struct { - key_bindings_t keys; - char *skin_name; -} config_t; - -enum { - SOLO -}; - -typedef struct { - int current_game; - solo_game_t solo; - color_scheme_t colors; - - SDL_Renderer* render; - SDL_Window *window; - SDL_Surface *screen; - - int font_count; - font_t fonts[10]; - - SDL_AudioDeviceID audio_device; - - config_t config; - - cetris_skin_t skin; -} cetris_ui; diff --git a/frontends/sdl/config.ini b/frontends/sdl/config.ini deleted file mode 100644 index 7dab064..0000000 --- a/frontends/sdl/config.ini +++ /dev/null @@ -1,16 +0,0 @@ -[das] -das = 220 -arr = 15 - -[game] -drop_delay = 20 -next_piece_delay = 40 -lock_delay = 300 -force_lock = 3000 -wait_on_clear = 0 -line_clear_delay = 0 - -[ui] -skin = puyo_arles_skin -dark_mode = 1 - diff --git a/frontends/sdl/data/LICENSE.txt b/frontends/sdl/data/LICENSE.txt deleted file mode 100644 index 75b5248..0000000 --- a/frontends/sdl/data/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ -
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/frontends/sdl/data/OpenSans-Regular.ttf b/frontends/sdl/data/OpenSans-Regular.ttf Binary files differdeleted file mode 100644 index 29bfd35..0000000 --- a/frontends/sdl/data/OpenSans-Regular.ttf +++ /dev/null diff --git a/frontends/sdl/data/lock.wav b/frontends/sdl/data/lock.wav Binary files differdeleted file mode 100644 index 6229891..0000000 --- a/frontends/sdl/data/lock.wav +++ /dev/null diff --git a/frontends/sdl/data/move_das.wav b/frontends/sdl/data/move_das.wav Binary files differdeleted file mode 100644 index dfc8dad..0000000 --- a/frontends/sdl/data/move_das.wav +++ /dev/null diff --git a/frontends/sdl/meson.build b/frontends/sdl/meson.build deleted file mode 100644 index 50277a6..0000000 --- a/frontends/sdl/meson.build +++ /dev/null @@ -1,29 +0,0 @@ -src = ['cetris_sdl.c'] - -deps = [cetris] -inc = [cetris_inc] - -if host_machine.system() == 'windows' - deps += compiler.find_library('SDL2', dirs: meson.current_source_dir() + '/win/SDL2-2.0.10/lib/x64') - deps += compiler.find_library('SDL2_ttf', dirs: meson.current_source_dir() + '/win/SDL2_ttf-2.0.15/lib/x64') - deps += compiler.find_library('SDL2_image', dirs: meson.current_source_dir() + '/win/SDL2_image-2.0.5/lib/x64') - inc += include_directories('win/SDL2-2.0.10/include') - inc += include_directories('win/SDL2_ttf-2.0.15/include') - inc += include_directories('win/SDL2_image-2.0.5/include') -else - deps += compiler.find_library('m') - deps += dependency('SDl2') - deps += dependency('SDL2_ttf') - deps += dependency('SDL2_image') -endif - -if host_machine.system() != 'windows' -run_command( - 'bash', '-c', 'cp -r $MESON_SOURCE_ROOT/frontends/sdl/data $MESON_BUILD_ROOT/frontends/sdl' -) -endif - -executable('cetris', src, - dependencies: deps, - include_directories: inc, - install: false) |