RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
korndog
I wanna be a ballerina!


Joined: 03 Jun 2003
Posts: 24
Location: Texas

PostPosted: Tue Jul 15, 2003 6:47 am    Post subject: Sprite drawing by y-coordinate [quote]

I am curious as to how others are drawing their sprites in back-to-front order. Right now my engine is mergesorting a linked-list of NPCs by their y-coordinate each frame. I usually have 20 sprite-based NPCs a map (the rest being tiles) so it works out to six list passes a frame.

I've worked on five rpg engines and this, more or less, is the way I've always done sprite drawing. What do you do?
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Tue Jul 15, 2003 9:15 am    Post subject: [quote]

In our engine the use of particle effects or other exessive use of objects such as lamp posts and decoration makes for possibly hundreds of sprites. Each frame, the engine goes through all of them checking their visibity. Usually only 1-20 objects are visible and they are sorted on y+z order using the STL sort implementation.
Back to top  
Sirocco(lazy)
Guest





PostPosted: Tue Jul 15, 2003 4:19 pm    Post subject: Yep. [quote]

I normally sort by Y/Z coords, where Y (depth) has priority and Z (height) is secondary... I know that's backwards from standard mathematical references, but I hardly care ;)

Check for visibility, then pass list to the drawing routine for masking, etc.

Fun.
Back to top  
Mandrake
elementry school minded asshole


Joined: 28 May 2002
Posts: 1341
Location: GNARR!

PostPosted: Wed Jul 16, 2003 2:42 pm    Post subject: [quote]

I usually create two arrays, one for sprites, and another for drawing order. This may seem like an overkill, but the second array is really a series of sprite refrences, and can have multiple refrences for the same sprite. This is good for a town, or a platform/shmup style game where you have a lot of repeating sprites. It works sort of like the old infinte bobs demo in the old demo scene. The first array is just basically graphics, with no extra information. The second array contains teh x, y, z values and the sprite's refrenece to the actual graphic.

You would then check for visibility (in the second array), sort them into a ressonable drawing order, then draw them to the screen. The nice thing is, the first array (with the actual graphics) is not touched until the drawing method is invoked. I usually use a quicksort based algoyrhtm I've concocted for sorting the values.
_________________
"Well, last time I flicked on a lighter, I'm pretty sure I didn't create a black hole."-
Xmark

http://pauljessup.com
Back to top  
korndog
I wanna be a ballerina!


Joined: 03 Jun 2003
Posts: 24
Location: Texas

PostPosted: Wed Jul 16, 2003 4:27 pm    Post subject: [quote]

I hadn't though of checking visibility before sorting... most of my test maps have been tiny abstract worlds, heh. The code I've done doesn't have any particle fx or anything.
Mandrake, I do something like that too. The NPCs in the list point to an animation array, and those point to pictures in a picture array.

Thanks for your replies.
Back to top  
golrien
Milk Maid


Joined: 09 Jun 2002
Posts: 40
Location: Shropshire, England

PostPosted: Wed Jul 16, 2003 9:55 pm    Post subject: [quote]

See, I use a bubblesort for y-sorting, because in this case it's mostly just looping around.. because the ssprites don't do an insane amount of moving, it's quite possibly the fastest. Then again, I guess a quicksort would loop through just as fast on already-sorted sprites, I just understand bubble sort better :)
Back to top  
LeoDraco
Demon Hunter


Joined: 24 Jun 2003
Posts: 584
Location: Riverside, South Cali

PostPosted: Thu Jul 17, 2003 2:43 am    Post subject: [quote]

golrien wrote:
See, I use a bubblesort for y-sorting, because in this case it's mostly just looping around.. because the ssprites don't do an insane amount of moving, it's quite possibly the fastest. Then again, I guess a quicksort would loop through just as fast on already-sorted sprites, I just understand bubble sort better :)


Actually, quicksort can be slower than bubble sort on already sorted data. (A smart bubble can actually have linear complexity on sorted data, whereas a quicksort can have quadratic complexity (rather than O(nlog n)) in the worst case. While this might never occur, it is a possibility.) Merge Sort itself is generally guaranteed a worst case complexity of O(nlog n), so it's generally better to use, especially if you're rolling your own implementations.
_________________
"...LeoDraco is a pompus git..." -- Mandrake
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
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 vote in polls in this forum