Results 1 to 5 of 5

Thread: [Resolved] Too slow (BitBlt)

  1. #1

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    [Resolved] Too slow (BitBlt)

    Is there any way I can speed this up?

    VB Code:
    1. Private Sub GameLoop()
    2.     Do Until boolPlay = False
    3.         DoEvents
    4.         intX1 = intX1 + 5 * intLevel
    5.         intY1 = intY1 + 5 * intLevel
    6.         'put the background on the form
    7.         RetVal = BitBlt(Me.hDC, 0, 0, picBack.ScaleWidth, picBack.ScaleHeight, picBack.hDC, 0, 0, SRCCOPY)
    8.         'picBuffer.Cls
    9.        
    10.         'put the sprite on the form
    11.         RetVal = BitBlt(Me.hDC, intX1, intY1, 67, 79, picSprite.hDC, 67, 0, SRCAND)
    12.         RetVal = BitBlt(Me.hDC, intX1, intY1, 67, 79, picSprite.hDC, 0, 0, SRCPAINT)
    13.    
    14.         'copy the buffer to the form
    15.         'RetVal = BitBlt(Me.hDC, 0, 0, picBuffer.ScaleWidth, picBuffer.ScaleHeight, picBuffer.hDC, 0, 0, SRCCOPY)
    16.         frmMeteor.Refresh
    17.     Loop
    18. End Sub

    I used to use a buffer but that only slowed it down even more...
    Last edited by McCain; Feb 17th, 2003 at 07:12 PM.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  2. #2
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Looks like it should be going pretty fast there.

    Are you recording how fast it is?

    (To do this use the gettickcount API call to time how fast the loop executes).

    You could get rid of the "RetVal = " if you're not using the variable for anything.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  3. #3
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    Theres a few things you can do.

    Your Blting everything everytime. you should try to blt only things that have changed (much harder to code, much, much faster to run).

    nearly all professional game titles use this "dirty rectangle" method. and you should use a buffer to avoid flicking.

    Rewriting in DirectX 7 will speed things up aswell.
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  4. #4

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Thanks for the help.
    I'll do what you've told me and we'll see if I can notice any better performace.
    It's probably the background that slows it down the most it think. It's 1024x768 - guess it's pretty hard work for the computer to blit that every time...
    Would it be faster to just blit parts of the back to where things used to be? (Like if I have a sprite that's 32x32 pixels at the coordinates 100, 100 then move the sprite 10 pixles to the right. Would it be faster to just blit the 10x32 piece of the background that was covered before of would the calculations take more time then we save on the smaller blit?)
    Hope I made sence...

    How would I use the GetTickCount to get the speed of the loop?
    Last edited by McCain; Feb 17th, 2003 at 07:11 PM.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  5. #5
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    I made a map editor That uses Bitblt
    NEARLY full screen( Maximize the editor) and I get 65 FPS.
    using 16x16 tiles at 1024x768 with GeForce 2 GO

    I've optimized the file size, AND code...

    Something that I found that helps a LOT
    somewhere make a variable at the top of the forum
    Private FormHDC as long

    in form resize
    FormHDC = Me.HDC

    Then in your code, replace Me.HDC with FormHDC
    THIS WILL INCREASE SPEED, probably a BUNCH

    NOTE: You put the FormHDC = Me.HDC under formResize because it *HAS* to be called everytime the source HDC changes (the form, in this case)
    plus, on Form_LOAD, it calls the form_resize sub, also so no need to put it in form_load

    killing two birds with one stone on that one.

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