Changeset 8565a42 in mainline for uspace/dist/src/c/demos/tetris/screen.c
- Timestamp:
- 2018-03-02T20:34:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1a81f69, d5e5fd1
- Parents:
- 3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
- git-committer:
- GitHub <noreply@…> (2018-03-02 20:34:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/dist/src/c/demos/tetris/screen.c
r3061bc1 r8565a42 148 148 sysarg_t ccap; 149 149 errno_t rc = console_get_color_cap(console, &ccap); 150 150 151 151 if (rc != EOK) 152 152 return false; 153 153 154 154 return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB); 155 155 } … … 161 161 { 162 162 winsize_t ws; 163 163 164 164 Rows = 0; 165 165 Cols = 0; 166 166 167 167 if (get_display_size(&ws) == 0) { 168 168 Rows = ws.ws_row; … … 171 171 172 172 use_color = get_display_color_sup(); 173 173 174 174 if ((Rows < MINROWS) || (Cols < MINCOLS)) { 175 175 char smallscr[55]; 176 176 177 177 snprintf(smallscr, sizeof(smallscr), 178 178 "the screen is too small (must be at least %dx%d)", … … 181 181 } 182 182 isset = 1; 183 183 184 184 scr_clear(); 185 185 } … … 197 197 if (isset) 198 198 scr_end(); 199 199 200 200 errx(1, "aborting: %s", why); 201 201 } … … 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.