Jump to content
  • Advertisement

Archived

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

DarkKiller

HighPerformanceCounter for TimeBasedMovement

This topic is 6018 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

Hi there, I have a simple Frame-Counter using GetTickCount but I need a high performance counter to get real good frame-independant values. Is there an other way then GetTickCount()? Thx

Share this post


Link to post
Share on other sites
Advertisement
But I don''t really understand how that works.

I checked the Tutorial (thankx for the tip) but I do not see the way he integrates the value of the timer into the calculation of the movement. (I hope that makes sense)

dark

Share this post


Link to post
Share on other sites
Here''s what I do for my Pong game:

In my game loop, I update the time and subtract it from the previous time, therefore getting the time for one frame only. Then I pass that value to an Update function, which I will describe below. Then the draw function is called.

For Pong, my Update function checks for keyboard input and moves the ball and paddles. If the down button was pressed, the paddle is moved downward X number of pixels. The X value is determined by mulitplying a certain speed constant by the elapsed time. So, whether Pong is running at 200 fps or 10 fps, the paddle can only move a certain distance in one second (otherwise, a fast machine would have extremely fast paddles, whereas a slow machine would have extremely slow paddles). I do the same type of calculation for the other paddle and the ball.

Hope that helps you.

Share this post


Link to post
Share on other sites
he passes in the value of amount of time passed into his movement equations. then he uses the dT (delta time a.k.a change in time) in a movement equation from physics

position = position + velocity * deltaTime;

instead of saying:

position = position + velocity;

that way you move at a constant velocity no matter what the framerate is. coolio?

-me

p.s. yeah i KNOW it''s better to say position += velocity * time, it''s just more clear for instructional purposes as typed above.

Share this post


Link to post
Share on other sites
Oh come on - can''t we learn to use the "Articles & Resources" link on every page of gamedev! Check it out; there are atleast 2 articles on this subject.

Share this post


Link to post
Share on other sites
@masterg: yes, maybe we should, but why should I have to if someone has fun to explain it by him/herself ?

@Erunama and Palidine: I do exactly that but my function doesn''t work right until now. I use GetTickCout to get the framerate but my function is not exact enough when I try to get the value for e.g. 10 times in a second.

I''ll work on it later.

thankx for your help!

Share this post


Link to post
Share on other sites
Perhaps a little code would help here. Anyway, here is a little snippet of my main game loop (the same as in NeHeGL).


    
// Process Application Loop

tickCount = GetTickCount (); // Get The Tick Count

Update (tickCount - window.lastTickCount); // Update The Counter

window.lastTickCount = tickCount; // Set Last Count To Current Count

Draw (); // Draw Our Scene


SwapBuffers (window.hDC); // Swap Buffers (Double Buffering)



As you can see, the tick count is updated every frame. This count is from the beginning of the program, but we only want to update based on the time since the previous frame. Therefore, we subtract the total time from the previous time (in my case, window.lastTickCount) and pass that value to our Update function. Then we update the previous time to have a reference for our next frame.

Edit: minor formatting mistake

[edited by - Erunama on June 27, 2002 2:06:40 PM]

Share this post


Link to post
Share on other sites
to compare it with mine:

This is my old standart fps function:

GLfloat GetFPS()
{
static DWORD tickold=GetTickCount();
static DWORD tick;
static long fps;
static DWORD tmptick;
static DWORD tickdiff;
static int framecount;
static bool started =false;

tick = GetTickCount();
tickdiff = (tick - tickold);

if (tickdiff>1000.0f)
{
fps = FPSFrameCount*(tickdiff/1000);
FPSFrameCount=0;
tickold = tick;
}

return (float)fps;
}

It works the same way.
The first problem with your function is that I have more then 1000 fps, sometimes. ....

well I could waste some time with a simple loop ... nice idea.
I will check it out again...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!