Starfield slow downs?

Just starting out? Need help? Post your questions and find answers here.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Starfield slow downs?

Post 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
--Kale

Image
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post 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
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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:
--Kale

Image
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

Exactly the same as TronDoc. Just one pause during disk activity.
Post Reply