Comments on "Programming Trivia"

Use the form below to leave your own comment.

Posted by SirNuke at May 29, 2007, in the evening

I was under the impression that SDL_Delay was meant for delaying a thread in a multi-threaded application. Not that it necessarily matters.

I personally use a timer approach (see this [ http://lazyfoo.net/SDL_tutorials/lesson14/index.php] tutorial).

My standard SDL main function looks a little like this C++ Pseudocode:

int main()
{
initialize_everything();
while (gamestate != QUIT)
{
timer.start();
switch (gamestate)
{
call the correct state object's event loop and draw function.
}
while (timer.getTicks() <= 1000 / FPS_CAP);
print_fps();
}
}

Somewhat unrelated: Are we allowed to use any HTML tags in the comments?

Posted by Tom at Jun 03, 2007, in the afternoon

The documentation wiki for SDL_Delay() is very sparse, and doesn't go into what the method is meant to be used for. My guess is that using it anyplace you want the thread to background is fair game.

I'd seen the tutorial you mentioned while looking for ways to throttle framerate, and noted this in the conclusion:

I'll admit, using a while loop to wait is a bit wasteful. Because the program is repeatedly checking if the time is up you're going using up 100% CPU. Another way is to make the program sleep using SDL_Delay(). This will drastically cut the amount of CPU the program uses. I could show you the code that does it but I have to let you figure some things out for yourself =).

I prefer SDL_Delay() personally because it means my computer fans don't kick in every time I run the game. ;)

Posted by Tom at Jun 03, 2007, in the afternoon

Looks like you can use HTML in the comments. (I'd forgotten, if you must know.)


New Comment