this repo has no description
0
fork

Configure Feed

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

reverted looping map #1542

nesbox f9e2a247 1f28e3aa

+96 -86
+7 -2
src/core/draw.c
··· 272 272 for (s32 j = y, jj = sy; j < y + height; j++, jj += size) 273 273 for (s32 i = x, ii = sx; i < x + width; i++, ii += size) 274 274 { 275 - s32 mi = tic_modulo(i, TIC_MAP_WIDTH); 276 - s32 mj = tic_modulo(j, TIC_MAP_HEIGHT); 275 + s32 mi = i; 276 + s32 mj = j; 277 + 278 + while (mi < 0) mi += TIC_MAP_WIDTH; 279 + while (mj < 0) mj += TIC_MAP_HEIGHT; 280 + while (mi >= TIC_MAP_WIDTH) mi -= TIC_MAP_WIDTH; 281 + while (mj >= TIC_MAP_HEIGHT) mj -= TIC_MAP_HEIGHT; 277 282 278 283 s32 index = mi + mj * TIC_MAP_WIDTH; 279 284 RemapResult retile = { *(src->data + index), tic_no_flip, tic_no_rotate };
+76 -82
src/studio/editors/map.c
··· 37 37 #define MAX_SCALE 4 38 38 #define FILL_STACK_SIZE (TIC_MAP_WIDTH*TIC_MAP_HEIGHT) 39 39 40 + static void normalizeMap(s32* x, s32* y) 41 + { 42 + while(*x < 0) *x += MAX_SCROLL_X; 43 + while(*y < 0) *y += MAX_SCROLL_Y; 44 + while(*x >= MAX_SCROLL_X) *x -= MAX_SCROLL_X; 45 + while(*y >= MAX_SCROLL_Y) *y -= MAX_SCROLL_Y; 46 + } 47 + 40 48 static tic_point getTileOffset(Map* map) 41 49 { 42 50 return (tic_point){(map->sheet.rect.w - 1)*TIC_SPRITESIZE / 2, (map->sheet.rect.h - 1)*TIC_SPRITESIZE / 2}; ··· 49 57 50 58 s32 mx = tic_api_mouse(tic).x + map->scroll.x - offset.x; 51 59 s32 my = tic_api_mouse(tic).y + map->scroll.y - offset.y; 60 + 61 + normalizeMap(&mx, &my); 52 62 53 63 *x = mx / TIC_SPRITESIZE; 54 64 *y = my / TIC_SPRITESIZE; ··· 391 401 392 402 tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; 393 403 394 - tic_api_rect(tic, rect.x, rect.y + map->anim.pos.sheet, rect.w, rect.h, tic->ram->vram.vars.clear); 395 - tic_api_rectb(tic, rect.x - 1, rect.y - 1 + map->anim.pos.sheet, rect.w + 2, rect.h + 2, tic_color_white); 404 + tic_api_rectb(map->tic, rect.x - 1, rect.y - 1 + map->anim.pos.sheet, rect.w + 2, rect.h + 2, tic_color_white); 396 405 397 406 for(s32 i = 1; i < rect.h; i += 4) 398 407 { ··· 501 510 502 511 static void drawCursorPos(Map* map, s32 x, s32 y) 503 512 { 504 - tic_mem* tic = map->tic; 505 - 506 513 char pos[sizeof "999:999"]; 507 514 508 515 s32 tx = 0, ty = 0; ··· 518 525 s32 py = y - (TIC_FONT_HEIGHT + 2); 519 526 if(py <= TOOLBAR_SIZE) py = y + (TIC_SPRITESIZE + 3); 520 527 521 - tic_api_rect(tic, px - 1, py - 1, width + 1, TIC_FONT_HEIGHT + 1, tic_color_white); 522 - tic_api_print(tic, pos, px, py, tic_color_light_grey, true, 1, false); 528 + tic_api_rect(map->tic, px - 1, py - 1, width + 1, TIC_FONT_HEIGHT + 1, tic_color_white); 529 + tic_api_print(map->tic, pos, px, py, tic_color_light_grey, true, 1, false); 523 530 524 531 if(map->mode == MAP_FILL_MODE && tic_api_key(map->tic, tic_key_ctrl)) 525 532 { 526 - tic_api_rect(tic, px - 1, py - 1 + TIC_FONT_HEIGHT, width + 1, TIC_FONT_HEIGHT + 1, tic_color_white); 527 - tic_api_print(tic, "replace", px, py + TIC_FONT_HEIGHT, tic->ram->vram.vars.clear, true, 1, false); 533 + tic_api_rect(map->tic, px - 1, py - 1 + TIC_FONT_HEIGHT, width + 1, TIC_FONT_HEIGHT + 1, tic_color_white); 534 + tic_api_print(map->tic, "replace", px, py + TIC_FONT_HEIGHT, tic_color_dark_blue, true, 1, false); 528 535 } 529 536 } 530 537 ··· 538 545 s32 mx = map->sheet.rect.x; 539 546 s32 my = map->sheet.rect.y; 540 547 548 + 541 549 for(s32 j = 0; j < map->sheet.rect.h; j++) 542 550 for(s32 i = 0; i < map->sheet.rect.w; i++) 543 - tic_api_mset(map->tic, x+i, y+j, (mx+i) + (my+j) * TIC_SPRITESHEET_COLS); 551 + tic_api_mset(map->tic, (x+i)%TIC_MAP_WIDTH, (y+j)%TIC_MAP_HEIGHT, (mx+i) + (my+j) * TIC_SPRITESHEET_COLS); 544 552 545 553 ram2map(map->tic->ram, map->src); 546 554 ··· 564 572 return (tic_point){mx, my}; 565 573 } 566 574 567 - static bool cursorVisible(Map* map) 568 - { 569 - tic_mem* tic = map->tic; 570 - 571 - s32 mx = tic_api_mouse(tic).x + map->scroll.x; 572 - s32 my = tic_api_mouse(tic).y + map->scroll.y; 573 - 574 - return mx >= 0 && my >= 0 && mx < MAX_SCROLL_X && my < MAX_SCROLL_Y; 575 - } 576 - 577 575 static void drawTileCursor(Map* map) 578 576 { 579 577 tic_mem* tic = map->tic; ··· 588 586 s32 sy = map->sheet.rect.y; 589 587 590 588 initBlitMode(map); 591 - tic_api_spr(tic, sx + map->sheet.blit.pages * sy * TIC_SPRITESHEET_COLS, 592 - pos.x, pos.y, map->sheet.rect.w, map->sheet.rect.h, 593 - NULL, 0, 1, tic_no_flip, tic_no_rotate); 589 + tic_api_spr(tic, sx + map->sheet.blit.pages * sy * TIC_SPRITESHEET_COLS, pos.x, pos.y, map->sheet.rect.w, map->sheet.rect.h, NULL, 0, 1, tic_no_flip, tic_no_rotate); 594 590 resetBlitMode(map->tic); 595 591 } 596 592 } 597 593 598 594 static void drawTileCursorVBank1(Map* map) 599 595 { 600 - if(!cursorVisible(map)) 601 - return; 602 - 603 596 if(map->scroll.active) 604 597 return; 605 598 ··· 616 609 617 610 static void processMouseDrawMode(Map* map) 618 611 { 619 - if(!cursorVisible(map)) 620 - return; 621 - 622 612 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 623 613 624 614 setCursor(map->studio, tic_cursor_hand); ··· 674 664 map->scroll.x = map->scroll.start.x - tic_api_mouse(tic).x; 675 665 map->scroll.y = map->scroll.start.y - tic_api_mouse(tic).y; 676 666 677 - map->scroll.x = CLAMP(map->scroll.x, -TIC80_WIDTH / 2, MAX_SCROLL_X - TIC80_WIDTH / 2); 678 - map->scroll.y = CLAMP(map->scroll.y, -TIC80_HEIGHT / 2, MAX_SCROLL_Y -TIC80_HEIGHT / 2); 667 + normalizeMap(&map->scroll.x, &map->scroll.y); 679 668 680 669 setCursor(map->studio, tic_cursor_hand); 681 670 } ··· 708 697 709 698 static void drawSelectionRect(Map* map, s32 x, s32 y, s32 w, s32 h) 710 699 { 711 - tic_mem* tic = map->tic; 712 - enum{Step = 3, color = tic_color_white, alt = tic_color_black}; 700 + enum{Step = 3}; 701 + u8 color = tic_color_white; 713 702 714 703 s32 index = map->tickCounter / 10; 715 - for(s32 i = x; i < (x+w); i++) {tic_api_pix(tic, i, y, index++ % Step ? color : alt, false);} index++; 716 - for(s32 i = y; i < (y+h); i++) {tic_api_pix(tic, x + w-1, i, index++ % Step ? color : alt, false);} index++; 717 - for(s32 i = (x+w-1); i >= x; i--) {tic_api_pix(tic, i, y + h-1, index++ % Step ? color : alt, false);} index++; 718 - for(s32 i = (y+h-1); i >= y; i--) {tic_api_pix(tic, x, i, index++ % Step ? color : alt, false);} 704 + for(s32 i = x; i < (x+w); i++) {tic_api_pix(map->tic, i, y, index++ % Step ? color : 0, false);} index++; 705 + for(s32 i = y; i < (y+h); i++) {tic_api_pix(map->tic, x + w-1, i, index++ % Step ? color : 0, false);} index++; 706 + for(s32 i = (x+w-1); i >= x; i--) {tic_api_pix(map->tic, i, y + h-1, index++ % Step ? color : 0, false);} index++; 707 + for(s32 i = (y+h-1); i >= y; i--) {tic_api_pix(map->tic, x, i, index++ % Step ? color : 0, false);} 719 708 } 720 709 721 710 static void drawPasteData(Map* map) ··· 734 723 735 724 if(checkMouseClick(map->studio, &rect, tic_mouse_left)) 736 725 { 726 + normalizeMap(&mx, &my); 727 + 737 728 mx /= TIC_SPRITESIZE; 738 729 my /= TIC_SPRITESIZE; 739 730 740 731 for(s32 j = 0; j < h; j++) 741 732 for(s32 i = 0; i < w; i++) 742 - tic_api_mset(tic, mx+i, my+j, data[i + j * w]); 733 + tic_api_mset(tic, (mx+i)%TIC_MAP_WIDTH, (my+j)%TIC_MAP_HEIGHT, data[i + j * w]); 743 734 744 735 ram2map(tic->ram, map->src); 745 736 ··· 788 779 my += -map->scroll.y; 789 780 790 781 drawSelectionRect(map, mx - 1, my - 1, w * TIC_SPRITESIZE + 2, h * TIC_SPRITESIZE + 2); 782 + } 783 + 784 + static void normalizeMapRect(s32* x, s32* y) 785 + { 786 + while(*x < 0) *x += TIC_MAP_WIDTH; 787 + while(*y < 0) *y += TIC_MAP_HEIGHT; 788 + while(*x >= TIC_MAP_WIDTH) *x -= TIC_MAP_WIDTH; 789 + while(*y >= TIC_MAP_HEIGHT) *y -= TIC_MAP_HEIGHT; 791 790 } 792 791 793 792 static void processMouseSelectMode(Map* map) ··· 952 951 } 953 952 } 954 953 } 954 + } 955 + 956 + static s32 moduloWrap(s32 x, s32 m) 957 + { 958 + s32 y = x % m; 959 + return (y < 0) ? (y + m) : y; // always between 0 and m-1 inclusive 955 960 } 956 961 957 962 // replace tile with another tile or pattern ··· 984 989 if(tic_api_mget(map->tic, i, j) == tile) 985 990 { 986 991 // offset pattern based on click position 987 - s32 oy = tic_modulo(j - y, map->sheet.rect.h); 988 - s32 ox = tic_modulo(i - x, map->sheet.rect.w); 992 + s32 oy = moduloWrap(j - y, map->sheet.rect.h); 993 + s32 ox = moduloWrap(i - x, map->sheet.rect.w); 989 994 990 995 u8 newtile = (mx + ox) + (my + oy) * TIC_SPRITESHEET_COLS; 991 996 tic_api_mset(map->tic, i, j, newtile); ··· 994 999 995 1000 static void processMouseFillMode(Map* map) 996 1001 { 997 - if(!cursorVisible(map)) 998 - return; 999 - 1000 1002 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 1001 1003 1002 1004 setCursor(map->studio, tic_cursor_hand); ··· 1033 1035 s32 w = sel->w * TIC_SPRITESIZE; 1034 1036 s32 h = sel->h * TIC_SPRITESIZE; 1035 1037 1038 + while(x+w<0)x+=MAX_SCROLL_X; 1039 + while(y+h<0)y+=MAX_SCROLL_Y; 1040 + while(x+w>=MAX_SCROLL_X)x-=MAX_SCROLL_X; 1041 + while(y+h>=MAX_SCROLL_Y)y-=MAX_SCROLL_Y; 1042 + 1036 1043 drawSelectionRect(map, x-1, y-1, w+2, h+2); 1037 1044 } 1038 1045 } ··· 1071 1078 static void drawMapReg(Map* map) 1072 1079 { 1073 1080 tic_mem* tic = map->tic; 1074 - 1075 1081 tic_rect rect = {MAP_X, MAP_Y, MAP_WIDTH, MAP_HEIGHT}; 1076 1082 1077 1083 bool handle = !sheetVisible(map) && checkMousePos(map->studio, &rect); ··· 1083 1089 checkMouseDown(map->studio, &rect, tic_mouse_right)); 1084 1090 1085 1091 { 1092 + s32 scrollX = map->scroll.x % TIC_SPRITESIZE; 1093 + s32 scrollY = map->scroll.y % TIC_SPRITESIZE; 1094 + 1086 1095 map2ram(tic->ram, map->src); 1087 1096 1088 1097 initBlitMode(map); 1089 - 1090 - s32 sx = tic_modulo(map->scroll.x, MAX_SCROLL_X); 1091 - s32 sy = tic_modulo(map->scroll.y, MAX_SCROLL_Y); 1092 - 1093 - tic_api_map(tic, sx / TIC_SPRITESIZE, sy / TIC_SPRITESIZE, 1094 - TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, 1095 - -sx % TIC_SPRITESIZE, -sy % TIC_SPRITESIZE, 0, 0, 1, NULL, NULL); 1096 - 1098 + tic_api_map(tic, map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, 1099 + TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, 0, 0, 1, NULL, NULL); 1097 1100 resetBlitMode(map->tic); 1098 1101 1099 1102 if (map->canvas.grid) ··· 1137 1140 for(s32 i = sel->x; i < sel->x+sel->w; i++) 1138 1141 { 1139 1142 s32 x = i, y = j; 1143 + normalizeMapRect(&x, &y); 1140 1144 1141 1145 s32 index = x + y * TIC_MAP_WIDTH; 1142 1146 *ptr++ = map->src->data[index]; ··· 1164 1168 for(s32 i = sel->x; i < sel->x+sel->w; i++) 1165 1169 { 1166 1170 s32 x = i, y = j; 1171 + normalizeMapRect(&x, &y); 1172 + 1167 1173 s32 index = x + y * TIC_MAP_WIDTH; 1168 1174 map->src->data[index] = 0; 1169 1175 } ··· 1266 1272 if(tic_api_key(tic, tic_key_down)) map->scroll.y += Step; 1267 1273 if(tic_api_key(tic, tic_key_left)) map->scroll.x -= Step; 1268 1274 if(tic_api_key(tic, tic_key_right)) map->scroll.x += Step; 1275 + 1276 + static const tic_key Keycodes[] = {tic_key_up, tic_key_down, tic_key_left, tic_key_right}; 1277 + 1278 + for(s32 i = 0; i < COUNT_OF(Keycodes); i++) 1279 + if(tic_api_key(tic, Keycodes[i])) 1280 + { 1281 + normalizeMap(&map->scroll.x, &map->scroll.y); 1282 + break; 1283 + } 1269 1284 } 1270 1285 1271 1286 static void tick(Map* map) ··· 1289 1304 1290 1305 VBANK(tic, 1) 1291 1306 { 1307 + tic_api_cls(tic, tic->ram->vram.vars.clear = tic_color_dark_blue); 1308 + 1292 1309 memcpy(tic->ram->vram.palette.data, getConfig(map->studio)->cart->bank0.palette.vbank0.data, sizeof(tic_palette)); 1293 1310 1294 - tic->ram->vram.vars.clear = tic_color_dark_blue; 1295 - 1296 - // draw fog 1297 - { 1298 - memcpy(&tic->ram->vram.screen, map->fog, sizeof(tic_screen)); 1299 - tic_api_rect(tic, -map->scroll.x, -map->scroll.y, MAX_SCROLL_X, MAX_SCROLL_Y, tic->ram->vram.vars.clear); 1300 - } 1301 - 1302 - // draw screen grid 1303 - SCOPE(tic_api_clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT)) 1311 + tic_api_clip(tic, 0, TOOLBAR_SIZE, TIC80_WIDTH - (sheetVisible(map) ? TIC_SPRITESHEET_SIZE+2 : 0), TIC80_HEIGHT - TOOLBAR_SIZE); 1304 1312 { 1305 - tic_api_clip(tic, 0, TOOLBAR_SIZE, TIC80_WIDTH - (sheetVisible(map) ? TIC_SPRITESHEET_SIZE+2 : 0), 1306 - TIC80_HEIGHT - TOOLBAR_SIZE); 1307 - 1308 - s32 sx = tic_modulo(-map->scroll.x, TIC80_WIDTH); 1309 - s32 sy = tic_modulo(-map->scroll.y, TIC80_HEIGHT); 1313 + s32 screenScrollX = map->scroll.x % TIC80_WIDTH; 1314 + s32 screenScrollY = map->scroll.y % TIC80_HEIGHT; 1310 1315 1311 - tic_api_line(tic, 0, sy, TIC80_WIDTH, sy, tic_color_grey); 1312 - tic_api_line(tic, sx, 0, sx, TIC80_HEIGHT, tic_color_grey); 1316 + tic_api_line(tic, 0, TIC80_HEIGHT - screenScrollY, TIC80_WIDTH, TIC80_HEIGHT - screenScrollY, tic_color_grey); 1317 + tic_api_line(tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, tic_color_grey); 1313 1318 } 1319 + tic_api_clip(tic, 0, 0, TIC80_WIDTH, TIC80_HEIGHT); 1314 1320 1315 1321 drawSheetVBank1(map, TIC80_WIDTH - TIC_SPRITESHEET_SIZE - 1, TOOLBAR_SIZE); 1316 1322 ··· 1384 1390 1385 1391 if(map->history) history_delete(map->history); 1386 1392 freeAnim(map); 1387 - 1388 - tic_mem* tic = getMemory(studio); 1389 1393 1390 1394 *map = (Map) 1391 1395 { 1392 1396 .studio = studio, 1393 - .tic = tic, 1397 + .tic = getMemory(studio), 1394 1398 .tick = tick, 1395 1399 .src = src, 1396 1400 .mode = MAP_DRAW_MODE, ··· 1450 1454 {0, 0, STUDIO_ANIM_TIME, &map->anim.pos.page, AnimEaseIn}, 1451 1455 }), 1452 1456 }, 1453 - .fog = map->fog, 1454 1457 .event = onStudioEvent, 1455 1458 .scanline = scanline, 1456 1459 }; 1457 1460 1458 1461 map->anim.movie = resetMovie(&map->anim.idle); 1459 1462 1463 + normalizeMap(&map->scroll.x, &map->scroll.y); 1460 1464 tic_blit_update_bpp(&map->sheet.blit, TIC_DEFAULT_BIT_DEPTH); 1461 - 1462 - if(!map->fog) 1463 - { 1464 - tic_api_cls(tic, tic_color_black); 1465 - for(s32 i = 0; i < TIC80_WIDTH + TIC80_HEIGHT; i += 4) 1466 - tic_api_line(tic, i, 0, 0, i, tic_color_dark_grey); 1467 - 1468 - map->fog = MOVE(tic->ram->vram.screen); 1469 - } 1470 1465 } 1471 1466 1472 1467 void freeMap(Map* map) 1473 1468 { 1474 - free(map->fog); 1475 1469 freeAnim(map); 1476 1470 history_delete(map->history); 1477 1471 free(map);
-2
src/studio/editors/map.h
··· 103 103 104 104 } anim; 105 105 106 - tic_screen* fog; 107 - 108 106 void (*tick)(Map*); 109 107 void (*event)(Map*, StudioEvent); 110 108 void (*scanline)(tic_mem* tic, s32 row, void* data);
+13
src/studio/editors/world.c
··· 52 52 { 53 53 map->scroll.x = (mx - TIC_MAP_SCREEN_WIDTH/2) * TIC_SPRITESIZE; 54 54 map->scroll.y = (my - TIC_MAP_SCREEN_HEIGHT/2) * TIC_SPRITESIZE; 55 + if(map->scroll.x < 0) 56 + map->scroll.x += TIC_MAP_WIDTH * TIC_SPRITESIZE; 57 + if(map->scroll.y < 0) 58 + map->scroll.y += TIC_MAP_HEIGHT * TIC_SPRITESIZE; 55 59 } 56 60 57 61 if(checkMouseClick(world->studio, &rect, tic_mouse_left)) ··· 62 66 s32 y = map->scroll.y / TIC_SPRITESIZE; 63 67 64 68 tic_api_rectb(world->tic, x, y, TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, tic_color_red); 69 + 70 + if(x >= TIC_MAP_WIDTH - TIC_MAP_SCREEN_WIDTH) 71 + tic_api_rectb(world->tic, x - TIC_MAP_WIDTH, y, TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, tic_color_red); 72 + 73 + if(y >= TIC_MAP_HEIGHT - TIC_MAP_SCREEN_HEIGHT) 74 + tic_api_rectb(world->tic, x, y - TIC_MAP_HEIGHT, TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, tic_color_red); 75 + 76 + if(x >= TIC_MAP_WIDTH - TIC_MAP_SCREEN_WIDTH && y >= TIC_MAP_HEIGHT - TIC_MAP_SCREEN_HEIGHT) 77 + tic_api_rectb(world->tic, x - TIC_MAP_WIDTH, y - TIC_MAP_HEIGHT, TIC_MAP_SCREEN_WIDTH+1, TIC_MAP_SCREEN_HEIGHT+1, tic_color_red); 65 78 } 66 79 67 80 static void tick(World* world)