Trouble Capping Framerate

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
JarrodParkes
ES Beta Backer
ES Beta Backer
Posts: 325
Joined: Thu Feb 25, 2010 2:39 pm
Current Project: Yes, iPhone Application(s)
Favorite Gaming Platforms: N64, PC
Programming Language of Choice: C++
Location: Mountain View, CA
Contact:

Trouble Capping Framerate

Post by JarrodParkes »

Hey, I am trying to ensure that my application runs at a certain frame rate, but keep getting stuck in probably some infinite loop. Here is what I am doing in code, if someone could take a look...

// inside the while(1) loop

int currentTime = SDL_GetTicks();
int msBetween = currentTime - lastTime;
bool delay = false;

if(msBetween < (1000 / FPS))
{
delay = true;
}

if(delay)
{
SDL_Delay((1000 / FPS) - msBetween);
delay = false;
}
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Trouble Capping Framerate

Post by xiphirx »

JarrodParkes wrote:Hey, I am trying to ensure that my application runs at a certain frame rate, but keep getting stuck in probably some infinite loop. Here is what I am doing in code, if someone could take a look...

// inside the while(1) loop

int currentTime = SDL_GetTicks();
int msBetween = currentTime - lastTime;
bool delay = false;

if(msBetween < (1000 / FPS))
{
delay = true;
}

if(delay)
{
SDL_Delay((1000 / FPS) - msBetween);
delay = false;
}
You never modify lastTime ;)
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
JarrodParkes
ES Beta Backer
ES Beta Backer
Posts: 325
Joined: Thu Feb 25, 2010 2:39 pm
Current Project: Yes, iPhone Application(s)
Favorite Gaming Platforms: N64, PC
Programming Language of Choice: C++
Location: Mountain View, CA
Contact:

Re: Trouble Capping Framerate

Post by JarrodParkes »

thanks! i got it fixed now =)
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Trouble Capping Framerate

Post by Falco Girgis »

Nice, I must have missed this post. Did that fix the problem we were talking about the other day?
User avatar
JarrodParkes
ES Beta Backer
ES Beta Backer
Posts: 325
Joined: Thu Feb 25, 2010 2:39 pm
Current Project: Yes, iPhone Application(s)
Favorite Gaming Platforms: N64, PC
Programming Language of Choice: C++
Location: Mountain View, CA
Contact:

Re: Trouble Capping Framerate

Post by JarrodParkes »

which problem? i think it so though :mrgreen:
Post Reply