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

Author Topic: 100% CPU on simple program?  (Read 10836 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?
« Reply #15 on: March 25, 2011, 02:38:59 am »
I fixed this problem a while ago, but it came up again in a different form with different source code.  The window source is below:
Code: [Select]
sf::RenderWindow App(sf::VideoMode(800, 600), "Dodger");
    App.UseVerticalSync(useVertSync);
    App.SetFramerateLimit(frameLimit);

use vert sync is true and framelimit is set to 45.  The program runs on an average amount of CPU, but it acts like a program running on 100% CPU (mouse flickers, disappears when you don't move it, boxes appear by mouse, etc.).  This started occurring all-of-the-sudden.  All of the images move quickly and at a normal pace.
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 #16 on: March 25, 2011, 03:16:50 pm »
my code isn't from the tut, it's my own

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
100% CPU on simple program?
« Reply #17 on: March 26, 2011, 02:35:14 pm »
Mine is now too, but the problem arised after.  To tell you the truth, I only said that I was using the tutorial code so I wouldn't have to post mine, cause I'm lazy... :)
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
Solution!
« Reply #18 on: April 08, 2011, 04:17:32 pm »
I just stopped thinking about this problem for a while.. but this morning it was really bugging me.. SO! I tried several things... and...

Code: [Select]

    sf::Sleep(0.01);


Doesn't seem to have any effect on speed AND the CPU goes to 0%! :D

w00t!

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Solution!
« Reply #19 on: April 10, 2011, 02:37:48 am »
Quote from: "strongdrink"
I just stopped thinking about this problem for a while.. but this morning it was really bugging me.. SO! I tried several things... and...

Code: [Select]

    sf::Sleep(0.01);


Doesn't seem to have any effect on speed AND the CPU goes to 0%! :D

w00t!
Or you could look at the second post in this thread. Your technique is equivalent to SetFramerateLimit(100);
The 100 comes from 1/0.01.
I use the latest build of SFML2

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #20 on: April 10, 2011, 06:08:51 am »
No I tried that, it didn't work either.. I think it might be a hardware problem

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
100% CPU on simple program?
« Reply #21 on: April 10, 2011, 10:26:13 pm »
Quote from: "strongdrink"
No I tried that, it didn't work either.. I think it might be a hardware problem
I doubt it. I'm 99% sure that SetFramerateLimit uses sf::Sleep (although I haven't checked, to be honest).
I use the latest build of SFML2

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #22 on: April 11, 2011, 12:44:16 am »
I don't think so... when i do

Code: [Select]

  App.SetFramerateLimit (0x30);


For instance.. it does nothing to my CPU.. but when i do

Code: [Select]

    sf::Sleep(0.01);


it lowers it to 0! it's wacked.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
100% CPU on simple program?
« Reply #23 on: April 13, 2011, 01:59:28 am »
Quote from: "strongdrink"
I don't think so... when i do

Code: [Select]

  App.SetFramerateLimit (0x30);


For instance.. it does nothing to my CPU.. but when i do

Code: [Select]

    sf::Sleep(0.01);


it lowers it to 0! it's wacked.
Why are you using hexadecimal in SetFramerateLimit?

Also, I was correct. This is how SFML handles FramerateLimit:
Code: [Select]
if (myFramerateLimit > 0)

    {

        float remainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime();

        if (remainingTime > 0)

            Sleep(remainingTime);

    }

In other words, using SetFramerateLimit has the exact same effect as your Sleep method.
I use the latest build of SFML2

strongdrink

  • Newbie
  • *
  • Posts: 43
    • View Profile
    • Email
100% CPU on simple program?
« Reply #24 on: April 13, 2011, 03:09:22 am »
i use hex because i believe it compiles faster.. dunno i guess i just like it :D

weiiiirdd... oh well as long as both of them work in the same way it doesn't matter i guess lol