summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-10-22 12:56:52 -0400
committerAndrew Opalach <andrew@akon.city> 2019-10-22 12:56:52 -0400
commitdc753ff2db5234dcfbac0eea4250e68d4455aef0 (patch)
tree7cd006ae5aae623f3fd09e7d2578992b225311cf /frontends
parent9fd2ebced8d3af6ad43323a2196e6638f7e6ecf5 (diff)
downloadcetris-dc753ff2db5234dcfbac0eea4250e68d4455aef0.tar.gz
cetris-dc753ff2db5234dcfbac0eea4250e68d4455aef0.tar.bz2
cetris-dc753ff2db5234dcfbac0eea4250e68d4455aef0.zip
greatly imporve memory usage of a game instance (5704 -> 788 bytes)
Diffstat (limited to 'frontends')
-rw-r--r--frontends/curses/curses_ui.c31
-rw-r--r--frontends/gl/main.c8
2 files changed, 19 insertions, 20 deletions
diff --git a/frontends/curses/curses_ui.c b/frontends/curses/curses_ui.c
index 5776af3..94b6141 100644
--- a/frontends/curses/curses_ui.c
+++ b/frontends/curses/curses_ui.c
@@ -91,14 +91,13 @@ void curses_init() {
#endif
start_color();
- init_pair(COLOR_NONE, COLOR_BLACK, COLOR_BLACK);
- init_pair(COLOR_O, COLOR_YELLOW, COLOR_BLACK);
- init_pair(COLOR_Z, COLOR_RED, COLOR_BLACK);
- init_pair(COLOR_S, COLOR_GREEN, COLOR_BLACK);
- init_pair(COLOR_T, COLOR_MAGENTA, COLOR_BLACK);
- init_pair(COLOR_L, COLOR_WHITE, COLOR_BLACK); // should be orange
- init_pair(COLOR_I, COLOR_CYAN, COLOR_BLACK);
- init_pair(COLOR_J, COLOR_BLUE, COLOR_BLACK);
+ init_pair(MINO_O, COLOR_YELLOW, COLOR_BLACK);
+ init_pair(MINO_Z, COLOR_RED, COLOR_BLACK);
+ init_pair(MINO_S, COLOR_GREEN, COLOR_BLACK);
+ init_pair(MINO_T, COLOR_MAGENTA, COLOR_BLACK);
+ init_pair(MINO_L, COLOR_WHITE, COLOR_BLACK); // should be orange
+ init_pair(MINO_I, COLOR_CYAN, COLOR_BLACK);
+ init_pair(MINO_J, COLOR_BLUE, COLOR_BLACK);
clear();
}
@@ -127,30 +126,30 @@ void draw_board() {
for (int y = CETRIS_BOARD_VISABLE; y < CETRIS_BOARD_Y; y++) {
int draw_y = y - CETRIS_BOARD_VISABLE + Y_OFFSET;
int draw_x = x * 2 + X_OFFSET;
- if (game.board[x][y].ghost) {
+ if (game.board[x][y] & SLOT_GHOST) {
attron(A_DIM);
mvaddstr(draw_y, draw_x, BLOCK);
attroff(A_DIM);
}
- if (game.board[x][y].occupied) {
- attron(COLOR_PAIR(game.board[x][y].c) | A_BOLD);
- if (game.board[0][y].remove_tick) {
+ if (game.board[x][y] & SLOT_OCCUPIED) {
+ attron(COLOR_PAIR(game.board[x][y] >> 5) | A_BOLD);
+ if (game.line_remove_tick[y]) {
if (game.tick % 2 == 0) {
mvaddstr(draw_y, draw_x, BLOCK);
}
} else {
mvaddstr(draw_y, draw_x, BLOCK);
}
- attroff(COLOR_PAIR(game.board[x][y].c) | A_BOLD);
+ attroff(COLOR_PAIR(game.board[x][y] >> 5) | A_BOLD);
}
}
int index = game.current_index;
- attron(COLOR_PAIR(game.piece_queue[index].c));
+ attron(COLOR_PAIR(game.piece_queue[index].t));
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
if (game.piece_queue[index].m[y][x]) {
- if (game.piece_queue[index].t == I || game.piece_queue[index].t == O) {
+ if (game.piece_queue[index].t == MINO_I || game.piece_queue[index].t == MINO_O) {
mvaddstr(6 + y, (x * 2) + 36, BLOCK);
} else {
mvaddstr(6 + y, (x * 2) + 37, BLOCK);
@@ -158,7 +157,7 @@ void draw_board() {
}
}
}
- attroff(COLOR_PAIR(game.piece_queue[index].c));
+ attroff(COLOR_PAIR(game.piece_queue[index].t));
attron(A_BOLD);
diff --git a/frontends/gl/main.c b/frontends/gl/main.c
index a9edd35..c1c6c2d 100644
--- a/frontends/gl/main.c
+++ b/frontends/gl/main.c
@@ -56,8 +56,8 @@ GLuint indices[] = {
1, 2, 3 // second triangle
};
-rbg_color colors[8] = {
- {0.0f, 0.0f, 0.0f}, // Black
+rbg_color colors[7] = {
+ //{0.0f, 0.0f, 0.0f}, // Black
{0.127f,0.219f,0.255f}, // Aqua
{0.61f,0.153f,0.112f}, // Olive
{0.177f,0.13f,0.201f}, // Purple
@@ -236,8 +236,8 @@ int main(void) {
glBindVertexArray(block.vao);
for (int x = 0; x < CETRIS_BOARD_X; x++) {
for (int y = 0; y < CETRIS_BOARD_Y; y++) {
- if (cetris.board[x][y].occupied) {
- update_block(&block, x, y, cetris.board[x][y].c);
+ if (cetris.board[x][y].flags & SLOT_OCCUPIED) {
+ update_block(&block, x, y, cetris.board[x][y].color);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
}