PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Determining Frame Rate-VBForums
Results 1 to 8 of 8

Thread: Determining Frame Rate

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    1

    Smile Determining Frame Rate

    Hi, it seems that what framerate I get by using Timers largely depends on what my draw code is (IE alpha image, or bitblt with a buffer form, etc).
    Is there a known method of trying to "control" the framerate to keep it at a certain number or within a certain range? Thanks!

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Determining Frame Rate

    There are ways.. but even still, whatever you do to control the framerate, still will depend on the code you're using to draw.

    Think about it, if you use a method like Sleeping for a certain amount of time.. it would go like this (I'm using stupid intervals just so you understand what I mean):

    Fast Drawing Version:
    1 Minute(s) : Fast code executes
    1 Minute(s) 10 Seconds : Sleep(30) ' sleep to try and balance out the frames..
    1 Minute(s) 11 Seconds : Next frame..

    Slow Drawing Version
    1 Minutes(s) : Slow code executes
    1 Minutes(s) 30 Seconds : Sleep(30) ' already slower anyway..
    1 Minutes(s) 31 Seconds : Next frame..

    Theres no sure-fire way, except cleaning up your code.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Determining Frame Rate

    Quote Originally Posted by chemicalNova
    Theres no sure-fire way, except cleaning up your code.
    Or better yet, use a game loop.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Determining Frame Rate

    I've given up on suggesting Gameloops.. noone listens

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5
    Hyperactive Member metalmidget's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia
    Posts
    342

    Re: Determining Frame Rate

    Does that mean you're also going to give up on telling everyone at VBForums that VB is crap and use C++ instead?

  6. #6
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Determining Frame Rate

    C# ftw

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Determining Frame Rate

    Quote Originally Posted by metalmidget
    Does that mean you're also going to give up on telling everyone at VBForums that VB is crap and use C++ instead?
    Dear god no.. I'm not stupid

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,467

    Re: Determining Frame Rate

    Quote Originally Posted by FrameRateMax
    Hi, it seems that what framerate I get by using Timers largely depends on what my draw code is (IE alpha image, or bitblt with a buffer form, etc).
    Is there a known method of trying to "control" the framerate to keep it at a certain number or within a certain range? Thanks!
    The Breakout game I'm working on is powered by DirectX, and since it's purely 2d, it tends to hit rather high framerates... In general, timers are bad for timing fast things. Use the System.Diatnostics.Stopwatch class.

    In the code below, it runs pretty consistently at roughly 40fps because of the Thread.Sleep() function. Note that it only runs if the elapsed time is less than 25 milliseconds, and only sleeps for the remainder of 25 milliseconds. Hope it helps.

    csharp Code:
    1. Stopwatch sw = new Stopwatch();
    2.             do
    3.             {
    4.                 sw.Start();
    5.                 f.Render();
    6.                 Application.DoEvents();
    7.                 sw.Stop();
    8.                 if (sw.ElapsedMilliseconds < 25)
    9.                     Thread.Sleep(25 - (int)sw.ElapsedMilliseconds);
    10.                 sw.Reset();
    11.             } while (f.Created);

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width