Skip to content

Commit 5d92669

Browse files
committed
Improve sprite scaling performance. Fix #17, Fix #18, Fix #19
1 parent feed474 commit 5d92669

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

src/suzy_inline.h

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ INLINE void Suzy::DrawSpriteLineLiteral(u16 data_begin, u16 data_end,
836836
ShiftRegisterReset(data_begin);
837837

838838
u32 h_accum = haccum_init;
839+
bool render = ((u32)y < (u32)GLYNX_SCREEN_HEIGHT);
839840

840841
while (m_state.shift_register_address < data_end)
841842
{
@@ -846,12 +847,26 @@ INLINE void Suzy::DrawSpriteLineLiteral(u16 data_begin, u16 data_end,
846847
u8 pen = m_state.pen_map[pi & 0x0F];
847848

848849
h_accum += (u32)hsiz;
850+
s32 pixel_count = (s32)(h_accum >> 8);
851+
h_accum &= 0xFF;
849852

850-
while (h_accum >= 0x100)
853+
if (pixel_count > 0)
851854
{
852-
DrawPixel(x, y, pen, type, collide, collision_id);
853-
x += dx;
854-
h_accum -= 0x100;
855+
if (render)
856+
{
857+
for (s32 p = 0; p < pixel_count; ++p)
858+
{
859+
DrawPixel(x, y, pen, type, collide, collision_id);
860+
x += dx;
861+
}
862+
863+
if ((dx > 0 && x >= GLYNX_SCREEN_WIDTH) || (dx < 0 && x < 0))
864+
render = false;
865+
}
866+
else
867+
{
868+
x += dx * pixel_count;
869+
}
855870
}
856871
}
857872
}
@@ -863,6 +878,7 @@ INLINE void Suzy::DrawSpriteLinePacked(u16 data_begin, u16 data_end,
863878
ShiftRegisterReset(data_begin);
864879

865880
u32 h_accum = haccum_init;
881+
bool render = ((u32)y < (u32)GLYNX_SCREEN_HEIGHT);
866882

867883
while (m_state.shift_register_address < data_end)
868884
{
@@ -884,11 +900,26 @@ INLINE void Suzy::DrawSpriteLinePacked(u16 data_begin, u16 data_end,
884900
u8 pen = m_state.pen_map[pi & 0x0F];
885901

886902
h_accum += (u32)hsiz;
887-
while (h_accum >= 0x100)
903+
s32 pixel_count = (s32)(h_accum >> 8);
904+
h_accum &= 0xFF;
905+
906+
if (pixel_count > 0)
888907
{
889-
DrawPixel(x, y, pen, type, collide, collision_id);
890-
x += dx;
891-
h_accum -= 0x100;
908+
if (render)
909+
{
910+
for (s32 p = 0; p < pixel_count; ++p)
911+
{
912+
DrawPixel(x, y, pen, type, collide, collision_id);
913+
x += dx;
914+
}
915+
916+
if ((dx > 0 && x >= GLYNX_SCREEN_WIDTH) || (dx < 0 && x < 0))
917+
render = false;
918+
}
919+
else
920+
{
921+
x += dx * pixel_count;
922+
}
892923
}
893924
}
894925
}
@@ -903,11 +934,26 @@ INLINE void Suzy::DrawSpriteLinePacked(u16 data_begin, u16 data_end,
903934
while (count--)
904935
{
905936
h_accum += (u32)hsiz;
906-
while (h_accum >= 0x100)
937+
s32 pixel_count = (s32)(h_accum >> 8);
938+
h_accum &= 0xFF;
939+
940+
if (pixel_count > 0)
907941
{
908-
DrawPixel(x, y, pen, type, collide, collision_id);
909-
x += dx;
910-
h_accum -= 0x100;
942+
if (render)
943+
{
944+
for (s32 p = 0; p < pixel_count; ++p)
945+
{
946+
DrawPixel(x, y, pen, type, collide, collision_id);
947+
x += dx;
948+
}
949+
950+
if ((dx > 0 && x >= GLYNX_SCREEN_WIDTH) || (dx < 0 && x < 0))
951+
render = false;
952+
}
953+
else
954+
{
955+
x += dx * pixel_count;
956+
}
911957
}
912958
}
913959
}

0 commit comments

Comments
 (0)