Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 100% CPU on simple program?  (Read 9850 times)

0 Members and 1 Guest are viewing this topic.

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« on: March 03, 2011, 03:39:32 am »
Why is my simple program taking up 100% of my CPU?  My code is from the documentation files (the first example).
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
100% CPU on simple program?
« Reply #1 on: March 03, 2011, 07:56:53 am »
Because you tell it to take 100% CPU. Well, in fact you don't tell it to not take 100% CPU ;)

Simply use SetFramerateLimit, UseVerticalSync or Sleep to slow down your program and let the CPU do something else.
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #2 on: March 03, 2011, 03:40:38 pm »
What would you suggest I limit the frame rate to?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
100% CPU on simple program?
« Reply #3 on: March 03, 2011, 04:13:57 pm »
Use vertical synchronization, it will give better visual results because the framerate will be synchronized with the monitor's refresh rate.
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #4 on: March 04, 2011, 12:45:43 am »
Is that in the documentation?  I'm assuming it is.  Thanks for the help.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
100% CPU on simple program?
« Reply #5 on: March 04, 2011, 07:49:52 am »
It is, all functions are documented. I don't know if it's in the tutorials.
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #6 on: March 04, 2011, 02:28:22 pm »
I used the UseVerticalSync and the program looks really good now, but it still takes up 100%.  Should I also limit the framerate?
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
100% CPU on simple program?
« Reply #7 on: March 04, 2011, 02:32:23 pm »
Really? It shouldn't. Try SetFramerateLimit (without UseVerticalSync), and if it still doesn't work then you probably have a problem.
Laurent Gomila - SFML developer

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #8 on: March 07, 2011, 02:28:14 pm »
It's working now.  Thanks for all of the help!
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #9 on: March 24, 2011, 04:06:04 pm »
I have the same problem but it isn't working for me...
I'm using Ubuntu 10.10.

  App.UseVerticalSync (true);

or

  App.UseVerticalSync (false);
  App.SetFramerateLimit (0x20);

both limit the rate, but the CPU satys at 100%

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #10 on: March 24, 2011, 04:14:04 pm »
I got rid of this problem a while ago.  Limiting the frame rate seems to limit the CPU.  I think your hardware might be affecting yours.  Mine only runs like 10% now.
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #11 on: March 24, 2011, 04:22:36 pm »
wurd.... hopefully in 2.0 it will be fixed :S

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
100% CPU on simple program?
« Reply #12 on: March 24, 2011, 05:27:01 pm »
VSync seems to not work with all drivers. I had this problem once on my laptop with an ATI Radeon HD blah-blah-something. SetFramerateLimit() should work in any case.

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #13 on: March 24, 2011, 11:30:53 pm »
Nope! I tried

Code: [Select]

  App.UseVerticalSync (false);
  App.SetFramerateLimit (0x20);


this

Code: [Select]

  App.UseVerticalSync (true);
  App.SetFramerateLimit (0x20);


this

Code: [Select]

  App.SetFramerateLimit (0x20);


and this

Code: [Select]

  App.UseVerticalSync (true);


on 2 differant computers, and it still maxed out the CPU at 100%

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
100% CPU on simple program?
« Reply #14 on: March 24, 2011, 11:31:48 pm »
Quote
My code is from the documentation files (the first example)

Which one?
Laurent Gomila - SFML developer