Seite 1 von 3

Punkte, Kreise & Geschwindigkeiten

Verfasst: 04.09.2008 19:36
von Captain_Qwark
Hallo PB'ler

Ich habe mir vor einer Weile PB zugelegt und verstauben lassen. Nun hab ich mich aber endlich aufgerafft und (mal wieder) mit den Programmieren angefangen. Als Einstieg sollte es was einfaches sein: Ein kleines Sternenfeld das von Rechts nach Links saust. Das klappt auch alles ganz gut, aber mir ist da etwa seltsames aufgefallen:

Codeschnippsel 1

Code: Alles auswählen

Procedure StarsDraw()
	ClearScreen(RGB(0, 0, 0))
	StartDrawing(ScreenOutput())
		For myCounterA = 0 To #myStarsQuantity Step 1
			Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
			Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
			Plot(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, RGB(200, 200, 200))
		Next myCounterA
	StopDrawing()
	FlipBuffers()
EndProcedure
Codeschnippsel 2

Code: Alles auswählen

Procedure StarsDraw()
	ClearScreen(RGB(0, 0, 0))
	StartDrawing(ScreenOutput())
		For myCounterA = 0 To #myStarsQuantity Step 1
			Circle(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, 1, RGB(100, 100, 100))
			Circle(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, 1, RGB(150, 150, 150))
			Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 1, RGB(200, 200, 200))
		Next myCounterA
	StopDrawing()
	FlipBuffers()
EndProcedure
Codeschnippsel 3

Code: Alles auswählen

Procedure StarsDraw()
	ClearScreen(RGB(0, 0, 0))
	StartDrawing(ScreenOutput())
		For myCounterA = 0 To #myStarsQuantity Step 1
			Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
			Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
			Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
		Next myCounterA
	StopDrawing()
	FlipBuffers()
EndProcedure
Der 1. Code ist der schnellste, sind ja auch nur Punkte. Beim 2. wird das ganze etwas träger, logisch hat ja eine ganze Menge Kreise zu Pinseln. Aber der 3. Code geht ja mal gar nicht: Wenn ich Kreis und Punktfunktionen mische, ist die Geschwindigkeit geringer als bei "Kreise-Only"

Meine Frage: Warum? Es sind doch weniger Kreise zu zeichnen?

M.f.G
Captain Qwark

P.S. PureBasic Version ist die 4.0 und das ganze läuft in einem WindowedScreen.

Verfasst: 04.09.2008 19:53
von Kaeru Gaman
Hi Qwark, willkommen im Forum!
(und Vorsicht, Ratchet läuft hier auch rum... *kicher*)

also, testen kann ichs jetzt nich so einfach, müßte man ja ein gerüst drumrum bauen...
am besten postest du immer codes, die man direkt per copy/paste in die PB-IDE einfügen kann,
dann sind die anderen fleißiger mit mal-eben-testen... ;)

also, was mir auffällt:
in deinem dritten code hast du radius 2, bei dem zweiten die drei kreise mit radius 1.
natürlich muss radius 2 mehr pixel in den kreis malen, und das dauert länger... ;)


grundsätzlich:
1. für so etwas ist es vielleicht besser, Sprites zu verwenden, die sind schneller als Draw.
2. im grunde solltest du etwas anders organisieren,
damit du den vorderen Layer wirklich komplett über die anderen zeichnest,
im moment zeichnest du ja alle drei durcheinander.
eigentlich brauchst du drei schleifen hintereinander, zuerst für Back,
dann für Middle, dann für Front.
3. bei Starfields mach ich persönlich das gerne so,
dass ich die neuberechnung in die selbe schleife packe wie das zeichnen,
dann muss ich das koordinaten-array nicht 2x durchdaddeln.

Verfasst: 04.09.2008 20:03
von marco2007
Kaeru Gaman hat geschrieben:(und Vorsicht, Ratchet läuft hier auch rum... *kicher*)
:mrgreen:

Verfasst: 04.09.2008 20:13
von Captain_Qwark
Erstmal Danke für die schnelle(n) Antwort(en). Das mit den 3 Ebenen ist mir garnicht aufgefallen, werd ich wohl noch ändern müssen :)

Hier mal der ganze Code zum testen und ausprobieren:

Code: Alles auswählen

