]> git.mxchange.org Git - flightgear.git/commit
Frederic Bouvier:
authorehofman <ehofman>
Wed, 9 Mar 2005 15:12:01 +0000 (15:12 +0000)
committerehofman <ehofman>
Wed, 9 Mar 2005 15:12:01 +0000 (15:12 +0000)
commitd1168b493ac0b6295d45826c19634c7d784cd728
tree1d9bc71eb8fbab1714329ef3c020859adfbf8be4
parentc1f250fd3340acb6b74603ba71771b441d7e7bb3
Frederic Bouvier:

Norman Vine wrote :

> Frederic Bouvier writes:
>
>> Quoting Andy Ross:
>>> * Hopefully in a CPU-friendly way.  I know that older versions of
>>>  the NVidia drivers did this by spinning in a polling loop
>>>  inside the driver.  I'm not sure if this has been fixed or not.
>>>
>>> From my experience, the latest non-beta Windows NVidia driver seems to eat CPU
>>
>> even with sync to vblank enabled. The CPU usage is always 100%.
>
> Buried in the PPE sources is a 'hackish' but portable way to limit CPU usage if the desired framerate is met
>
>  /*
>    Frame Rate Limiter.
>
>    This prevents any one 3D window from updating faster than
>    about 60Hz.  This saves a ton of CPU time on fast machines.
>
>    ! I THINK I MUNGED THE VALUE FOR ulMilliSecondSleep() NHV !
>  */
>
>  static ulClock *ck = NULL ;
>
>  if ( frame_rate_limiter )
>  {
>     if ( ck == NULL )
>     {
>       ck = new ulClock ;
>       ck -> update () ;
>     }
>
>     int t_ms = (int) ( ck->getDeltaTime() * 1000.0 ) ; /* Convert to ms */
>
>     if ( t_ms < 16 )
>       ulMilliSecondSleep ( 16 - t_ms ) ;
>  }
>
>

I implemented the method pointed out by Norman. It works great on windows and saves me a lot of CPU cycles. This way, I can get the same framerate in moderately populated areas and have CPU idle 50% of the time instead of wildly looping in the NVidia driver while waiting to sync on vblank.

It has been tested on Linux by Melchior. He saw the same gain in CPU cycles.
src/Main/main.cxx