It is currently Fri Dec 15, 2017 4:17 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Object update order
PostPosted: Mon Aug 15, 2016 8:51 pm 
Offline
User avatar

Joined: Fri Apr 08, 2016 5:58 pm
Posts: 93
Location: California, USA
Kasumi wrote:
You're not limited to 16 objects. You can change at any time by changing object num. And variables are indeed accessed with OBJaddrhigh,x (or whatever piece of RAM they want) where X is their object number.

Edit: I suppose it's true you'd be limited to 16 if you didn't want page crossing, but I don't think it's too big a concern. In the worst case, you can arrange the RAM so that variables that will suffer the page cross penalty are ones that aren't accessed frequently.

Okay that took a really long time to wrap my head around, but I think I'm seeing that. You're talking about arranging all the variables sequentially, with all 'OBJxhigh' listed, then all 'OBJxlow', etc. I don't understand where OBJaddrlow comes in to play though.

Also, in general I see a lot of interplay between the words 'sprite' and 'object'. I've been using the term 'spriteRAM' (in my mind at least) to describe the OAMDMA page. That's obviously not what you're meaning with 'spriteramstart' though, and I'm just gonna take that at face value....

tepples wrote:
$4000 is the APU. Did you mean $0400?


Er... Yeah... That's embarrassing. That's me taking numbers off the top of my head on my phone here.


Top
 Profile  
 
 Post subject: Re: Object update order
PostPosted: Mon Aug 15, 2016 9:30 pm 
Offline
User avatar

Joined: Wed Apr 02, 2008 2:09 pm
Posts: 1046
Sprite, object, actor can all refer to the same things. Really, I probably should call it objectramstart since I call my stuff objects these days. But I didn't when I started. :D

I call the hardware sprite RAM mirror OAM. But none of that particularly matters so long as whatever you're calling whatever makes sense to you.

Basically I go through the list of objects like this:

Code:
ldx #objectnum-1
spritestart:   
   
   

spriteend:
   dex
   bpl spritestart

So code between spriteend and spritestart can load OBJRAM,x and get the byte associated with that object. And you've already correctly seen that the memory is basically
Code:
OBJaddrhigh =  spriteramstart+0
OBJaddrhigh0 = spriteramstart+0
OBJaddrhigh1 = spriteramstart+1
OBJaddrhigh2 = spriteramstart+2
;etc

which is how it all works.
Code:
lda OBJaddrhigh0
;is equivalent to
ldx #0
lda OBJaddrhigh,x

lda OBJaddrhigh1
;is equivalent to
ldx #1
lda OBJaddrhigh,x

The loop above initializes X to the right slot before the object itself is run. I typically don't change it throughout. If X is changed, remember to change it back or really bad things can happen when the object returns to the loop.

As far as OBJaddrlow/OBJaddrhigh... it's just something I do, but the actual variables/number of variables you use for this method (which I think is basically tokumaru's method) is agnostic to how you access/lay them out.

Anyway it's an address for an indirect jmp, more or less. in between spritestart and spriteend, I have something like:

Code:
lda OBJaddrlow,x
sta tempptrlow
lda OBJaddrhigh,x
sta tempptrhigh

jmp (tempptrlow)


To create an object (after finding a free slot) which tokumaru describes in this post, I run code like this:

Code:
lda #<playerobject.main
sta OBJaddrlow,x
lda #>playerobject.main
sta OBJaddrhigh,x
;Replace playerobject.main with the label for the code of whatever object you want to make


The object itself at its simplest looks like this
Code:
playerobject.main:;This is reached because of the indirect jmp
;Code here can access the object slot's RAM immediately with
;something like lda OBJxvel,x
;But this object only returns so the look can continue
jmp spriteend;This returns to the loop so the next object/the rest of the program can run

There are other ways to do it, but that is what I personally use OBJaddrlow and OBJaddrhigh for.

_________________
https://kasumi.itch.io/indivisible


Top
 Profile  
 
 Post subject: Re: Object update order
PostPosted: Tue Aug 16, 2016 9:21 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
Here's how I do it:

Code:
Object::SLOT_COUNT = $18 ;number of object slots

