Drawing problem: mixed circle and plot slows down
we just discovered an issue I wasn't aware before:
mixing Plot and Circle in the same step of a loop can significantly slow down the execution.
this testcode was hacked together by three people:
Code: Select all
; ========================================================================
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
; ========================================================================
on a CRT the result was 240, 80, 40, 40, 40 FpS, on a TFT it was 120, 60, 4, 4, 4
4 FpS when altering circle and plot in the same loopstep, really strange.
could others please test and confirm, disprove or explain?