The advantage of a dll is the speed achieved from any looping and or math commands. The initial creating of pointers and and the use of memblocks is still subject to the speed of DarkBASIC. So, yes, drawing can be faster using a DLL but may not be worth it depending on what you want to do.
Quote: "If you've got the "Extras" folder with the DBC install, have a look at the "LotsOfSprites" example. It puts 1000 images to screen each refresh, stopping off on the way to rotate those images, and runs at about 90fps on my computer (though mine seems to have that as a limit as to how fast it can transfer data from a memblock back to the screen).
Pasting 1000 images in DBC alone is crippling on the computer, Screen fps drops to something like 10 or 20 at best, and drawing sprites is even slower."
The lots of sprites demo is a bit misleading and maybe not the greatest benchmark of image speed as a result of using a DLL. Lots of sprites copies a single bitmap to bitmap zero after redrawing the bitmap in the background so it's not really showing any sprites at all and it runs slower than I though it would probably because of the MAKE MEMBLOCK FROM BITMAP command.
I wrote up a demo in DBC without a DLL that "pastes 1000 sprites to the screen". It runs at about 73 FPS on my machine, but from what I can tell the original Extras lots of sprites runs at about 54 FPS on my machine.
rem lots of sprites
rem latch
rem 06/10/2009
rem a variation of the lotsosprites demo but entirely in BASIC
set display mode 640,480,16
sync on
sync rate 0
autocam off
randomize timer()
make object cube 1,25
yrotate object 1,45
position camera 0,200,-400
point camera 0,0,0
set object ambient 1,rgb(80,80,80)
set directional light 0,1,-.1,.3
set ambient light 0
color backdrop 0
sync
dim pos(1000,3)
for i=1 to 1000
pos(i,0)=rnd(640)
pos(i,1)=rnd(480)
xdir=rnd(4)-2 : if xdir=0 then xdir=-1
ydir=rnd(4)-2 : if ydir=0 then ydir=-1
pos(i,2)=xdir
pos(i,3)=ydir
next i
for img=0 to 35
yrotate object 1,img*10
get image img+1,304,222,336,258,1
sync
next img
create bitmap 1,bitmap width(0),bitmap height(0)
backdrop off
delete object 1
cls 0
ink rgb(255,0,255),0
img=0
do
copy bitmap 1,0
cls
inc img
if img > 36 then img=1
for i=1 to 1000
if (pos(i,0) > 639) | (pos(i,0) < 1)
pos(i,2)=0-pos(i,2)
endif
pos(i,0)=pos(i,0)+pos(i,2)
if (pos(i,1) > 479) | (pos(i,1) < 1)
pos(i,3)=0-pos(i,3)
endif
pos(i,1)=pos(i,1)+pos(i,3)
paste image img,pos(i,0),pos(i,1),1
next i
`set current bitmap 0
text 0,0,str$(screen fps())
`set current bitmap 1
sync
loop
And if you really want to take the illusion of multiple images on the screen to an extreme, check out this code from Kevin Picone. This has virtually and unlimited number of images on the display with no change in FPS. It's a cool trick and shows that depending on what you are doing, a little clever programming will supercede the need for a DLL:
Rem * Title : 2d_Unlimited_sprites
Rem * Author : Kevin Picone
Rem * Date : 21,Mar,2001
` *=---------------------------------------------------------------------=*
`
` >> Unlimited Pasted Images V0.01 <<
`
` By Kevin Picone
`
` 18,April,2001
`
` (c) copyright 2001, By Kevin Picone, All Rights Reserved.
`
` *=---------------------------------------------------------------------=*
`
` So What does this do ?:
` =======================
`
` I'd have to say that this effect is perhaps my favourite of all time.
` I remember this done on the Vic 20! and then the C64 some years later,
` it seemed amazing then, unlimited sprites without slow down ?,
` impossible !!. But once you hit upon the trick, it's really very
` simple. And for the record NO !, it doesn't give you unlimited image
` pastes per sync :), it's just FOOLS the viewer into thinking that's what
` it's doing. :)
`
` Cya,
` Kevin Picone
`
` *=---------------------------------------------------------------------=*
` Constants
i=0
No=i : inc i
Yes=i : inc i
Sync on
sync rate 60
Hide Mouse
screen_width=640
screen_height=480
Title$= "Unlimited Pasted Images"
Version$= "V0.01"
TextYPos=-100
`pick a size for our Image
bob_size=32
` Create an Image
for lp=0 to (bob_size/2)-1
ink rgb(rnd(255),rnd(255),rnd(255)),0
box lp,lp,(bob_size-1)-lp,(bob_size-1)-lp
next lp
get image 1,0,0,bob_size-1,bob_size-1
cls
` Init Frame Buffers
` ------------------
screens=6
dim buffers(screens)
for lp=1 to screens
create bitmap lp,screen_width,screen_height
buffers(lp)=lp
next lp
` Init Sprites/Images Position
` ----------------------------
xpos#=screen_Width/2
Ypos#=screen_Height/2
xspeed#=1+(rnd(15)-rnd(15))
yspeed#=1+(rnd(15)-rnd(15))
` Starting Number of Images
Numb_of_images=1
do
` The main effect routine
set current bitmap buffers(1)
paste image 1,xpos#,ypos#
xpos#=xpos#-(xspeed#/screens)
ypos#=ypos#-(yspeed#/screens)
if xpos#<0 or xpos#>(screen_width-bob_size) then xspeed#=xspeed#*-1
if ypos#<0 or ypos#>(screen_height-bob_size) then yspeed#=yspeed#*-1
` Randomly change the Speed values
xspeed#=xspeed#+(rnd(6)-rnd(6))
yspeed#=yspeed#+(rnd(6)-rnd(6))
` Limit The Speed values so our image doesn't move to fast
if xspeed#=>30 then xspeed#=30
if xspeed#<-30 then xspeed#=-30
if yspeed#=>30 then yspeed#=30
if yspeed#<-30 then yspeed#=-30
if buffers(1)=1 then inc Numb_of_images
copy bitmap buffers(1),0
` roll frames
for lp=1 to screens
buffers(lp-1)=buffers(lp)
next lp
buffers(screens)=buffers(0)
` Display Some Program By Information
set current bitmap 0
if inkey$()=""
Display_UWProgramInfo(Title$,version$,textypos,0)
text 540,textypos,"Images:"+str$(numb_of_images)
if textypos<0 then inc textypos,2
endif
sync
loop
` *=----------------------------------------------------------------=*
` *=---------- Display Program TITLE & UWdesign BLURB INFO ---------=*
` *=----------------------------------------------------------------=*
Function Display_UWProgramInfo(Title$,version$,ypos,clearflag)
if clearflag=1 then cls 0
ink rgb(255,255,255),rgb(255,255,255)
x=0: y=ypos: yh=15
text x,y,title$+" "+version$: y=y+yh
text x,y,"Code By:Kevin Picone": y=y+yh
text x,y,"Email: picone"+"@"+"giant.net.au":y=y+yh
text x,y,"Url: www"+"."+"uwdesign"+"."+"50megs"+"."+"com":y=y+yh
text x,y,"Fps:"+str$(screen fps()): y=y+yh
EndFunction
As far as using LOCK BACK BUFFER, it is a bit slow. Actually slower than bitmap/memblock commands if I remember correctly. It is useful and it gives you a pointer to what's being drawn on bitmap 0. But it uses pitch, so you'd have to calculate the scan line length to find the positions and colors of individual pixels. And to use it in real time, the pointer can constantly change so you'd have to lock it to get the pointer each time you want to manipulate it (it being the back buffer). I'm not trying to discourage you, just giving you a heads up in case you thought there would be a blazing speed burst by manipulating the back buffer.
You should check out Ashingda's flood fill on the Code Snippets board. He uses full screen memblocks and does complete, multishaped flood fills in milliseconds. Pretty good code and leaves any drawing one would do with the 2d commands in the dust in terms of speed. Now that code in a DLL, because of the looping and the 16 bit calculations, would rival the speed of commercial apps I wouldn't doubt (though there are a few tweaks here and there that could imporve it).
Enjoy your day.