Create function to update only secondary sprites to optimize die roll animation (#11)

This commit is contained in:
xCrystal
2023-09-30 13:30:30 +02:00
parent 49a3f6b8c8
commit 8967898bc9
3 changed files with 34 additions and 4 deletions

View File

@@ -202,7 +202,7 @@ DIE_MAX_NUMBER EQU 6
add DIE_MAX_NUMBER
add $1
ld [wDieRoll], a
farcall _UpdateSprites
farcall _UpdateSecondarySprites
call GetJoypad
ldh a, [hJoyPressed]
bit B_BUTTON_F, a
@@ -221,6 +221,7 @@ DIE_MAX_NUMBER EQU 6
ret
.confirm_roll
call UpdateSprites
ld a, TRUE
ld [wScriptVar], a
ret
@@ -270,8 +271,8 @@ BoardMenu_BreakDieAnimation:
ld a, $8 * SPRITEOAMSTRUCT_LENGTH ; with SPRITE_ANIM_OBJ_BOARD_MENU_APPEAR_DIE_NUMBER
jr nz, .go
ld a, $4 * SPRITEOAMSTRUCT_LENGTH ; w/o SPRITE_ANIM_OBJ_BOARD_MENU_APPEAR_DIE_NUMBER
ldh [hUsedSpriteIndex], a
.go
ldh [hUsedSpriteIndex], a
farcall _UpdateSpritesAfterOffset
ld de, SFX_STRENGTH

View File

@@ -3078,6 +3078,35 @@ InitSprites:
dw wObject11Struct
dw wObject12Struct
_UpdateSecondarySprites:
; this is a shorter _UpdateSprites for when only secondary sprites have changed since the last sprites update,
; but NOT expanded, which would require to displace primary (NPC) sprites in OAM.
; if it is detected that the size of secondary sprites has increased in the end,
; fall back to calling _UpdateSprites to avoid corruption.
ld a, [wVramState]
bit 0, a
ret z
ld a, [hUsedSpriteIndex]
push af
xor a
ldh [hUsedSpriteIndex], a
.go
ldh a, [hOAMUpdate]
push af
ld a, 1
ldh [hOAMUpdate], a
call InitSecondarySprites
pop af
ldh [hOAMUpdate], a
ldh a, [hUsedSpriteIndex]
ld c, a
pop af
cp c
ret nc
jp _UpdateSprites
InitSecondarySprites:
ld a, [wDisplaySecondarySprites]
bit SECONDARYSPRITES_BOARD_MENU_F, a