Subject: [stella] Y-Sorting alternative for Thomas :-) From: Manuel Polik <cybergoth@xxxxxxxx> Date: Sun, 24 Mar 2002 17:52:23 +0100 |
Hi there! Here's how I sort the sprites in my intelligent flicker routine. It is adopted from Steve Judds and Pasi Ojalas excellent sorting article in C= Hacking #18. It goes like this: ; Init Sortloop LDA #$80 STA sprtlst+MAXSPRITE ; Set Head node LDX #MAXSPRITE-1 ; Sprites to sort ; Y Sort Sprites SortYPos LDY #MAXSPRITE SortLoop: LDA sprtlst,Y ;Linked list of objects BMI Link STY tempVar1 ; Head index TAY ;Next object LDA vpos,Y ;If farther, then CMP vpos,X ;move down list BCS SortLoop TYA LDY tempVar1 ;Insert into list Link: STA sprtlst,X ;X -> rest of list TXA STA sprtlst,Y ;beginning of list -> X DEX BPL SortYPos Might this be even quicker than bubble-sort? :-) Accessing data is way cool, too, this iterates once through the sorted(!) list: LDX sprtlst+MAXSPRITE Loop Do Something YYYY,X LDA sprtlst,X TAX BPL Loop Greetings, Manuel ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[stella] Tie-Fighters!!!, Manuel Polik | Thread | Re: [stella] Y-Sorting alternative , Thomas Jentzsch |
[stella] Tie-Fighters!!!, Manuel Polik | Date | Re: [stella] Y-Sorting alternative , Thomas Jentzsch |
Month |