Results 1 to 4 of 4

Thread: Pls explain this procedure * solved

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Pls explain this procedure * solved

    Im debugging my friend's program and I can't understand the use of this piece of code:

    Code:
    Public Sub FPS()
       
        Do While mlngFrameTime + (1000 \ MAX_FPS) > gdx.TickCount
            DoEvents
        Loop
        mlngFrameTime = gdx.TickCount
    
        If mlngTimer + 1000 <= gdx.TickCount Then
            mlngTimer = gdx.TickCount
            mintFPS = mintFPSCounter + 1
            mintFPSCounter = 0
        Else
            mintFPSCounter = mintFPSCounter + 1
        End If
    End Sub
    mintFPS and mintFPSCounter are used only in this procedure . My first thought was a logical error, but I don't know what the procedure is for, hence, how it should have been coded.

    FPS is used only in the FadeIn procedure (called) and in the main loop (DDraw.FPS). I think it's used to run DoEvents, since the main loop doesn't have one, but I can't figure out the purpose of the If statement. Neither could she, so she left it in the program after building up on a template she downloaded.

    If you could give me a better code for whatever purpose this code was meant for, I'd really appreciate it.
    Last edited by leinad31; Dec 2nd, 2002 at 03:07 PM.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    VB Code:
    1. Public Sub FPS()
    2.  
    3.     'The code is looping a while before gdx.tickCount is bigger then the rest...
    4.     Do While mlngFrameTime + (1000 \ MAX_FPS) > gdx.TickCount
    5.         'Just waits here...
    6.         DoEvents
    7.     Loop
    8.    
    9.     'assigns a new "time" to the varaibale
    10.     mlngFrameTime = gdx.TickCount
    11.    
    12.     'checks if there has been more then one seccond since last time.
    13.     If mlngTimer + 1000 <= gdx.TickCount Then
    14.         'assigns a new "time" to the varaibale
    15.         mlngTimer = gdx.TickCount
    16.         'increeses the variable by one more then mintFPSCounter
    17.         mintFPS = mintFPSCounter + 1
    18.         'sets the mintFPSCounter-variable to 0
    19.         mintFPSCounter = 0
    20.     Else
    21.         'increases the variable by one.
    22.         mintFPSCounter = mintFPSCounter + 1
    23.     End If
    24. End Sub

    I think your code is used to count Frames Per Second = FPS





    Ooooo****, by telling you that, I became an addictive member...****...
    Last edited by NoteMe; Dec 2nd, 2002 at 12:47 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    So if I were to output the FPS to the user then mintFPS would be of use.

    Since mintFPS isn't found anywhere else in the project, I can remove the If statement?

    As to the loop, what's the point of the comparison? Can't I just put DoEvents in the main loop? As I see it, I can either:

    1) Call FPS from the main loop and the code 'just waits' to exit the Do While loop, or
    2) I can run DoEvents, without the comparison, everytime the main loop cycles and do away with the procedure.

    Which is the better way and why? Is there a reason to avoid DoEvents, hence, the If statement?

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If you don't want the app to show FPS, I suppose you can delete the whole SUB...

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