Speed of this.Refresh & Paint event.

wyrd

Well-known member
Joined
Aug 23, 2002
Messages
1,408
Location
California
I noticed that the Paint event automatically gives a blank Graphics object, which would mean Id have to redraw every object in my game (at most 115). Theres also an option to set auto backbuffer, right?

Obviously the Refresh method and Paint event makes things simplistic an easy, I was wondering just how fast or slow it is? Would I benefit more if I were to just use a single Graphics object and clear moving object by hand (which obviously wouldnt be all 115), or would the speed different in my small game not matter much?

Maybe I should take the easy route, and if speed isnt efficient enough, try out the "old fasion" way of creating my own back buffer and just clearing/drawing items that are moving?

Oh and btw, how do you set the backbuffer option for a form? :P
 
Originally posted by wyrd

Oh and btw, how do you set the backbuffer option for a form? :P

You use DoubleBuffering to do that.
Set those properites to true in your form like this:
Code:
SetSTyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWMPaint, True)
SetStyle(ControlStyles.UserPaint, True)
Windows will draw the fastest way possible for it :)

As for your object, I think GDI+ will have some trouble drawing 115 objects at one time especially if they are big :)
 
You could use Invalidate instead of Refresh. Then youd only have to redraw the sections that changed.

I found this to turn really nasty sometimes because if you stray onto areas that arent invalidated they just wont show up.
 
Mutant:
Hmm, I see. Will that still clear the backbuffer on every Paint or will I have to manually clear areas now?

BTW objects are only 32x32.
 
Hmm, okay. Well Ill try it out, should be able to easily convert it from Paint event to my own routine if redrawing 115 images becomes to much of a slow down. Need to test it anyway, because if it cant handle this then theres no way itll be able to handle an NES style 2D game.
 
advice to to get it faster

you might want to change all your mathematical operations to integer because it takes alot of processor usage to perform complex math operations when you have single, double, etc. variables...if you run task manager while youre running your program drag the task manager above the form and look at the processor usage then youll see! most gaming programmers use this technique to lessen flickering and at the same time processor usage
 
You should redraw the entire scene every time, thats just how its done. Drawing 110 32x32 objects shouldnt slow things down too much, if this is a windowed GDI+ game.
 
You should redraw the entire scene every time, thats just how its done. Drawing 110 32x32 objects shouldnt slow things down too much, if this is a windowed GDI+ game.

Hmm. I was always under the impression that you shouldnt draw any more then you have to (which in 99% of the cases is the entire game). Well any way, good to know drawing 110 objects shouldnt be to big a deal.
 
Keep in mind that all 3D games are redrawing the entire screen every time - its not as big a deal as it once was. Back in the "old days", you wanted to use Dirty Rectangles to only update what needed updating because things were much slower to draw.

On a game I was working on, I had been drawing roughly 1000 14x14 images using DirectX in fullscreen. My original design had them setup as separate buffers, each drawn through a separate call. The speed was extremely slow (20-30 FPS) on my PIII 700 with GeForce 2 GTS. I modified the code to use one buffer and jumped to 500+ FPS (no waiting on the vsync).

Now I know youre not using DirectX, but the point is that there may be different ways to draw things that may speed things up (or slow them down, if done wrong). So Id test out your theory of drawing 110 objects and see what the speed looks like in a sample app. If it looks ok then youre good to go. If not, you may have to rethink how you design the GUI parts (such as structures to store whats changed and redraw only that).

-Nerseus
 
Back
Top