Time based movement delta problem

Started by
3 comments, last by JohnBolton 17 years ago
I don't know if i'm getting a good figure for my delta. At 319fps i'm geting 0.004 and 0.003 as my delta. Then at 154fps i'm getting 0.006 and 0.007 as my delta. It doesn't sem very percise does it? Check out my code.

// FPS
if(SDL_GetTicks() - m_startTime >= 1000)
{
    m_fps = m_totalFrames;
    m_totalFrames = 0;
    m_startTime = SDL_GetTicks();
}
m_totalFrames++;

// Time based movement
m_oldTime = m_newTime;
m_newTime = SDL_GetTicks();
m_diffTime = m_newTime - m_oldTime;
m_delta = float(m_diffTime)/1000.0f; // <- o_0
Any ideas?
Advertisement
It looks fine to me. The time deltas may seem small, but they are measured in seconds and are running at several-hundred Hertz. You can easily verify that the values are okay:

319 * 0.004 = 1.276
319 * 0.003 = 0.957

154 * 0.006 = 0.924
154 * 0.007 = 1.078

So the total delta over a second is indeed roughly unit, as required.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Thanks for the reply. I see alot of page ripping. I'm going to try to average out the 3-5 delta totals and see if that helps. Thanks again.
Hold on. What do you mean by 'page ripping'. This isn't a vertical-sync issue, is it?

I'm not sure what you're trying to achieve, but I get the feeling that averaging deltas together isn't the solution. Could you tell us what you're using the delta for and exactly what's wrong with the results?

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Quote:Original post by dsage
I don't know if i'm getting a good figure for my delta. At 319fps i'm geting 0.004 and 0.003 as my delta. Then at 154fps i'm getting 0.006 and 0.007 as my delta. It doesn't sem very percise does it?

Since SDL_GetTicks returns the number of milliseconds as an integer, it can't get any more precise than that.

John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement