[SDL] animations etc

David Olofson david.olofson at reologica.se
Tue Sep 17 02:28:00 PDT 2002


On Tuesday 17 September 2002 10:17, screwtape at froup.com wrote:
[...]
> hint: if your list-of-happenings is a C array, the library function
> qsort is likely to be helpful.

I'd suggest using something more lightweight, or rather, something that's 
optimized for the job. Of course, we probably aren't talking about 
thousands of objects here, but inserting + qsort()ing all the time might 
still turn out to be expensive, especially if it turns out that you have 
to sort more than once per video (or logic) frame.


> If you're using C++, I think the STL
> has a sorted queue class.

That's probably more suitable.


If you don't have large numbers of events queued up at any time, you can 
just use a linked list ("queue"), which is scanned for the right position 
when inserting each new event. "Sort while inserting" rather than "mix, 
then sort".

The next stage is to optimize the seach pattern when adding events to the 
queue. Read up on sorting in general, and priority queues in particular, 
unless you feel like doing some serious wheel reinvention here! :-)


> [1] Traditionally this things are called 'events', but SDL already has
> things called 'events' that work in a rather different fashion. To
> avoid confusion, I've called them 'happenings'

How about game_event_t? ;-)


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'




More information about the SDL mailing list