Type

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

 

Mathe

Betreff: Type

BeitragFr, Jan 23, 2009 17:42
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,

ich hab mich mal aus langweile an einer einfachen Kosinus- und Sinusberechnung gehockt nun jetzt hab ich ein Problem wenn ich 11 Bälle hinzufüge braucht der PC schon 10 bis 15 Millisekunden um alle Bälle zu zeichnen. Was kann ich dagegen tun?

Bälle hinzufügen mit Mausklick(links):
Code: [AUSKLAPPEN]

Graphics 640,480,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
;
Global baelle%
;
Type Ball
   Field X%,Y%
   Field BallG%
   Field alpha%
   Field speed#
End Type
;
Repeat
   Cls
   NewBall()
   UpdateBall()
   Flip
Until KeyHit(1) End
;
Function UpdateBall()
draw% = MilliSecs()
For ba.Ball = Each Ball
   z = z + 1
   xcos# = ba\speed*(ba\BallG*Cos(ba\alpha))
   rxcos% = xcos
   ysin# = ba\speed*(ba\BallG*Sin(ba\alpha))
   rysin% = ysin
   Xtest% = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   Ytest% = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   If Xtest >= 640 - ba\BallG + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest >= 480 - ba\BallG + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Or Xtest <= 0 + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest <= 0 + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Then ba\alpha = ba\alpha + 90
   If ba\alpha > 360 Then ba\alpha = ba\alpha - 360
   
   ba\X = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   ba\Y = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   
   Color 255,255,255
   Oval ba\X,ba\Y,ba\BallG,ba\BallG,0
   Color 255,0,0
   Line ba\X + ba\BallG/2,ba\Y + ba\BallG/2, ba\X + ba\BallG/2 + ba\BallG*Cos(ba\alpha), ba\Y + ba\BallG/2 + ba\BallG*Sin(ba\alpha)
   
   ;If z = 1 Then
   ;   Text 640/2,0, "XCos: " + xcos + " / rXCos: " + rxcos + " / Xball: " + ba\X,1
   ;   Text 640/2,15, "YCos: " + ysin + " / rYSin: " + rysin + " / Yball: " + ba\Y,1
   ;   
   ;EndIf
Next
Text 640/2,0, "RenderingTime: " + (MilliSecs()- draw) + " m/s",1
Text 640/2,15, "Bälle: " + baelle,1
End Function
;
Function NewBall()
If MouseHit(1) Then
baelle = baelle + 1
   ba.Ball = New Ball
      ba\X = MouseX()
      ba\Y = MouseY()
      ba\BallG = Rand(10,40)
      ba\alpha = Rand(0,360)
      ba\speed = Rnd(0.1,0.9) ;ba\speed = 0.1
Else
   Oval MouseX(),MouseY(),5,5,0
EndIf
End Function

the FR3AK

BeitragFr, Jan 23, 2009 17:45
Antworten mit Zitat
Benutzer-Profile anzeigen
Draw3D benutzen, denn die Draw Befehle von B3D sind langsam...

Noobody

BeitragFr, Jan 23, 2009 18:02
Antworten mit Zitat
Benutzer-Profile anzeigen
Das Problem liegt bei der Ovalfunktion - die verbraucht in Blitz extrem viel Rechenleistung.
Entweder nimmst du die Ovalfunktion im Codearchiv, die ist schon ein Stück schneller, oder du machst im Voraus ein Bild mit einem Kreis, lädst dieses und zeichnest es ein.
Die Draw3D ist natürlich auch eine Lösung, aber wenn es nur um die Kreise geht, musst du ja nicht gleich auf 3D - Beschleunigung umsteigen Wink
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun
 

Mathe

BeitragFr, Jan 23, 2009 18:27
Antworten mit Zitat
Benutzer-Profile anzeigen
hmmm... dazu müssen aber pro Ball ein Neues Bild erstellt werden denn die Bälle hab unterschiedliche Größen...
Das wären dann rund 30 Bälle...
Rand(10,40)

Goodjee

BeitragFr, Jan 23, 2009 18:47
Antworten mit Zitat
Benutzer-Profile anzeigen
30 bilder sind nichts...
"Ideen sind keine Coladosen, man kann sie nicht recyclen"-Dr. House
http://deeebian.redio.de/ http://goodjee.redio.de/

Xaymar

ehemals "Cgamer"

BeitragFr, Jan 23, 2009 18:49
Antworten mit Zitat
Benutzer-Profile anzeigen
11-15ms? naja ich hab nen schnelleren pc und nur 0-1ms bei 25 bällen, bei ca 50 bällen dann 55ms

aber gleich auf 3d umsteigen is wirklich n bisschen heftig.

meine lösung: erstelle die bilder im code!
beispiel:
Code: [AUSKLAPPEN]
ballw=40:ballh=40
ball = CreateImage(ballw,ballh)
SetBuffer ImageBuffer(ball)
Oval 0,0,ballw-1,ballh-1,0
SetBuffer BackBuffer()


auf deinen Code übertragen:
Code: [AUSKLAPPEN]
Graphics 640,480,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
;
Global baelle%
;
Type Ball
   Field X%,Y%
   Field BallG%
   Field alpha%
   Field speed#
   Field bild
End Type
;
Repeat
   Cls
   NewBall()
   UpdateBall()
   Flip
