Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Force frames per second?  (Read 3070 times)

0 Members and 1 Guest are viewing this topic.

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Force frames per second?
« on: May 27, 2013, 11:16:37 AM »

Is there a way to force the game to run at 60 frames per second on every PC ? Trying to get a game to work with the same Sleep(); times for different performance PC's. Thanks
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Force frames per second?
« Reply #1 on: May 27, 2013, 12:48:46 PM »

It can be used tricks with Game.CurrentTime instead of Sleep().
On of the examples of using:

Code: WME Script
  1. var CurTime = Game.CurrentTime;
  2. while (something)
  3. {
  4.   if (Game.CurrentTime - CurTime < 16) //if not expired 16 ms (for 60 fps) - do nothing
  5.   {
  6.     Sleep(0);
  7.   }
  8.   else
  9.   {
  10.     CurTime = Game.CurrentTime();
  11.     ...
  12.   }
  13. }

Real time of iteration executing with Sleep() consists of time to run all commands in iteration (that always processor-dependent and different on varrious CPU's) and time of Sleep() (which can be considered as processor-independent). So iteration time with using Sleep() always various and definitely more than time of Sleep().
And in the above example time of iteration always is no less (but may be more), than the necessary 16 ms, so fps will be no more than 60. You can use it in render-specific places and in the main loop if necessary. Thus even game engine will give more than 60 fps, all calculations, inputs, loops etc will work at no more than 60 fps and approximately equal on all systems.

Is there a way to force the game to run at 60 frames per second on every PC ? Trying to get a game to work with the same Sleep(); times for different performance PC's. Thanks
« Last Edit: May 28, 2013, 10:44:35 AM by 2.0 »
Logged

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Force frames per second?
« Reply #2 on: May 27, 2013, 09:45:16 PM »

Thanks 2.0, but I still am a little confused. What I am mainly trying to do is get a certain window update script to always run properly for different platforms. So if the game didnt run all at 60 fps, then it would be ok to just get that window script to do it. Any way you can help me by putting together a quick demo project of what you mean? Thanks so much.
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Force frames per second?
« Reply #3 on: May 28, 2013, 10:43:14 AM »

Frankly speaking, I made an example, but it showed that this method doesn't work :) That is I received absolutely same results as with Sleep() use (also corrected example above).

I can add only that to limit fps on value 60 by means of Sleep (), in loops it is necessary to use a delay not less than 16 ms (Sleep(16)).
Logged
 

Page created in 0.046 seconds with 20 queries.