Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Almost 100% processor time at main menu [SOLVED]  (Read 2059 times)

isitanos

  • Bay Watcher
  • Seasonal river flood nostalgic
    • View Profile
Almost 100% processor time at main menu [SOLVED]
« on: October 13, 2007, 12:42:00 am »

I don't know if it qualifies as a bug, but I find it weird that DF takes almost 100% of the processor time to display the main menu: what is it doing at that time?

It's the same thing when you put the game on pause; granted, some animations are still running, and maybe there's some pathfinding to do when you manage stuff, but even when it has been on pause for 10 min, the game still takes up the same amount of processor time.

[SOLVED]: Apparently the solution is to activate the option SyncToVBlank on your Nvidia card. I don't know if the problem/solution exists on other 3d cards. Up to now I have only tried this on linux, while running under wine; you must have the package nvidia-settings installed, and then run from command line:

code:
 # nvidia-settings --assign="SyncToVBlank=1" 


DF is now taking between 6 and 25% of the processor when at the main menu or paused, whereas it was taking 100% the whole time before.
Funnily enough, I got the idea to try this setting from an almost entirely unrelated page on the Gentoo linux wiki.
I am sure that under windows you can enable the same settings somewhere in your nvidia card config, I'll look for it as soon as I boot back under windows.

Now the question is: what is this setting, what does it do, and why must we enable it for DF to run properly. Is it a bug in DF, or does DF use a peculiar rendering method?

[ October 25, 2007: Message edited by: isitanos ]

Logged

AlanL

  • Bay Watcher
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #1 on: October 13, 2007, 01:01:00 am »

It probably runs a loop straight through instead of doing callbacks.
Logged

Sewerbird

  • Escaped Lunatic
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #2 on: October 13, 2007, 11:12:00 am »

DF goes as fast as CPU can allow: frame rate is largely tied to it, I believe.
Logged

Toady One

  • The Great
    • View Profile
    • http://www.bay12games.com
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #3 on: October 13, 2007, 04:33:00 pm »

I don't have this problem.  When people have had this problem, if I remember it has been related to OpenGL/driver issues.  I'm at 0% on the main menu.  0% paused during dwarf mode as well.

[ October 13, 2007: Message edited by: Toady One ]

Logged
The Toad, a Natural Resource:  Preserve yours today!

BurnedToast

  • Bay Watcher
  • Personal Text
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #4 on: October 13, 2007, 11:10:00 pm »

I seem to be sitting at around 25% - 30% usage on the main menu, and it's at 90% - 100% while paused.

OpenGL/driver issues you say? hmm. I have the latest drivers for my card. I don't suppose anyone has more information about this?

or maybe my cpu just sucks  :(

Logged
An ambush! curse all friends of nature!

isitanos

  • Bay Watcher
  • Seasonal river flood nostalgic
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #5 on: October 13, 2007, 11:30:00 pm »

I never had any problem with my graphics card, and I run a wide variety of opengl games on this computer. Nevertheless, I'll update to the latest Nvidia driver and see what happens (hopefully it doesn't break something else: usually they recommend you don't upgrade unless you're having problems).
Logged

isitanos

  • Bay Watcher
  • Seasonal river flood nostalgic
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #6 on: October 14, 2007, 01:49:00 pm »

So, I upgraded to the latest Nvidia drivers, and DF at the main menu still takes up near-100% of the processor time. I don't know what else I could try...

[ October 25, 2007: Message edited by: isitanos ]

Logged

isitanos

  • Bay Watcher
  • Seasonal river flood nostalgic
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #7 on: October 25, 2007, 10:23:00 am »

SOLVED, see original post.
Logged

Jaqie Fox

  • Bay Watcher
  • Genuine Girl Techie!
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #8 on: October 25, 2007, 04:30:00 pm »

I betcha in order to properly deal with windows that cover over DF and then are moved off while paused, Toady implemented a constantly redrawing window when running the game nomatter where it is, so it will not suffer 'blank' areas where the other window covered it over until the game is made active or unpaused again.  That would explain this whole thing, actually.
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #9 on: October 25, 2007, 11:09:00 pm »

In the Win32 API, when windows pass over yours, Windows sends a message to your window indicating a) that a part of the window needs to be redrawn, and b) what area that is. Because of this, there's no need to constantly redraw your window come hell or high water to deal with windows moving across yours, you can just wait and only redraw part of the window if instructed to. There may be some reason outside my experience to do things differently, but if so, I'm not aware of it.

Edit: On the topic of the solution you found: Try enabling the framerate display in in the init file, and experiment with and without that option. You'll almost certainly find that the reason Dwarf Fortress seems to be well-behaved now is that its framerate is lower when you enabled that option.

