Main Menu

performance of commands?

Started by stef, October 23, 2005, 01:13:03 PM

Previous topic - Next topic

stef

Hi!

Is it a difference between the command "rotatesprite" and "turnsprite"?
Is one faster?

What dimensions can a sprite have?
Is it only in size of power of 2 like 8x8, 16x16, 64x64, etc.

Greetings
stef

kevin

#1
Quotes it a difference between the command "rotatesprite" and "turnsprite"?
Is one faster?


TurnSprite rotates the sprite left/right.  

Is basically this operation

PlayBASIC Code: [Select]
 Angle#=GetSpriteAngle(ThisSprite)
RotateSprite ThisSprite,WrapAngle(Angle#,TurnAmountinDegrees#)






QuoteWhat dimensions can a sprite have?
Is it only in size of power of 2 like 8x8, 16x16, 64x64, etc.

Any.  A general rule is smaller is better.

stef

#2
Hi!

Have a "small" problem.

Running code below you can see, that filled ellipses are vanishing too early (in minimizing).

Maybe you can fix this.

Greetings
stef

PlayBASIC Code: [Select]
; PROJECT : r2
; AUTHOR : stef
; CREATED : 28.11.2005
; EDITED : 28.11.2005
; ---------------------------------------------------------------------





OpenScreen 800,600,32,2

RenderToScreen

For x = 1.0 To 12.0
fac1#= (100000/x)
fac#= fac1#/100000


EllipseC 120*fac#+400*(1-fac#),100,10*fac#,20*fac#,0,RGB(240,240,0)
EllipseC 120*fac#+400*(1-fac#),150,10*fac#,20*fac#,1,RGB(240,240,0)
CircleC 120*fac#+400*(1-fac#),200,20*fac#,0,RGB(240,240,0)
CircleC 120*fac#+400*(1-fac#),250,20*fac#,1,RGB(240,240,0)


Print fac1#
Print fac#

Next


Sync
WaitKey

End






stef

#3
Hi!

Maybe you can fix this:

Thanks in advance!


x#=6.78
y#=0.23
z#=x#^y#

z1#=6.78^0.23

print "z#="+str$(z#)
print "z1#="+str$(z1#)
sync
waitkey




Fixed in PB v1.12

stef

Hi!

I don't want to get on nerves
It seems to be a simple rounding error.
I think it's necessary to fix it.

Greetings
stef

kevin

Yes, it's caused by a bad round in pre-solve pass.   Don't panic, it's listed on my to do list, so I will certainly get to it.   With any luck it'll be corrected in the next patch.

stef

Hi!

That's not a really a bug, but I have speed-problems with fractal calc.

The example (it generates a fractal pixel by pixel) below is TOO slow. I think i should be at least 10 times faster.
Do somebody know the reason?

Thanks and Greetings
stef


openscreen 640,480,16,1

x#=-1.257
y#=-0.126
z#=0.02
z2#=0.015

For ypoint=0 To 479
For xpoint=0 To 639
x1#=x#+(z#/640)*xpoint
y1#=y#+(z2#/480)*ypoint
x2#=x#+(z#/640)*xpoint
y2#=y#+(z2#/480)*ypoint

 For b=0 To 200
  x3#=x2#*x2#-y2#*y2#+x1#
  y3#=2*x2#*y2#+y1#
  a#=Sqrt(x3#*x3#+y3#*y3#)
  x2#=x3#
  y2#=y3#
  If a#>=2.0 Then Exit
 Next
If a#>2.0
 r=255-b
 g=0
 b=50+b

 col1=lsl32(r,16)+g+b

 dotc xpoint,ypoint,col1

 EndIf

sync
Next
Next

WaitKey
End


kevin

#7
QuoteDo somebody know the reason?

Well, that's easy, your trying to run a brute operation (ie running 640*480 * possibly 200 iterations) through the current VM.

While the new VM is about 2 to 3 timers faster than the current speed,  it would still  choke on that level of brute force iterations.   The only real option is to reduce the work load (the number of operations per pixel) being performed.

You can do that by using built in functions over rolling your own and via shifting redundant calculations outside the inner loops. Also syncing less

A bit like.


PlayBASIC Code: [Select]
openscreen 640,480,16,1

x#=-1.257
y#=-0.126
z#=0.02
z2#=0.015


zover640#=z#/640

For ypoint=0 To 479
Tempy1#=y#+(z2#/480)*ypoint
// Tempy2#=y#+(z2#/480)*ypoint

lockbuffer
For xpoint=0 To 639
y1#=Tempy1#
y2#=y1#
x1#=x#+zover640#*xpoint
x2#=x1#

For b=0 To 200
x3#=x2#*x2#-y2#*y2#+x1#
y3#=2*x2#*y2#+y1#
if getdistance2d(0,0,x3#,y#)>=2.0
dotc xpoint,ypoint,rgb(255-b,g,b+50)
exit
endif
x2#=x3#
y2#=y3#
Next

Next
unlockbuffer

if mod(ypoint,5)=0 then sync

Next


WaitKey
End





stef

Hi!

Thanks for fast reply!

It was of course a 'brute operation' and your code works much faster now.

What do you mean with 'VM'? I think 'virtual machine'?

What's the difference between 'old  VM' and 'new VM'?

Both codes from above you can't really run in fullscreenmode.Is this also VM related?

Greetings
stef

stef

#9
Hi!

The code below (480000 red points) needs about 10sec on my laptop.

(what about command 'dotfastc' ?)

edit:with 'lockbuffer' the code needs 3sec


tim1=timer()
For ypoint=0 To 599
For xpoint=0 To 799

 dotc xpoint,ypoint,rgb(255,0,0)
 
Next
Next
tim2=timer()
print tim2-tim1
sync
WaitKey
End

kevin

QuoteWhat do you mean with 'VM'? I think 'virtual machine'?

  Yes.

QuoteWhat's the difference between 'old VM' and 'new VM'?

  A better question is, what is the 'same'    Virtually Nothing internally !

QuoteBoth codes from above you can't really run in fullscreenmode.Is this also VM related?

  Yeah, the majority of it would be.  I doubt, it'll be capable of such brute force until we've implemented at least pointers and some 'compile on demand' features, or built a 'produce native binary' translation layer.    
 

  Dots.

 While there's some definite baggage on the dot command.  I'm not sure if there's much to be gained in implementing a stripped version (ie. assumes locked buffer and colour in buffer format).   Since it still requires various control changes to just fill one dot.  But we could try it...

  I had been thinking about a DrawArray command.  Which would take an array (1d, or 2d ) of  32bit rgb and draw them to the current buffer.   That'd prolly give faster results in the sort term.    But that's an untested theory

stef

#11
Hi Kevin!

I know you are a hard working man! (It seems that you never sleeps :) )

But I am working for days on the code (shorten) below.

Don't know why it crashes.
The problem is function dotscolor()

Run it in debug mode!!!!!!!!!!!!!!!!!




Global maxiter#=128


w# = 640  
h# = 480  


openscreen  w#, h#, 16, 1
  xstart# = -2.025
  ystart# = -1.125
  xende# = 0.6
  yende# = 1.125
 
  fac#=0.999


do
     Cls 0
     xende# = xende#*fac#
     xstart#=xstart#*fac#
     ystart#=ystart#*fac#
     yende#=yende#*fac#
     xzoom# = (xende# - xstart#) / w#
     yzoom# = (yende# - ystart#) / h#
     
     mandelbrot(w#, h#, xstart#, ystart#, xzoom#, yzoom#)

     sync
loop
End


Function mandelbrot(w1#, h1#, xstart1#, ystart1#, xzoom1#, yzoom1#)

 ;LockBuffer
  For x# = 0 To w1#-1
     For y# = 0 To h1#-1
        h# = DotsColor(xstart1# + xzoom1# * x#, ystart1# + yzoom1# * y#)
       ;etc
       ;
        dotc x#, y#, rgb(255,0,0);test
     
     Next
  Next
 ;UnlockBuffer
EndFunction


function DotsColor(xval#, yval#)

 While (j# < maxiter#) And (m# < 4.0)
 
 j#=j#+1.0  
     m# = r# * r# - i# * i#
     i# = 2.0 * r# * i# + yval#
     r# = m# + xval#

endwhile

  j1# = j# / maxiter#
 
EndFunction j1#



kevin

#12
At a quick look, something (R#) is hitting infinity.  Which ='s  crash the VM..  I've No Idea why this happens.


PlayBASIC Code: [Select]
function DotsColor(xval#, yval#)
#print "Dot Colour"
While (j# < maxiter#) And (m# < 4.0)
j#=j#+1.0
m# = r# * r# - i# * i#
i# = 2.0 * r# * i# + yval#
r# = m# + xval#
#print r#
#break
endwhile

j1# = j# / maxiter#

EndFunction j1#


stef

#13
Hi!

Yes it's working with 'abs(r#)

Will present it in folder 'source codes' under 'appleman'

But have still the feeling something is blocking te program.
Should run faster.

Greetings
stef

kevin

#14
Stef,

  I've been working on a way to help out with some brute force calculations. Basically I'm trialing a specialized function to resolve the expression manually.   Now the results aren't mind blowing mind you, but there certainly a big improvement over the original version (was testing the code you posted here)

  The original takes about 90-95 seconds on my duron 800mhz,  the Pb1.11 revision takes 63/65 seconds and the latest version (in PB1.12 - will release a patch over the weekend)  has shaved another 15 seconds off that.  So it'll do in about 48-51 seconds.  

 Not a  brilliant improvement, but it's something for the time being.  


PlayBASIC Code: [Select]
openscreen 640,480,16,1
createcamera 1
cameracls 1,off
x#=-1.257
y#=-0.126
z#=0.02
z2#=0.015


SyncEvery=10

StartTime=timer()

zover640#=z#/640
two#=2
For ypoint=0 To 479
Tempy1#=y#+(z2#/480)*ypoint
// Tempy2#=y#+(z2#/480)*ypoint

capturetoscene
clsscene
For xpoint=0 To 639
y1#=Tempy1#
y2#=y1#
fastcalc x1#=zover640#*xpoint+x#
x2#=x1#

temp#=0
For b=0 To 200
fastcalc x3#=y2#*y2#=temp#,x2#*x2#-temp#+x1#
fastcalc y2#=two#*x2#*y2#+y1#
if getdistance2d(0,0,x3#,y2#)>=2.0
dotc xpoint,ypoint,rgb(255-b,g,b+50)
exit
endif
x2#=x3#
Next

Next
drawcamera 1

gosub ShowINfo

Next



WaitKey
End


ShowINfo:
boxc 0,0,100,30,true,0
f=fps()
text 0,0,f
text 50,0,(640*SyncEvery)
text 0,15,(timer()-starttime)/1000.0

if mod(ypoint,SyncEvery)=0 then sync
;'sync
return