Until KeyHit(1) End
;
Function UpdateBall()
draw% = MilliSecs()
For ba.Ball = Each Ball
   z = z + 1
   xcos# = ba\speed*(ba\BallG*Cos(ba\alpha))
   rxcos% = xcos
   ysin# = ba\speed*(ba\BallG*Sin(ba\alpha))
   rysin% = ysin
   Xtest% = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   Ytest% = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   If Xtest >= 640 - ba\BallG + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest >= 480 - ba\BallG + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Or Xtest <= 0 + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest <= 0 + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Then ba\alpha = ba\alpha + 90
   If ba\alpha > 360 Then ba\alpha = ba\alpha - 360
   
   ba\X = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   ba\Y = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   DrawImage ba\bild,ba\X,ba\Y
   Color 255,0,0
   Line ba\X + ba\BallG/2,ba\Y + ba\BallG/2, ba\X + ba\BallG/2 + ba\BallG*Cos(ba\alpha), ba\Y + ba\BallG/2 + ba\BallG*Sin(ba\alpha)
   
   ;If z = 1 Then
   ;   Text 640/2,0, "XCos: " + xcos + " / rXCos: " + rxcos + " / Xball: " + ba\X,1
   ;   Text 640/2,15, "YCos: " + ysin + " / rYSin: " + rysin + " / Yball: " + ba\Y,1
   ;   
   ;EndIf
Next
Text 640/2,0, "RenderingTime: " + (MilliSecs()- draw) + " m/s",1
Text 640/2,15, "Bälle: " + baelle,1
End Function
;
Function NewBall()
If MouseHit(1) Then
baelle = baelle + 1
   ba.Ball = New Ball
      ba\X = MouseX()
      ba\Y = MouseY()
      ba\BallG = Rand(10,40)
      ba\alpha = Rand(0,360)
      ba\speed = Rnd(0.1,0.9) ;ba\speed = 0.1
      ba\bild = CreateImage(ba\BallG,ba\BallG)
      SetBuffer ImageBuffer(ba\bild)
      Color 255,255,255
      Oval 0,0,ba\BallG,ba\BallG,0
      SetBuffer BackBuffer()
Else
   Oval MouseX(),MouseY(),5,5,0
EndIf
End Function
Warbseite
 

Zauberwürfel

BeitragFr, Jan 23, 2009 19:23
Antworten mit Zitat
Benutzer-Profile anzeigen
Dann muss er die Bälle ja immer noch erstellen ;D
Ja ich bin audiophil. Jetzt ist es raus.

TimBo

BeitragSa, Jan 24, 2009 1:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab mir nicht alles durchgelesen, mach aber mal Flip 0, wenn du den Speed ermitteln willst.

Wenn es schon gesagt wurde, pech Laughing
Viele Grüße
TimBo
mfg Tim Borowski // CPU: Ryzen 2700x GPU: Nvidia RTX 2070 OC (Gigabyte) Ram: 16GB DDR4 @ 3000MHz OS: Windows 10
Stolzer Gewinner des BCC 25 & BCC 31
hat einen ersten Preis in der 1. Runde beim BWInf 2010/2011 & 2011/12 mit BlitzBasic erreicht.
 

Mathe

BeitragSa, Jan 24, 2009 11:00
Antworten mit Zitat
Benutzer-Profile anzeigen
so ich hab jetzt 30 Kreise zeichnen lassen und jetzt brauch ich bei 100 Bilder gerade mal 1 - 2 ms...

danke
Code: [AUSKLAPPEN]

Graphics 640,480,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
;
Global baelle%
;
Type Ball
   Field X%,Y%
   Field BallG%
   Field alpha%
   Field speed#
   Field image
End Type
;
Dim Image(30)
;
Repeat
   Image(b) = CreateImage(b+10,b+10)
   SetBuffer ImageBuffer(Image(b))
   Color 255,255,255
   Oval 0,0,b+10,b+10,0
   SetBuffer BackBuffer()
   b = b + 1
Until b > 30
   
Repeat
   Cls
   NewBall()
   UpdateBall()
   Flip
Until KeyHit(1) End
;
Function UpdateBall()
draw% = MilliSecs()
For ba.Ball = Each Ball
   z = z + 1
   xcos# = ba\speed*(ba\BallG*Cos(ba\alpha))
   rxcos% = xcos
   ysin# = ba\speed*(ba\BallG*Sin(ba\alpha))
   rysin% = ysin
   Xtest% = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   Ytest% = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   If Xtest >= 640 - ba\BallG + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest >= 480 - ba\BallG + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Or Xtest <= 0 + Int(ba\speed*(ba\BallG*Cos(ba\alpha))) Or Ytest <= 0 + Int(ba\speed*(ba\BallG*Sin(ba\alpha))) Then ba\alpha = ba\alpha + 90
   If ba\alpha > 360 Then ba\alpha = ba\alpha - 360
   
   ba\X = ba\X + ba\speed*(ba\BallG*Cos(ba\alpha))
   ba\Y = ba\Y + ba\speed*(ba\BallG*Sin(ba\alpha))
   
   
   DrawImage ba\Image, ba\X,ba\Y
   
   ;If z = 1 Then
   ;   Text 640/2,0, "XCos: " + xcos + " / rXCos: " + rxcos + " / Xball: " + ba\X,1
   ;   Text 640/2,15, "YCos: " + ysin + " / rYSin: " + rysin + " / Yball: " + ba\Y,1
   ;   
   ;EndIf
Next
Text 640/2,0, "RenderingTime: " + (MilliSecs()- draw) + " m/s",1
Text 640/2,15, "Bälle: " + baelle,1
End Function
;
Function NewBall()
If MouseHit(1) Then
baelle = baelle + 1
   ba.Ball = New Ball
      ba\X = MouseX()
      ba\Y = MouseY()
      ba\BallG = Rand(10,40)
      ba\image = Image(40 - ba\BallG)
      ba\alpha = Rand(0,360)
      ba\speed = Rnd(0.1,0.9) ;ba\speed = 0.1
Else
   Oval MouseX(),MouseY(),5,5,0
EndIf
End Function

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group