this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

some optimizations

Nesbox b6d91a39 f724c8c9

+37 -49
+1 -1
src/defines.h
··· 35 35 #define CONCAT2(a, b) a ## b 36 36 #define CONCAT(a, b) CONCAT2(a, b) 37 37 #define MACROVAR(name) CONCAT(name, __LINE__) 38 - #define DEFER(start, end) for(int MACROVAR(_i_) = (start,0); !MACROVAR(_i_); ++MACROVAR(_i_), end) 38 + #define DEFER(start, end) for(start, *MACROVAR(_i_) = NULL; !MACROVAR(_i_); ++MACROVAR(_i_), end) 39 39 #define SCOPE(exp) for(int MACROVAR(_i_) = 0; !MACROVAR(_i_); ++MACROVAR(_i_), exp) 40 40 #define FOR(type,it,list) for(type it = list, *MACROVAR(_end_) = it + COUNT_OF(list); it != MACROVAR(_end_); ++it) 41 41 #define FREE(ptr) do { if(ptr) free(ptr); } while (0)
+33 -47
src/studio/editors/sprite.c
··· 89 89 initTileSheet(sprite); 90 90 } 91 91 92 - static u8 getSheetPixel(Sprite* sprite, s32 x, s32 y) 93 - { 94 - return tic_tilesheet_getpix(&sprite->sheet, x, y); 95 - } 96 - 97 - static void setSheetPixel(Sprite* sprite, s32 x, s32 y, u8 color) 98 - { 99 - tic_tilesheet_setpix(&sprite->sheet, x, y, color); 100 - } 101 - 102 92 static s32 getIndexPosX(Sprite* sprite) 103 93 { 104 94 return (sprite->x + sprite->blit.page * TIC_SPRITESHEET_COLS) * TIC_SPRITESIZE; ··· 158 148 drawCursorBorder(sprite, x + mx, y + my, Size, Size); 159 149 160 150 if(checkMouseDown(&rect, tic_mouse_left)) 161 - sprite->color = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); 151 + sprite->color = tic_tilesheet_getpix(&sprite->sheet, sx + mx / Size, sy + my / Size); 162 152 163 153 if(checkMouseDown(&rect, tic_mouse_right)) 164 - sprite->color2 = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); 154 + sprite->color2 = tic_tilesheet_getpix(&sprite->sheet, sx + mx / Size, sy + my / Size); 165 155 } 166 156 } 167 157 ··· 207 197 208 198 for(s32 j = 0; j < pixels; j++) 209 199 for(s32 i = 0; i < pixels; i++) 210 - setSheetPixel(sprite, sx+i, sy+j, color); 200 + tic_tilesheet_setpix(&sprite->sheet, sx+i, sy+j, color); 211 201 212 202 history_add(sprite->history); 213 203 } ··· 223 213 224 214 for(s32 sy = t, i = 0; sy < b; sy++) 225 215 for(s32 sx = l; sx < r; sx++) 226 - setSheetPixel(sprite, sx, sy, sprite->select.back[i++]); 216 + tic_tilesheet_setpix(&sprite->sheet, sx, sy, sprite->select.back[i++]); 227 217 228 218 tic_rect* rect = &sprite->select.rect; 229 219 ··· 234 224 235 225 for(s32 sy = t, i = 0; sy < b; sy++) 236 226 for(s32 sx = l; sx < r; sx++) 237 - setSheetPixel(sprite, sx, sy, sprite->select.front[i++]); 227 + tic_tilesheet_setpix(&sprite->sheet, sx, sy, sprite->select.front[i++]); 238 228 239 229 history_add(sprite->history); 240 230 } ··· 247 237 248 238 for(s32 sy = rect.y, i = 0; sy < b; sy++) 249 239 for(s32 sx = rect.x; sx < r; sx++) 250 - sprite->select.back[i++] = getSheetPixel(sprite, sx, sy); 240 + sprite->select.back[i++] = tic_tilesheet_getpix(&sprite->sheet, sx, sy); 251 241 252 242 { 253 243 tic_rect* rect = &sprite->select.rect; ··· 318 308 319 309 static void floodFill(Sprite* sprite, s32 l, s32 t, s32 r, s32 b, s32 x, s32 y, u8 color, u8 fill) 320 310 { 321 - if(getSheetPixel(sprite, x, y) == color) 311 + if(tic_tilesheet_getpix(&sprite->sheet, x, y) == color) 322 312 { 323 - setSheetPixel(sprite, x, y, fill); 313 + tic_tilesheet_setpix(&sprite->sheet, x, y, fill); 324 314 325 315 if(x > l) floodFill(sprite, l, t, r, b, x-1, y, color, fill); 326 316 if(x < r) floodFill(sprite, l, t, r, b, x+1, y, color, fill); ··· 333 323 { 334 324 for(s32 sy = t; sy <= b; sy++) 335 325 for(s32 sx = l; sx <= r; sx++) 336 - if(getSheetPixel(sprite, sx, sy) == color) 337 - setSheetPixel(sprite, sx, sy, fill); 326 + if(tic_tilesheet_getpix(&sprite->sheet, sx, sy) == color) 327 + tic_tilesheet_setpix(&sprite->sheet, sx, sy, fill); 338 328 } 339 329 340 330 static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t) ··· 363 353 s32 sx = l + mx / Size; 364 354 s32 sy = t + my / Size; 365 355 366 - u8 color = getSheetPixel(sprite, sx, sy); 356 + u8 color = tic_tilesheet_getpix(&sprite->sheet, sx, sy); 367 357 u8 fill = left ? sprite->color : sprite->color2; 368 358 369 359 if(color != fill) ··· 436 426 { 437 427 s32 mx = tic_api_mouse(tic).x - x; 438 428 s32 my = tic_api_mouse(tic).y - y; 439 - sprite->color = getSheetPixel(sprite, rect.x + mx / Size, rect.y + my / Size); 429 + sprite->color = tic_tilesheet_getpix(&sprite->sheet, rect.x + mx / Size, rect.y + my / Size); 440 430 } 441 431 442 432 drawPanelBorder(tic, canvasRect.x - 1, canvasRect.y - 1, canvasRect.w + 2, canvasRect.h + 2); ··· 483 473 484 474 for(s32 sy = rect.y, j = y; sy < b; sy++, j += Size) 485 475 for(s32 sx = rect.x, i = x; sx < r; sx++, i += Size) 486 - tic_api_rect(tic, i, j, Size, Size, getSheetPixel(sprite, sx, sy)); 476 + tic_api_rect(tic, i, j, Size, Size, tic_tilesheet_getpix(&sprite->sheet, sx, sy)); 487 477 } 488 478 489 479 static void upCanvas(Sprite* sprite) ··· 585 575 586 576 for(s32 pixel_y = top; pixel_y < bottom; pixel_y++) 587 577 for(s32 pixel_x = left; pixel_x < right; pixel_x++) 588 - setSheetPixel(sprite, pixel_x, pixel_y, sprite->color2); 578 + tic_tilesheet_setpix(&sprite->sheet, pixel_x, pixel_y, sprite->color2); 589 579 590 580 clearCanvasSelection(sprite); 591 581 ··· 605 595 for(s32 y = sprite_y + rect->y; y < bottom; y++) 606 596 for(s32 x = sprite_x + rect->x, i = sprite_x + rect->x + rect->w - 1; x < right; x++, i--) 607 597 { 608 - u8 color = getSheetPixel(sprite, x, y); 609 - setSheetPixel(sprite, x, y, getSheetPixel(sprite, i, y)); 610 - setSheetPixel(sprite, i, y, color); 598 + u8 color = tic_tilesheet_getpix(&sprite->sheet, x, y); 599 + tic_tilesheet_setpix(&sprite->sheet, x, y, tic_tilesheet_getpix(&sprite->sheet, i, y)); 600 + tic_tilesheet_setpix(&sprite->sheet, i, y, color); 611 601 } 612 602 613 603 history_add(sprite->history); ··· 627 617 for(s32 y = sprite_y + rect->y, i = sprite_y + rect->y + rect->h - 1; y < bottom; y++, i--) 628 618 for(s32 x = sprite_x + rect->x; x < right; x++) 629 619 { 630 - u8 color = getSheetPixel(sprite, x, y); 631 - setSheetPixel(sprite, x, y, getSheetPixel(sprite, x, i)); 632 - setSheetPixel(sprite, x, i, color); 620 + u8 color = tic_tilesheet_getpix(&sprite->sheet, x, y); 621 + tic_tilesheet_setpix(&sprite->sheet, x, y, tic_tilesheet_getpix(&sprite->sheet, x, i)); 622 + tic_tilesheet_setpix(&sprite->sheet, x, i, color); 633 623 } 634 624 635 625 history_add(sprite->history); ··· 1421 1411 for(s32 y = rect.y; y < b; y++) 1422 1412 for(s32 x = rect.x, i = rect.x + rect.w - 1; x < r; x++, i--) 1423 1413 { 1424 - u8 color = getSheetPixel(sprite, x, y); 1425 - setSheetPixel(sprite, x, y, getSheetPixel(sprite, i, y)); 1426 - setSheetPixel(sprite, i, y, color); 1414 + u8 color = tic_tilesheet_getpix(&sprite->sheet, x, y); 1415 + tic_tilesheet_setpix(&sprite->sheet, x, y, tic_tilesheet_getpix(&sprite->sheet, i, y)); 1416 + tic_tilesheet_setpix(&sprite->sheet, i, y, color); 1427 1417 } 1428 1418 1429 1419 history_add(sprite->history); ··· 1438 1428 for(s32 y = rect.y, i = rect.y + rect.h - 1; y < b; y++, i--) 1439 1429 for(s32 x = rect.x; x < r; x++) 1440 1430 { 1441 - u8 color = getSheetPixel(sprite, x, y); 1442 - setSheetPixel(sprite, x, y, getSheetPixel(sprite, x, i)); 1443 - setSheetPixel(sprite, x, i, color); 1431 + u8 color = tic_tilesheet_getpix(&sprite->sheet, x, y); 1432 + tic_tilesheet_setpix(&sprite->sheet, x, y, tic_tilesheet_getpix(&sprite->sheet, x, i)); 1433 + tic_tilesheet_setpix(&sprite->sheet, x, i, color); 1444 1434 } 1445 1435 1446 1436 history_add(sprite->history); ··· 1460 1450 1461 1451 for(s32 y = rect.y, i = 0; y < b; y++) 1462 1452 for(s32 x = rect.x; x < r; x++) 1463 - buffer[i++] = getSheetPixel(sprite, x, y); 1453 + buffer[i++] = tic_tilesheet_getpix(&sprite->sheet, x, y); 1464 1454 1465 1455 for(s32 y = rect.y, j = 0; y < b; y++, j++) 1466 1456 for(s32 x = rect.x, i = 0; x < r; x++, i++) 1467 - setSheetPixel(sprite, x, y, buffer[j + (Size-i-1)*Size]); 1457 + tic_tilesheet_setpix(&sprite->sheet, x, y, buffer[j + (Size-i-1)*Size]); 1468 1458 1469 1459 history_add(sprite->history); 1470 1460 } ··· 1481 1471 1482 1472 for(s32 y = rect.y; y < b; y++) 1483 1473 for(s32 x = rect.x; x < r; x++) 1484 - setSheetPixel(sprite, x, y, sprite->color2); 1474 + tic_tilesheet_setpix(&sprite->sheet, x, y, sprite->color2); 1485 1475 1486 1476 clearCanvasSelection(sprite); 1487 1477 ··· 1677 1667 static void copyToClipboard(Sprite* sprite) 1678 1668 { 1679 1669 s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE; 1680 - u8* buffer = malloc(size); 1681 1670 1682 - if(buffer) 1671 + DEFER(u8* buffer = malloc(size), free(buffer)) 1683 1672 { 1684 1673 tic_rect rect = getSpriteRect(sprite); 1685 1674 s32 r = rect.x + rect.w; ··· 1687 1676 1688 1677 for(s32 y = rect.y, i = 0; y < b; y++) 1689 1678 for(s32 x = rect.x; x < r; x++) 1690 - tic_tool_poke4(buffer, i++, getSheetPixel(sprite, x, y) & 0xf); 1679 + tic_tool_poke4(buffer, i++, tic_tilesheet_getpix(&sprite->sheet, x, y) & 0xf); 1691 1680 1692 1681 toClipboard(buffer, size, true); 1693 - 1694 - free(buffer); 1695 1682 } 1696 1683 } 1697 1684 ··· 1710 1697 } 1711 1698 1712 1699 s32 size = sprite->size * sprite->size * TIC_PALETTE_BPP / BITS_IN_BYTE; 1713 - u8* buffer = malloc(size); 1714 1700 1715 - SCOPE(free(buffer)) 1701 + DEFER(u8* buffer = malloc(size), free(buffer)) 1716 1702 { 1717 1703 if(fromClipboard(buffer, size, true, false)) 1718 1704 { ··· 1722 1708 1723 1709 for(s32 y = rect.y, i = 0; y < b; y++) 1724 1710 for(s32 x = rect.x; x < r; x++) 1725 - setSheetPixel(sprite, x, y, tic_tool_peek4(buffer, i++)); 1711 + tic_tilesheet_setpix(&sprite->sheet, x, y, tic_tool_peek4(buffer, i++)); 1726 1712 1727 1713 history_add(sprite->history); 1728 1714 }
+3 -1
src/system/sdl/main.c
··· 1575 1575 1576 1576 static s32 start(s32 argc, char **argv, const char* folder) 1577 1577 { 1578 - DEFER(platform.studio = studioInit(argc, argv, TIC80_SAMPLERATE, folder), platform.studio->close()) 1578 + platform.studio = studioInit(argc, argv, TIC80_SAMPLERATE, folder); 1579 + 1580 + SCOPE(platform.studio->close()) 1579 1581 { 1580 1582 if (platform.studio->config()->cli) 1581 1583 {