Quote: "Well who would run a program with sync off? lol "
Any noob who hasn't read the help files!
@Caleb1994
My tests gave similar results to yours, so you are right when you say "Get image" takes zero time - it just takes less than a millisecond to execute. However, the key point is that "Sync" becomes much slower!
@All
Well, here are my test results - drawing to offscreen bitmaps, grabbing an image and pasting that to bitmap 0 is indeed faster than just drawing to screen in the first place:
rem startup
Sync On
Sync Rate 0
Set Display Mode 1024, 768, 32
Make Object Sphere 1, 1
For T = 1 to 50
Sync
Next T
Create Bitmap 1, 1024, 768
Set Current Bitmap 0
CLS RGB(255, 0, 0)
Get image 1, 0, 0, 50, 50
`Load Image "FormOne.bmp", 1
CLS 0
rem Test Pasting images to screen
TimerOne = Timer()
For T = 1 to 100
Paste image 1, 0, 0
Next T
Sync
TimerTwo = Timer()
break Str$(TimerTwo - TimerOne) + "Ms to draw images to bitmap 0. Press ESC to continue"
rem Paste images to offscreen bitmap, then get image and paste to
Do
One = Timer()
Set Current Bitmap 1
CLS 0 : rem I think this is the problem - it knocks off 5fps!
For T = 1 to 10
Paste image 1, 0, 0
Next T
Get image 2, 0, 0, 1024, 768
Set Current Bitmap 0
Two = Timer()
remstart
rem A Way of clearing the bitmap - but slower than CLS
Make Memblock 1, (1024*768*4) + 12
Write Memblock DWord 1, 0, 1024
Write Memblock DWord 1, 4, 768
Write Memblock DWord 1, 8, 32
Make Bitmap From Memblock 1, 1
Delete Memblock 1
Set Current Bitmap 0
remend
Paste image 2, 0, 0, 1
Text 50, 50, "Screen FPS = " + Str$(Screen FPS())
Text 50, 70, "Time taken to draw images " + Str$(Two - One) + "Ms"
Text 50, 90, "Time needed for Sync: " + Str$(Four - Three) + "Ms"
Three = Timer()
Sync
Four = Timer()
Loop
I get 31Ms for bitmap 0 (about 32fps), and 20Ms for bitmap 1 (about 50fps). That's with Windows Media Player open and an mp3 playing, in place of the proper code to hike the screen fps.
That impressed me, but when I tried adding it to Dark Windows I actually got a lower frame rate than when I drew straight to the screen. I've attached an experimental copy of the library, but the important points are the start and end of the "DW_Draw_Update(Memblock)".
rem Check for optimisations - if true, draw to bitmap
If Header_DrawToBitmap(0) > 0
Set Current Bitmap Header_DrawToBitmap(0)
` Copy Bitmap 0, 1
endif
If Header_DrawToBitmap(0) > 0
Get Image Header_DrawToBitmapImg(0), 0, 0, Header_SWidth(0) + 1, Header_SHeight(0) + 1
CLS 0
Set Current Bitmap 0
Paste Image Header_DrawToBitmapImg(0), 0, 0, 1
` Copy Bitmap 1, 0
` Set Current Bitmap 0
endif
(The remmed out bits were an alternative method that was slightly faster, but I didn't like the idea of locking bitmap 0 in case the user still had other stuff to do after updating DW)
If I call "DW_Draw_To_Screen" and set all images to be drawn to the screen, I get 56 frames a second. If I use "DW_Draw_To_Bitmap()", placed at line 57, I only get 42/43 fps. I think it's a combination of CLS 0 and the fact that the image I draw to bitmap 0 has to be transparent. I can't come up with any faster way of redrawing all images to screen, short of writing a dll like the "lotsofsprites" example that came with DB, and I don't want to go down that road.
That brings me to OBese87's idea. It would be great to draw all inactive forms once, and keep pasting that image on screen and then draw the currently active form on top. I haven't properly tested this, but drawing one image of the screen per loop gives me 80-90 frames a second with 100 forms, and transparency enabled (Windows Media Player open again).
While this doubles my frame rate, I'm still troubled about one feature of DW that's currently under construction. You may have noticed the parameter "ClickType" when creating forms. "FormType" would be a better name for it, because in Windows there are three types of forms. There are your normal ones (like the ones already in DW - you click one, and it goes to the front), there are floating palettes (like the ones in Corel PhotoPaint, or the toolboxes that appear in MS Word/PowerPoint etc), and there are Message boxes (which always stay on top until you close them).
Message boxes are easy to add, but Palette forms are going to be tricky - they can be moved in front of normal forms, but are always active and always clickable. Any ideas?
"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."