Why so slow?!

BlitzPlus Forums/BlitzPlus Programming/Why so slow?!

Mero(Posted 2004) [#1]
I worked alot on Blitz3D, and that code ran fast, but in B+ it's awfully slow if I move picture about 640x480, for example, and even WinAMP is glitching!

SetBuffer CanvasBuffer(canvas)
Repeat
Cls
DrawImage imgBack, MouseX(), MouseY()
FlipCanvas canvas
Until MouseHit(1)

Why?
If I put Delay (30) at the end of the loop, it runs much more better...


Eikon(Posted 2004) [#2]
When moving to B+ you should take advantage of the event structure. See if this does any better:

AutoSuspend 1
CreateTimer 60
Repeat
    Select WaitEvent()
        Case $803: Exit ; X Closes the program
        
        Case $4001      ; Timer tick event (60 fps)
        Cls

        DrawImage imgBack, MouseX(Canvas), MouseY(Canvas)

        FlipCanvas Canvas, 1
 
    End Select
Forever



Mero(Posted 2004) [#3]
Thanks alot,
it works really fast, but it doesn't really describe why my code is so slow... where's the real reason of my code of being so slow, does anybody knows? :) 8)


Eikon(Posted 2004) [#4]
Because your previous loop is only giving the CPU time with the FlipCanvas true statement. Here we have frame limiting as well which means we are only executing the code every 60ms.

You could modify your old code like this:
SetBuffer CanvasBuffer(canvas)
Timer = CreateTimer(60)
Repeat
Cls
DrawImage imgBack, MouseX(), MouseY()
FlipCanvas canvas: WaitTimer Timer
Until MouseHit(1) 
to achieve the same effect.


Warren(Posted 2004) [#5]
Or try throwing in a "delay(10)" after the flip. That will give up the processor to other tasks that want it.


Mero(Posted 2004) [#6]
OK, it seems quite simple... This way I'll give CPU a little time to wait while graphic data is sending to the videocard?