Page 1 of 1

Starfield slow downs?

Posted: Sun Jun 01, 2003 1:35 pm
by Kale
I've coded a starfield, but on my PC it seems to slow down intermitently. Its starts ok then after a few seconds jerks a bit then back to normal then jerks a bit more then normal, etc...etc...

Could this be my PC doing something in the background or do you guys get the same thing? Is it a problem with the Code?

Code: Select all

;===========================================================================
;-CONSTANTS
;===========================================================================

#APP_NAME = "Stars v1.0"
#NUMBER_OF_STARS = 500

;===========================================================================
;-GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;===========================================================================

Global Quit.b
Fade.l = 0

Structure Star
    xPos.f
    yPos.f
    xStep.f
    colour.l
EndStructure
Dim Stars.Star(#NUMBER_OF_STARS)

;===========================================================================
;-PROCEDURES
;===========================================================================

;simple error checking
Procedure HandleError(result, text.s)
    If result = 0 : MessageRequester("Error", text, #PB_MessageRequester_Ok) : End : EndIf
EndProcedure

;init stars
Procedure InitStars()
    For x = 0 To #NUMBER_OF_STARS - 1
        Stars(x)\xPos = Random(640)
        Stars(x)\yPos = Random(220)
         If x < #NUMBER_OF_STARS / 3
            Stars(x)\xStep = (Random(100) / 100) + 0.1
            Stars(x)\colour = RGB(70, 70, 70)
        ElseIf x >= #NUMBER_OF_STARS / 3 And x < (#NUMBER_OF_STARS / 3) * 2
            Stars(x)\xStep = (Random(100) / 100) + 0.2
            Stars(x)\colour = RGB(140, 140, 140)
        Else
            Stars(x)\xStep = (Random(100) / 100) + 0.3
            Stars(x)\colour = RGB(255, 255, 255)
        EndIf
    Next x
EndProcedure

;move stars on the 'x' axis
Procedure MoveStarsX()
    For x = 0 To #NUMBER_OF_STARS - 1
        Stars(x)\xPos - Stars(x)\xStep
        If Stars(x)\xPos < 0
            Stars(x)\xPos = 640
            Stars(x)\yPos = Random(220)
        EndIf
    Next x
EndProcedure

;===========================================================================
;-GEOMETRY / SCREEN
;===========================================================================

HandleError(InitSprite(), "Error Initialising DirectX:"+Chr(10)+"Microsoft DirectX v7.0+ must be installed correctly."+Chr(10)+"Offending Command: InitSprite()")
HandleError(InitKeyboard(), "Error Initialising DirectX:"+Chr(10)+"Microsoft DirectX v7.0+ must be installed correctly."+Chr(10)+"Offending Command: InitKeyboard()")
HandleError(OpenScreen(640, 480, 32, #APP_NAME), "640x480 32bit Screen could not be opened correctly.")
ChangeGamma(0, 0, 0, 1)

InitStars()

;===========================================================================
;-MAIN LOOP
;===========================================================================

Repeat

    FlipBuffers()
    ClearScreen(0, 0, 0)

    StartDrawing(ScreenOutput())
        For x = 0 To #NUMBER_OF_STARS - 1
            Plot(Stars(x)\xPos, Stars(x)\yPos, Stars(x)\colour)
        Next x
    StopDrawing()
    MoveStarsX()

    If Fade < 255
        Fade + 4
        ChangeGamma(Fade, Fade, Fade, 0)
    EndIf
    ExamineKeyboard()
    
    If KeyboardReleased(#PB_Key_Escape)
        Repeat
            ChangeGamma(Fade, Fade, Fade, 0)
            Fade - 4
        Until Fade <= 0
        Quit = 1
    EndIf

    Delay(1)
    HandleError(IsScreenActive(), "'Alt-Tabbing' is not yet supported.")

Until Quit = 1
End

Posted: Sun Jun 01, 2003 1:44 pm
by tinman
There is a slight slowdown visible on my computer every now and again, but I've got an MP3 playing in the background ;)

Without that in the background it's a bit worse. It looks like the starfield speeds up now and again (possibly that the delay between frames gets shorter), rather than slowing down.

Posted: Sun Jun 01, 2003 9:05 pm
by TronDoc
there was a quick "jerk" in the motion about two
to three seconds after starting the program in the IDE
at the same time the HDD was accessed for some reason.
(buffers flushing??)
otherwise I stared at it awhile without doing any
other activity and it stayed a smooth and constant
speed for over two minutes. (I got bored and
couldn't wait any longer LOL)
Joe

'98 original version
250Mhz pII 256 Mb RAM
cruddy atir3 RagePro

Posted: Mon Jun 02, 2003 12:15 am
by Kale
hmmm, thanks for testing it out, i think its probably my PC, time for a new one i think, this one's had more 'upgrades' then i care to remember and its a bit 'taped together' inside :lol:

Posted: Mon Jun 02, 2003 6:43 pm
by geoff
Exactly the same as TronDoc. Just one pause during disk activity.