Jump to content

Maximum FPS


f13rce
 Share

Recommended Posts

Hey lads,

 

I'm making an online shooter, and I've noticed that my game is running about 140-200 FPS.

When the FPS is dropped to 60 because several lightnings and stuff, the game is calculating variables way slower (logical).

 

In an online game (especially a shooter) that might be annoying for people who have a not-so-good PC there. So I'd like to set the maximum FPS to 60.

So my question is; Is there any function in C or on Leadwerks to set the maximum FPS?

 

Thanks, :)

 

Ivar

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Flip(1);

 

 

Flip simply flips the back buffer to the front buffer, effectively drawing all of the frame's updates to the window/screen. It must be included in the program loop every frame.

Flip(0) - Won't use VSync so the framerate won't be limited by the monitor refresh rate. Make sure you use AppSpeed in all of your time dependent values such as movement, and you should use UpdateWorld(AppSpeed()) as well.

Flip(1) - Uses VSync to make sure the buffer is flipped at the same frequency as your monitor's refresh rate.

Flip(-1) - Uncaps the buffer update rate.

 

According to the wiki, Flip(1) just makes it refresh at the rate of the computer screen. What happens when someones monitor refreshes faster than others? And god forbid someone is playing on a 3D capable monitor at 120Hz

 

 

I would personally suggest doing something like this:

int value = 0;

if(value >= AppSpeed()*60) 
{
   //Do Stuff

   value = 0;
}

else value++;

 

AppSpeed checks the refresh rate and returns a normalized value. So if the refresh rate is 120, it will return 0.5 if its 30 it will return 2. When multiplied by a multiple of 60 (one second) you get that many seconds. So if you want a refresh rate of every 2 seconds, do AppSpeed()*120;

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

int value = 0;

if(value >= AppSpeed()*60)
{

 

That's exactly the same as writing

 

 

if(0 >= AppSpeed()*60)
{

 

And that's almost always going to be false. It will only be true when AppSpeed() returns 0 (since 0 * 60 = 0).

 

 

According to the wiki, Flip(1) just makes it refresh at the rate of the computer screen. What happens when someones monitor refreshes faster than others? And god forbid someone is playing on a 3D capable monitor at 120Hz

 

 

AppSpeed checks the refresh rate and returns a normalized value. So if the refresh rate is 120, it will return 0.5 if its 30 it will return 2. When multiplied by a multiple of 60 (one second) you get that many seconds. So if you want a refresh rate of every 2 seconds, do AppSpeed()*120;

 

Apparently my screen refreshes at 600 Hz with a response time of 2 ms. I'm assuming that's a typo on the box, and they've put too many zeroes on, since that's amazingly fast - and 2 ms should equal 500 Hz. Even 500 Hz seems hard to believe though (It's a Samsung SyncMaster T220A)

 

Personally, I do this:

 

//Global space
float RenderGap = 1000.0f/60.0f;
float TimeWaiting = 0.0f;
float LastAppTime;

int main()
{
//Calculate logic etc.
RenderScreen(); //Note, this is not a leadwerks command - it's defined below
}

void RenderScreen()
{
  TimeWaiting += AppTime() - LastAppTime;
  LastAppTime = AppTime();
  if(TimeWaiting >= RenderGap)
  {
     //TimeWaiting = 0.0f;
     TimeWaiting -= RenderGap; //Edit - This line gives better accuracy - but the above line still works...
     //Do lighting, post-processing, etc.
     Flip(0);
  }
  //If it wasn't time to render - this function returns without actually rendering.
}

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

That's exactly the same as writing

 

 

if(0 >= AppSpeed()*60)
{

 

And that's almost always going to be false. It will only be true when AppSpeed() returns 0 (since 0 * 60 = 0).

 

 

 

Thats kinda the point. You want this piece of code to only run once a second, there for running as the same time as all the other copies of the game on other computers. The engine is created so that the AppTime is done at a specific speed across all computers, which is one second per second.

 

My code will increment until reaches the one second mark which will be a result of AppSpeed * 60. Again if your monitor refresh rate is that high, the AppSpeed value is higher until it matches one second.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Without trying to be nasty - why would you only want to do your 'stuff' once per second? I must be missing something.

 

It sounds like, whatever the frame rate, it's going to be jumpy as objects teleport around once per second... Personally I do 'stuff' 50 times per second, and render, ..no faster than.. 60 times per second.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...