Results 1 to 13 of 13

Thread: Increasing framerate

  1. #1

    Thread Starter
    Member EternalKnight's Avatar
    Join Date
    Apr 2001
    Posts
    53

    Increasing framerate

    I have created a "Solar Simulator" which very accurately calculates orbits and gravitational forces. I use the PictureBox.Circle command to draw the "planets" on the backbuffer and then I set the output picturebox's picture equal to the backbuffer's image.

    The reason I am doing it this way is to eliminate screen flicker, but I am running into some serious framerate issues. Doing the calculations with double precision variables takes almost no time at all. 3/4's of the time is spent drawing the spheres and flipping the screen buffer.

    I am almost positive that there is a faster way to do this. Any suggestions?

  2. #2
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    Use the API

    Use the API instead of using VB's built in functions, they are notoriously slow. You can use bitblt to copy from 2 different places and the elipse api punction to draw circles.

    If you want to use DC's and such to store you gfx in memory just go look around or ask on the forums for a bitblt demo using DC's. You're bound to get one

    Hope this helps.


    Drewski
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  3. #3
    Addicted Member
    Join Date
    Jul 2001
    Location
    Germany, BW
    Posts
    157

    Talking posting ??

    hy, could you post your prog .. seems to be interesting ..

    cya
    Old enough to know better,
    but young enough to don't give a ****!

  4. #4
    Zaei
    Guest
    If you really go an think about it, Circle, Line, etc, are just wrappers on API functions already. Use circle for your circles, and then use PaintPicture to flip. It's BitBlt for Picture boxes. It that doesnt speed things up, then go to API (they take almost the same parameters anyway).

    Z.

  5. #5
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    ya it sounds cool...

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Here's a tutorial on Bitblt for those who are bitblock-challenged =)

    http://vbden.tripod.com/articles/invmask.htm
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Member EternalKnight's Avatar
    Join Date
    Apr 2001
    Posts
    53
    I implemented your suggestions, but it didn't speed up noticibly... Considering that on average I do 100 iterations of the gravitational formula per frame and most frames don't even have much movement, I guess I'm not all that surprised.

    About posting it, I most definitely will... Right now it is horribly coded and there are a couple bugs... Maybe in a few hours?

  8. #8

    Thread Starter
    Member EternalKnight's Avatar
    Join Date
    Apr 2001
    Posts
    53
    Keep in mind that I am very new to VB. There are a couple mistakes in how I apply some of the mathmatical formulas, but this should simulate orbits of planets around a sun many many many times more accurately than anything I have seen.

    I plan on completely rewriting most of the code, but I would still love to hear your comments.

  9. #9
    jenk
    Guest

    Planets

    Just D/L - not bad!

    Speed issues:

    Remember to clear just the graphics that have moved -
    (rather than object.cls)

    Drawing directly onto the form and not bothering with pictureboxes may help to. You can still control refreshes
    for smooth graphics using just a form.

    stuff like object.fillcolor / .circle is slow to - use the api equivalent.

    HTH

    Cheers

    J.

  10. #10

    Thread Starter
    Member EternalKnight's Avatar
    Join Date
    Apr 2001
    Posts
    53
    Thanks for the suggestions I will implement them as soon as I get to work.

  11. #11
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Use one picturebox.
    AutoRedraw = True, Visible = True.
    Draw your graphics, and then use PictureBox.Refresh to update it.

    VB has built in double-buffering, ain't it nifty? Picture-swapping and picture manipulation always result in bad framerates.
    "1 4m 4 1337 #4xz0r!'
    Janus

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Also for your gravity formula you may want to implement a look-up table, if it is very slow.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    and actually...
    Object.FillColor/FillStyle/Circle/Line/etc. Simply call the API methods with the correct properties, saving you a LOT of work. Use 'em if they are simpler, they're not THAT much slower.
    "1 4m 4 1337 #4xz0r!'
    Janus

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