How to fix fps?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
keynet
Posts: 18
Joined: Wed Jun 27, 2012 9:07 am

How to fix fps?

Post by keynet »

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!
From Seoul, South Korea
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to fix fps?

Post by CuteAlien »

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/
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
MarcusD
Posts: 16
Joined: Sat Nov 27, 2010 12:57 pm
Location: South Yorkshire, UK

Re: How to fix fps?

Post by MarcusD »

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.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: How to fix fps?

Post by randomMesh »

Sleep in a game loop is just stupid. Don't do it.
"Whoops..."
MarcusD
Posts: 16
Joined: Sat Nov 27, 2010 12:57 pm
Location: South Yorkshire, UK

Re: How to fix fps?

Post by MarcusD »

Why exactly?
Irrlicht's Great, Irrlicht's Good. Irrlicht's better, than a lump of wood.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: How to fix fps?

Post by hendu »

How so? That's entirely correct and much better than needlessly wasting users' cpu at 100%.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: How to fix fps?

Post by Nadro »

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
MarcusD
Posts: 16
Joined: Sat Nov 27, 2010 12:57 pm
Location: South Yorkshire, UK

Re: How to fix fps?

Post by MarcusD »

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.
That makes absolutely no sense what so ever. I hardly think a few nanoseconds is gonna make much difference.
Irrlicht's Great, Irrlicht's Good. Irrlicht's better, than a lump of wood.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: How to fix fps?

Post by randomMesh »

So you drive your car with the handbrake on to stay within the speed limits? THAT makes absolutely no sense.
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
vitek wrote: The best solution is to write frame rate independent code.
http://gamedev.stackexchange.com/questi ... on-windows

Need more?
"Whoops..."
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: How to fix fps?

Post by hendu »

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.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: How to fix fps?

Post by mongoose7 »

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.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: How to fix fps?

Post by randomMesh »

hendu wrote:it's quite unrelated to wasting power.
keynet wrote: My goal is to synchronize multiple clients(users) via game server, so I want to fix every client's fps.
Were do you read wasting power? The thread starter wanted to !synchronize multiple clients!.
"Whoops..."
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: How to fix fps?

Post by Nadro »

hendu 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.
But Sleep methods in a game loop is worse than a some wasted hardware power :P
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to fix fps?

Post by Mel »

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
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: How to fix fps?

Post by hendu »

Were do you read wasting power?
Here:
randomMesh wrote:Sleep in a game loop is just stupid. Don't do it.
Nadro wrote:But Sleep methods in a game loop is worse than a some wasted hardware power :P
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 unnecessarily ;)

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.
Post Reply