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...
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
; ========================================================================