From 41cbf30ae8b7c209154045722c62f7aaae94dddc Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 1 Nov 2018 21:30:24 +0100 Subject: [PATCH] remove buggy 'p', fix vt220 issue, implement SIGCONT vt220 is unable to cope with screen_setup() and show_minefield() in rapid succession because downloading (parsing?) the DRCS takes a while. resolution: only send .init_seq once. also: an experimental 'choord on flag' mode is implemented behind a -D... flag --- README.md | 1 - mines.c | 37 ++++++++++++++++++++++++------------- mines.h | 2 -- schemes.h | 4 ++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c9481fa..4501c22 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ Complete documentation and screenshots can be found on the | `^`/`G`/`g`/`$` | move to the very left / bottom / top / right | | `i` | flag / unflag | | `o` | open / chord | -| `p` | chord all open adjacent cells | | space | modeful, either open or flag | | `s` | toggle mode for space (open/flag) | | `r` | restart game | diff --git a/mines.c b/mines.c index 8cd384f..b2fa0af 100644 --- a/mines.c +++ b/mines.c @@ -162,7 +162,6 @@ int minesviiper(void) { flag_cell: case CTRSEQ_MOUSE_RIGHT: case 'i': flag_square (g.p[0], g.p[1]); break; - case 'p':if(choord_around(g.p[0],g.p[1]))return GAME_LOST;break; quesm_cell: case '?':quesm_square (g.p[0], g.p[1]); break; case CTRSEQ_CURSOR_LEFT: @@ -199,7 +198,7 @@ int minesviiper(void) { case ':': switch (ex_cmd()) { case EX_QUIT: return GAME_QUIT; - case EX_HELP: printf (KEYHELP); break; + case EX_HELP: printf (KEYHELP); break; //TODO: charset problems with vt220 case EX_RESZ: timer_setup(0); interactive_resize(); @@ -288,15 +287,6 @@ int choord_square (int line, int col) { return 0; } -int choord_around(int row, int col) { - AROUND(g.p[0], g.p[1]) { - if (AR_CELL.o == OPENED && get_neighbours (ROW, COL, 1) == 0) { - if (choord_square (ROW, COL)) return GAME_LOST; - } - } - return GAME_INPROGRESS; -} - int uncover_square (int l, int c) { if (f.c[l][c].o == OPENED) return 0; /* nothing to do */ @@ -349,7 +339,14 @@ int do_uncover (int* is_newgame, int actor) { timer_setup(1); } - if (HI_CELL.f == FLAG ) return GAME_INPROGRESS; //TODO: could choord? +#ifdef COORD_ON_FLAG + if (HI_CELL.f == FLAG ) { + if (choord_square(g.p[0], g.p[1])) return GAME_LOST; + else return GAME_INPROGRESS; + } +#else + if (HI_CELL.f == FLAG ) return GAME_INPROGRESS; +#endif if (HI_CELL.o == CLOSED) { if (uncover_square (g.p[0], g.p[1])) return GAME_LOST; } else if (get_neighbours (g.p[0], g.p[1], 1) == 0) { @@ -859,6 +856,11 @@ void signal_setup (void) { exit(1); } + if (sigaction(SIGCONT, &saction, NULL) < 0 ) { + perror ("SIGCONT"); + exit (1); + } + if (sigaction(SIGINT, &saction, NULL) < 0 ) { perror ("SIGINT"); exit (1); @@ -873,23 +875,32 @@ void signal_handler (int signum) { move_ph (1, f.w*CW-(CW%2)-3-(dtime>999)); printf ("[%03d]", g.t?dtime:0); break; + case SIGCONT: + /* NOTE: will leave the VT220 in special graphics charset */ + screen_setup(0); + screen_setup(1); + show_minefield (g.c?SHOWMINES:NORMAL); + break; case SIGINT: exit(128+SIGINT); } } void screen_setup (int enable) { + static int sent_init; if (enable) { raw_mode(1); printf ("\033[s\033[?47h"); /* save cursor, alternate screen */ printf ("\033[H\033[J"); /* reset cursor, clear screen */ printf ("\033[?1000h\033[?25l"); /* enable mouse, hide cursor */ - print (op.scheme->init_seq); /* swich charset, if necessary */ + if (!sent_init++) /* swich charset, if necessary and only once*/ + print (op.scheme->init_seq); } else { print (op.scheme->reset_seq); /* reset charset, if necessary */ printf ("\033[?9l\033[?25h"); /* disable mouse, show cursor */ printf ("\033[?47l\033[u"); /* primary screen, restore cursor */ raw_mode(0); + sent_init = 0; } } diff --git a/mines.h b/mines.h index cc9924e..4aca95b 100644 --- a/mines.h +++ b/mines.h @@ -23,7 +23,6 @@ " z :center cursor on minefield\n" \ " o :open/choord\n" \ " i :flag/unflag\n" \ - " p :choord around\n" \ " space:modeful cursor (either open or flag)\n" \ " s :toggle mode for space (open/flag)\n" \ " mX :set a mark for letter X\n" \ @@ -88,7 +87,6 @@ int uncover_square (int, int); void flag_square (int, int); void quesm_square (int, int); int choord_square (int, int); -int choord_around(int, int); int do_uncover (int*, int); int ex_cmd(void); void set_mark(void); diff --git a/schemes.h b/schemes.h index 964e255..d4169ec 100644 --- a/schemes.h +++ b/schemes.h @@ -144,8 +144,8 @@ struct minescheme symbols_doublewidth = { .cell_width = 1, .display_width = 2, - //TODO: after transmitting the DRCS the terminal gets unresponsive for a few seconds, causing the minefield to not be fully - //drawn after a screen_setup() + /* NOTE: sending the DRCS makes the VT220 hang for a few seconds. Then + the input buffer will not be cleared to read the minefield afterwards */ .init_seq = "\033P0;1;0;4;1;1{P" /*config for DRCS "P": 7x10,erase-all*/ "??~^^^^/??N????\033\\" /* flag at '!' resembling ▕▀ */ "\033(0\033*B\033+P" /* G0=Graphics,G2=ASCII,G3="P" */ -- 2.39.3