;	========================================================================
	Enumeration
		#myWindowID
	EndEnumeration

	#myWindowWidth = 800 : #myWindowHeight = 600 : #myStarsQuantity =  150
	#myStarSpeedF  = 1.5 : #myStarSpeedM   =   1 : #myStarSpeedB    =  0.5

;	========================================================================
	Structure ntStarType
		PositionX.f
		PositionY.f
	EndStructure

	Global Dim StarsLayerF.ntStarType(#myStarsQuantity)
	Global Dim StarsLayerM.ntStarType(#myStarsQuantity)
	Global Dim StarsLayerB.ntStarType(#myStarsQuantity)

	Global myEvent.l    = 0 : Global myKeyPressed.l = 0
	Global myCounterA.w = 0

;	========================================================================
	Procedure StarsCalculate()
		For myCounterA = 0 To #myStarsQuantity Step 1
			If (StarsLayerB(myCounterA)\PositionX - #myStarSpeedB) < 0
				StarsLayerB(myCounterA)\PositionX = #myWindowWidth -1
				StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
			Else
				StarsLayerB(myCounterA)\PositionX = StarsLayerB(myCounterA)\PositionX - #myStarSpeedB
			EndIf
			
			If (StarsLayerM(myCounterA)\PositionX - #myStarSpeedM) < 0
				StarsLayerM(myCounterA)\PositionX = #myWindowWidth -1
				StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
			Else
				StarsLayerM(myCounterA)\PositionX = StarsLayerM(myCounterA)\PositionX - #myStarSpeedM
			EndIf
			
			If (StarsLayerF(myCounterA)\PositionX - #myStarSpeedF) < 0
				StarsLayerF(myCounterA)\PositionX = #myWindowWidth -1
				StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
			Else
				StarsLayerF(myCounterA)\PositionX = StarsLayerF(myCounterA)\PositionX - #myStarSpeedF
			EndIf
		Next myCounterA
	EndProcedure

	Procedure StarsDraw()
		ClearScreen(RGB(0, 0, 0))
		StartDrawing(ScreenOutput())
			For myCounterA = 0 To #myStarsQuantity Step 1
				Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
				Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
				Plot(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, RGB(200, 200, 200))
			Next myCounterA
		StopDrawing()
		FlipBuffers()
	EndProcedure

;	========================================================================
	If Not InitSprite()
		MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitSprite( )", #PB_MessageRequester_Ok ) : End
	EndIf

	If Not InitKeyboard()
		MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitKeyboard( )", #PB_MessageRequester_Ok ) : End
	EndIf

	If Not OpenWindow(#myWindowID, 0, 0, #myWindowWidth, #myWindowHeight, "Sternenfeld", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
		MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindow( )", #PB_MessageRequester_Ok ) : End
	EndIf

	If Not OpenWindowedScreen(WindowID(#myWindowID), 0, 0, #myWindowWidth, #myWindowHeight, 0, 0, 0)
		MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindowedScreen( )", #PB_MessageRequester_Ok ) : End
	EndIf

;	========================================================================
	For myCounterA = 0 To #myStarsQuantity Step 1
		StarsLayerB(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
		StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

		StarsLayerM(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
		StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

		StarsLayerF(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
		StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
	Next myCounterA

;	========================================================================
	Repeat
		myEvent = WaitWindowEvent(10)
		ExamineKeyboard()
		If KeyboardPushed(#PB_Key_Escape)
			myKeyPressed = #PB_Key_Escape
		EndIf
		StarsCalculate()
		StarsDraw()
	Until myKeyPressed = #PB_Key_Escape

;	========================================================================
	End

;	========================================================================
M.f.G
Captain Qwark

P.S. Ja der Ratchet sucht den Clank :)

Verfasst: 04.09.2008 20:28
von Kaeru Gaman
also, du musst in der dritten routine einen hammer-tippfehler drinhaben,
muss ich nochmal buchstabengenau vergleichen,
aber die ist ja EXTREM langsamer, das darf nicht sein.
wenn ich beim zweiten den Radius beim dritten circle durch 2 ersetze, ist es immer noch flüssig.
also, da muss irgendwo der teufel im detail stecken....

PS:
also ich hab jetzt mehrfach rumkopiert aus den anderen routinen,
immer wenn man plot und circle in der selben schleife mischt,
kommt so ein langsames gezuckel raus...

kann das noch jemand bestätigen? :shock:

Code: Alles auswählen

;   ========================================================================
   Enumeration
      #myWindowID
   EndEnumeration

   #myWindowWidth = 800 : #myWindowHeight = 600 : #myStarsQuantity =  150
   #myStarSpeedF  = 1.5 : #myStarSpeedM   =   1 : #myStarSpeedB    =  0.5

;   ========================================================================
   Structure ntStarType
      PositionX.f
      PositionY.f
   EndStructure

   Global Dim StarsLayerF.ntStarType(#myStarsQuantity)
   Global Dim StarsLayerM.ntStarType(#myStarsQuantity)
   Global Dim StarsLayerB.ntStarType(#myStarsQuantity)

   Global myEvent.l    = 0 : Global myKeyPressed.l = 0
   Global myCounterA.w = 0

;   ========================================================================
   Procedure StarsCalculate()
      For myCounterA = 0 To #myStarsQuantity Step 1
         If (StarsLayerB(myCounterA)\PositionX - #myStarSpeedB) < 0
            StarsLayerB(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
         Else
            StarsLayerB(myCounterA)\PositionX = StarsLayerB(myCounterA)\PositionX - #myStarSpeedB
         EndIf
         
         If (StarsLayerM(myCounterA)\PositionX - #myStarSpeedM) < 0
            StarsLayerM(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
         Else
            StarsLayerM(myCounterA)\PositionX = StarsLayerM(myCounterA)\PositionX - #myStarSpeedM
         EndIf
         
         If (StarsLayerF(myCounterA)\PositionX - #myStarSpeedF) < 0
            StarsLayerF(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
         Else
            StarsLayerF(myCounterA)\PositionX = StarsLayerF(myCounterA)\PositionX - #myStarSpeedF
         EndIf
      Next myCounterA
   EndProcedure

   Procedure StarsDraw1()
      ClearScreen(RGB(0, 0, 0))
      StartDrawing(ScreenOutput())
         For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
            Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
            Plot(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, RGB(200, 200, 200))
         Next myCounterA
      StopDrawing()
      FlipBuffers()
   EndProcedure

  Procedure StarsDraw2()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
           Circle(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, 1, RGB(100, 100, 100))
           Circle(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, 1, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
     StopDrawing()
     FlipBuffers()
  EndProcedure

  Procedure StarsDraw3()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
           Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
           Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
     StopDrawing()
     FlipBuffers()
  EndProcedure

   Procedure StarsDraw4()
      ClearScreen(RGB(0, 0, 0))
      StartDrawing(ScreenOutput())
         For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
            Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
            Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
         Next myCounterA
      StopDrawing()
      FlipBuffers()
   EndProcedure

  Procedure StarsDraw5()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
           Circle(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, 1, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
     StopDrawing()
     FlipBuffers()
  EndProcedure


;   ========================================================================
   If Not InitSprite()
      MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitSprite( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not InitKeyboard()
      MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitKeyboard( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not OpenWindow(#myWindowID, 0, 0, #myWindowWidth, #myWindowHeight, "Sternenfeld", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
      MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindow( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not OpenWindowedScreen(WindowID(#myWindowID), 0, 0, #myWindowWidth, #myWindowHeight, 0, 0, 0)
      MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindowedScreen( )", #PB_MessageRequester_Ok ) : End
   EndIf

;   ========================================================================
   For myCounterA = 0 To #myStarsQuantity Step 1
      StarsLayerB(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
      StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

      StarsLayerM(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
      StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

      StarsLayerF(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
      StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
   Next myCounterA

;   ========================================================================
   Repeat
      myEvent = WaitWindowEvent(1)
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape)
         myKeyPressed = #PB_Key_Escape
      EndIf
      StarsCalculate()
      StarsDraw5()
   Until myKeyPressed = #PB_Key_Escape

;   ========================================================================
   End

;   ========================================================================

Verfasst: 04.09.2008 20:37
von Captain_Qwark
Das mit dem Tippfehler währe ne Möglichkeit ... hab aber beim Testen immer nur das "Plot" gegen "Circle" ausgetauscht und den Größenparameter hinzugefügt. Nix großartiges also ... aber schön zu Wissen das es nicht am Rechner liegt :)

Ein Fall für Akte X

M.f.G.
Captain Qwark

Edit: Mist bist schneller beim Testen als ich beim Tippen :D

Verfasst: 04.09.2008 21:36
von THEEX
Also um einen wirklichen Vergleich zu haben, hab ich mal die Framerate hoch gesetzt und eine FPS-Messung vorgenommen. Das Rausnehmen der Eventabfrage macht scheinbar keinen bzw. kaum Unterschied.
Also man sieht extreme Geschwindigkeitsunterschiede. Wobei auch die 1. Variante bei ca 230 FPS leicht ruckelig erscheint. Jedoch muß ich sagen, hab ich auch nicht mehr FPS raus geholt, als ich alle Berechnungen weggelassen hab, daher scheint die Berechnung sehr schnell zu sein. 80 FPS hatte ich mit Varinate 2, bei Variante 3, 4 und 5 kam ich auf ca. 40 FPS. Ich werd mal noch was anderes ausprobiern, dauert aber wohl länger... ;-)

Die FPS-Messung ist nicht sonderlich genau, hab nur einen früheren Code von mir verwendet, den Schnitt innerhalb 10 Sekunden errechnet.

Code: Alles auswählen

;   ========================================================================
   Enumeration
      #myWindowID
   EndEnumeration

   #myWindowWidth = 800 : #myWindowHeight = 600 : #myStarsQuantity =  150
   #myStarSpeedF  = 1.5 : #myStarSpeedM   =   1 : #myStarSpeedB    =  0.5

;   ========================================================================
   Structure ntStarType
      PositionX.f
      PositionY.f
   EndStructure

   Global Dim StarsLayerF.ntStarType(#myStarsQuantity)
   Global Dim StarsLayerM.ntStarType(#myStarsQuantity)
   Global Dim StarsLayerB.ntStarType(#myStarsQuantity)

   Global myEvent.l    = 0 : Global myKeyPressed.l = 0
   Global myCounterA.w = 0

;   ========================================================================
Procedure.f FpS2() 
  Static Start_Zeit, Frames, SendFrames.f 
  Zeit_akt = GetTickCount_() 
  Frames + 1 
  ZeitU = Zeit_akt - Start_Zeit 
  If ZeitU 
    SendFrames = Frames / ZeitU 
  EndIf  
  If Zeit_akt >= Start_Zeit + 10000 
    Start_Zeit = Zeit_akt 
    Frames = 0 
  EndIf 
  ProcedureReturn SendFrames * 1000 
EndProcedure
;   ========================================================================
   Procedure StarsCalculate()
      For myCounterA = 0 To #myStarsQuantity Step 1
         If (StarsLayerB(myCounterA)\PositionX - #myStarSpeedB) < 0
            StarsLayerB(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
         Else
            StarsLayerB(myCounterA)\PositionX = StarsLayerB(myCounterA)\PositionX - #myStarSpeedB
         EndIf
         
         If (StarsLayerM(myCounterA)\PositionX - #myStarSpeedM) < 0
            StarsLayerM(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
         Else
            StarsLayerM(myCounterA)\PositionX = StarsLayerM(myCounterA)\PositionX - #myStarSpeedM
         EndIf
         
         If (StarsLayerF(myCounterA)\PositionX - #myStarSpeedF) < 0
            StarsLayerF(myCounterA)\PositionX = #myWindowWidth -1
            StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))
         Else
            StarsLayerF(myCounterA)\PositionX = StarsLayerF(myCounterA)\PositionX - #myStarSpeedF
         EndIf
      Next myCounterA
   EndProcedure

   Procedure StarsDraw1()
      ClearScreen(RGB(0, 0, 0))
      StartDrawing(ScreenOutput())
         For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
            Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
            Plot(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, RGB(200, 200, 200))
         Next myCounterA
         DrawText(0, 0, StrF(FpS2()))
      StopDrawing()
      FlipBuffers()
   EndProcedure

  Procedure StarsDraw2()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
           Circle(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, 1, RGB(100, 100, 100))
           Circle(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, 1, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
        DrawText(0, 0, StrF(FpS2()))
     StopDrawing()
     FlipBuffers()
  EndProcedure

  Procedure StarsDraw3()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
           Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
           Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
        DrawText(0, 0, StrF(FpS2()))
     StopDrawing()
     FlipBuffers()
  EndProcedure

   Procedure StarsDraw4()
      ClearScreen(RGB(0, 0, 0))
      StartDrawing(ScreenOutput())
         For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
            Plot(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, RGB(150, 150, 150))
            Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
         Next myCounterA
         DrawText(0, 0, StrF(FpS2()))
      StopDrawing()
      FlipBuffers()
   EndProcedure

  Procedure StarsDraw5()
     ClearScreen(RGB(0, 0, 0))
     StartDrawing(ScreenOutput())
        For myCounterA = 0 To #myStarsQuantity Step 1
            Plot(StarsLayerB(myCounterA)\PositionX, StarsLayerB(myCounterA)\PositionY, RGB(100, 100, 100))
           Circle(StarsLayerM(myCounterA)\PositionX, StarsLayerM(myCounterA)\PositionY, 1, RGB(150, 150, 150))
           Circle(StarsLayerF(myCounterA)\PositionX, StarsLayerF(myCounterA)\PositionY, 2, RGB(200, 200, 200))
        Next myCounterA
        DrawText(0, 0, StrF(FpS2()))
     StopDrawing()
     FlipBuffers()
  EndProcedure


;   ========================================================================
   If Not InitSprite()
      MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitSprite( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not InitKeyboard()
      MessageRequester("Sternenfeld", "Es ist ein DirectX Fehler aufgetreten - InitKeyboard( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not OpenWindow(#myWindowID, 0, 0, #myWindowWidth, #myWindowHeight, "Sternenfeld", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
      MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindow( )", #PB_MessageRequester_Ok ) : End
   EndIf

   If Not OpenWindowedScreen(WindowID(#myWindowID), 0, 0, #myWindowWidth, #myWindowHeight, 0, 0, 0)
      MessageRequester("Sternenfeld", "Es ist ein Fehler aufgetreten - OpenWindowedScreen( )", #PB_MessageRequester_Ok ) : End
   EndIf

;   ========================================================================
   For myCounterA = 0 To #myStarsQuantity Step 1
      StarsLayerB(myCounterA)\PositionX = Int(Random(#myWindowWidth - 1))
      StarsLayerB(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

      StarsLayerM(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
      StarsLayerM(myCounterA)\PositionY = Int(Random(#myWindowHeight - 1))

      StarsLayerF(myCounterA)\PositionX = Int(Random(#myWindowWidth -1))
      StarsLayerF(myCounterA)\PositionY = Int(Random(#myWindowHeight -1))
   Next myCounterA

;   ========================================================================
   SetFrameRate(1000)
;   ========================================================================

   Repeat
      ;myEvent = WindowEvent()
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape)
         myKeyPressed = #PB_Key_Escape
      EndIf
      StarsCalculate()
      StarsDraw1()
   Until myKeyPressed = #PB_Key_Escape

;   ========================================================================
   End

;   ========================================================================

Verfasst: 04.09.2008 22:05
von Kaeru Gaman
@X

das wird aber nicht überall funktionieren.
du müßtest FlipBuffers mit NoSync aufrufen (bzw. bei manchen funktioniert auch SmartSync), um wirklich eine unabhängige messung bekommen zu können.
ansonsten wird das SetFrameRate bei vielen Systemen bei einem WindowedScreen ignoriert und mit dem Desktop synchronisiert.

ich mess mal kurz bei dem code von mir nach...

[edit]
so, kurz nachgemessen, also nur das FpS hinzugefügt, nix an der Framerate oder am Sync geschraubt:

ich bekomm bei 1.: 59.9 FpS, bei 2.: 59.3 FpS

... und bei 3, 4 und 5 bekomme ich nur 4 FpS
deswegen auch mein erstaunen oben, und meine aussage, dass da doch was nicht stimmen kann.

Verfasst: 04.09.2008 22:06
von THEEX
Das ist der Code von dir mit FPS erweitert...

Verfasst: 04.09.2008 22:13
von Kaeru Gaman
nein du hast ein SetFrameRate(1000) drin... ;)

damit bekomme ich 120 beim ersten, 60 beim zweiten und immer noch 4 bei den anderen...

also, irgendein problem muss das Draw haben, wenn man plot und circle abwechselt...