Skip to content

Commit

Permalink
fix tic_modulo (#2676)
Browse files Browse the repository at this point in the history
* use modulus to loop map

* use tic_modulo in drawMap

* fix tic_modulo for large negative values
  • Loading branch information
anescient authored Sep 9, 2024
1 parent e62e892 commit 794ee52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/core/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,8 @@ static void drawMap(tic_core* core, const tic_map* src, s32 x, s32 y, s32 width,
for (s32 j = y, jj = sy; j < y + height; j++, jj += size)
for (s32 i = x, ii = sx; i < x + width; i++, ii += size)
{
s32 mi = i;
s32 mj = j;

while (mi < 0) mi += TIC_MAP_WIDTH;
while (mj < 0) mj += TIC_MAP_HEIGHT;
while (mi >= TIC_MAP_WIDTH) mi -= TIC_MAP_WIDTH;
while (mj >= TIC_MAP_HEIGHT) mj -= TIC_MAP_HEIGHT;
s32 mi = tic_modulo(i, TIC_MAP_WIDTH);
s32 mj = tic_modulo(j, TIC_MAP_HEIGHT);

s32 index = mi + mj * TIC_MAP_WIDTH;
RemapResult retile = { *(src->data + index), tic_no_flip, tic_no_rotate };
Expand Down
8 changes: 4 additions & 4 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ inline u32 tic_rgba(const tic_rgb* c)

inline s32 tic_modulo(s32 x, s32 m)
{
if(x >= m) return x % m;
if(x < 0) return x % m + m;

return x;
s32 r = x % m;
if (r < 0)
r += m;
return r;
}

tic_blitpal tic_tool_palette_blit(const tic_palette* src, tic80_pixel_color_format fmt);
Expand Down

0 comments on commit 794ee52

Please sign in to comment.