14
« on: December 07, 2007 »
ok guys, again: im trying to get all the speed possible, but only in software mode (no WritePixel(Fast))!
i thought it could be useful for everyone, if there'd be a stable (and sometimes faster) software version of this, especially for demos or stuff. can you help me getting the code even faster?
;.lib "kernel32.dll"
;apiRtlMoveMemory(Destination*,Source,Length):"RtlMoveMemory"
;apiRtlMoveMemory2(Destination,Source*,Length):"RtlMoveMemory"
Const ScreenWidth=320
Const ScreenHeight=240
Graphics ScreenWidth,ScreenHeight,32,2
SetBuffer BackBuffer()
Global VideoBank=CreateBank(ScreenWidth*ScreenHeight*4) ;create virtual buffer in 32 bit(4 bytes per pixel)
BufferInfo=CreateBank(32) ;store buffer information here
LockBuffer()
apiRtlMoveMemory BufferInfo,GraphicsBuffer()+72,32
size=PeekInt(BufferInfo,20) * PeekInt(BufferInfo,24) * PeekInt(BufferInfo,28)/8 ;global size of buffer in bytes
offset=PeekInt(BufferInfo,0) ;?not sure? - i think its the offset of the buffer in the RAM
UnlockBuffer()
If BankSize(VideoBank)<size Then RuntimeError "Could not create buffer"
Repeat
col=Rand($000000,$FFFFFF)
For currentpos=0 To size Step 4 ;<- this is the drawing loop, which fills the screen!
PokeInt VideoBank,currentpos,col ;draw to virtual buffer
Next
;Pixel(MouseX(),MouseY()) ;mousecursor
apiRtlMoveMemory2 offset,VideoBank,size ;copy virtual buffer to graphics buffer
Color 255,0,0
Text 10,10,GetFPS()
Flip 0
Until KeyHit(1)
End
Global FPS,FPSFrame,FPSTime ;stolen from ashadow ;)
Function GetFPS(ms=1000)
ctime=MilliSecs()
FPSFrame=FPSFrame+1
If ctime-FPSTime>ms
FPS=FPSFrame*1000/ms
FPSFrame=0
FPSTime=ctime
EndIf
Return FPS
End Function
Function Pixel(x=-1,y=-1,hexcol=$000000)
If x>-1 And x<ScreenWidth And y>-1 And y<ScreenHeight Then PokeInt VideoBank,(y*(ScreenWidth)*4)+(x*4),hexcol
End Function
PS: look for the drawing loop, i noticed some strange things in there:
1. it seems that adding a random drawing color increases speed
2. for-next-loops are the fastest. normally, while-wend should be the fastest, but its the slowest and repeat-until is ranked 2nd
PS2: having a good processor/fast ram increases speed very strong: i got ~250fps on my sempron 3000+ and about ~920fps on a athlon 3200+. what fps do you have? also, Devils Child has even more fps with writepixelfast, which is always slower on my PCs