CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    29

    Timing Game Speed.

    How Would I go about timing how fast my game runs no matter the frame rate speed?

    Limiting Frame speed does work, but I don't think frame speed is reliable on such an important aspect of game programming.

    Thanks.

  2. #2
    Join Date
    Jun 2007
    Location
    MA-USA
    Posts
    247

    Re: Timing Game Speed.

    Code:
    DWORD dwTick;
    DWORD dwLast;
    float framespersec;
    float secsperframe;
    
    // Before the game loop begins...
    dwLast = GetTickCount();
    
    // For each iteration of the game loop...
    dwTick = GetTickCount();
    framespersec = 1000.0F / (float)(dwTick - dwLast)
    secsperframe = (float)(dwTick - dwLast) / 1000.0F;
    dwLast = dwTick;
    It is important to use time base movement so things move the same speed on all computers.
    Code:
    const float unitspersec = 0.001F;
    float distancetomove = secsperframe * unitspersec;
    I hope i wrote all that right...lol

  3. #3
    Join Date
    Oct 2008
    Posts
    29

    Re: Timing Game Speed.

    What does / by float do?

    And also, Do I put this in the main while loop before the render function, or do I put it in the frame rending function?

    Thanks.

  4. #4
    Join Date
    Nov 2008
    Posts
    13

    Re: Timing Game Speed.

    Basically what he is saying that you make your code do animations or change not by the no. of frames but the no. of seconds that have passed. If you can implement that in your code on your own then you needn't use any code that he has written, however that'[s how many people would do it.

    I'd suggest getting a book on making Game Engines, it doesn't matter whether it teaches you to make 2D games or 3D, the basic structure is what matters, the rest of the resources are easilly available on the internet. It might be possible for you to find some Game Engine tutorial online, and if that works for you then why not.

  5. #5
    Join Date
    Oct 2008
    Posts
    29

    Re: Timing Game Speed.

    Any game books you suggest?
    Also I probably need to know a little more math like trig.

    I'm only 16 so Id say I'm pushing a little, going into trig.

    Oh and btw, I think I know what 1000.0f / float is. Is it dividing by floats highest point?

  6. #6
    Join Date
    Jun 2007
    Location
    MA-USA
    Posts
    247

    Re: Timing Game Speed.

    Code:
    framespersec = 1000.0F / (float)(dwTick - dwLast);
    Means that i want the result of (dwTick - dwLast) to be casted into
    floating point value before dividing 1000.0F by it, which is to prevent
    the final result from being rounded into an integer value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured