Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TRY_DRAW_SPOT_PIXEL #2055

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -5684,7 +5684,7 @@ u16 SpeciesToCryId(u16 species)
// To draw a spot pixel, add 4 to the color index
#define SPOT_COLOR_ADJUSTMENT 4
/*
The macro below handles drawing the randomly-placed spots on Spinda's front sprite.
The macros below handle drawing the randomly-placed spots on Spinda's front sprite.
Spinda has 4 spots, each with an entry in gSpindaSpotGraphics. Each entry contains
a base x and y coordinate for the spot and a 16x16 binary image. Each bit in the image
determines whether that pixel should be considered part of the spot.
Expand All @@ -5696,18 +5696,26 @@ u16 SpeciesToCryId(u16 species)
coordinate is calculated as (baseCoord + (given 4 bits of personality) - 8). In effect this
means each spot can start at any position -8 to +7 off of its base coordinates (256 possibilities).

The macro then loops over the 16x16 spot image. For each bit in the spot's binary image, if
DRAW_SPINDA_SPOTS loops over the 16x16 spot image. For each bit in the spot's binary image, if
the bit is set then it's part of the spot; try to draw it. A pixel is drawn on Spinda if the
pixel on Spinda satisfies the following formula: ((u8)(colorIndex - 1) <= 2). The -1 excludes
transparent pixels, as these are index 0. Therefore only colors 1, 2, or 3 on Spinda will
allow a spot to be drawn. These color indexes are Spinda's light brown body colors. To create
pixel is between FIRST_SPOT_COLOR and LAST_SPOT_COLOR (so only colors 1, 2, or 3 on Spinda will
allow a spot to be drawn). These color indexes are Spinda's light brown body colors. To create
the spot it adds 4 to the color index, so Spinda's spots will be colors 5, 6, and 7.

The above is done two different ways in the macro: one with << 4, and one without. This
is because Spinda's sprite is a 4 bits per pixel image, but the pointer to Spinda's pixels
The above is done in TRY_DRAW_SPOT_PIXEL two different ways: one with << 4, and one without.
This is because Spinda's sprite is a 4 bits per pixel image, but the pointer to Spinda's pixels
(destPixels) is an 8 bit pointer, so it addresses two pixels. Shifting by 4 accesses the 2nd
of these pixels, so this is done every other time.
*/

// Draw spot pixel if this is Spinda's body color
#define TRY_DRAW_SPOT_PIXEL(pixels, shift) \
if (((*(pixels) & (0xF << (shift))) >= (FIRST_SPOT_COLOR << (shift))) \
&& ((*(pixels) & (0xF << (shift))) <= (LAST_SPOT_COLOR << (shift)))) \
{ \
*(pixels) += (SPOT_COLOR_ADJUSTMENT << (shift)); \
}

#define DRAW_SPINDA_SPOTS(personality, dest) \
{ \
s32 i; \
Expand Down Expand Up @@ -5737,17 +5745,11 @@ u16 SpeciesToCryId(u16 species)
/* of the two pixels is being considered for drawing */ \
if (column & 1) \
{ \
/* Draw spot pixel if this is Spinda's body color */ \
if ((u8)((*destPixels & 0xF0) - (FIRST_SPOT_COLOR << 4))\
<= ((LAST_SPOT_COLOR - FIRST_SPOT_COLOR) << 4))\
*destPixels += (SPOT_COLOR_ADJUSTMENT << 4); \
TRY_DRAW_SPOT_PIXEL(destPixels, 4); \
} \
else \
{ \
/* Draw spot pixel if this is Spinda's body color */ \
if ((u8)((*destPixels & 0xF) - FIRST_SPOT_COLOR) \
<= (LAST_SPOT_COLOR - FIRST_SPOT_COLOR)) \
*destPixels += SPOT_COLOR_ADJUSTMENT; \
TRY_DRAW_SPOT_PIXEL(destPixels, 0); \
} \
} \
\
Expand Down