Results 1 to 6 of 6

Thread: Smooth Timers and Clearing up DirectDraw

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    Smooth Timers and Clearing up DirectDraw

    OK, So I got two questions.
    1) I need a smooth method of timing. I am animating an image and the VB timer is not very accurate, I was wondering if anyone else had a suggestion - perhaps using GetTickCount somehow? I dunno.
    2) I have never been good at clearing up DC's and whatnots, preferring just to use the good 'ole "End" command and leave it at that, but with DirectDraw I'm seeing a 2ish% drop in system resources every time I run my program, presumably becuase I am not deleting my surfaces afterwards. Could someone help by telling me what needs deleting when I end my program and how to delete it (i'm not exactly well versed in DX).
    Help much appreciated.
    Dave.

  2. #2
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    1)

    Code:
    Dim lTimer As Long
    
    lTimer = GetTickCount()
    
    Do While bRunning
        If GetTickCount() - lTimer >= 10 Then
            ' Actions here
    
            lTimer = GetTickCount()
        End If
    
        DoEvents
    Loop
    This will run the code at "'Actions here" at leat every 10 milliseconds (may vary if your loop is not fast enough, but most of the time this'll do fine)


    2) In this case, DX is the DirectX object, DD the DirectDraw object and a sample surface is called DDSurface...

    Code:
    DD.RestoreDisplayMode
    Set DDSurface = Nothing
    Set DD = Nothing
    Set DX = Nothing
    Basically, you perform all actions which are needed to restore the system first, then set all the components to nothing in the reversed order at which you created them (in the sample, DX was created first, DD next and the DDSurface last, so they're destroyed in reverse order)...


    Hope this helps...


    Btw, NEVER use 'End', it's a very BAD habit... unload forms using 'Unload Form1', so they have a chance to unload properly. You might not notice any difference, but once you get more advanced in VB, the 'End' command might crash the whole program, so it's better to not get used to it now, than to re-learn it later...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    1) GetTickCount example

    2) [Just saw your post PsychoMark]
    I agree, well I use a 'ShutDown' function instead, that looks like this:
    Code:
    Sub ShutDown()
       'Release modules
       mBitmap.ShutDown
       mSound.ShutDown
       mInput.ShutDown
       mGame.ShutDown
       
       'Release windows
       Unload frmMain
       Unload frmLog
       
       'Exit
       End
    End Sub
    Last edited by Fox; May 10th, 2001 at 12:50 PM.

  4. #4
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I noticed that in your game, but the Shutdown function itself is not a DX or VB function, so you'll still have to build it yourself. (if anyone doesn't know what game I'm talking about, check this thread...

    A final tip: as you might have seen in Fox's code, it uses multiple modules. This is good! I've only once made a game with DirectX which fitted into one module, but it becomes a mess. Try to seperate your graphics and sound code, or parts of the game (like the menu, the game itself, etc.)... if you write your code to be flexible enough, you can easily modify or extend it later...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    UK
    Posts
    49

    Excellent

    Thanks a lot!

    One question, is it good practise to have a loop going constantly with no time period interval? I've never used a constant loop before, only timers, because I always believed that loop round and round and round was bad practise.
    Dave.

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I always use a loop with my DirectX games, because it's fullscreen and has main focus anyways. And it's much faster, a timer can't keep up with the 60-80 FPS I normally have...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

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