summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-11-01 02:20:44 -0400
committerAndrew Opalach <andrew@akon.city> 2019-11-01 02:20:44 -0400
commitb38217359345669b73c8efc3a175033d7ab0128f (patch)
tree435b1f33fe0268f63065f684c2ace662def39dd1
parentd52aa7a2d292e09fe4ae0c4c95f3fa72a4ccddae (diff)
downloadcetris-b38217359345669b73c8efc3a175033d7ab0128f.tar.gz
cetris-b38217359345669b73c8efc3a175033d7ab0128f.tar.bz2
cetris-b38217359345669b73c8efc3a175033d7ab0128f.zip
performace test
-rw-r--r--frontends/gl/drawable.c5
-rw-r--r--frontends/gl/drawable.h2
-rw-r--r--frontends/gl/main.c4
-rw-r--r--frontends/gl/ui.c45
-rw-r--r--frontends/gl/ui.h2
m---------ini0
-rwxr-xr-xtest/word_count.sh2
7 files changed, 47 insertions, 13 deletions
diff --git a/frontends/gl/drawable.c b/frontends/gl/drawable.c
index 86f2410..3d150fc 100644
--- a/frontends/gl/drawable.c
+++ b/frontends/gl/drawable.c
@@ -61,7 +61,10 @@ 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) {
+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);
+
glGenVertexArrays(1, &drawable->vao);
glBindVertexArray(drawable->vao);
diff --git a/frontends/gl/drawable.h b/frontends/gl/drawable.h
index 41b9a72..6e971ff 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);
+void new_rectangle(drawable_t* drawable, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
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 ffd5794..3634b63 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 f21292c..6d9ae4d 100644
--- a/frontends/gl/ui.c
+++ b/frontends/gl/ui.c
@@ -1,5 +1,6 @@
#include <glad/glad.h>
#include <stdio.h>
+#include <stdlib.h>
#include "ui.h"
#include "drawable.h"
@@ -12,36 +13,52 @@ 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);
+ }
- glGenTextures(1, &board->block.texture);
- load_image("block.jpg", board->block.texture);
+ 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);
}
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);
+
}
}
}
}
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;
@@ -49,20 +66,32 @@ 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 4854ab0..c6b1f6a 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 block;
+ drawable_t **blocks;
cetris_game game;
cetris_config config;
} tetris_board_t;
diff --git a/ini b/ini
-Subproject 3401f2ed3153c6093c2f434e205cf6e7775a02d
+Subproject 9b15f721fd53b1beb8364f8763e2207963ac4fd
diff --git a/test/word_count.sh b/test/word_count.sh
new file mode 100755
index 0000000..50fc734
--- /dev/null
+++ b/test/word_count.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+wc frontends/curses/curses_ui.c frontends/curses/meson.build frontends/sdl/cetris_sdl.c frontends/sdl/cetris_sdl.h frontends/gl/drawable.c frontends/gl/drawable.h frontends/gl/skin.c frontends/gl/skin.h frontends/gl/main.c frontends/gl/shader.c frontends/gl/shader.h frontends/gl/ui.c frontends/gl/ui.h frontends/gl/meson.build lib/*