Changeset a35b458 in mainline for uspace/app/tetris/screen.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/screen.c
r3061bc1 ra35b458 147 147 sysarg_t ccap; 148 148 errno_t rc = console_get_color_cap(console, &ccap); 149 149 150 150 if (rc != EOK) 151 151 return false; 152 152 153 153 return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB); 154 154 } … … 160 160 { 161 161 winsize_t ws; 162 162 163 163 Rows = 0; 164 164 Cols = 0; 165 165 166 166 if (get_display_size(&ws) == 0) { 167 167 Rows = ws.ws_row; … … 170 170 171 171 use_color = get_display_color_sup(); 172 172 173 173 if ((Rows < MINROWS) || (Cols < MINCOLS)) { 174 174 char smallscr[55]; 175 175 176 176 snprintf(smallscr, sizeof(smallscr), 177 177 "the screen is too small (must be at least %dx%d)", … … 180 180 } 181 181 isset = 1; 182 182 183 183 scr_clear(); 184 184 } … … 196 196 if (isset) 197 197 scr_end(); 198 198 199 199 fprintf(stderr, "aborting: %s", why); 200 200 abort(); … … 213 213 int j; 214 214 int ccol; 215 215 216 216 /* Always leave cursor after last displayed point */ 217 217 curscreen[D_LAST * B_COLS - 1] = -1; 218 218 219 219 if (score != curscore) { 220 220 moveto(0, 0); … … 222 222 curscore = score; 223 223 } 224 224 225 225 /* Draw preview of next pattern */ 226 226 if ((showpreview) && (nextshape != lastshape)) { … … 228 228 static int r = 5, c = 2; 229 229 int tr, tc, t; 230 230 231 231 lastshape = nextshape; 232 232 233 233 /* Clean */ 234 234 resume_normal(); … … 241 241 moveto(r + 2, c - 1); 242 242 putstr(" "); 243 243 244 244 moveto(r - 3, c - 2); 245 245 putstr("Next shape:"); 246 246 247 247 /* Draw */ 248 248 start_standout(nextshape->color); … … 252 252 t = c + r * B_COLS; 253 253 t += nextshape->off[i]; 254 254 255 255 tr = t / B_COLS; 256 256 tc = t % B_COLS; 257 257 258 258 moveto(tr, 2*tc); 259 259 putstr(" "); … … 261 261 resume_normal(); 262 262 } 263 263 264 264 bp = &board[D_FIRST * B_COLS]; 265 265 sp = &curscreen[D_FIRST * B_COLS]; … … 269 269 if (*sp == (so = *bp)) 270 270 continue; 271 271 272 272 *sp = so; 273 273 if (i != ccol) { … … 278 278 moveto(RTOD(j), CTOD(i)); 279 279 } 280 280 281 281 if (so != cur_so) { 282 282 if (so) … … 287 287 } 288 288 putstr(" "); 289 289 290 290 ccol = i + 1; 291 291 /* … … 297 297 * the next cell is a different color. 298 298 */ 299 299 300 300 if ((i > STOP) || (sp[1] != bp[1]) || (so != bp[1])) 301 301 continue; 302 302 303 303 if (sp[2] != bp[2]) 304 304 sp[1] = -1; … … 309 309 } 310 310 } 311 311 312 312 if (cur_so) 313 313 resume_normal(); 314 314 315 315 console_flush(console); 316 316 } … … 323 323 { 324 324 int l = str_size(s); 325 325 326 326 moveto(Rows - 2, ((Cols - l) >> 1) - 1); 327 327 328 328 if (set) 329 329 putstr(s); … … 341 341 { 342 342 suseconds_t timeout = fallrate; 343 343 344 344 while (timeout > 0) { 345 345 cons_event_t event; 346 346 347 347 if (!console_get_event_timeout(console, &event, &timeout)) 348 348 break; … … 359 359 * and increase speed. 360 360 */ 361 361 362 362 if (timeleft <= 0) { 363 363 faster(); 364 364 timeleft = fallrate; 365 365 } 366 366 367 367 /* 368 368 * Wait to see if there is any input. If so, take it and … … 371 371 * make timeleft zero and return -1. 372 372 */ 373 373 374 374 wchar_t c = 0; 375 375 376 376 while (c == 0) { 377 377 cons_event_t event; 378 378 379 379 if (!console_get_event_timeout(console, &event, &timeleft)) { 380 380 timeleft = 0; 381 381 return -1; 382 382 } 383 383 384 384 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 385 385 c = event.ev.key.c; 386 386 } 387 387 388 388 return (int) c; 389 389 } … … 395 395 { 396 396 wchar_t c = 0; 397 397 398 398 while (c == 0) { 399 399 cons_event_t event; 400 400 401 401 if (!console_get_event(console, &event)) 402 402 return -1; 403 403 404 404 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 405 405 c = event.ev.key.c; 406 406 } 407 407 408 408 return (int) c; 409 409 }
Note:
See TracChangeset
for help on using the changeset viewer.