summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-10-23 19:53:39 -0400
committerAndrew Opalach <andrew@akon.city> 2019-10-23 19:53:39 -0400
commit6fa5bc504edfa4299b0b5d46d299cb5741654243 (patch)
treefbebaed7215f0d6b5069d97e4dd199538cf394d9 /frontends
parentce7bc0b52aa8db24eb417786763be843efcd640b (diff)
downloadcetris-6fa5bc504edfa4299b0b5d46d299cb5741654243.tar.gz
cetris-6fa5bc504edfa4299b0b5d46d299cb5741654243.tar.bz2
cetris-6fa5bc504edfa4299b0b5d46d299cb5741654243.zip
optimize cpu usage
Diffstat (limited to 'frontends')
-rw-r--r--frontends/curses/curses_ui.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/frontends/curses/curses_ui.c b/frontends/curses/curses_ui.c
index f3ebaa8..9b458dc 100644
--- a/frontends/curses/curses_ui.c
+++ b/frontends/curses/curses_ui.c
@@ -84,7 +84,7 @@ void curses_init() {
curs_set(0);
noecho();
keypad(stdscr, TRUE);
- nodelay(stdscr, true);
+ timeout(16);
#ifdef _WIN32 // only resize manually on windows
resize_term(WIN_LINE, WIN_COL);
@@ -122,15 +122,32 @@ void *game_loop(void) {
void draw_board() {
mvaddstr(0, 0, PLAY_FIELD_STR);
- for (int x = 0; x < CETRIS_BOARD_X; x++) {
- 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] & SLOT_GHOST) {
- attron(A_DIM);
+
+ for (int y = 0; y < 4; y++) {
+ for (int x = 0; x < 4; x++) {
+ if ((game.current.m[y]>>(3 - x))&1) {
+ int draw_x = X_OFFSET + ((x + game.current.pos.x) * 2);
+ int draw_y = Y_OFFSET + (y + game.current.pos.y) - CETRIS_BOARD_VISABLE;
+ int ghost_y = Y_OFFSET + (y + game.current.ghost_y) - CETRIS_BOARD_VISABLE;
+ attron(COLOR_PAIR(game.current.t) | A_BOLD);
mvaddstr(draw_y, draw_x, BLOCK);
+
+ if ((default_matrices[game.piece_queue[game.current_index]][y]>>(3 - x))&1) {
+ mvaddstr(6 + y, (x * 2) + 36, BLOCK);
+ }
+
+ attroff(COLOR_PAIR(game.current.t) | A_BOLD);
+ attron(A_DIM);
+ mvaddstr(ghost_y, draw_x, BLOCK);
attroff(A_DIM);
}
+ }
+ }
+
+ for (int x = 0; x < CETRIS_BOARD_X; x++) {
+ for (int y = game.highest_line; 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] & SLOT_OCCUPIED) {
attron(COLOR_PAIR(game.board[x][y] >> 5) | A_BOLD);
if (game.line_remove_tick[y]) {
@@ -144,17 +161,6 @@ void draw_board() {
}
}
- int index = game.current_index;
- attron(COLOR_PAIR(game.piece_queue[index]));
- for (int x = 0; x < 4; x++) {
- for (int y = 0; y < 4; y++) {
- if ((default_matrices[game.piece_queue[index]][y]>>(3 - x))&1) {
- mvaddstr(6 + y, (x * 2) + 36, BLOCK);
- }
- }
- }
- attroff(COLOR_PAIR(game.piece_queue[index]));
-
attron(A_BOLD);
char score[50];