diff options
| author | 2019-11-01 02:38:46 -0400 | |
|---|---|---|
| committer | 2019-11-01 02:38:46 -0400 | |
| commit | 346c2b763deb1fad251285c100029f9ded3e153c (patch) | |
| tree | 43d8aa62acca331764a61159fb6bf82aa34c5b3e /frontends | |
| parent | b38217359345669b73c8efc3a175033d7ab0128f (diff) | |
| download | cetris-346c2b763deb1fad251285c100029f9ded3e153c.tar.gz cetris-346c2b763deb1fad251285c100029f9ded3e153c.tar.bz2 cetris-346c2b763deb1fad251285c100029f9ded3e153c.zip | |
Revert "performace test"
This reverts commit 0127a9958da2b84e0f6c735b22228ab841577c0b.
Diffstat (limited to 'frontends')
| -rw-r--r-- | frontends/gl/drawable.c | 5 | ||||
| -rw-r--r-- | frontends/gl/drawable.h | 2 | ||||
| -rw-r--r-- | frontends/gl/main.c | 4 | ||||
| -rw-r--r-- | frontends/gl/ui.c | 45 | ||||
| -rw-r--r-- | frontends/gl/ui.h | 2 |
5 files changed, 13 insertions, 45 deletions
diff --git a/frontends/gl/drawable.c b/frontends/gl/drawable.c index 3d150fc..86f2410 100644 --- a/frontends/gl/drawable.c +++ b/frontends/gl/drawable.c @@ -61,10 +61,7 @@ void update_rect(drawable_t *block, GLfloat x, GLfloat y, GLfloat w, GLfloat h, //glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); } -void new_rectangle(drawable_t* drawable, GLfloat x, GLfloat y, GLfloat w, GLfloat h) { - calc_pos(&vertices[0], x, y, w, h); - set_block_texture(&vertices, 2); - +void new_rectangle(drawable_t* drawable) { glGenVertexArrays(1, &drawable->vao); glBindVertexArray(drawable->vao); diff --git a/frontends/gl/drawable.h b/frontends/gl/drawable.h index 6e971ff..41b9a72 100644 --- a/frontends/gl/drawable.h +++ b/frontends/gl/drawable.h @@ -9,6 +9,6 @@ typedef struct { GLuint texture; } drawable_t; -void new_rectangle(drawable_t* drawable, GLfloat x, GLfloat y, GLfloat w, GLfloat h); +void new_rectangle(drawable_t* drawable); void update_rect(drawable_t *block, GLfloat x, GLfloat y, GLfloat w, GLfloat h, uint8_t mino); bool load_image(char* file_name, GLuint texture); diff --git a/frontends/gl/main.c b/frontends/gl/main.c index 3634b63..ffd5794 100644 --- a/frontends/gl/main.c +++ b/frontends/gl/main.c @@ -131,7 +131,7 @@ int main(void) { cetris_start_game(&ui.board.game); load_tetris_board(&ui.board, 50.0f, 155.0f, 150.0f, 645.0f); - //new_rectangle(&ui.board.block); + new_rectangle(&ui.board.block); load_skin("test", &ui.skin); @@ -148,7 +148,7 @@ int main(void) { glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - draw_tetris_board(&ui); + //draw_tetris_board(&ui); draw_current(&ui); SDL_GL_SwapWindow(window); diff --git a/frontends/gl/ui.c b/frontends/gl/ui.c index 6d9ae4d..f21292c 100644 --- a/frontends/gl/ui.c +++ b/frontends/gl/ui.c @@ -1,6 +1,5 @@ #include <glad/glad.h> #include <stdio.h> -#include <stdlib.h> #include "ui.h" #include "drawable.h" @@ -13,52 +12,36 @@ void load_tetris_board(tetris_board_t *board, GLfloat x, GLfloat y, GLfloat w, G board->x_offset = x; board->y_offset = y; - - board->blocks = (drawable_t **)malloc(sizeof(drawable_t *) * board->config.board_x); - for (int i = 0; i < board->config.board_x; i++) { - board->blocks[i] = (drawable_t *)malloc(sizeof(drawable_t) * board->config.board_y); - } - for (int s = 0; s < board->config.board_x; s++) { - for (int j = 0; j < board->config.board_y; j++) { - new_rectangle(&board->blocks[s][j], x + (s * board->block_width), - y + (j * board->block_height), board->block_width, board->block_height); - } - } - - //glGenTextures(1, &board->blocks[0][0].texture); - //load_image("blocks.jpg", board->block[0][0].texture); + glGenTextures(1, &board->block.texture); + load_image("block.jpg", board->block.texture); } void draw_tetris_board(cetris_ui *ui) { - //glBindVertexArray(ui->board.block.vao); + glBindVertexArray(ui->board.block.vao); glBindTexture(GL_TEXTURE_2D, ui->skin.block_texture); for (int x = 0; x < ui->board.game.config.board_x; x++) { for (int y = ui->board.game.highest_line; y < ui->board.game.config.board_y; y++) { if (ui->board.game.board[x][y] & SLOT_OCCUPIED) { - glBindVertexArray(ui->board.blocks[x][y].vao); - /* update_rect(&ui->board.block, ui->board.x_offset + (x * ui->board.block_width), ui->board.y_offset + (y * ui->board.block_height), ui->board.block_width, ui->board.block_height, (ui->board.game.board[x][y] >> 5)); - */ - glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); } } } } void draw_current(cetris_ui *ui) { - //glBindTexture(GL_TEXTURE_2D, ui->skin.block_texture); - //glBindVertexArray(ui->board.block.vao); + glBindTexture(GL_TEXTURE_2D, ui->skin.block_texture); + glBindVertexArray(ui->board.block.vao); for (int s = 0; s < 4; s++) { for (int j = 0; j < 4; j++) { if ((ui->board.game.current.m[s]>>(3 - j))&1) { - /* GLfloat block_x = ui->board.x_offset + (j + ui->board.game.current.pos.x) * ui->board.block_width; @@ -66,32 +49,20 @@ void draw_current(cetris_ui *ui) { GLfloat block_y = ui->board.y_offset + (s + ui->board.game.current.pos.y) * ui->board.block_height; - */ - - int x = j + ui->board.game.current.pos.x; - int y = s + ui->board.game.current.pos.y; - glBindVertexArray(ui->board.blocks[x][y].vao); - /* + update_rect(&ui->board.block, block_x, block_y, ui->board.block_width, ui->board.block_height, ui->board.game.current.t); - */ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); - /* GLfloat ghost_y = ui->board.y_offset + (s + ui->board.game.current.ghost_y) * ui->board.block_height; - */ - - y = s + ui->board.game.current.ghost_y; - glBindVertexArray(ui->board.blocks[x][y].vao); - /* + update_rect(&ui->board.block, block_x, ghost_y, ui->board.block_width, ui->board.block_height, ui->board.game.current.t); - */ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); } } diff --git a/frontends/gl/ui.h b/frontends/gl/ui.h index c6b1f6a..4854ab0 100644 --- a/frontends/gl/ui.h +++ b/frontends/gl/ui.h @@ -10,7 +10,7 @@ typedef struct { GLfloat x_offset; GLfloat y_offset; - drawable_t **blocks; + drawable_t block; cetris_game game; cetris_config config; } tetris_board_t; |