Author Topic: CPU saver plugin  (Read 4985 times)

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
CPU saver plugin
« on: July 10, 2019, 12:44:17 PM »
iL asked me to have a look at this so I made one.

Seems to work ok. My CPU usage shows 0 most of the time.

Have tried it in a couple of games with no lag.

Please test  :)


-- edit --

Have made this 2 plugins. There is 'C' for Channel and 'G' for Game.

You can use either one or both of them. If anyone has problems using this in-game, they can use the 'C' only and give their CPU a rest between games, although I am having no problems using it.

Note: The "Game" starts in the pre-game lobby, everything else is "Channel".



« Last Edit: July 11, 2019, 03:18:11 AM by Lambchops »
its gooder to hax hard and NEVER get caught!

Offline fois

  • Grunt
  • ***
  • Posts: 248
  • Chicken
    • View Profile
Re: CPU saver plugin
« Reply #1 on: July 10, 2019, 05:59:08 PM »
cnc-ddraw can do it as well :)

Not sure how you're doing it, but make sure you take advantage of timeBeginPeriod and timeEndPeriod otherwise a sleep call will take at least 15ms on the default resolution which is dangerously close to the limt. The game runs at 60 fps (giving you only 16.6ms time for a frame), that means there would only be 1.6ms left for the rendering/game logic per frame (Could cause lag in online games on lower end hardware and/or notebooks)

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: CPU saver plugin
« Reply #2 on: July 11, 2019, 12:58:15 AM »
Not sure how you're doing it, but make sure you take advantage of timeBeginPeriod and timeEndPeriod otherwise a sleep call will take at least 15ms on the default resolution which is dangerously close to the limt. The game runs at 60 fps (giving you only 16.6ms time for a frame), that means there would only be 1.6ms left for the rendering/game logic per frame (Could cause lag in online games on lower end hardware and/or notebooks)

I have implimented it to only sleep when the message queue is empty, this mimics the normal windows multitasking behaviour. So when the process is busy it will not sleep at all, so there is no set amount of sleep calls per frame.

timeBeginPeriod and timeEndPeriod are global settings that effect the entire OS and all processes, reducing these on a struggling system would probably decrease performance overall.

So far it appears to be working correctly, although I only spent a couple of hours doing it last night, so please test on any low-end gear you have available and let me know if there are any problems.

its gooder to hax hard and NEVER get caught!

Offline Lambchops

  • Ogre Mage
  • ********
  • Posts: 1541
    • View Profile
Re: CPU saver plugin
« Reply #3 on: July 11, 2019, 03:22:18 AM »
Ok have split this into 2 plugins .... 1 for channel, 1 for game (see top post)

I have also changed it to count the number of triggers before it sleeps.

When I tried 500 ( sleeps 1 time out of 500 ) in-game CPU went up to about 40%, so I set it back at 200 and CPU usage is back at 0. Seems to work well.
its gooder to hax hard and NEVER get caught!

Offline iL

  • Administrator
  • Ogre Mage
  • *****
  • Posts: 1653
    • View Profile
Re: CPU saver plugin
« Reply #4 on: July 11, 2019, 05:40:21 AM »
I have also changed it to count the number of triggers before it sleeps.

When I tried 500 ( sleeps 1 time out of 500 ) in-game CPU went up to about 40%, so I set it back at 200 and CPU usage is back at 0. Seems to work well.
So, can that "magic" numbers depend on the computer performance?
I don't like such way as it should be changed for very new/very old computers as i understand.

Need to test that properly before releasing...
Need help to translate War2Combat to German, French, Italian, Polish or another language: http://forum.war2.ru/index.php/topic,4728.0.html
Please, contact me if you are interested in that.