[SDL] Framerate independence?

Kuon - Nicolas Goy - 時期精霊 (Goyman.com SA) - 675 kuon at goyman.com
Wed Mar 28 00:47:36 PDT 2007


On Mar 27, 2007, at 5:51 PM, Scott Harper wrote:


>
> If you have a better way of dealing with these inconsistencies,
> PLEASE let me know!  I would love very much to not have to get into
> it that far with my next game! ^_^

As I said before in a mail, you could implement a multi threaded  
engine. It's the way modern CPU are going.

In my game, to give you a simplistic schema, I have the rendering  
thread, which goes freely inside a rendering loop, and I have the  
animation thread. The animation thread runs at a certain rate. Let's  
say, 100 times per second (whith proper time management... It gives  
you 10 ms max per computation, which is enough for a lot of math on  
modern machines), this thread update some data, let's say,  
caracterPosition.

Then, the render thread simply read the current position and render  
it. You can implement this in two ways:
- The rendering thread lock the data, that mean the animation thread  
has to be prepared for this and adjust timers accordingly.
- The rendering thread don't lock the data, and simply read what's  
here. In this case, the code is simpler, but you have a risk of  
rendering half one frame, half the other. We use that way, because we  
noticed no visual problem as render is faster than animation.

Best regards

--
Kuon

"Your computer requests another OS, deny or allow?"
"You should stop playing with that, or it will eventually works."

Company website:
http://www.goyman.com/

Personal blog:
http://arkhi.goyman.com/blojsom/blog/default/





More information about the SDL mailing list