this repo has no description
0
fork

Configure Feed

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

line() api optimizations #1826

nesbox 7a29eab2 74ad203b

+19 -31
+19 -31
src/core/draw.c
··· 59 59 return tic_tool_peek4(tic->ram->vram.mapping, color & 0xf); 60 60 } 61 61 62 - static void setPixel(tic_core* core, s32 x, s32 y, u8 color) 62 + static inline void setPixel(tic_core* core, s32 x, s32 y, u8 color) 63 63 { 64 64 const tic_vram* vram = &core->memory.ram->vram; 65 65 ··· 573 573 drawEllipse(memory, x, y, a, b, mapColor(memory, color), setElliPixel); 574 574 } 575 575 576 - static void drawLine(tic_mem* tic, float x0, float y0, float x1, float y1, u8 color) 576 + static inline float initLine(float *x0, float *x1, float *y0, float *y1) 577 577 { 578 - enum{Left = 0, Top = 0, Right = TIC80_WIDTH, Bottom = TIC80_HEIGHT}; 579 - 580 - if(fabs(x0 - x1) < fabs(y0 - y1)) 578 + if (*y0 > *y1) 581 579 { 582 - if (y0 > y1) 583 - { 584 - SWAP(x0, x1, float); 585 - SWAP(y0, y1, float); 586 - } 587 - 588 - float t = (x1 - x0) / (y1 - y0); 589 - 590 - if(y0 < Top) x0 = x0 + (Top - y0) * t, y0 = Top; 591 - if(y1 > Bottom) x1 = x1 + (Bottom - y0) * t, y1 = Bottom; 592 - 593 - for (float y = y0; y <= y1; y++) 594 - setPixel((tic_core*)tic, x0 + (y - y0) * t, y, color); 580 + SWAP(*x0, *x1, float); 581 + SWAP(*y0, *y1, float); 595 582 } 596 - else 597 - { 598 - if (x0 > x1) 599 - { 600 - SWAP(x0, x1, float); 601 - SWAP(y0, y1, float); 602 - } 603 583 604 - float t = (y1 - y0) / (x1 - x0); 584 + float t = (*x1 - *x0) / (*y1 - *y0); 605 585 606 - if(x0 < Left) y0 = y0 + (Left - x0) * t, x0 = Left; 607 - if(x1 > Right) y1 = y1 + (Right - x0) * t, x1 = Right; 586 + if(*y0 < 0) *x0 -= *y0 * t, *y0 = 0; 587 + if(*y1 > TIC80_WIDTH) *x1 += (TIC80_WIDTH - *y0) * t, *y1 = TIC80_WIDTH; 608 588 609 - for (float x = x0; x <= x1; x++) 610 - setPixel((tic_core*)tic, x, y0 + (x - x0) * t, color); 611 - } 589 + return t; 590 + } 591 + 592 + static void drawLine(tic_mem* tic, float x0, float y0, float x1, float y1, u8 color) 593 + { 594 + if(fabs(x0 - x1) < fabs(y0 - y1)) 595 + for (float t = initLine(&x0, &x1, &y0, &y1); y0 < y1; y0++, x0 += t) 596 + setPixel((tic_core*)tic, x0, y0, color); 597 + else 598 + for (float t = initLine(&y0, &y1, &x0, &x1); x0 < x1; x0++, y0 += t) 599 + setPixel((tic_core*)tic, x0, y0, color); 612 600 } 613 601 614 602 typedef struct