Skid dust bug when an object with child sprites was loaded

Discussion in 'Discussion and Q&A Archive' started by SpirituInsanum, Mar 12, 2014.

Thread Status:
Not open for further replies.
  1. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    I decided to give child sprites a try and imported s2's bridge in s1. I also had to import the BuildSprites_MultiDraw routine from s2, as well as DisplaySprite3.

    The bridge itself works and shows fine. So I guess the object and routines were properly converted.

    But now there's a bug with the skid dust. DAGarden tells me it happens in S Factor as well, possibly under similar circumstances, so I guess the reason for the bug is well hidden.

    As soon as an object with child sprites is shown for the first time, the skid dust will stop updating its art.

    This is how it looks before a spin dash:

    /monthly_03_2014/post-1059-0-67180200-1394661821_thumb.png

    And this is how it looks after a spindash:

    /monthly_03_2014/post-1059-0-60931700-1394661832_thumb.png

    The spindash's art loads properly.

    The bug won't happen if I prevent the object with child sprites from being displayed. More precisely, as long as BuildSprites_MultiDraw isn't being ran at least once, the bug doesn't happen. But I can't find anything wrong with the routine.

    Here's the routine if anyone needs to see (if it's of any importance, I'm using s3's mapping format):

    BuildSprites_MultiDraw:
    move.l a4,-(sp) ; save a4
    lea ($FFFFF700).w,a4 ; load camera x position
    movea.w art_tile(a0),a3
    movea.l mappings(a0),a5
    moveq #0,d0

    ; check if object is within X bounds
    move.b mainspr_width(a0),d0 ; load pixel width
    move.w x_pos(a0),d3
    sub.w (a4),d3
    move.w d3,d1
    add.w d0,d1
    bmi.w BuildSprites_MultiDraw_NextObj
    move.w d3,d1
    sub.w d0,d1
    cmpi.w #320,d1
    bge.w BuildSprites_MultiDraw_NextObj
    addi.w #128,d3

    ; check if object is within Y bounds
    btst #4,d4
    beq.s @cont1
    moveq #0,d0
    move.b mainspr_height(a0),d0 ; load pixel height
    move.w y_pos(a0),d2
    sub.w 4(a4),d2
    move.w d2,d1
    add.w d0,d1
    bmi.w BuildSprites_MultiDraw_NextObj
    move.w d2,d1
    sub.w d0,d1
    cmpi.w #224,d1
    bge.w BuildSprites_MultiDraw_NextObj
    addi.w #128,d2
    bra.s @cont2
    @cont1:
    move.w y_pos(a0),d2
    sub.w 4(a4),d2
    addi.w #128,d2
    andi.w #$7FF,d2
    cmpi.w #-32+128,d2
    blo.s BuildSprites_MultiDraw_NextObj
    cmpi.w #32+128+224,d2
    bhs.s BuildSprites_MultiDraw_NextObj
    @cont2:
    ; create the main sprite if any
    moveq #0,d1
    move.b mainspr_mapframe(a0),d1 ; get current frame
    beq.s @cont3
    add.w d1,d1
    movea.l a5,a1
    adda.w (a1,d1.w),a1
    move.w (a1)+,d1
    subq.w #1,d1
    bmi.s @cont3
    move.w d4,-(sp)
    bsr.w ChkDrawSprite ; draw the sprite
    move.w (sp)+,d4
    @cont3:
    ori.b #$80,render_flags(a0) ; set onscreen flag
    lea sub2_x_pos(a0),a6
    moveq #0,d0
    move.b mainspr_childsprites(a0),d0 ; get child sprite count
    subq.w #1,d0 ; if there are 0, go to next object
    bcs.s BuildSprites_MultiDraw_NextObj
    @loop:
    swap d0
    move.w (a6)+,d3 ; get X pos
    sub.w (a4),d3
    addi.w #128,d3
    move.w (a6)+,d2 ; get Y pos
    sub.w 4(a4),d2
    addi.w #128,d2
    andi.w #$7FF,d2
    addq.w #1,a6
    moveq #0,d1
    move.b (a6)+,d1 ; get mapping frame
    add.w d1,d1
    movea.l a5,a1 ; load mapping address
    adda.w (a1,d1.w),a1
    move.w (a1)+,d1
    subq.w #1,d1
    bmi.s @skip
    move.w d4,-(sp)
    bsr.w ChkDrawSprite
    move.w (sp)+,d4
    @skip:
    swap d0
    dbf d0,@loop ; repeat for number of child sprites
    ; loc_16804:
    BuildSprites_MultiDraw_NextObj:
    movea.l (sp)+,a4 ; reload a4
    bra.w BuildSprites_NextObj
    ; End of function BuildSprites


    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||

    ; sub_1680A:
    ChkDrawSprite:
    cmpi.b #80,d5 ; has the sprite limit been reached?
    blo.s DrawSprite_Cont ; if it hasn't, branch
    rts ; otherwise, return
    ; End of function ChkDrawSprite
    And I can't figure out why.

    Any idea?
     

    Attached Files:

    Last edited by a moderator: Mar 12, 2014
  2. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    Fixed. I had to save a6 at the beginning and restore it at the end (and who wrote that routine? it's movem for sp's dammit).
     
  3. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Glad you fixed it, and I must say, that art is sweet.  You've always put as lot of effort into your work.  Keep it up.
     
Thread Status:
Not open for further replies.