What method to use for my sprite engine

Started by
1 comment, last by Witchcraven 19 years, 6 months ago
I have a simple game in the works, but I still want it to be very efficent. So far I have tried 2 rendering techniques, and I am not sure which one to stick with. One is stack based. I have a stack of references to sprites that need to be drawn. The stack is rebuilt evertime a sprite is created or deleted. There will probably be between 20 and 500 sprites any any given time, so it is not a huge performance hit. Plus the stack is a simple array, there is no allocation/delocation. The other option is a linked list of sprites to draw. It never has to be rebuilt entirly. A reference is added/deleted as needed. The downside to this is it takes slightly more memory and requires frequent allocation/delocation. Which should I use? I am considering the stack one, but the linked list one is currently in use (although I have not written sprite deletion for it yet). The stack is simpler code wise too. I am tempted to use it. Should I? Or is there some other alternative that is even better?
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved
Advertisement
An array caches MUCH BETTER than a linked list, so if performance is important, and creation/deletion is infrequent, then that's the way to go.

Does draw order matter? If not, you could just take the last item and put it in the slot for an element that's going away, and shrink the "size" by one, without re-building the list. Or you can memmove() the elements over one slot when removing (or inserting) without re-building the entire list; because of caching, this will be surprisingly efficient.

Linked lists are good for things you don't traverse every frame.
enum Bool { True, False, FileNotFound };
Good idea about the memmove. It will in most cases be more efficent than rebuilding the entire stack. Order does matter though, but I build the stack in order. It should work out. But I will have several stacks for different layers anyway. That way when I rebuild the particle stack (which will happen often) I dont have to rebuild the others. Thanks
--------------------------I present for tribute this haiku:Inane Ravings OfThe Haunting JubilationA Mad Engineer©Copyright 2005 ExtrariusAll Rights Reserved

This topic is closed to new replies.

Advertisement