Results 1 to 3 of 3

Thread: Frame Rate

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    1

    Question Frame Rate

    I am building a game, and as most vb programs, there are a few event based aspects. But my engine is not. and I am trying to run my engine as fast as I can and for all of my events to happen. my first solution was to put it in a timer, but as you probably already know, a timer is not fast enough when it comes to redrawing the full screen in neccesary moments. I have implemented in my engine the following code:

    dim events as boolean
    ...
    events= false
    do
    DoEvents
    if events = true then exit do
    loop
    ...
    'in every event I have implated the following
    events = true

    this work, as long as an event happens, but it does not give me a steady frame rate because it comes to a crwal when I'm doing nothing and when I move my mouse for example, it sky rockets... I want to know if there is a better way of knowing if the events have been completed??

    any help would be greatly appreciated....

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well you could use the GetTickCount API declared in the Win32 API. Then to get the event-rate you want (not the framerate!), you do this:

    VB Code:
    1. Dim eFPS As Long
    2. Dim A As Long
    3. Dim B As Long
    4. ...
    5. eFPS = 40
    6. A = GetTickCount
    7. Do
    8.    B = GetTickCount
    9.    DoEvents
    10.    If (B - A) >= (1000 / eFPS) Then
    11.       'Change Player Positions, etc.
    12.    End If  
    13.    'Draw stuff, perform interpolation (make 3d animations smooth, etc.
    14.    A = GetTickCount
    15. Loop

    Okay. This code defines the events/second (40 event calls/second). Then it finds out the clock time. After doing this, it checks the clock time again to see if enough time has passed to make the events run at 40 events/second. If it has, then you get to do the events. Even if it hasn't you still draw the screen. Then it finds out the clock time again to compare.

    I hope you understand
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Zaei
    Guest
    Be sure you separate game ticks from frames per second. Generally, a game loop looks like this:
    Code:
    While bRunning
       If Update > GetTickCount Then
            Start = GetTickCount + 30
            '//Update game objects, etc
       End If
       '//Render Scene
       DoEvents '//This will process all waiting windows messages, 
                       '// Including any KeyDown Events, etc.
    Wend
    
    '//Cleanup
    This way, everything runs at the same speed on any machine that can keep up, and renders the scene as fast as the machine can handle. Multiple frames can be rendered between game updates. DoEvents does exactly what it says =). When the program hits that, any KeyDowns, MouseMoves, etc get executed, and the game continues, so you dont need that "events = true" thing.

    Z.

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