Results 1 to 6 of 6

Thread: CPU usage during GameLoop

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    CPU usage during GameLoop

    Wow! I found out that during the "GameLoop" Cpu usage is 100%. There are needs/ways to make this value smalller???

    this is the code for gameloop:
    VB Code:
    1. While GameRunning
    2.         'DoSomestuffhere
    3.        
    4.         CheckIfIHaveToExitThisLoop   'for stopping gameloop
    5.         DoEvents
    6.     Wend
    Thx,
    Xmas
    Learn, this is the Keyword...

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    I don't think that te loop you posted is causing the 100% CPU usage.
    The code you show would allows other application to step (DoEvents).
    I guess your code for timehandling (if you have something like that) is the problem, are you using the Timer Control?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    No, I'm not using Timer Control
    I just tried to create a new project and put this code in:
    VB Code:
    1. Option Explicit
    2. Dim GameRunning As Boolean
    3. Private Sub Form_Load()
    4.     Me.Show
    5.     GameRunning = True
    6.    
    7.     While GameRunning
    8.         DoEvents
    9.     Wend
    10. End Sub
    11.  
    12. 'Exit loop when closing form
    13. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    14.     GameRunning = False    
    15. End Sub
    This code still gets 100% of CPU load.
    The program that says 100% of CPU load is the Norton System Doctor. Win98 SE.

    The doevents lets my application and VB IDE to step (I think). Other application always will step, even without it.

    Thx
    Xmas.
    Learn, this is the Keyword...

  4. #4
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    Yes, the CPU usage is 100%. But that doesn't mean that you can't use the CPU anymore. If another program wants time on the cpu, it will get it, because of the doevents statement. However, whenever there is a time where no other program is using the cpu, your program is using it, and therefore it is 100%. I think that you will not acutally notice any speed decrease in other programs while your running your program. Your program uses all the cpu when it can, but it will always yield to others because of the doevents. i don't think its a problem.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Yes, in fact I didn't noticed any performance loss...

    Thanks a lot,

    Xmas.
    Learn, this is the Keyword...

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    When you do a loop, it takes all AVAILABLE power. Think of this as being very low-priority; if another application wants the CPU time, VB simply takes less CPU %, and thus more time. This is the same principle why having 2 graphics applications open at one time (say, 3DSMax and Half-Life) will really start to slow down your computer.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width