Archived

This topic is now archived and is closed to further replies.

CD3DApplication timer too fast

This topic is 5304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, hope some one help me out of this. Look at the CD3DApplication::Render3DEnvironment(), the function is as followed. Check out the DXUtil_Timer that part, from what I understand TIMER_GETELAPSEDTIME returns time in seconds. And if you use QueryPerformanceCounter() in that DXUtil_Timer(), the return values will always be nonzero (I think).
HRESULT CD3DApplication::Render3DEnvironment()
{
    // Check device coorperative level stuff...

    ....


    // Get elapsed time so far.

    FLOAT fElapsed = DXUtil_Timer(TIMER_GETELAPSEDTIME);
    if((0.0f == fElapsed) && m_bFrameMoving)
        return S_OK;


    if(m_bFrameMoving)
    {
        m_fElapsed = fElapsed;
        FrameMove();
    }


    Render();
    UpdateStats();


    m_lpD3DDevice->Present(...);
    return S_OK;
}
In this case, FrameMove() is called, and followed by Render() and so on. And my question here is, if Render3DEnvironment() is called 85 times a second, my FrameMove() will get called 85 times a second too. That's too fast for animatin' some movements isn't it? If this is the case, FrameMove() frame rate dependent. And when I run my game on a higher end PC, those in game characters are gonna move much faster... ?? Can some one help clarify this to me? Thanks so much!
[edited by - HaywireGuy on June 3, 2003 6:19:00 AM]

Share this post


Link to post
Share on other sites
This is precisely where my problem lies. You see, the function
Render3DEnvironment() gets called very very frequently in the
game loop, which causes FrameMove() to be frame rate dependent.
And if the FrameMove() is frame rate dependent, then I can't
base it on time.

For an example, Render3DEnvironment() gets called 80 times a
second, I might not want FrameMove() to be called 80 times a
second, because it's too fast for animatin' anythin' at all.
Especially the check if(fElapsed == 0.0f), this is almost TRUE
for all the times when Render3DEnvironment() is called. And as
a result, FrameMove() gets called almost all the times (near 80
times per second).

Shouldn't they be checkin' this instead: if(fElapsed > 0.2f)
then only call FrameMove(), in this case I'll have FrameMove()
called 5 times a second. Reasonable?

But still you know, how did they make all their samples in SDK
execute the same way regardless of the frame rate you get on
your machine... How? This is my question


[edited by - HaywireGuy on June 3, 2003 9:05:22 AM]

Share this post


Link to post
Share on other sites
Ok to clarify RhoneRanger's answer:

Time Based Animation depends on the time elapsed between each movement (not each frame of animation). Thus, you want to check how much time has passed since the last time you moved the object.

In my duck game, for example, I have the ducks flying at a constant speed (10 feet per second). When I move a duck, I record the time that the move occurred. The next time a move() is executed on the duck, I check to see how much time has passed since the last move. If, for example, 50 milliseconds have passed (0.05 seconds) since the last move, then I will multiply my duck's movement rate by that amount: 10 * 0.05 = 0.5 feet. Thus, for this move, I will only move the duck by 0.5 feet.

At a higher framerate, my move() function will be called more often, and the time between move() calls will be shorter. By using the same algorithm, the duck will move a shorter distance: 20 milliseconds since last move = 0.02 seconds. 10 * 0.02 = 0.2 feet.

I hope this makes sense.

[edited by - Teric on June 3, 2003 4:17:17 PM]

Share this post


Link to post
Share on other sites
Thanks guys, and Teric, your explaination makes perfect sense
to me. And I can now explain why those SDK samples execute the
same speed no matter what the frame rate is, they used GetTime
() in their FrameMove() and causes the animation to be time-
based.





Share this post


Link to post
Share on other sites