mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2024-06-12 13:29:30 +00:00
More tweaks and fixes
* Adjusted tile calculation when drawing sprites * Fixed incorred draw order in 16x16 sprite * Added more early-out checks to save work
This commit is contained in:
parent
b4025f11fc
commit
e0912c8956
|
@ -195,11 +195,13 @@ _RenderDirtyTile
|
||||||
pea >TileStore ; Need that addressing flexibility here. Callers responsible for restoring bank reg
|
pea >TileStore ; Need that addressing flexibility here. Callers responsible for restoring bank reg
|
||||||
plb
|
plb
|
||||||
plb
|
plb
|
||||||
|
txy
|
||||||
|
|
||||||
lda TileStore+TS_SPRITE_FLAG,y ; This is a bitfield of all the sprites that intersect this tile, only care if non-zero or not
|
lda TileStore+TS_SPRITE_FLAG,y ; This is a bitfield of all the sprites that intersect this tile, only care if non-zero or not
|
||||||
beq :nosprite
|
beq :nosprite
|
||||||
|
|
||||||
jsr BuildActiveSpriteArray ; Build the sprite index list from the bit field
|
jsr BuildActiveSpriteArray ; Build the sprite index list from the bit field
|
||||||
|
sta ActiveSpriteCount
|
||||||
|
|
||||||
lda TileStore+TS_VBUFF_ARRAY_ADDR,y ; Scratch space
|
lda TileStore+TS_VBUFF_ARRAY_ADDR,y ; Scratch space
|
||||||
sta _SPR_X_REG
|
sta _SPR_X_REG
|
||||||
|
@ -209,9 +211,6 @@ _RenderDirtyTile
|
||||||
sta _SPR_X_REG
|
sta _SPR_X_REG
|
||||||
ply
|
ply
|
||||||
|
|
||||||
; ldx TileStore+TS_SPRITE_ADDR,y
|
|
||||||
; stx _SPR_X_REG
|
|
||||||
|
|
||||||
lda TileStore+TS_TILE_ID,y ; build the finalized tile descriptor
|
lda TileStore+TS_TILE_ID,y ; build the finalized tile descriptor
|
||||||
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
and #TILE_VFLIP_BIT+TILE_HFLIP_BIT ; get the lookup value
|
||||||
xba
|
xba
|
||||||
|
|
68
src/Sprite.s
68
src/Sprite.s
|
@ -95,7 +95,7 @@ _AddSprite
|
||||||
|
|
||||||
:open
|
:open
|
||||||
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
||||||
jsr _GetTileAddr ; This applies the TILE_ID_MASK
|
jsr _GetBaseTileAddr ; This applies the TILE_ID_MASK
|
||||||
sta _Sprites+TILE_DATA_OFFSET,x
|
sta _Sprites+TILE_DATA_OFFSET,x
|
||||||
|
|
||||||
lda #SPRITE_STATUS_OCCUPIED+SPRITE_STATUS_ADDED
|
lda #SPRITE_STATUS_OCCUPIED+SPRITE_STATUS_ADDED
|
||||||
|
@ -717,11 +717,15 @@ _UpdateSpriteX
|
||||||
:ok
|
:ok
|
||||||
_UpdateSpriteXnc
|
_UpdateSpriteXnc
|
||||||
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
sta _Sprites+SPRITE_ID,x ; Keep a copy of the full descriptor
|
||||||
jsr _GetTileAddr ; This applies the TILE_ID_MASK
|
jsr _GetBaseTileAddr ; This applies the TILE_ID_MASK
|
||||||
|
cmp _Sprites+TILE_DATA_OFFSET,x
|
||||||
|
beq :no_tile_change
|
||||||
sta _Sprites+TILE_DATA_OFFSET,x
|
sta _Sprites+TILE_DATA_OFFSET,x
|
||||||
|
|
||||||
jsr _PrecalcAllSpriteInfo ; Cache stuff
|
jsr _PrecalcAllSpriteInfo ; Cache stuff
|
||||||
|
jsr _DrawSpriteSheet ; Render the sprite into internal space if the tile id has changed
|
||||||
|
|
||||||
|
:no_tile_change
|
||||||
lda _Sprites+SPRITE_STATUS,x
|
lda _Sprites+SPRITE_STATUS,x
|
||||||
ora #SPRITE_STATUS_UPDATED
|
ora #SPRITE_STATUS_UPDATED
|
||||||
sta _Sprites+SPRITE_STATUS,x
|
sta _Sprites+SPRITE_STATUS,x
|
||||||
|
@ -754,16 +758,19 @@ _MoveSpriteX
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
_MoveSpriteXnc
|
_MoveSpriteXnc
|
||||||
|
cmp _Sprites+SPRITE_X,x
|
||||||
|
bne :changed1
|
||||||
sta _Sprites+SPRITE_X,x ; Update the X coordinate
|
sta _Sprites+SPRITE_X,x ; Update the X coordinate
|
||||||
tya
|
tya
|
||||||
sta _Sprites+SPRITE_Y,x ; Update the Y coordinate
|
cmp _Sprites+SPRITE_Y,x
|
||||||
|
bne :changed2
|
||||||
|
rts
|
||||||
|
|
||||||
; pla
|
:changed1
|
||||||
; jsr _GetSpriteVBuffAddrTmp ; A = x-coord, Y = y-coord
|
sta _Sprites+SPRITE_X,x ; Update the X coordinate
|
||||||
; ldy _Sprites+VBUFF_ADDR,x ; Save the previous draw location for erasing
|
tya
|
||||||
; sta _Sprites+VBUFF_ADDR,x ; Overwrite with the new location
|
:changed2
|
||||||
; tya
|
sta _Sprites+SPRITE_Y,x ; Update the Y coordinate
|
||||||
; sta _Sprites+OLD_VBUFF_ADDR,x
|
|
||||||
|
|
||||||
jsr _PrecalcAllSpriteInfo ; Can be specialized to only update (x,y) values
|
jsr _PrecalcAllSpriteInfo ; Can be specialized to only update (x,y) values
|
||||||
|
|
||||||
|
@ -781,7 +788,7 @@ _MoveSpriteXnc
|
||||||
; NUM_BUFF_LINES equ 24
|
; NUM_BUFF_LINES equ 24
|
||||||
|
|
||||||
MAX_SPRITES equ 16
|
MAX_SPRITES equ 16
|
||||||
SPRITE_REC_SIZE equ 54
|
SPRITE_REC_SIZE equ 52
|
||||||
|
|
||||||
; Mark each sprite as ADDED, UPDATED, MOVED, REMOVED depending on the actions applied to it
|
; Mark each sprite as ADDED, UPDATED, MOVED, REMOVED depending on the actions applied to it
|
||||||
; on this frame. Quick note, the same Sprite ID cannot be removed and added in the same frame.
|
; on this frame. Quick note, the same Sprite ID cannot be removed and added in the same frame.
|
||||||
|
@ -801,27 +808,26 @@ VBUFF_ADDR equ {MAX_SPRITES*4} ; Fixed address in sprite/mask banks
|
||||||
SPRITE_ID equ {MAX_SPRITES*6}
|
SPRITE_ID equ {MAX_SPRITES*6}
|
||||||
SPRITE_X equ {MAX_SPRITES*8}
|
SPRITE_X equ {MAX_SPRITES*8}
|
||||||
SPRITE_Y equ {MAX_SPRITES*10}
|
SPRITE_Y equ {MAX_SPRITES*10}
|
||||||
; OLD_VBUFF_ADDR equ {MAX_SPRITES*12}
|
TILE_STORE_ADDR_1 equ {MAX_SPRITES*12}
|
||||||
TILE_STORE_ADDR_1 equ {MAX_SPRITES*14}
|
TILE_STORE_ADDR_2 equ {MAX_SPRITES*14}
|
||||||
TILE_STORE_ADDR_2 equ {MAX_SPRITES*16}
|
TILE_STORE_ADDR_3 equ {MAX_SPRITES*16}
|
||||||
TILE_STORE_ADDR_3 equ {MAX_SPRITES*18}
|
TILE_STORE_ADDR_4 equ {MAX_SPRITES*18}
|
||||||
TILE_STORE_ADDR_4 equ {MAX_SPRITES*20}
|
TILE_STORE_ADDR_5 equ {MAX_SPRITES*20}
|
||||||
TILE_STORE_ADDR_5 equ {MAX_SPRITES*22}
|
TILE_STORE_ADDR_6 equ {MAX_SPRITES*22}
|
||||||
TILE_STORE_ADDR_6 equ {MAX_SPRITES*24}
|
TILE_STORE_ADDR_7 equ {MAX_SPRITES*24}
|
||||||
TILE_STORE_ADDR_7 equ {MAX_SPRITES*26}
|
TILE_STORE_ADDR_8 equ {MAX_SPRITES*26}
|
||||||
TILE_STORE_ADDR_8 equ {MAX_SPRITES*28}
|
TILE_STORE_ADDR_9 equ {MAX_SPRITES*28}
|
||||||
TILE_STORE_ADDR_9 equ {MAX_SPRITES*30}
|
TILE_STORE_ADDR_10 equ {MAX_SPRITES*30}
|
||||||
TILE_STORE_ADDR_10 equ {MAX_SPRITES*32}
|
SPRITE_DISP equ {MAX_SPRITES*32} ; pre-calculated index for jmp (abs,x) based on sprite size
|
||||||
SPRITE_DISP equ {MAX_SPRITES*34} ; pre-calculated index for jmp (abs,x) based on sprite size
|
SPRITE_CLIP_LEFT equ {MAX_SPRITES*34}
|
||||||
SPRITE_CLIP_LEFT equ {MAX_SPRITES*36}
|
SPRITE_CLIP_RIGHT equ {MAX_SPRITES*36}
|
||||||
SPRITE_CLIP_RIGHT equ {MAX_SPRITES*38}
|
SPRITE_CLIP_TOP equ {MAX_SPRITES*38}
|
||||||
SPRITE_CLIP_TOP equ {MAX_SPRITES*40}
|
SPRITE_CLIP_BOTTOM equ {MAX_SPRITES*40}
|
||||||
SPRITE_CLIP_BOTTOM equ {MAX_SPRITES*42}
|
IS_OFF_SCREEN equ {MAX_SPRITES*42}
|
||||||
IS_OFF_SCREEN equ {MAX_SPRITES*44}
|
SPRITE_WIDTH equ {MAX_SPRITES*44}
|
||||||
SPRITE_WIDTH equ {MAX_SPRITES*46}
|
SPRITE_HEIGHT equ {MAX_SPRITES*46}
|
||||||
SPRITE_HEIGHT equ {MAX_SPRITES*48}
|
SPRITE_CLIP_WIDTH equ {MAX_SPRITES*48}
|
||||||
SPRITE_CLIP_WIDTH equ {MAX_SPRITES*50}
|
SPRITE_CLIP_HEIGHT equ {MAX_SPRITES*50}
|
||||||
SPRITE_CLIP_HEIGHT equ {MAX_SPRITES*52}
|
|
||||||
|
|
||||||
; Maintain the index of the next open sprite slot. This allows us to have amortized
|
; Maintain the index of the next open sprite slot. This allows us to have amortized
|
||||||
; constant sprite add performance. A negative value means no slots are available.
|
; constant sprite add performance. A negative value means no slots are available.
|
||||||
|
|
|
@ -29,7 +29,7 @@ DISP_MASK equ $0018 ; Isolate the size bits
|
||||||
jsr _DrawSprite
|
jsr _DrawSprite
|
||||||
|
|
||||||
lda tmp3
|
lda tmp3
|
||||||
ora #DISP_VFLIP
|
ora #DISP_HFLIP
|
||||||
tax
|
tax
|
||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
|
@ -38,7 +38,7 @@ DISP_MASK equ $0018 ; Isolate the size bits
|
||||||
jsr _DrawSprite
|
jsr _DrawSprite
|
||||||
|
|
||||||
lda tmp3
|
lda tmp3
|
||||||
ora #DISP_HFLIP
|
ora #DISP_VFLIP
|
||||||
tax
|
tax
|
||||||
ldy tmp2
|
ldy tmp2
|
||||||
lda tmp1
|
lda tmp1
|
||||||
|
@ -196,6 +196,7 @@ draw_16x16h
|
||||||
clc
|
clc
|
||||||
tax
|
tax
|
||||||
tya
|
tya
|
||||||
|
adc #64
|
||||||
pha
|
pha
|
||||||
adc #128
|
adc #128
|
||||||
tay
|
tay
|
||||||
|
|
|
@ -75,6 +75,17 @@ _GetTileAddr
|
||||||
asl ; x128
|
asl ; x128
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
; Ignore the horizontal flip bit
|
||||||
|
_GetBaseTileAddr
|
||||||
|
asl ; Multiply by 2
|
||||||
|
asl ; x4
|
||||||
|
asl ; x8
|
||||||
|
asl ; x16
|
||||||
|
asl ; x32
|
||||||
|
asl ; x64
|
||||||
|
asl ; x128
|
||||||
|
rts
|
||||||
|
|
||||||
; On entry
|
; On entry
|
||||||
;
|
;
|
||||||
; B is set to the correct BG1 data bank
|
; B is set to the correct BG1 data bank
|
||||||
|
@ -115,7 +126,7 @@ _RenderTile2
|
||||||
|
|
||||||
txa
|
txa
|
||||||
jsr BuildActiveSpriteArray ; Build the max 4 array of active sprites for this tile
|
jsr BuildActiveSpriteArray ; Build the max 4 array of active sprites for this tile
|
||||||
sta ActiveSpriteCount
|
; sta ActiveSpriteCount
|
||||||
|
|
||||||
lda TileStore+TS_VBUFF_ARRAY_ADDR,y ; Scratch space
|
lda TileStore+TS_VBUFF_ARRAY_ADDR,y ; Scratch space
|
||||||
sta _SPR_X_REG
|
sta _SPR_X_REG
|
||||||
|
|
Loading…
Reference in New Issue
Block a user