Assember: 16bit bubble sort

Страница 5/5
1 | 2 | 3 | 4 |

By hit9918

Prophet (2911)

Аватар пользователя hit9918

24-10-2011, 15:26


@hit9918
Thanks, look at the new code and how I use the order[] array
Is there any speed trick I can use?

Yes! pointerarray Wink
The value by which you sort (transformY ?) should be part of struct sprite.
Then, instead of the order array, you got an array of pointers to struct sprite.
Then the sort will be swapping in the pointerarray instead in the indexarray
(but really only swap in the pointerarray).
And then all those order[] acesses are gone in the entire app.

//add transformY to struct sprite.

struct sprite* sprarr[maxsprites];

//initialisation of pointerarray
for (i = 0; i < maxsprites; i++)
	sprarr[i] = &(sprite[i]);	//pointer[i] = address of sprite[i]

Then sort it by acessing
	sprarr[i]->transformY;	//-> instead . when the thing is a pointer

Because sprarr will be so much your view to the sprites, this array would deserve to be called just "sprite", and what was called "sprite" before, could be called "spritememory".
Then, where "sprite[order[i]].foo" was written before, it would read "sprite[i]->foo".

Then, you can kill the last indexing and replace sprite[i] by *pointer++.

	struct sprite **p;
	struct sprite *s;
	p = sprite; //if you named the pointerarray "sprite"
	for (i = 0 ; i < maxsprites; i++) {
		s = *p++;
		use s->x , s->y etc
	}

And this s = *p++ in my codes is POP HL Smile

Страница 5/5
1 | 2 | 3 | 4 |