Jump to content
  • Advertisement
Sign in to follow this  
Witchcraven

What method to use for my sprite engine

This topic is 5464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!