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

Author Topic: C++ Version / Power Usage Very High [SOLVED]  (Read 2001 times)

0 Members and 1 Guest are viewing this topic.

Kain Nobel

  • Newbie
  • *
  • Posts: 38
    • View Profile
C++ Version / Power Usage Very High [SOLVED]
« on: January 22, 2022, 02:11:07 pm »
Hello and good day!

I have two questions that may or may not be related. They may or may not even be easy to answer, and that's OK too. The first one should be easy enough...

Question 1

I'd have to really dig through tutorials and documentation (and I did for a little bit) but...

What version of C++ should I be using? C++14? C++17? ISO or GNU matter? Any other "rule of thumb"? I'm using (paraphrasing) C++14 GNU (ISO with GNU extension). I've experimented with changing these selections around a tiny bit only because of my next question...

Question 2

What could be making Power Usage rate as Very High and what would be a good way to drop this rating? Does SFML generally use a lot of power always or would it be because I might have something set up incorrectly as far as C++ standard, ISO/GNU, etc? I honestly don't believe it is anything having to do with what I've made thus far but here is details of what I have done...

(click to show/hide)



Other than 2 "Musics" playing, and a image being drawn (once) I could have nothing going on, not touching any buttons, and the power usage is the only one that fluctuates and it hits "Very high" a lot for no apparent reason. CPU is "fairly stable" (although it would be cool if it was lower) and Memory is right where I'd want and expect it to be thus far.

Any ideas what could possibly be making my Power Usage high? With my frame rate set at steady 60 via SFML, should I be calling a sleep function in main loop or would that just slow down the application each frame and mess up the FPS? Any other suggestions to drop the power usage? I don't think anything can be done about CPU, I recall it always being about that high from the start, so I think its more in the scope of SFML than anything I've written.
« Last Edit: January 23, 2022, 10:43:09 am by Kain Nobel »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: C++ Version / Power Usage Very High
« Reply #1 on: January 22, 2022, 04:05:33 pm »
1- i think any of these would be good
2- you are probably running your program at max speed (as seens with 52% use of CPU). put a sleep in each iteration: https://www.sfml-dev.org/documentation/2.5.1/group__system.php#gab8c0d1f966b4e5110fd370b662d8c11b

something like
[your code]
window.clear();
window.draw(your sprites, etc);
window.display();
sf::sleep(sf::milliseconds(10));
 
Visit my game site (and hopefully help funding it? )
Website | IndieDB

kojack

  • Sr. Member
  • ****
  • Posts: 310
  • C++/C# game dev teacher.
    • View Profile
Re: C++ Version / Power Usage Very High
« Reply #2 on: January 22, 2022, 04:32:17 pm »
For part 1, it really depends on if you need the newer features or something you are adding to your project needs them.
I mainly stayed on much older C++, but I've now jumped to C++17 due to the "if constexpr" command (lets me do compile time logic in my vector maths classes) and because the awesome Entt library needs C++17.

Part 2
I'm also setting it to 60Hz using the window's setFramerateLimit function. A simple app with ImGui rendering a giant texture (plus other engine stuff) gives me:

I'm running on a Threadripper and RTX2080TI though.
I don't have sound playing, that may be affecting things.

The slight disk usage you have will be due to the sf::Music. Unlike Sound, Music streams in from disk as it plays, rather than loading it all in advance. Better for memory, but needs to keep loading.

52% CPU does seem really high for what you are doing though.

Kain Nobel

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: C++ Version / Power Usage Very High [SOLVED]
« Reply #3 on: January 23, 2022, 10:46:29 am »
Alright cool, putting it to sleep for 10 milliseconds as suggested really dropped the values down to almost nothing, the difference is like night and day. (Its running as 0 to 2% CPU now with Power Usage at Very Low).

Thank you both :D SOLVED!

 

anything