"SyncToVBlank=1" means enabling vertical sync, which forces the game to only redraw while the monitor is in its vertical blank. This makes more sense if you understand how CRT monitors and TV screens work. Laptop/flat screen LCDs are completely different, and none of this applies. Basically, there's an electron gun inside the tube that has to move across and fire information at every single pixel on the screen, every time the monitor refreshes, to excite the pixels and make them light up. It starts at the top left corner of the screen, and ends at the bottom right. Once it does, there's a period where the gun scrolls back up to the top left, and this period of time is called the vertical blank.

Monitors have a native refresh rate, and they generally just refresh at that rate regardless of what your programs do. This is traditionally 60 frames per second. The software, on the other hand, has a separate frame rate. 60 is the "holy number" that people like to target for software frame rate because it's the traditional monitor refresh rate; drawing more than 60 frames per second is pointless, because you physically can't display things faster than the monitor can refresh the screen. Games are very intense though, and have to do a lot of things between frames. Besides calculating all the graphics, they have to handle user input, AI, and everything else in the game, updating the game state by one tiny step. So sometimes games aren't the full 60 frames per second.

One problem that occurs when you don't have exactly 60 frames per second is tearing. Tearing happens when the software changes what they want displayed while the monitor is drawing, half way across the screen. If your guy moves in that change, you can get, for one tiny fraction of a second, half of them in the previous frame and half in the next one. Because it's so fast, most people don't notice it, but it bothers those who do, and it can become noticeable in faster games.

The solution is vertical sync. By forcing the game to only draw its graphics while the monitor is in its vertical blank, no tearing is possible, because the software frames are synchronized with the monitor refresh. This sounds great until you realize that it makes games which would otherwise pull 50 frames per second (ie, they JUST MISSED the vertical blank deadline, a little bit slower than the monitor) idle so much waiting for the NEXT vertical blank that it drops from 50 to 30 frames per second. Which is fine if you don't notice this, but if you do, it sucks.

How does this affect Dwarf Fortress? The default framerate for DF is 100 frames per second, much higher than your vertical blank. Dwarf Fortress runs this speed because time is counted in frames, not in real time -- the game does everything it has to internally, and then draws, each frame. If the framerate drops, Dwarf Fortress slows down everything in the game. Feeding a very high framerate to DF keeps your dwarves moving at a brisk pace. Enabling vertical sync forces DF to reduce its framerate to the monitor's, thus preventing the game from updating as much as it'd like to, and forcing it to yield back processor time it would otherwise use for thinking about what to do next. It will indeed reduce your processor load, but it's a pretty good bet that if you enable framerate display in the init file, you'll see that the reason the processor load has dropped is because the framerate is lower now than it was before.

[ October 26, 2007: Message edited by: Jonathan S. Fox ]

Logged

Keiseth

  • Bay Watcher
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #10 on: October 26, 2007, 01:05:00 am »

Wow. Thanks a bunch for all of that information, Jonathan! I never fully knew how VSync worked prior to that.
Logged

Aquillion

  • Bay Watcher
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #11 on: October 26, 2007, 03:20:00 am »

So, um, am I missing something, or should Dwarf Fortress have the option to not try and draw every one of those 100 frames per second (without slowing down the game logic itself), given that there's no way they'll all be displayed anyway?  Or does it just not matter, because the underlying graphics software generally handles it?

[ October 26, 2007: Message edited by: Aquillion ]

Logged
We don't want another cheap fantasy universe, we want a cheap fantasy universe generator. --Toady One

Toady One

  • The Great
    • View Profile
    • http://www.bay12games.com
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #12 on: October 26, 2007, 03:26:00 am »

You can customize the number in the next version, and the ogl bits are decoupled from the game logic.  I set it at 50, because I could tell at lower numbers that it was set at lower numbers.  The game logic itself still runs at 100, since everything is timed for that.  It also lets you set vertical sync from the init.  So you should be able to set the graphical frames number lower if you are having CPU trouble at the title screen or when you are paused for whatever reason.  There's probably more that can be done with the screen updates and when it draws a quad onto one of the page buffers and so on, but I'm not doing more with it for the time being.
Logged
The Toad, a Natural Resource:  Preserve yours today!

Jaqie Fox

  • Bay Watcher
  • Genuine Girl Techie!
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #13 on: October 26, 2007, 11:47:00 am »

*claps excitedly* Thanks so much! I didn't say anything but have been fervently hoping that you would decouple drawing and game logic, and you did one better by allowing it to be configured!

Thanks again!

Logged

isitanos

  • Bay Watcher
  • Seasonal river flood nostalgic
    • View Profile
Re: Almost 100% processor time at main menu [SOLVED]
« Reply #14 on: October 26, 2007, 07:01:00 pm »

Thanks Jonathan for the very interesting explanation. I'll enable the frame rate display and toggle that graphics card setting to see what it does.

And many thanks Toady for the improvement you just made to the game!

Logged
Pages: [1] 2