Too too slow

Discuss any general programming issues here
Post Reply
ArtBlink
Posts: 484
Joined: Mon Nov 01, 2010 10:37 am
Location: Albert - France
Contact:

Too too slow

Post by ArtBlink »

Hello, try this cde

Code: Select all

@SCREEN {Mode="Ask",Width=800, Height=600}

SetFillStyle(#FILLCOLOR)
SetFontStyle(#EDGE, #BLACK, 1)
CreateBrush(1,32,64,$000000)
SelectBrush(1)
Circle(1,0,11,$AA0000)
Circle(9,0,11,$AA0000)
Box(2,6,28,60,$AA0000)
Box(5,22,22,10,$111111,{RoundLevel = 50})
Box(5,50,22,5,$111111,{RoundLevel = 50})
Box(5,30,21,20,$CC0000)
SetFillStyle(#FILLNONE)
Line(5,30,5,50,$111111)
Line(26,30,26,50,$111111)
Line (31,0,31,64,$000000)
Line (5,21,6,6,$880000)
Line (26,21,25,6,$880000)
Line (6,6,9,3,$880000)
Line (25,6,22,3,$880000)
Line (9,3,22,3,$880000)
Box(6,56,20,8,$880000)
EndSelect
SetBrushTransparency(1, #BLACK)
X=320 
Y=50 
Angle=0 
vitesse=0 
SetFillStyle(#FILLCOLOR)
SetFormStyle(#EDGE, #BLACK, 1)
SetFormStyle(#ANTIALIAS)

Function supercar()
	Flip
	Cls
	Local Avance = IsKeyDown("UP") 
	Local Recule = IsKeyDown("Down") 
	Local Droite = IsKeyDown("RIGHT") 
	Local Gauche = IsKeyDown("LEFT")

	If Avance = True 
		Vitesse=vitesse+0.3
		If vitesse>10 Then vitesse=10
	Else
		If vitesse>0
			vitesse=vitesse-0.1
		EndIf
	EndIf
	
	If Recule = True
		Vitesse=vitesse-0.5
		If vitesse<-5 Then vitesse=-5
	Else
		If vitesse<0 
			vitesse=vitesse+0.2
		EndIf
	EndIf
	
	If vitesse>0 And vitesse<0.1 Then vitesse=0
	Radians=Angle*0.01745
	X=X+Cos(Radians)*vitesse
	Y=Y-Sin(Radians)*vitesse
	If X>680 Then X=-40
	If X<-40 Then X=680
	If Y<-40 Then Y=520
	If Y>520 Then Y=-40
	If vitesse<>0
		If Droite = True Then Angle=Angle-4
		If Gauche = True Then Angle=Angle+4
	EndIf
	Box(0,0,640,480,#GREEN)
	Box(10,10,620,460,$555555,{RoundLevel = 50})
	Box(100,100,440,280,#GREEN,{RoundLevel = 50})
	TextOut(0,0,"vitesse : ")
	TextOut(80,0,Round(Abs(vitesse*10)))
	TextOut(110,0,"Km/h")
	TextOut(#CENTER,150,"INSTRUCTION")
	TextOut(#CENTER,160,"-----------")
	TextOut(#CENTER,180,"Fleche HAUT pour accélérer")
	TextOut(#CENTER,190,"Fleche Bas pour Freiner-reculer")
	TextOut(#CENTER,200,"Fleche droite et gauche pour la rotation de la tuture")
	TextOut(#CENTER,240,"ATTENTION")
	TextOut(#CENTER,250,"---------")
	TextOut(#CENTER,270,"Vous ne pouvez pas faire tourner la voiture")
	TextOut(#CENTER,280,"si elle ne roule pas ;-)")
	DisplayBrush(1,X,Y,{AnchorX = 0.5, AnchorY = 0.5,rotate=-90+Angle})
	
EndFunction
SetInterval (1,supercar,40)
BeginDoubleBuffer

Repeat
	WaitEvent
Forever
You see? the result is too slow, on A1200 with amos the same programm turn at 25 FPS... Why on Amiga NG, this small script is slow?

I don't understand the problem. You know what is it the problem?

Help, i want to finish this game
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Too too slow

Post by jalih »

Hello,

Try to minimize all function calls. You should probably pre-draw the whole race track into brush, so in a game loop you can draw it with one DisplayBrush() call.

you can also substitude these:

Code: Select all

   Radians=Angle*0.01745
   X=X+Cos(Radians)*vitesse
   Y=Y-Sin(Radians)*vitesse
   If X>680 Then X=-40
   If X<-40 Then X=680
   If Y<-40 Then Y=520
   If Y>520 Then Y=-40
with this:

Code: Select all

	Radians=Angle*0.01745
	X=X+Cos(Radians)*vitesse
	Y=Y-Sin(Radians)*vitesse
	X=(X + 800) % 800
	Y=(Y + 600) % 600
or you can use Wrap() function.
ArtBlink
Posts: 484
Joined: Mon Nov 01, 2010 10:37 am
Location: Albert - France
Contact:

Re: Too too slow

Post by ArtBlink »

Thanks, but Wrap command is more more slower than If test in CPU times :-(

After some speed test... vector display command is too slow, so, i have make scroll with bitmap bank and the game turn at 27 FPS on A1 800Mhz
Post Reply