replaced print/exits combinations by sysfatal, to overcome 'unusable' window resulting from fatal error. (experimental) warp the mouse to the middle of the window for each new brick that starts dropping - to have sufficient space left and right to move the falling brick. (experimental) replaced the white/black blinking when a row disappears by fading to white - looks nicer. Axel. Reference: /n/sources/patch/applied/games-xs-fatal-warp-blink Date: Thu Jun 16 02:00:26 CES 2005 --- /sys/src/games/xs.h Thu Jun 16 01:56:40 2005 +++ /sys/src/games/xs.h Thu Jun 16 01:56:36 2005 @@ -30,6 +30,7 @@ int pcsz = 32; Point pos; Image *bb, *bbmask, *bb2, *bb2mask; +Image *whitemask; Rectangle br, br2; long points; int dt; @@ -309,6 +310,7 @@ pos.x += nrand(NX)*pcsz; }while(collide(Pt(pos.x, pos.y+pcsz-DY), piece)); drawpiece(); + moveto(mousectl, Pt(rboard.min.x + Dx(rboard)/2, rboard.min.y +Dy(rboard)/2)); flushimage(display, 1); } @@ -344,7 +346,6 @@ int lev[N]; int i, j, h; Rectangle r; - Image *col; h = 0; for(i=0; iwhite, nil, ZP); + draw(screen, r, display->white, whitemask, ZP); flushimage(display, 1); } - for(i=0; i<6; i++){ + for(i=0; i<5; i++){ pause(500); if(newscreen){ drawboard(); break; } - col = (i&1)? display->white : display->black; for(j=0; jwhite, whitemask, ZP); } flushimage(display, 1); } @@ -624,10 +624,8 @@ Rectangle r; long dx, dy; - if(new && getwindow(display, Refmesg) < 0){ - fprint(2, "can't reattach to window"); - exits("redraw"); - } + if(new && getwindow(display, Refmesg) < 0) + sysfatal("can't reattach to window"); r = screen->r; pos.x = (pos.x - rboard.min.x) / pcsz; pos.y = (pos.y - rboard.min.y) / pcsz; @@ -641,11 +639,8 @@ DY = 4; pcsz = DY*8; DMOUSE = pcsz/3; - if(pcsz < 8){ - fprint(2, "screen too small: %d\n", pcsz); - threadexitsall(nil); - exits("too small"); - } + if(pcsz < 8) + sysfatal("screen too small: %d", pcsz); rboard = screen->r; rboard.min.x += (dx-pcsz*NX)/2; rboard.min.y += (dy-pcsz*NY)/2+32; @@ -666,10 +661,8 @@ bbmask = allocimage(display, Rect(0,0,N*pcsz,N*pcsz), GREY1, 0, 0); bb2 = allocimage(display, Rect(0,0,N*pcsz,N*pcsz+DY), screen->chan, 0, 0); bb2mask = allocimage(display, bb2->r, GREY1, 0, 0); - if(bb==0 || bbmask==0 || bb2==0 || bb2mask==0){ - fprint(2, "allocimage fail (bb)\n"); - exits("allocimage"); - } + if(bb==0 || bbmask==0 || bb2==0 || bb2mask==0) + sysfatal("allocimage fail (bb)"); draw(screen, screen->r, display->white, nil, ZP); drawboard(); setpiece(piece); @@ -695,37 +688,27 @@ snprint(buf, sizeof(buf), "%ds", N); initdraw(0, 0, buf); mousectl = initmouse(nil, display->image); /* BUG? */ - if(mousectl == nil){ - fprint(2, "[45]s: mouse init failed: %r\n"); - exits("mouse"); - } + if(mousectl == nil) + sysfatal("[45]s: mouse init failed: %r"); keyboardctl = initkeyboard(nil); /* BUG? */ - if(keyboardctl == nil){ - fprint(2, "[45]s: keyboard init failed: %r\n"); - exits("kbd"); - } + if(keyboardctl == nil) + sysfatal("[45]s: keyboard init failed: %r"); starttime = time(0); srand(starttime); snprint(buf, sizeof(buf), "/sys/games/lib/%dscores", N); scores = open(buf, OWRITE); - if(scores < 0){ - fprint(2, "can't open %s\n", buf); - exits("scores file"); - } + if(scores < 0) + sysfatal("can't open %s: %r", buf); tb = 0; if(screen->depth < 3){ tb = allocimage(display, Rect(0,0,16,16), 0, 1, -1); - if(tb == 0){ - fprint(2, "allocimage fail (tb)\n"); - exits("allocimage"); - } + if(tb == 0) + sysfatal("allocimage fail (tb)"); } for(i = 0; ichan, 1, txpix[i]); - if(tx[i] == 0){ - fprint(2, "allocimage fail (tx)\n"); - exits("allocimage"); - } + if(tx[i] == 0) + sysfatal("allocimage fail (tx)"); if(screen->depth < 3){ loadimage(tb, tb->r, txbits[i], 32); draw(tx[i], tx[i]->r, tb, nil, ZP); @@ -733,6 +716,10 @@ } if(tb != 0) freeimage(tb); + + whitemask = allocimage(display, Rect(0,0,1,1), CMAP8, 1, setalpha(DWhite, 0x7F)); + if(whitemask==0) + sysfatal("allocimage fail (whitemask)"); threadsetname("4s-5s"); timerc= chancreate(sizeof(int), 0);