Hello Guest

Author Topic: 100% CPU core usage with empty Scene?  (Read 3698 times)

0 Members and 1 Guest are viewing this topic.

hinst

  • Member
  • Posts: 7
    • View Profile
100% CPU core usage with empty Scene?
« on: October 17, 2015, 12:27:58 PM »
Sorry a stupid question.
Studying hello-world app here.
I get 100% CPU core usage with target framerate set to 60. AverageFramerate returns 60. I wonder what is wrong with it (or with me)

Yeah and FRAPS app shows 400 frames per second. Same when I set FixedFramerate to true. A bug perhaps?

If I set "always enable vsync for OpenGL" in Catalyst Control Center then I get 60 FPS and low CPU core usage

Even when I use  CCC workaround, I get funny readings from Game.Framerate, like 30 then 40 then 30 (target set to 60)
« Last Edit: October 18, 2015, 04:00:19 AM by hinst »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #1 on: October 20, 2015, 11:34:55 AM »
It sounds like all of these things stem from how the update loop in Otter is structured.  SFML is going to use 100% of the cpu since the program is not sleeping at all, but instead rendering constantly and waiting for the next update.  I attempted to use SFML's built in SetFramerateLimit(), which would reduce cpu useage, but it was incredibly unstable and buggy on a lot of systems for some reason, so I opted to write a custom limiter instead.  If you set the vertical sync to true in the game window parameters for Otter that might make a difference?

Fraps reporting 400fps is probably because the rendering is going that fast even when the framerate is fixed, but the update is locked at the target framerate per second which is what shows up when the game reports its own framerate.  Basically Otter is always rendering as much as possible, but only updating at the target framerate.

hinst

  • Member
  • Posts: 7
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #2 on: October 22, 2015, 10:26:46 AM »
Thanks for the explanation;

So is it possible to enable VSync programmatically? Seems like Otter.Game class does not have VSync property

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #3 on: October 26, 2015, 11:52:26 AM »
It's the last parameter in the SetWindow method I believe, true or false. http://otter2d.com/docs/class_otter_1_1_game.html#addb32f74bbe10000c42b97b5117a9edd

I believe it can be set when you do new Game() as well.  I think I had to do it this way because it's not something you can change without destroying and reopening a window.

hinst

  • Member
  • Posts: 7
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #4 on: November 04, 2015, 04:35:07 AM »
I tried enabling VSync using SetWindow method and it works;
but I still do not get update rate = 60.   

I get frame rate == 60 == FRAPS and update rate == 40 == game.Framerate.   

It would be awesome if I could get frame rate == 60 == update rate. Am I the only one who has this problem?

hinst

  • Member
  • Posts: 7
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #5 on: November 12, 2015, 11:33:23 AM »
I created a minimal app which reproduces the problem with frame rate and frame time measurement. It only has an empty scene

Testing app: http://pastebin.com/pghTVszW
What I get: https://drive.google.com/file/d/0B9QPF4Dcx5xtRVVPbzZWVTJ6R0U/view?usp=sharing

When I first noticed the problem with time measurement, I searched the internets a bit and found two more possible methods of time measurement in C#: QueryPerformanceCounter and some MultimediaTimer. I write results obtained from each timer to console and I get very different results

Output as plain text: http://pastebin.com/UwXAi2Fq

MultimediaTimer seems to give more accurate result but I am not sure yet; QueryPerformanceCoutner is mad which is strange. I used QueryPerformanceCounter API from native non-.net apps and it worked fine
« Last Edit: November 12, 2015, 11:46:19 AM by hinst »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #6 on: November 13, 2015, 02:28:04 PM »
I get the "High resolution clock isn't available." exception, am I missing something to run this example?

hinst

  • Member
  • Posts: 7
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #7 on: November 14, 2015, 03:06:06 AM »
I am not sure, but seeing this comment in code:
Code: [Select]
// Not running Windows 8 or higher.
perhaps Windows 8 + is required for MediaTimer. Do you run Windows 8?
// I only wrote class App; I copied MediaTimer class from some page

-----
I tried to set Game.FixedFramerate = false; seems like it resolves my problem; both framerate and RealDeltaTime.
When I set FixedFramerate = false then I get update-rate = 58...62.
When I set FixedFramerate = true then I get update-rate = 31 and things move approximately 1.8x faster than they should
« Last Edit: November 14, 2015, 05:50:25 AM by hinst »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: 100% CPU core usage with empty Scene?
« Reply #8 on: November 14, 2015, 11:21:09 AM »
I'm on Windows 7.

If you're used to using DeltaTime in your games then setting fixed framerate to false should be what you want to do.  I'm still unsure as to why you experience weird time issues with fixed framerate on though, but using realdeltatime to do stuff in fixed framerate mode is probably not going to be very reliable.