f13rce Posted May 20, 2010 Share Posted May 20, 2010 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 Quote 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 More sharing options...
Canardia Posted May 20, 2010 Share Posted May 20, 2010 Flip(1); 1 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
f13rce Posted May 20, 2010 Author Share Posted May 20, 2010 Thanks Lumooja Quote 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 More sharing options...
Shard Posted May 22, 2010 Share Posted May 22, 2010 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; Quote 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 More sharing options...
Mumbles Posted May 24, 2010 Share Posted May 24, 2010 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. } Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
Shard Posted May 25, 2010 Share Posted May 25, 2010 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. Quote 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 More sharing options...
Mumbles Posted May 25, 2010 Share Posted May 25, 2010 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. Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
Recommended Posts
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.