Skip to content

Commit

Permalink
add getters for sprite x,y,unk6_1 and tilenum
Browse files Browse the repository at this point in the history
  • Loading branch information
DizzyEggg committed Dec 23, 2024
1 parent 1304aab commit 6441fae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 23 additions & 2 deletions include/structs/sprite_oam.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ typedef struct SpriteOAM
(spritePtr)->attrib1 |= _shapeVal; \
}

#define SpriteGetTileNum_LocalVar(spritePtr, _tileNum) \
{ \
_tileNum = (spritePtr)->attrib3; \
_tileNum >>= SPRITEOAM_SHIFT_TILENUM; \
_tileNum &= SPRITEOAM_MAX_TILENUM; \
}

#define SpriteSetTileNum(spritePtr, _tileNum) \
{ \
u32 _tileNumVal = _tileNum; \
Expand All @@ -188,6 +195,14 @@ typedef struct SpriteOAM
(spritePtr)->attrib3 |= _tileNumVal; \
}

#define SpriteAddTileNum(spritePtr, addVal) \
{ \
u32 _tileNumValAdd; \
SpriteGetTileNum_LocalVar(spritePtr, _tileNumValAdd); \
_tileNumValAdd += (addVal); \
SpriteSetTileNum(spritePtr, _tileNumValAdd); \
}

#define SpriteSetPriority(spritePtr, _priority) \
{ \
u32 _priorityVal = _priority; \
Expand Down Expand Up @@ -233,6 +248,8 @@ typedef struct SpriteOAM
(spritePtr)->attrib2 |= _sizeVal; \
}

#define SpriteGetX(spritePtr)(((spritePtr)->attrib2 >> SPRITEOAM_SHIFT_X) & SPRITEOAM_MAX_X)

#define SpriteSetX(spritePtr, _x) \
{ \
u32 _xSpriteVal = _x; \
Expand All @@ -252,7 +269,9 @@ typedef struct SpriteOAM
(spritePtr)->attrib2 = _xSpriteVal; \
}

#define SpriteGetY(spritePtr, _y) \
#define SpriteGetY(spritePtr)(((spritePtr)->unk6 >> SPRITEOAM_SHIFT_WORKING_Y) & SPRITEOAM_MAX_WORKING_Y)

#define SpriteGetY_LocalVar(spritePtr, _y) \
{ \
_y = (spritePtr)->unk6; \
_y >>= SPRITEOAM_SHIFT_WORKING_Y; \
Expand All @@ -271,7 +290,7 @@ typedef struct SpriteOAM
#define SpriteAddY(spritePtr, addVal) \
{ \
u32 _yVal; \
SpriteGetY(spritePtr, _yVal); \
SpriteGetY_LocalVar(spritePtr, _yVal); \
_yVal += (addVal); \
SpriteSetY(spritePtr, _yVal); \
}
Expand All @@ -285,6 +304,8 @@ typedef struct SpriteOAM
(spritePtr)->unk6 |= _unk6_0Val; \
}

#define SpriteGetUnk6_1(spritePtr)(((spritePtr)->unk6 >> SPRITEOAM_SHIFT_UNK6_1) & SPRITEOAM_MAX_UNK6_1)

#define SpriteSetUnk6_1(spritePtr, _unk6_1) \
{ \
u32 _unk6_1Val = _unk6_1; \
Expand Down
12 changes: 4 additions & 8 deletions src/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,10 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 *
}
else {
// Animations add to existing tileNum
s32 tileNum = sprite->attrib3;
tileNum &= SPRITEOAM_MAX_TILENUM;
tileNum >>= SPRITEOAM_SHIFT_TILENUM;

SpriteSetTileNum(sprite, tileNum + a1->vramTileOrMaybeAnimTimer);
SpriteAddTileNum(sprite, a1->vramTileOrMaybeAnimTimer);
}

pos = ((sprite->attrib2 >> SPRITEOAM_SHIFT_X) & SPRITEOAM_MAX_X) ;
pos = SpriteGetX(sprite);
pos += a1->pos.x - 0x100;

if (pos < -64)
Expand All @@ -235,7 +231,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 *

SpriteSetX(sprite, pos);

pos = ((sprite->unk6 >> SPRITEOAM_SHIFT_WORKING_Y) & SPRITEOAM_MAX_WORKING_Y);
pos = SpriteGetY(sprite);
pos += a1->pos.y - 0x200;
if (pos < -64)
return;
Expand All @@ -245,7 +241,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 *
SpriteSetOamY(sprite, pos);

// Set paletteNum
if (!((sprite->unk6 >> SPRITEOAM_SHIFT_UNK6_1) & SPRITEOAM_MAX_UNK6_1)) {
if (!SpriteGetUnk6_1(sprite)) {
SpriteSetPalNum(sprite, a1->paletteNum);
}

Expand Down

0 comments on commit 6441fae

Please sign in to comment.