Sprite sorting?

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
cdoty
Very interested
Posts: 117
Joined: Wed Nov 29, 2006 2:54 pm
Location: Houston, TX
Contact:

Sprite sorting?

Post by cdoty » Mon Jul 14, 2008 4:34 am

I'm writing a dynamic sprite list routine, and need to sort the list.

I'm curious to find out what value everyone would sort on?

My thought would be the bottom on the sprite. This assumes that the sprite data is justified to the bottom of the sprite, and sprites always appear on the ground (no sprite is floating). There would be a problem with layering of sprites at the same location.

A 'z' position might be better. The only issue I can see is finding a way to ensure a sprite can draw over the top of another sprite, but not draw over a higher priority sprite. For example, the explosion of a sprite should show over the sprite, but not draw over any other sprite at the same level, that is a higher priority. I guess I could have a sprite attachment field, and not sort the attachments. This would also have the advantage of allowing multiple attachments to a sprite, and the order of the attachments could be controlled, similar to the sprite link field. And, the position of the attachment would be automatically controlled.

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Mon Jul 14, 2008 6:54 am

If I understand you correctly, you what to simulate 'planes' of sprites. I mean, lower priority sprites have lower priority explosions/etc that don't overlay on the upper pseudo sprite plane, correct?

If that's the case, then I'd just section off the sprite table into 2 or more pseudo planes. Unless it's something pretty complicated, that would be easier in my opinion than writing a dynamic sprite display list.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Mon Jul 14, 2008 12:06 pm

For priority stuff, I arrange the code in my stuff so that high priority sprites (like explosions that have to cover everything) are entered into the list first, then not so high ones and so on... works nicely.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

cdoty
Very interested
Posts: 117
Joined: Wed Nov 29, 2006 2:54 pm
Location: Houston, TX
Contact:

Post by cdoty » Tue Jul 15, 2008 5:38 am

What if the objects change 'z' positions on the screen? Then you have to insert and remove them into the list.

I've started the routine; it isn't looking too complicated, at this point. I've coded everything, except for the attachment part. I still have to test it.

I plan to put up an example of the routine, with source code.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Tue Jul 15, 2008 4:05 pm

For changing Z pos, I don't know really... I'm more of a half dynamic stuff user... I have plenty of hardcoding done in my stuff (as part of optimizations, I need as much performance as possible... to do so, keeping things simple, at least for me).
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Jul 15, 2008 7:12 pm

Make a fake Z value for each sprite with certain levels predefined for things like explosions. Binary sort the list to order everything before generating the sprite list. If you keep the Z value range small, the binary sort will be fast. A binary sort is b*N, where b is the number of bits in the field to sort by, and N is the number of elements in the list.

Post Reply