How to fix fps?
How to fix fps?
Hello, I'm Korean programmer, and I'm very interested in using Irrlicht engine
I'm now making a simple 2D Game with this engine, but I have a question.
My goal is to synchronize multiple clients(users) via game server, so I want to fix every client's fps.
I want to render 60 frame per second, solidly, but I cannot find any information about this.
Does anybody know how to solve this problem?
Please help me!
I'm now making a simple 2D Game with this engine, but I have a question.
My goal is to synchronize multiple clients(users) via game server, so I want to fix every client's fps.
I want to render 60 frame per second, solidly, but I cannot find any information about this.
Does anybody know how to solve this problem?
Please help me!
From Seoul, South Korea
Re: How to fix fps?
In short - don't synchronize screen-updates, it's not a good idea.
Here's a really good article on such stuff: http://gafferongames.com/networking-for ... etworking/
Here's a really good article on such stuff: http://gafferongames.com/networking-for ... etworking/
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to fix fps?
this is how I do it
Code: Select all
#include "mmsystem.h"
#pragma comment(lib, "winmm.lib")
#define REQUIRED_FPS 60
...
...
...
DWORD startRender, renderTime;
DWORD pause=1000/REQUIRED_FPS;
while(device->run())
{
startRender=timeGetTime();
driver->beginScene(true, true, 0, *videodata);
smgr->drawAll();
driver->endScene();
renderTime=timeGetTime()-startRender;
Sleep(renderTime<pause?pause-renderTime:0);
}
...
...
...
Irrlicht's Great, Irrlicht's Good. Irrlicht's better, than a lump of wood.
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: How to fix fps?
Why exactly?
Irrlicht's Great, Irrlicht's Good. Irrlicht's better, than a lump of wood.
Re: How to fix fps?
How so? That's entirely correct and much better than needlessly wasting users' cpu at 100%.
Re: How to fix fps?
A time parameter for a sleep method is a minimal time, which CPU will be waiting, so the waiting time may be similar to a parameter value, but may be be higher too, thats why this function shouldn't be used for methods like this.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: How to fix fps?
That makes absolutely no sense what so ever. I hardly think a few nanoseconds is gonna make much difference.Nadro wrote:A time parameter for a sleep method is a minimal time, which CPU will be waiting, so the waiting time may be similar to a parameter value, but may be be higher too, thats why this function shouldn't be used for methods like this.
Irrlicht's Great, Irrlicht's Good. Irrlicht's better, than a lump of wood.
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: How to fix fps?
So you drive your car with the handbrake on to stay within the speed limits? THAT makes absolutely no sense.
Need more?
rogerborg wrote: I'd strongly recommend not relying on that, for reasons that we've previously discussed in many threads asking why sleep() doesn't give an accurate or consistent framerate.
Using frame delta times and vsync (and/or sleep(0) just for niceness) will give you far better results than trying to achieve any particular frame rate.
hybrid wrote: Better make your program framerate independent, the wait solutions are always approximative, because it won't handle changing system load well, and the usual precision errors will also lead to some differences.
FuzzYspo0N wrote: Use the timer instead of the frames per second, there will never be consistency in frames cos of diversity of hardware, even if you limit it, it can go below 30. Rather use the timer
http://gamedev.stackexchange.com/questi ... on-windowsvitek wrote: The best solution is to write frame rate independent code.
Need more?
"Whoops..."
Re: How to fix fps?
Your quotes are mainly about fps independent code. Of course it's proper practise to code for time and not frames, but it's quite unrelated to wasting power.
Re: How to fix fps?
It really didn't seem to be relevant. Yes, runnable threads are not always on CPU, but this is only if there is a load on the system. Usually games are played as the only app. And if you happen to be calculating a spreadsheet or finding the next Mersenne prime in the background, you expect bad frame rates. I'd use Sleep(1) (we *are* talking about Windows?) until you find a problem and only then try to find an answer.
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: How to fix fps?
hendu wrote:it's quite unrelated to wasting power.
Were do you read wasting power? The thread starter wanted to !synchronize multiple clients!.keynet wrote: My goal is to synchronize multiple clients(users) via game server, so I want to fix every client's fps.
"Whoops..."
Re: How to fix fps?
But Sleep methods in a game loop is worse than a some wasted hardware powerhendu wrote:Your quotes are mainly about fps independent code. Of course it's proper practise to code for time and not frames, but it's quite unrelated to wasting power.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Re: How to fix fps?
I don't get it, why fixing the framerate of the clients would help synchronizing them?. But if you want to fix the frames per second, it is simple, just enable VSync in all the clients, and all will run at 60 FPS, this may prove more or less useful, but irrlicht wise, this is a valid solution, much simpler than idling the engine.
On the field of the client-server applications, on the other hand, synchronizing all the clients so they run all the same at the same time is unnecesary complex. It is much simpler that each client requested the information each time it needed it, and that the server simply fed it. And that the client sent its information to the server as many times as posible, and that the server collected this information as many times as posible, In a rough draft. Minimize the data sent and received per connection, and you could be done. This makes the application free from the time constraints, and the clients will be kept updated more or less well, depending on the quality of their connections.
Just my 2 cents
On the field of the client-server applications, on the other hand, synchronizing all the clients so they run all the same at the same time is unnecesary complex. It is much simpler that each client requested the information each time it needed it, and that the server simply fed it. And that the client sent its information to the server as many times as posible, and that the server collected this information as many times as posible, In a rough draft. Minimize the data sent and received per connection, and you could be done. This makes the application free from the time constraints, and the clients will be kept updated more or less well, depending on the quality of their connections.
Just my 2 cents
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How to fix fps?
Here:Were do you read wasting power?
randomMesh wrote:Sleep in a game loop is just stupid. Don't do it.
I disagree. What if I'm playing on a laptop on battery? Not only do you shorten my play time from 5h to 2h (for example), you're also frying my balls unnecessarilyNadro wrote:But Sleep methods in a game loop is worse than a some wasted hardware power
edit: In a desktop case, if you waste power like that you're also removing that power from your other threads.
The fear about longer blocking due to sleep is unfounded: if the system is busy, that block will happen in some other call anyway, be it a call to a standard library, swapbuffers...
So it's best to sleep the remaining time to not to waste CPU, and if it happens to sleep longer than requested, that "longer" part would have blocked anyway in some other function.