It is currently Sun Jan 20, 2019 11:54 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Nov 26, 2018 1:34 pm 
Offline

Joined: Tue Aug 28, 2018 8:54 am
Posts: 117
Location: Edmonton, Canada
I'm working on the collisions on my map right now. I have two general options: 1) use tile numbers directly or 2) have separate array with bounding boxes + additional behavior parameters/callbacks

Because maps are dynamic and I store level ID, I cannot just use absolute,x addressing and have to use indirect. So far I came up with something like the code below. Does it make sense to use multiple pointers for each property (I will probably allocate more generic pointers to save ZP space later) or there is smarter trick to deal with this?

Code:
; I did not test this code yet, it may contain some small mistakes. Treat is as pseudo code
.segment "ZEROPAGE"
   collisionX1: .res 2
   collisionY1: .res 2
   collisionX2: .res 2
   collisionY2: .res 2
...
Load:
   ; here I load labels statically, but those addresses
   ; will be loaded with from another array like
   ; lda level_num
   ; asl a
   ; tax
   ; lda level_collisions, x
   ; etc...
   lda Level_1_Collisions_x1
   sta collisionX1
   lda Level_1_Collisions_x1+1
   sta collisionX1+1
   ...
   lda Level_1_Collisions_y2
   sta collisionY2
   lda Level_1_Collisions_y2+1
   sta collisionY2+1
   
   ldy #0
   ; get first bounding box x1
   lda (collisionX1),y
   ; get first bounding box y1
   lda (collisionY1),y
      
.segment "RODATA"
   ; Bounding box parallel array
   Level_1_Collisions_x1:
        .byte 32, $FF ; endmarker
    Level_1_Collisions_y1:
        .byte 40
    Level_1_Collisions_x2:
        .byte 40
    Level_1_Collisions_y2:
        .byte 64


Edit: typo in code


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 1:54 pm 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 464
Code:
   lda Level_1_Collisions_x1
   sta collisionX1
   lda Level_1_Collisions_x1+1
   sta collisionX1+1

Doesn't make any sense. I think you meant to do this?

Code:
   lda #.lobyte(Level_1_Collisions_x1)
   sta collisionX1
   lda #.hibyte(Level_1_Collisions_x1)
   sta collisionX1+1

But yes, it is reasonable to have several pointers in zeropage to do this.


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 1:59 pm 
Offline

Joined: Tue Aug 28, 2018 8:54 am
Posts: 117
Location: Edmonton, Canada
pubby wrote:
Code:
   lda Level_1_Collisions_x1
   sta collisionX1
   lda Level_1_Collisions_x1+1
   sta collisionX1+1

Doesn't make any sense. I think you meant to do this?


=( You are correct. I was just typing this in the notepad to give an idea. I shall compile my examples next time...

pubby wrote:
But yes, it is reasonable to have several pointers in zeropage to do this.


Thank you for the feedback.


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 2:48 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11094
Location: Rio de Janeiro - Brazil
Yes, I've used multiple ZP pointers to solve problems like this before. It may seem a little wasteful at first, but as long as you have the RAM to spare, it's fine.


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 2:55 pm 
Offline

Joined: Tue Aug 28, 2018 8:54 am
Posts: 117
Location: Edmonton, Canada
tokumaru wrote:
Yes, I've used multiple ZP pointers to solve problems like this before. It may seem a little wasteful at first, but as long as you have the RAM to spare, it's fine.


Yes, wasting ram, especially ZP was my original concert. I can still reuse those pointers tough, just need to make sure to save them or just not overlap in other code.
My second concern is if I want to add more properties there. Like bounding box type etc..., I will need more and more pointers + I will be wasting space where hitbox type is default and no properties are really needed. Although ROM is not that precious. And I should get away with this at least for demo, and then solve it when I get to the point when it doesn't work.

Edit: spelling


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 5:39 pm 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 464
Interleaved arrays are an option too. That would reduce the number of pointers.


Top
 Profile  
 
PostPosted: Mon Nov 26, 2018 6:16 pm 
Offline

Joined: Tue Aug 28, 2018 8:54 am
Posts: 117
Location: Edmonton, Canada
pubby wrote:
Interleaved arrays are an option too. That would reduce the number of pointers.


Do you mean instead of x1, x2, x3, y1, y2, y3 use x1, y1, x2, y2, x3, y3?

It is more uglier to iterate then. If I have 5 properties for each object I will need to do something like this:

Code:
    sty tmp1 ; save index

    lda (ptr),y ; to access first property
    iny
    lda (ptr),y; to access the second property
    dex ; decrease to access first again
    lda (ptr),y ; to access first property

    lda tmp1 ; step to next object
    clc
    adc #5
    tay


Would be nice to be able to add offset to the to the indirect pointer (lda (ptr)+2,y), otherwise I will have to manipulate Y to get properties not in order, which is very error prone.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group