Code:
Object::InstancesType: .res Object::SLOT_COUNT ;type of the object occupying the slot
Object::InstancesNext: .res Object::SLOT_COUNT ;link to the next slot in the same list
Object::InstancesLogicState: .res Object::SLOT_COUNT ;index of the logic routine the object is currently using
Object::InstancesXFraction: .res Object::SLOT_COUNT ;fractional part of the object's horizontal coordinate
Object::InstancesXLow: .res Object::SLOT_COUNT ;low byte of the object's horizontal coordinate
Object::InstancesXHigh: .res Object::SLOT_COUNT ;high byte of the object's horizontal coordinate
Object::InstancesYFraction: .res Object::SLOT_COUNT ;fractional part of the object's vertical coordinate
Object::InstancesYLow: .res Object::SLOT_COUNT ;low byte of the object's vertical coordinate
Object::InstancesYHigh: .res Object::SLOT_COUNT ;high byte of the object's vertical coordinate
Object::InstancesSpeedXFraction: .res Object::SLOT_COUNT ;fractional part of the object's horizontal speed
Object::InstancesSpeedX: .res Object::SLOT_COUNT ;integer part of the object's horizontal speed
Object::InstancesSpeedYFraction: .res Object::SLOT_COUNT ;fractional part of the object's vertical speed
Object::InstancesSpeedY: .res Object::SLOT_COUNT ;integer part of the object's vertical speed
Object::InstancesAngle: .res Object::SLOT_COUNT ;angle of the object
Object::InstancesSpeedFraction: .res Object::SLOT_COUNT ;fractional part of the object's angular speed
Object::InstancesSpeed: .res Object::SLOT_COUNT ;integer part of the object's angular speed
Object::InstancesBoundingBox: .res Object::SLOT_COUNT ;index of the object's bounding box
Object::InstancesCollisionResponse: .res Object::SLOT_COUNT ;indicates how the object presents itself to the world
Object::InstancesPatternsOffset: .res Object::SLOT_COUNT ;base index for the object's patterns
Object::InstancesAttributes: .res Object::SLOT_COUNT ;various flags that control sprite attributes
Object::InstancesAnimationScriptLow: .res Object::SLOT_COUNT ;low byte of the pointer to the current animation script
Object::InstancesAnimationScriptHigh: .res Object::SLOT_COUNT ;high byte of the pointer to the current animation script
Object::InstancesAnimationCounter: .res Object::SLOT_COUNT ;number of frames to wait before advancing to the next animation frame
Object::InstancesExtendedState: .res Object::SLOT_COUNT ;index of a byte in the table of extended states
Object::InstancesIndexLow: .res Object::SLOT_COUNT ;low byte of the object's index in the list it was loaded from
Object::InstancesIndexHigh: .res Object::SLOT_COUNT ;high byte of the object's index in the list it was loaded from
Object::InstancesSpawnBlockX: .res Object::SLOT_COUNT ;horizontal coordinate of the 128x128-pixel block the object originates from
Object::InstancesSpawnBlockY: .res Object::SLOT_COUNT ;vertical coordinate of the 128x128-pixel block the object originates from
Object::InstancesSlopeThreshold: .res Object::SLOT_COUNT ;position of the highest point of the ledge on which the object is standing
Object::InstancesLink: .res Object::SLOT_COUNT ;link to an active object related to this one
Object::InstancesCustom0: .res Object::SLOT_COUNT ;memory for active objects
Object::InstancesCustom1: .res Object::SLOT_COUNT ;memory for active objects

Of course this adds up to a lot more than 256 bytes (24 slots * 32 bytes = 768 bytes), so I actually split these definitions across different pages to avoid page crossing when accessing these properties. Not that the occasional page crossing would've been a big deal, but since I could avoid it for free, I decided to do it.

Guilty wrote:
How does a given object check its own variables if it could be in any slot?

When processing the objects, a loop manipulates X (in my case, the slot order is defined by linked lists) before calling each object's update routine, so when the object is called, X is already pointing to the slot of where its instance is loaded. This value is also stored in a variable, so object routines can temporarily use X for other purposes if they need to, and later they can reload the slot index from the variable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 7 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


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