slow runtime...

BlitzMax Forums/BlitzMax Beginners Area/slow runtime...

Zeptera(Posted 2005) [#1]
hi there,

when i use "drawpixmap" to draw a background image, and then "drawpixmap" again for a front image(player) its going very slow when my player moves to the left or right...? why does this happen? i know it has something to do with buffers, but the original "SetBuffer Backbuffer()" command is not there, and the manual docs are confusing me as hell!

does anyone know how to fix this?


skn3(Posted 2005) [#2]
DrawPixmap is intended for image manipulation in ram (slow). You should be looking at drawimage instead. Drawimage will draw an image loaded with LoadImage, which is stored in video memory (fast)


Zeptera(Posted 2005) [#3]
well,it somewhat worked...but the background image is totaly weird..! its like ten similiar programs in weird colors all running beside each other...

maybe its my graphics card...


tonyg(Posted 2005) [#4]
Zeptera, post your code as this doesn't make sense at the moment.
ALL images are drawn to the 'backbuffer' automatically which is why there is no 'setbuffer' in bmx. You still need to 'flip' though.


Zeptera(Posted 2005) [#5]
hi, thanks for replying... here is the code

Graphics 1024,768

mamma1=LoadImage("mamma1.jpg")
mamma2=LoadImage("mamma2.jpg")
mamma3=LoadImage("mamma3.jpg")
natur=LoadPixmap("natur.jpg")

playerx#=512
playery#=600

While Not KeyHit(KEY_ESCAPE)

'playernm=playernm

Cls

' SetColor (0,25,255)

' DrawText ("Welcome to my game!",0,750)
' DrawText ("" + playernm$,0,730 )

If KeyDown(KEY_UP)
playery=playery-5
' playernm=playernm+1
EndIf

If KeyDown(KEY_DOWN)
playery=playery+5
' playernm=playernm+1
EndIf

If KeyDown(KEY_LEFT)
playerx=playerx-5
' playernm=playernm+1
EndIf

If KeyDown(KEY_RIGHT)
playerx=playerx+5
' playernm=playernm+1
EndIf

If playerx > 960
playerx = 960
EndIf

If playerx < 0
playerx = 0
EndIf

' DrawPixmap natur,0,0

DrawImage mamma3,playerx,playery

Flip

Wend


End


teamonkey(Posted 2005) [#6]
That works fine for me. Can you take a screenshot to show us what's going wrong?


PowerPC603(Posted 2005) [#7]
I tried your code and when the DrawPixMap command is not commented, the other image Mamma3 goes slower and slower each game loop.
Is that the problem you described?

In the beginning it goes quite fast, but the longer the program is running, the Mamma3 picture can be repositioned slower and slower each game loop.

I tried adding a FlushMem right after the DrawPixMap command and now it is not slowing down anymore after each game loop.
DrawPixMap natur, 0, 0
FlushMem

It is still slow, but now it doesn't slow down each game loop.

If you want it faster, why not load the "natur.jpg" as an Image, using LoadImage and draw it with DrawImage?
That way it is MUCH faster.


ImaginaryHuman(Posted 2005) [#8]
Sometimes I wonder if the `slower and slower` problem is to do with pixmaps creating images as they are copied over and not freeing the images afterwards. .. ends up using virtual memory even. ??/


PowerPC603(Posted 2005) [#9]
I guess that would be the case, because after about 10 seconds, my entire system almost came to a complete halt.
Pressing Escape took about 5 seconds, before BMax executed the command to end the program.

That's why I tried the FlushMem command, and it seems to work.
Now the program runs at the same speed all the time, without my system coming to a almost complete halt.

Now when I start any program, it loads very slowly.
I think because my graphics memory is full (don't know for sure).
But this can be fixed easily by just rebooting.


Zeptera(Posted 2005) [#10]
thats the acctual problem...

its looks weird when i say : Loadimage and drawimage natur.jpg

i dont know how to take screenie...can you tell me?


tonyg(Posted 2005) [#11]
Zeptera, What do you mean? The first loads the image to memory, the second draws it to the backbuffer. It's the same as BlitzBasic.
I haven't found out how to take a BMX specific screen but somebody else suggest using 'print screen'.


PowerPC603(Posted 2005) [#12]
Did you try it with a different file (not natur.jpg)?

I tried it with a picture from my collection, and in both cases, they were displayed exactly the same (= shown correctly).

If it works with another picture, then open "natur.jpg" in a paint-package (Microsoft Paint for example) and resave it (preferably to a different file), then delete the original and replace it by the resaved file.
It could be that the format of "natur.jpg" is slightly corrupted.


Zeptera(Posted 2005) [#13]
ah well, "natur.jpg" is very colorful, taken with a nikon. I will try that way soon, thanks for posting!


Zeptera(Posted 2005) [#14]
heh...well iam using a mac so there is no "printscreen" here :D


tonyg(Posted 2005) [#15]
Services / screen / Grab Screen?


Zeptera(Posted 2005) [#16]
in game? i dont get that...


teamonkey(Posted 2005) [#17]
Use
Graphics 800,600,0

to run it in a window instead of full screen.


Zeptera(Posted 2005) [#18]
ah...when i use graphics 800,600,0 it works like it should(i mean the picture is there correctly), so why doesnt it work ok in 1024,768?


teamonkey(Posted 2005) [#19]
Does it work at 800x600 or 640x480 fullscreen?


Zeptera(Posted 2005) [#20]
yeah, but not in 1024,768...

thanks to all for answering!


Dreamora(Posted 2005) [#21]
perhaps it helps to speed up when using the right types for the images so it does not need to search them in the system again and again every loop?

mamma1:TImage=LoadImage("mamma1.jpg")
mamma2:TImage=LoadImage("mamma2.jpg")
mamma3:TImage=LoadImage("mamma3.jpg")
natur:TImage=LoadPixmap("natur.jpg")

( or TPixMap if pixmap is used )